# Yaw - Pitch - Roll problem

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

## Recommended Posts

I'm trying to make a small game, where the user controls an airplane through yaw, pitch and roll.The angles are updated whenever the player presses the keys.I use the following code to compute the transformation matrix, but it does not work correctly. Can somebody please tell me what do I do wrong here, or how to do this correctly.Thank you. ... Translation = TranslationMatrix(translation_x,translation_y,translation_z); PitchRotation = IdentityMatrix(); RollRotation = IdentityMatrix(); YawRotation = IdentityMatrix(); YawRotation = RotationAroundAxis(Center,YawAxis,YawAngle); PitchAxis = Transform(PitchAxis,YawRotation); RollAxis = Transform(RollAxis,YawRotation); PitchRotation = RotationAroundAxis(Center,PitchAxis,PitchAngle); RollAxis = Transform(RollAxis,PitchRotation); YawAxis = Transform(YawAxis,PitchRotation); RollRotation = RotationAroundAxis(Center,RollAxis,RollAngle); PitchAxis = Transform(PitchAxis,RollRotation); YawAxis = Transform(YawAxis,RollRotation); Result = ScaleMatrix; Result = Multiply(Result,YawRotation); Result = Multiply(Result,PitchRotation); Result = Multiply(Result,RollRotation); Result = Multiply(Result,Translation); ... D3DDevice->SetTransform(D3DTS_WORLD,&Result); ... Where : Center.x = 0.0f; Center.y = 0.0f; Center.z = 0.0f; PitchAxis.x = 1.0f; PitchAxis.y = 0.0f; PitchAxis.z = 0.0f; RollAxis.x = 0.0f; RollAxis.y = 0.0f; RollAxis.z = 1.0f; YawAxis.x = 0.0f; YawAxis.y = 1.0f; YawAxis.z = 0.0f;

##### Share on other sites
You can simplify your procedure and still get the results you want.

Try something like this:

mat = IdentityMatrix()
...
Pitch=Yaw=Roll=0
keyboard input(Pitch,Yaw,Roll)
...
Transform(mat, Pitch,Yaw,Roll)
SetTransform(WORLD,&mat)

Transform(mat a, float Pitch, float Yaw, float Roll){	float t00,t01,t02,t10,t11,t12,t20,t21,t22,ct,st;	ct = cos(Pitch); st = sin(Pitch);	t10 = ct*a[1][0] - st*a[2][0];	t11 = ct*a[1][1] - st*a[2][1];	t12 = ct*a[1][2] - st*a[2][2];	t20 = st*a[1][0] + ct*a[2][0];	t21 = st*a[1][1] + ct*a[2][1];	t22 = st*a[1][2] + ct*a[2][2];	a[1][0] = t10;	a[1][1] = t11;	a[1][2] = t12;	a[2][0] = t20;	a[2][1] = t21;	a[2][2] = t22;	ct = cos(Yaw); st = sin(Yaw);	t00 = ct*a[0][0] - st*a[2][0];	t01 = ct*a[0][1] - st*a[2][1];	t02 = ct*a[0][2] - st*a[2][2];	t20 = st*a[0][0] + ct*a[2][0];	t21 = st*a[0][1] + ct*a[2][1];	t22 = st*a[0][2] + ct*a[2][2];	a[0][0] = t00;	a[0][1] = t01;	a[0][2] = t02;	a[2][0] = t20;	a[2][1] = t21;	a[2][2] = t22;	ct = cos(Roll); st = sin(Roll);	t00 = ct*a[0][0] - st*a[1][0];	t01 = ct*a[0][1] - st*a[1][1];	t02 = ct*a[0][2] - st*a[1][2];	t10 = st*a[0][0] + ct*a[1][0];	t11 = st*a[0][1] + ct*a[1][1];	t12 = st*a[0][2] + ct*a[1][2];	a[0][0] = t00;	a[0][1] = t01;	a[0][2] = t02;	a[1][0] = t10;	a[1][1] = t11;	a[1][2] = t12;}

Translation can be done with a simple offset for each vert/object.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634067
• Total Posts
3015321
×