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?

You are experiencing Gimbal lock. Do a quick search on the net and you should be able to find a couple different ways to handle the rotations differently to deal with this.

Out of curiosity…would replacing the two glRotate*() procedures with glRotatef(90.0f,1.0f,1.0f,0.0f) fix the problem?

Halcyon

Edit: Sorry, forgot to mention that I was reading the Red Book, and it says the glRotate*(…) procedure does a rotation around an arbitrary axis. So, instead of doing two consecutive rotation around two axes, would just having one rotation around one axis (the combination of the other two axes) prevent the gimbal lock? Because if you can specify any axis, it is a lot like what a quaternion does (allow rotation about an arbitraty axis).

[This message has been edited by Halcyon (edited 01-06-2003).]

It seems to me like you don’t understand the opengl local coordinate system. Indeed, if you use glRotate, you will rotate the axes as well. Even the glTranslate will translate the cube in the direction of the new z-axis. So it works differently than the world coordinate transformations that are used in pov-ray, for example. A quick fix here would be to reverse the order of your transformations. When you get the hang of it, you will find out that there are several advantages in the way opengl does it’s transformations.

you idea works perfectly… in theory.
The problem is that the combined axis and the combined angle are very, very difficult to compute.

The best way, in my opinion, to handle combined rotations (and hence the gimbal lock) is as matrices, because it’s very simple to use with opengl (you work directly on the modelview matrix, you do only standard opengl calls like glRotated) but some other people prefer quaternions because they allow for more effective computations.