PDA

View Full Version : how to rotate a object around different axes for many times?

pango
01-06-2003, 05:10 AM
I wrote codes below to rotate a cube aroud x axes first,and then rotate around Y axes:

glPushMatrix();
glRotatef(90.0,0,1,0);
glRotatef(90.0,1,0,0);
glTranslatef(0,0,-5);
DrawCube();
glPopMatrix();

but I fail,after execuete the "glRotatef(90.0,1,0,0);" statement,the Y axes also rotate around x,and then execuete the "glRotatef(90.0,0,1,0);" statement,the cube looks like turn round z axes,so I fail.
anyone can help me?how to rotate a object around different axes for many times?

Deiussum
01-06-2003, 05:44 AM
I think you are probably running into gimbal lock. There are a couple ways around this. One of them is to learn quaternions. Another is to store your own rotation matrix, and as you apply new rotations pre-multiply the new rotation to the current rotation matrix. You'll have to learn a little about matrix math for this. If you look at the back of the red book you can get the formulas for building rotation matrices.

John Jenkins
01-06-2003, 05:55 AM
Good old gimbal lock. It has had me by the balls for quite some time. Let me introduce a new word to your vocabulary, Quaternions. It is an ugly word but a nice rotation. If you lookup trackball.c on google I am sure you can get a sample class that you can use in your program to rotate. One more cool thing, it also allows you to rotate using the mouse.

hirni
01-07-2003, 09:32 AM
Originally posted by John Jenkins:
Good old gimbal lock.

Just curious, what is gimbal lock?