Archived

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

rotation around 3 axes

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

Recommended Posts

What i am trying to do is this. I have a flying saucer that i have aligned to the angle of the terrain directly below it. This i have done using rotations around the x and z axes. This works fine. D3DXMatrixTranslation(&matWorld, vLoc.x, vLoc.y, vLoc.z); D3DXMatrixRotationY( &matRotateY, -vR.x ); D3DXMatrixRotationX( &matRotateX, -vR.y ); D3DXMatrixRotationZ( &matRotateZ, -vR.z ); D3DXMatrixMultiply( &matTemp, &matRotateZ, &matRotateY ); D3DXMatrixMultiply( &matTemp, &matRotateX, &matTemp ); D3DXMatrixMultiply( &matWorld, &matTemp, &matWorld ); matLocal = matWorld; The trouble is, when I spin around the y axis also (to spin the saucer), it looks like a coin spinning on a table. How do I get out of this???? Any pointers?? TIA

Share on other sites
Well I''m an OpenGL user, so I don''t really know what those D3DX functions do, but it seems to mee that you are experiencing gimbal lock. Two solutions spring to mind:

1) Don''t build the matrix based on the current angles and position. Keep a copy of the saucer''s rotation matrix with the saucer itself. Then each frame, base a matrix on the CHANGE of the angles in respect to last frame, instead of the absolute angles. Then multiply the current matrix by the new one and save it to your saucer. Then add the position to this matrix and sent it to D3D.

2) Use quaternions and build the matrix from that. This is the preferable method, but it takes a lot more explaining. I suggest you check the articles section and search for quaternions.

Hope that helped.

Share on other sites
Thanks, I''ll try Quarternions

Share on other sites
Would it work to just spin the saucer around the y axis _before_ rotating around the x and z axes, instead of after?

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631766
• Total Posts
3002218
×