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

Barn Door

Avoiding Gimbal Lock with Quaternions

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