Jump to content
  • Advertisement

Archived

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

Barn Door

Avoiding Gimbal Lock with Quaternions

This topic is 5900 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

Hello, Can anybody explain why this code doesn't fix gimbal lock? The principle, I think, is that you maintain a quaternion which holds the current orientation of the object you are trying to spin and then multiply it by a change in orientation before converting to a matrix. (x_rot and z_rot are set in the keyboard handler to a constant and currOrientation is a global quaternion initialized to the identity) Am I close?
    
//initialize matrices

D3DXMatrixIdentity(&rotation);
D3DXMatrixIdentity(&translation);
D3DXMatrixIdentity(&world);

// create quaternion to represent change in orientation

D3DXQUATERNION change;
D3DXQuaternionRotationYawPitchRoll(&change, 0.0f, x_rot, z_rot);

x_rot = z_rot = 0;

//update current orientation

currOrientation*= change;

//change it to a matrix

D3DXMatrixRotationQuaternion(&rotation, &currOrientation);

// add to translation and set

D3DXMatrixTranslation(&translation, 0.0, 0.0f, 5.0);
D3DXMatrixMultiply(&world, &rotation, &translation);

g_d3d_device->SetTransform(D3DTS_WORLD, &world );
     
Thanks, BD. [edited by - Barn Door on July 28, 2002 3:44:48 PM] [edited by - Barn Door on July 28, 2002 3:46:51 PM]

Share this post


Link to post
Share on other sites
Advertisement

  • 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!