I wrote codes below to rotate a cube aroud x axes first,and then rotate around Y axes:
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?
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.
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.
Originally posted by John Jenkins:
Good old gimbal lock.
Just curious, what is gimbal lock?