# Rotation Question

## Recommended Posts

ok so i have a 3D object... and it's rotated Yaw, Pitch, Roll arbitrary amount yaw, pitch, roll what i want it to do is that if, say it's already rolls +15 degrees and i want to yaw or pitch the thing after that... like an airplane... im pretty sure that this has been discussed somewhere on gamedev, but i cant find one that i understand... im VERY lacking in trig/Matrix/vector math thank you

#### Share this post

##### Share on other sites
I gather you want all rotations to be about the object's local axes rather than the world axes, correct?

If so, you'll have to ditch Euler angles (at least as you're using them currently) and instead maintain your object's orientation from frame to frame (most likely in matrix or quaternion form). You then update the orientation incrementally by applying relative rotations about the object's local axes.

This does require some knowledge of 3D math, and/or a math library that can perform these functions for you. If you get stuck or need additional help, I can point you to some source code that might be of use to you.

#### Share this post

##### Share on other sites
right, i understand what you're saying, but i dont know how to do it...

so i have the Starting matrix (Matrix.Zero?) and I add a Matrix.RotationYawPitchRoll to it? or do i completely forget about yawpitchroll...

I get the concept, i just dont actually know how to do it...

#### Share this post

##### Share on other sites
Quote:
 Original post by perkbrianright, i understand what you're saying, but i dont know how to do it...so i have the Starting matrix (Matrix.Zero?) and I add a Matrix.RotationYawPitchRoll to it? or do i completely forget about yawpitchroll...I get the concept, i just dont actually know how to do it...
Your starting matrix can be any orientation (although identity is often a sensible choice). From there, you update the orientation incrementally each frame or 'tick' using small (generally speaking) rotations about the object's local axes.

Note that concatenating rotations in matrix or quaternion form does not involve addition, but rather multiplication.

You can use your RotationYawPitchRoll() function, but the rotation needs to be applied locally, not globally. Based on your mention of this function I'm going to venture a guess that you're using row-vector notation. With this notational convention, the 'delta' rotation should go on the left, e.g.:
Matrix44 delta;delta.RotationYawPitchRoll(yaw * dt, pitch * dt, roll * dt);my_orientation = delta * my_orientation;my_orientation.orthogonalize();
When using column-vector notation, the terms should be reversed. Also, note that when using incremental rotations the orientation matrix should be orthogonalized periodically to prevent drift (with quaternions this equates to normalization).

#### Share this post

##### Share on other sites
...how do i orthogonolize? im using Microsoft.DirectX.Matrix and the only function it has with anything to do with orthogonalization is OrthoRH and OrthoLH...

which both do "Builds a Left/Right-handed Orthogonal projection matrix" they take

Width,Height,zNearPlane and zFarPlane... all floats...

is that what i need?

#### Share this post

##### Share on other sites
Quote:
 Original post by perkbrianis that what i need?
Nope, those functions are for building an orthographic projection, which is unrelated.

Orthogonalizing a rotation matrix is more or less equivalent to orthonormalizing a set of basis vectors. An easy way to do the latter in 3D is:
forward.normalize();side = cross(up,forward);side.normalize();up = cross(forward,side);
To orthogonalize your rotation matrix, simply extract the basis vectors, perform the above operations, and then reset the basis vectors of the matrix.

#### Share this post

##### Share on other sites
thank you very much, it works perfectly...

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Forum Statistics

• Total Topics
627719
• Total Posts
2978797

• 10
• 9
• 21
• 14
• 12