Rotation issue

Started by
0 comments, last by Adam_42 14 years, 8 months ago
Hi everyone... I've seen some posts on this matter, even on gamedev, but none seemed to be able to solve this problem. I have an airplane which has its own up, look and right vectors. In order to make it fly, I perform a pitching rotation first (X-axis) and then, according to the user input I turn it left or right with D3DXMatrixRotationAxis. Then, I transform the up, look and right vectors according to this matrix, like this:

D3DXMatrixIdentity(&pitchMatrix);
D3DXMatrixRotationX(&pitchMatrix, pitchAngle);

D3DXMatrixIdentity(&turnMatrix);
D3DXMatrixRotationAxis(&turnMatrix, yawAngle);

D3DXMatrixIdentity(&this->transformMatrix);
D3DXMatrixMultiply(&this->transformMatrix, &pitchMatrix, &turnMatrix);

this->look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
this->right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
this->up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);

//This is probably a nasty hack to remove translation from the matrix, but I
//don't even think this will ever be used
D3DXMATRIX translationless = this->transformMatrix;
translationless._41 = 0.0f;
translationless._42 = 0.0f;
translationless._43 = 0.0f;
translationless._44 = 1.0f;

D3DXVec3TransformNormal(&this->look, &this->look, &translationless);
D3DXVec3TransformNormal(&this->right, &this->right, &translationless);
D3DXVec3TransformNormal(&this->up, &this->up, &translationless);

D3DXVec3Normalize(&this->look, &this->look);
D3DXVec3Cross(&this->right, &this->up, &this->look);
D3DXVec3Normalize(&this->right, &this->right);
D3DXVec3Cross(&this->up, &this->look, &this->right);
D3DXVec3Normalize(&this->up, &this->up);


The problem here is that after 90 or -90 degrees the airplane just spins out of control, because the up vector seems to be transformed somehow incorrectly... Am I doing something wrong here? I don't think there is a Gimbal lock here, but I may obviously be wrong... Thanks in advance! P.S.: If it helps, I can post a video of what happens in youtube or something...
http://sagito.wordpress.com
Advertisement
It sounds like you've come across Gimbal Lock.

The standard solution is to use quaternions for rotation as described at the bottom of that article.

This topic is closed to new replies.

Advertisement