Archived

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

Naku

Rotation in 3D

Recommended Posts

Naku    151
HI, I have a game that I''m working on where I have a spaceship that I have to rotate in space. Initially while the spaceship is facing forwards along the z-axis the ship moves fine, it will loop and circle around the x and y-axis. The problem comes when I change the direction I''m facing. For example to loop I normally rotate aroung the ship around the x-axis but is the ship turns 90 degrees then tries to loop it rolls. I know I need to rotate the ship about its local coordiates rather than the world coordiates but I''m not quite sure how to do it. I''m using DX8 and D3D. Does anyone have any sugestions. Thanx *Naku

Share this post


Link to post
Share on other sites
johnb    351
Try reversing the order in which you apply the rotations. By this I mean that you are doing two things to the spaceship: ''looping'' around the x axis and ''turning'' to face a particular direction.

You don''t say how you are applying these to the spaceship but one way is using matrices. You create a ''looping'' matrix ''L'' and a ''turning'' matrix ''T'' and apply them to the spaceship.

It sounds like you are applying T then L, turning it then making it loop, but this is giving you unexpected results. To do what you want, have it looping about the same axis even after it has turned, you should apply L then T. This is the usual way of doing rotations in the body frame of reference: do them before the body is rotated into world coordinates.

One way to do this is reverse the order of the matrices when you multiply them, i.e. use T * L instead of L * T. If you don''t want to use matrices you can reverse the order the rotations are done in your code.

Share this post


Link to post
Share on other sites
Naku    151
Thanx,

That''s fixed half of the problem. I can loop when I''m half way through a turn or I can reorder the order I multiply the matricies in to circle while half way through a turn but I really need to be able to do both, any ideas.

I''m using D3DXMatrixRotationX, D3DXMatrixRotationY and D3DXMatrixRotationZ with D3D8DEVICE::MultiplyTransform() to apply the rotation to the object. And storing the ship''s X, Y and Z axis rotation values.

thanx.

*Naku

Share this post


Link to post
Share on other sites