Sign in to follow this  
cghill

Mesh rotation from direction, up, and side vectors

Recommended Posts

I'm creating a flight simulator, and I have the 3D movement implemented and working correctly. Now I'm trying to draw the spacecraft mesh correctly as I move through the 3D world. The transformation and scaling is easy, but I haven't been able to get the Matrix.RotationYawPitchRoll function to correctly model the spacecraft's rotation as moves through the world. I have the spacecraft's front (direction), up, and side vectors, and from them I must figure out how to rotate the craft from the original orientation (which I also know). I have tried using the Acos of the Dot product of the original vs current side/up/front vectors but it doesn't work correctly. Any help would be appreciated. Thanks a lot!

Share this post


Link to post
Share on other sites
You don't need Euler angles or any sort of 'yaw, pitch, roll' function. The forward, up, and side vectors that you already have available are in fact the basis vectors of the rotation matrix for the object. All you need to do is load them into a matrix directly, and then concatenate this matrix with your translation and scaling matrices in the appropriate order.

I'm guessing DX from what you posted, correct? If so, the basis vectors go in the rows of the matrix, and the concatenation order is S*R*T.

'Hope that helps.

Share this post


Link to post
Share on other sites
From what I understand, I am supposed to create a matrix such as this:

[Side.X , Side.Y , Side.Z ]
[Up.X , Up.Y , Up.Z ]
[Front.X, Front.Y, Front.Z]

And substitute this as the rotation matrix? This doesn't seem intuitive, and therefore I think I greatly misinterpreted what you said/meant. Could you please elaborate on what you meant by them being the basis vectors, and how to load them into a Matrix directly. Again, I greatly appreciate your help.

[edit] Yes, you are correct in assuming I'm using DirectX!

Share this post


Link to post
Share on other sites
Quote:
Original post by cghill
From what I understand, I am supposed to create a matrix such as this:

[Side.X , Side.Y , Side.Z ]
[Up.X , Up.Y , Up.Z ]
[Front.X, Front.Y, Front.Z]

And substitute this as the rotation matrix? This doesn't seem intuitive, and therefore I think I greatly misinterpreted what you said/meant.
Nope, that's exactly what I meant :) Just construct the matrix as above (remember to set the rest of the matrix to identity) and then concatenate the three transform matrices in the order scale->rotation->translation to get your final transform matrix.

If you try it and it doesn't work, post the relevant code and maybe I or someone else can spot the problem.

Share this post


Link to post
Share on other sites

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

Sign in to follow this