Jump to content
  • Advertisement

Archived

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

nitzan

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


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

Share this post


Link to post
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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!