Archived

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

ipso

rotation around 3 axes

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 this post


Link to post
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 this post


Link to post
Share on other sites