#### Archived

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

# Quaternion switching axis? problems with rotations

This topic is 5420 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have 2 solutions to fixing my gimbal lock, unfortunately neither work and ill explain after each code paste: D3DXMATRIX matWorld,matRotation,matTranslation,matScale,matView; D3DXMatrixIdentity( &matTranslation ); D3DXMatrixScaling( &matScale, sx, sy, sz ); D3DXQUATERNION qR; D3DXVECTOR3 vPosition; vPosition.x = 0; vPosition.y = 0; vPosition.z = 0; D3DXQuaternionRotationYawPitchRoll(&qR, ry/RADIAN_TO_DEGREES,rx/RADIAN_TO_DEGREES,rz/RADIAN_TO_DEGREES); D3DXMatrixAffineTransformation(&matRotation, 1.00f, NULL, &qR, &vPosition); D3DXMatrixInverse(&matRotation, NULL, &matRotation); D3DXMatrixMultiply(&matTranslation,&matRotation, &matTranslation); D3DXMatrixMultiply(&matTranslation, &matScale, &matTranslation); ----------------------------------------------------------------- this gives me a problem with the axis, when I lift the plain up(tail down) the object rotates correct, yet if I rotate the plane to bank left, and then put the tail down(towards back Z) in order to rotate in a circle it rotates the entire plan still on the Y axis so it yaws up and down. yet the world positions r still correct, the plane is MOVING in the correct circle, yet the plane''s actual rotation is screwed up. Being the physics r correct. ----------------------------------------------------------------- D3DXMATRIX matWorld,matRotation,matTranslation,matScale,matView; D3DXMatrixIdentity( &matTranslation ); D3DXMatrixScaling( &matScale, sx, sy, sz ); D3DXQUATERNION qR; D3DXVECTOR3 vAxis; vAxis.x = 1.0f; vAxis.y = 0.0f; vAxis.z = 0.0f; D3DXQuaternionRotationAxis( &qR, &vAxis, rx/RADIAN_TO_DEGREES ); D3DXMatrixRotationQuaternion( &matRotation, &qR ); D3DXMatrixMultiply( &matTranslation, &matRotation , &matTranslation ); vAxis.x = 0.0f; vAxis.y = 1.0f; vAxis.z = 0.0f; D3DXQuaternionRotationAxis( &qR, &vAxis, ry/RADIAN_TO_DEGREES ); D3DXMatrixRotationQuaternion( &matRotation, &qR ); D3DXMatrixMultiply( &matTranslation, &matRotation , &matTranslation ); vAxis.x = 0.0f; vAxis.y = 0.0f; vAxis.z = 1.0f; D3DXQuaternionRotationAxis( &qR, &vAxis, rz/RADIAN_TO_DEGREES ); D3DXMatrixRotationQuaternion( &matRotation, &qR ); D3DXMatrixMultiply( &matTranslation, &matRotation , &matTranslation ); D3DXMatrixMultiply(&matTranslation, &matScale, &matTranslation); ----------------------------------------------------------------- This solution, while the other problem does not occur, gives me the exact same gimbal lock that was occuring with my original use of non quaternions. Basically same outcome of not useing quaternions at all.... Any ideas would be awesome, thanks much.

##### Share on other sites
Any ideas fellas? Also on the first example,

When I do a loop in a circle AROUND the Xaxis(updown or pitch roll) everything works correctly, when I then try to circle AROUND the Yaxis(bank left then pitch my tail down or away in Z+) it pitches my plane object UPDOWN as if it thinks it is still rotating about the same axis... strange, so I think my axis r staying, maybe I need to change the axis somehow? thanks again, any replys would be great. Even if just ideas.

##### Share on other sites
What you need to do is transform the vector containing the velocity of the camera before you add it to the current position vector. Use the D3DXVec3TransformNormal() function. For a great example of how to do it step-by-step, look at the UpdateCamera() function in the Cull example that is included in the SDK

Dustin Franklin
Mircrosoft DirectX MVP

[edited by - circlesoft on February 8, 2004 10:06:31 PM]

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633678
• Total Posts
3013292
×