i expose my problem! I'm rotate the cube recalculating the individual coordinates of each vertex at each rotation and I must say I'm getting excellent results. If the cube rotates along a single axis everything to perfection, however, rotates along two or three axes vertices ranging widening causing the cube after a bit of time has stratospheric size. Below is the code for the rotation, behind which I think is hiding problem. The multiplication of the components of the individual vertices for the respective row of the rotation matrix make the vertex detached from its trajectory, but I do not understand why.
//for each cube
for(contatoreOnDraw=0;contatoreOnDraw<numberOfCube;contatoreOnDraw++)
{
x=contatoreOnDraw*3;
y=(contatoreOnDraw*3)+1;
z=(contatoreOnDraw*3)+2;
gl.glPushMatrix();
gl.glTranslatef(translation[row][x], translation[row][y], translation[row][z]);
float angle=2;
//Rotation matrix 3x3
c =(float) Math.cos(angle*(Math.PI/180));
s =(float) Math.sin(angle*(Math.PI/180));
rotation[0][0] = (rX*rX*(1-c)) + c;
rotation[0][1] = (rX*rY*(1-c))-rZ*s;
rotation[0][2] = (rX*rZ*(1-c))+rY*s;
rotation[1][0] = (rY*rX*(1-c))+rZ*s;
rotation[1][1] = (rY*rY*(1-c)) + c;
rotation[1][2] = (rY*rZ*(1-c))-rX*s;
rotation[2][0] = (rX*rZ*(1-c))-rY*s;
rotation[2][1] = (rY*rZ*(1-c))+rX*s;
rotation[2][2] = (rZ*rZ*(1-c)) + c;
//Updating each vertex component
for(int i=0;i<70;i=i+3)
{
vX_tmp=(rotation[0][0]*cubes[contatoreOnDraw].getVertices(i))+(rotation[0][1]*cubes[contatoreOnDraw].getVertices(i+1))+(rotation[0][2]*cubes[contatoreOnDraw].getVertices(i+2));
vY_tmp=(rotation[1][0]*cubes[contatoreOnDraw].getVertices(i))+(rotation[1][1]*cubes[contatoreOnDraw].getVertices(i+1))+(rotation[1][2]*cubes[contatoreOnDraw].getVertices(i+2));
vZ_tmp=(rotation[2][0]*cubes[contatoreOnDraw].getVertices(i))+(rotation[2][1]*cubes[contatoreOnDraw].getVertices(i+1))+(rotation[2][2]*cubes[contatoreOnDraw].getVertices(i+2));
cubes[contatoreOnDraw].setVertices(i, vX_tmp);
cubes[contatoreOnDraw].setVertices(i+1, vY_tmp);
cubes[contatoreOnDraw].setVertices(i+2, vZ_tmp);
}
cubes[contatoreOnDraw].draw(gl);
gl.glPopMatrix();
}
Thanks to all!!
glRotate
functions? – vallentin