Advertisement Jump to content
Sign in to follow this  
allecsro

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.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!