Archived

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

Apouche

Ship rotating in 3D

Recommended Posts

I want my ship to rotate in every angles (yaw pitch roll). I''ve learned it was adviced to use quatenions but I don''t know how to implement them in my case. Is there someone who can explain me?

Share this post


Link to post
Share on other sites
D3DXMatrixRotationYawPitchRoll(&matShip, 1.0f,2.0f,3.0f);

is the C code to create a quaternion rotation by 1 radians yaw 2 radians pitch and 3 radians roll. as you can see, directX 9 makes quaternion rotation VERY easy. All you have to do is set that matrix as the world view to make any 3d object rotate as desired with the command:

g_lpdevice->SetTransform(D3DTS_WORLD, &matShip);

(where g_lpdevice is your aquired device and matShip is a D3DXMATRIX)

anyway read the docs more on those commands, i am sure you can find your answer there.

Brett Lynnes
cheez_keeper@hotmail.com

[edited by - cheez_keeper on May 2, 2003 2:21:12 AM]

Share this post


Link to post
Share on other sites
D3DXMatrixRotationYawPitchRoll hasn’t got anything to do with quaternions, but I don’t think they are the way to go anyway in your case.
Here''s an article that might help, and some code.


  

D3DXMATRIX createWorldMatrix(const D3DXVECTOR3 &pos;, const D3DXVECTOR3 &a, D3DXMATRIX &localFrame)
{
//pos == the ships curent position

//a == the euler angles you want to rotate with this frame

//localFrame == the ships current orientation


D3DXMATRIX rotMat;
D3DXMATRIX transMat;
D3DXMATRIX worldMat;

if (a.x)
{
D3DXMatrixRotationX(&rotMat, a.x);
localFrame=rotMat*localFrame;
}
if (a.y)
{
D3DXMatrixRotationY(&rotMat, a.y);
localFrame=rotMat*localFrame;
}
if (a.z)
{
D3DXMatrixRotationZ(&rotMat, a.z);
localFrame=rotMat*localFrame;
}

D3DXMatrixTranslation(&transMat, pos.x, pos.y, pos.z);
worldMat=localFrame*transMat;
return worldMat;
}



Hope this helped!

PS
Of course it couldn''t hurt to also have a quaternion representation of the orientation since they''re great for other kind of rotations like SLERPing.

Share this post


Link to post
Share on other sites