gimbal lock? quaternions? complex numbers?
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.
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.
Edit: Also, Daerax, a member here of GameDev.net, recently posted a huge journal entry on quaternions which you can view here.
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).
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
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement