3D Rotation around Local Axes

Background: I have been working on the problem of 3D object rotation around its local axes, using OpenGL. After having extensively searched on different forums for a mathematical model for updating the axes as x/y/z rotations happen, I found this to be the most helpful resource.

http://nehe.gamedev.net/article/camera_class_tutorial/18010/

The Problem: I am currently stumbling upon a rather trivial issue. An example from the resource mentioned above does a 45 degree rotation around y-axis; hence x- and z-axes need to be updated. The new x-axis is calculate as (0.707, 0, 0.707), which makes sense. The z-axis is (-0.707, 0, 0.707), which is also intuitive. The corresponding gl commands are:

glRotatef(x_rot, 0.707, 0, 0.707);
glRotatef(y_rot, 0, 1, 0);
glRotatef(z_rot, -0.707, 0, 0.707);

Now I am rotating first around y-axis by 45 degrees. After that the x-rotation looks good. It is around the updated (local) axis, as intended.

Then, I remove x-rotation; but when I apply z-rotation it does not look right. It is not rotating along the local z-axis. The axis looks correct mathematically, but I am not sure what could be going wrong graphically.

EDIT:

The example is around the middle of that page.

链接地址: http://www.djcxy.com/p/81840.html

上一篇: 如何在OpenGL中渲染具有不同颜色的边的立方体?

下一篇: 围绕局部轴的3D旋转