#### Archived

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

# Ship rotating in 3D

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

## 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 on other sites
if you meen in VB, it is:

D3DXMatrixRotationAxis matShip, vec3(1, 1, 1), Angle

##### Share on other sites
No I mean in C++ and using quaternions

##### 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 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 on other sites
Excuse me I was absent few days and thank you for your answers it helped me a lot...

##### Share on other sites
WOW ! 3D SHIP is ROTATING !!!

Seems like cool game. can''t wait to see it

• 23
• 10
• 19
• 15
• 14