Jump to content
  • Advertisement


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

Barn Door

Avoiding Gimbal Lock with Quaternions

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


// create quaternion to represent change in orientation

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

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!