Hi,
my problem is this:
I am creating 5 cubes (like the 5-th side of a dice),with GL_QUADS, 6 faces. They rotate about themselves on all 3 axis. The code looks like this:
//angle changes constantly,resets to 0 once >= 360
//center cube
glPushMatrix();
glRotatef(angle, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
glRotatef(angle, 0, 0, 1);
drawCube(0, 0, 0);
glPopMatrix();
//lower left cube
glPushMatrix();
glTranslatef(-8, -8, 0);
glRotatef(angle, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
glRotatef(angle, 0, 0, 1);
drawCube(0, 0, 0);
glPopMatrix();
//lower right cube
glPushMatrix();
glTranslatef(8, -8, 0);
glRotatef(angle, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
glRotatef(angle, 0, 0, 1);
drawCube(0, 0, 0);
glPopMatrix();
//upper right cube
glPushMatrix();
glTranslatef(8, 8, 0);
glRotatef(angle, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
glRotatef(angle, 0, 0, 1);
drawCube(0, 0, 0);
glPopMatrix();
//upper left cube
glPushMatrix();
glTranslatef(-8, 8, 0);
glRotatef(angle, 1, 0, 0);
glRotatef(angle, 0, 1, 0);
glRotatef(angle, 0, 0, 1);
drawCube(0, 0, 0);
glPopMatrix();
//and drawCube looks like this:
void drawCube(float x, float y, float z)
{
glPushMatrix();
glTranslatef(x, y, z);
glBegin(GL_QUADS);
//draw faces.....
glEnd();
glPopMatrix();
}
Now along with these rotations I would like to have the corner cubes, in pairs, make an X-like motion along the center cuber. That is the lower left rotate along the center cube like a moon, and the upper right move in the same axis (Rotate along the diagonal). I’d like the same for the upper left and lower right cubes only move along their diagonal. How shoud I rotate my cubes? If I add another rotation for, say, the lower left cube, the rotation has undesired effects and not the effect I want.
P.S. Do you know any good tutorials for explaining rotations and translations in depth?