Rotations

Hi everyone. I am trying to rotate an object around its local axes. With the following code, I can get it to rotate around its local x axis, but it rotates around the world y and z axes.

glTranslatef(0.0f, 0.0f, trans);
glRotatef(rotz, 0.0f, 0.0f, 1.0f);
glRotatef(roty, 0.0f, 1.0f, 0.0f);
glRotatef(rotx, 1.0f, 0.0f, 0.0f);

glBegin( GL_TRIANGLES );
glColor4f( 1.0f, 1.0f, 1.0f, 0.5f ); glVertex3f( 0.0f, 0.0f, 0.87f );
glVertex3f( -0.57f, 0.0f, -0.87f );
glVertex3f( 0.57f, 0.0f, -0.87f );
glEnd();

I tried to switch the order of the rotate functions, but the last one called would be the axes that was rotated around correctly. If anyone knows what I am doing wrong, or what I should do instead, please explain.

Thanks.

try incrementing the angles after glEnd()->

eg rotz+=2.0;

this would rotate the object around at a continous 2 degree angle.

also, try taking the ‘f’ out from after the points .I don’t think you need it when you put the ‘f’ after the function name. I’m not sure about this but it works for me.

good luck.

You may want to look at this:
http://www.3dgamedev.com/articles/eulers_are_evil.htm

If you need more help let me know (I think that I just recently experienced your problem).

Hi Scott!

If you want to rotate the object around its local axes the translate command shoud not be the first command, because it translates the object into world space. Remember that the order of the matrix operations is important (not only rotations, also translations).

Try to but the translate command AFTER your rotations (the order of those define the dehavior too).

Hope that helped!

Kind regards,

LG

(And may the vector be with you!)