PDA

View Full Version : Rotation order



HenriH
08-27-2008, 09:54 PM
I want to verify one thing:

Lets say I want to rotate an object (in this order) 30 degrees around the Y-axis, 20 degrees around the X-axis and finally 10 degrees around the Z-axis, what is the correct order of applying the rotation matrices in OpenGL?

Is it Z*X*Y, like this:

glRotatef (10.0f, 0.0f, 0.0f, 1.0f);
glRotatef (20.0f, 1.0f, 0.0f, 0.0f);
glRotatef (30.0f, 0.0f, 1.0f, 0.0f);

or Y*X*Z, such as:

glRotatef (30.0f, 0.0f, 1.0f, 0.0f);
glRotatef (20.0f, 1.0f, 0.0f, 0.0f);
glRotatef (10.0f, 0.0f, 0.0f, 1.0f);

Thanks.

dletozeun
09-02-2008, 10:12 AM
Is it Z*X*Y, like this:

glRotatef (10.0f, 0.0f, 0.0f, 1.0f);
glRotatef (20.0f, 1.0f, 0.0f, 0.0f);
glRotatef (30.0f, 0.0f, 1.0f, 0.0f);


This one is correct as you need to set transformations in the reverse order.

David Doria
09-07-2008, 06:38 AM
I don't know what you are doing exactly, but you should probably never think of rotation as those three independent rotations. glRotatef is expecting axis-angle form of the roation

http://en.wikipedia.org/wiki/Rotation_representation_(mathematics)

of course you can break it down into the three rotations around the x, y, and axis (that is Euler's rotation theorem) but then you have to keep track of the order and that'll get super annoying (as you already see!)

Good luck.
Dave