I calculate my coordinates when i create a layer with a std::vector
, filled with cube
objects(wich is a class of mine):
for(int J = 0; J < mapSize; J++)
{
for(int I = 0; I < mapSize; I++)
{
x = (J - I) * (cubeSize/2);
y = (J + I) * (cubeSize/4);
c = new cube(cubeSize, x, y, z, I, J);
cs.push_back(*c);
}
}
I wanna do this : cs[getCubeByID(mouseX, mouseY)].setTexture(...);
Example of use: The cube in I-J [0, 0]
have the number 0
in the cubes array. if i click on 0,0
i got this number.
EDIT: We gave me the formula to get a J or a I with a pair of x,y in the comments, thanks a lot. I only need to convert this pair of I-J to the entry number of my array like the example i gave.
I tried : int entry = (J - 1) * size + (I - 1);
and the selected cube is not so far from the one i want but still not the right formula. Modular arithmetic can fix my problem but i don't understand how it's working.