# Rotate?

How can I rotate an object around an
axis while preventing the axis rotating?

I draw the axis and the object, and
when I try to JUST rotate the object,
I find that the axis rotates also.

Thanks a lot!

glPushMatrix/glPopMatrix may help.

You’re talking about when you’re using the glRotate function right? I ran into this problem also. I managed to work around this using my own matrix and rotation code. I just pass it the local vertices of the object I want rotated. Though I would like to know how to rotate a singe object using OpenGL also.

As RandyU said, you can use glPushMatrix, glPopMatrix. you use it something like so.

for each object
{
glPushMatrix();
ObjectTransformations();
DrawObject();
glPopMatrix();
}

To rotate an object around x,y,z:

Around x
y’ = y * Cos(angx) - z * Sin(angx);
z’ = y * Sin(angx) + z * Cos(angx);

Around y
x’ = x * Cos(angy) + z * Sin(angy);
z’ = -x * Sin(angy) + z * Cos(angy);

Around z
x’ = x * Cos(angz) - y * Sin(angz);
y’ = x * Sin(angz) + y * Cos(angz);

If you are drawing the axis and jsut want to watch an object roate around it (I think this is what you want) put your code to draw the axis before you use the glRotatef() function.