gimbal lock? quaternions? complex numbers?

Started by
5 comments, last by JohnBolton 18 years, 5 months ago
Hi! I decided, two weeks ago, to create a simple 3D game using D3D. Everything was going well until I had to rotate (drag) this object using the mouse. I tried this using the D3DXMatrixRotation function, but the result was, I found later, a gimbal lock... I searched everywhere (including gamedev articles) for a nice tutorial about quaternions, but they're all very mathematical or oriented to OpenGL... The DirectX SDK's explanation is very abstract and the samples are just too complicated for my actual directx/math knowledge... I don't want the all code (I'm also avoiding to use d3dutil functions), but an example would be nice - maybe a tutorial... Please, forgive my terrible english. Thanks in advance.
Advertisement
Sorry I can't offer more help, but this is a decent explanation of quaternions. Wikipedia actually has an article on using quaternions for rotations here, but it's overly technical so you probably won't find it as much help, but it can't hurt giving it a look.

Edit: Also, Daerax, a member here of GameDev.net, recently posted a huge journal entry on quaternions which you can view here.
I will read it right now. Thanks for your quick answer, nilkn.
Which D3DXMatrixRotation function did you use? What caused the gimbal lock? Simply inserting quaternions into your code won't magically cure gimbal lock (since using a matrix also prevents gimbal lock and you are already using one).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
if you only use two dimensions to rotate around you dont get the gimbal lock do you?
Hi again!
I'm really sorry to bother you people again but I just can't solve this rotation problem... I will try to explain better this time:

The code I have is:

void Object::MouseMove(long lMouseXPos, long lMouseYPos, long lMouseOldXPos, long lMouseOldYPos)
{
if (m_bRotating)
{
m_fYRot -= (float) (lMouseXPos - lMouseOldXPos) / 100.0f;
m_fXRot -= (float) (lMouseYPos - lMouseOldYPos) / 100.0f;
D3DXMatrixRotationYawPitchRoll(&m_matObject, m_fYRot, m_fXRot, m_fZRot);
m_lpDevice->SetTransform(D3DTS_WORLD, &m_matObject);
Render();
}
...
}

Mouse left and right for Yaw rotation... Up and Down for Pitch rotation...

When the Yaw rotation is 0.0f, the Pitch rotates the direction I want...
The problem is that when the Yaw rotation is equal to 3.14f, and I drag the mouse down, the Pitch rotation inverts... Is this a math problem? If so, please elucidate me...

Thanks again
That behavior may be correct(your description is a little ambiguous). Think of it this way: Your friend is facing you. He pitches his head in a positive direction and his face points up (for example). Then he turns around facing away from you and pitches his head again in a positive direction. Again, his face will point up, but the back of his head (which is what you see) points down. Is that what is happening?
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement