I have read 3DS models into the OpenGL, and I can rotate them around the Z axis. But I don’t know how to make them rotate around the other two axises:X, Y?

Is there anyone can help me? Please tell me! Thanks a lot!

Huh ? That is very trivial OpenGL, nothing to do with algorithms.

From the spec :

void glRotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z);

produces a rotation of angle degrees around the vector (x y z).

So for z axis you have :

glRotated(alpha,0,0,1);

for y axis you have :

glRotated(alpha,0,1,0);

other weird angle :

glRotated(alpha,0,sqrt(2)/2,sqrt(2)/2);

see http://pyopengl.sourceforge.net/documentation/manual/glRotate.3G.html

EDIT: and you even don’t have to normalize the vector your rotate around.

But I found the 3DS models are different from the models built by OpenGL, so I can not only simply use the “glRotatef” to control models to rotate.

So is there any other method to solve the problem?

Whell, i had that problem the other day, when i was trying to rotate some models in my own editor.

At the end I used the technique called Compose Affine Transformations(a foolish name, it´s obvious).

You have to get a matrix. This matrix is

“Translate” * Rotate * Translate

“Translate” =

|1 0 0 -x|

|0 1 0 -y|

|0 0 1 -z|

|0 0 0 1|

Rotate is the matrix that containts the axis to rotate,

Translate =

|1 0 0 x|

|0 1 0 y|

|0 0 1 z|

|0 0 0 1|

For more information:

“Computer Graphics Using opengl” i have second edition but i believe that there´s a third.

In the second is the chapter five.

glTranslate and glRotate do exactly what José is talking about. If you have a model that is being drawn with OpenGL, unless it is doing very odd things, glRotate and glTranslate will work. What library are you using to load this 3DS model?

I defined myself interface to load 3DS, and didn’t use other library.

Now I have another problem: how to set the up-direction of the camera?Is there any reference I can refer to?Please help me!

Thanks!