I am making a rubix cube game in OpenGL and I have run into a problem with rotations. When doing multiple rotations (x, y, z) the axis gets rotated as well (ie when doing an x-axis rotation of 90 or 270 deg the y-axis becomes the z-axis and z-axis becomes the y-axis).
Is there any way to stop the axis from rotating but allowing the object to translate or is there a trick to get around this.
Here is a small part of my code for the translations.
glPushMatrix();
glRotatef(xrot, 1.0, 0.0, 0.0); //rotates the unit cube into place
glRotatef(yrot, 0.0, 1.0, 0.0);
glRotatef(zrot, 0.0, 0.0, 1.0);
glTranslatef(xoff, yoff, zoff); //translates the unit cube into place
glRotatef(xrotset, 1.0, 0.0, 0.0); //rotates the unit cube in its place
glRotatef(yrotset, 0.0, 1.0, 0.0);
glRotatef(zrotset, 0.0, 0.0, 1.0);
glBegin(GL_QUADS); //draws the cube
for( int i = 0; i < unitIndices.size(); i++ )
{
GLint *curIndices;
curIndices = unitIndices[i].getVals();
glColor3fv(unitColors[i].getVals());
glNormal3fv(unitNorms[i].getVals());
glVertex3fv(unitVerts[curIndices[0]].getVals());
glVertex3fv(unitVerts[curIndices[1]].getVals());
glVertex3fv(unitVerts[curIndices[2]].getVals());
glVertex3fv(unitVerts[curIndices[3]].getVals());
}
glEnd();
glPopMatrix();
This is just how I have the drawing for each unit cube 27 of these make up the "rubix cube". The problem lies in the xrot, yrot and zrot lines.
Thanks.