View Full Version : Rotations

04-21-2000, 07:36 AM
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 );

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.


05-07-2000, 11:44 PM
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.

05-08-2000, 11:00 AM
You may want to look at this:

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

05-09-2000, 11:59 AM
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 http://www.opengl.org/discussion_boards/ubb/biggrin.gif

(And may the vector be with you!)