#### Archived

This topic is now archived and is closed to further replies.

# rotation question

This topic is 5779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I rotate a cube like this: 1) glRotatef( 0, 1.0f, 0.0f, 0.0f); glRotatef(45, 0.0f, 1.0f, 0.0f); glRotatef(45, 0.0f, 0.0f, 1.0f); drawCube() it draws differently from this: 2) glRotatef(45, 0.0f, 0.0f, 1.0f); glRotatef(45, 0.0f, 1.0f, 0.0f); glRotatef( 0, 1.0f, 0.0f, 0.0f); drawCube() or this: 3) glRotatef(45, 0.0f, 0.0f, 1.0f); glRotatef( 0, 1.0f, 0.0f, 0.0f); glRotatef(45, 0.0f, 1.0f, 0.0f); drawCube() Why does this happen ? 2 and 3 draws the same rotated cube, but in 1 its not rotated quite the same. Is this Gimbal Lock ? I implemented quaternions and it also drew it like in numbers 2 and 3. Any help would be appreciated. Nitzan ------------------------- www.geocities.com/nitzanw www.scorchedearth3d.net -------------------------

##### Share on other sites
Rotation is not commutative. Think about it: if you rotate a body around the x-axis, it''s already changed its poisition on the x-axist. The results of now rotating it around the z-axis doesn''t logically place the body in the same position as first rotating it around z-axis and then around the x-axis. It''s a simple think-about-it-yourself question.

Hope this helps,
Crispy

##### Share on other sites
You''re multiplying matrices when you call glRotate, glTranslate, glScale. Matrix multiplication is not commutative.

##### Share on other sites
Also, if You are familiar with matrices, You know, that matrix of rotation (f-angle) around say z axis is:

   cos(f) sin(f) 0-sin(f) cos(f) 0 0      0      1

(It will be different for other 2 axes)
Now performing several rotation is the same as multiplying corresponding matrices - but matrix multiplication is not commutative => result will be different!
If You are unfamiliar with matrices, then just take thick book, and try to rotate it around axis passing the walls of your room You''ll notice the difference

##### Share on other sites
Wow xgOblin! You were definitely faster than me

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632960
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×