# Mesh rotation from direction, up, and side vectors

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

## 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 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 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.

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

##### Share on other sites
Quote:
 Original post by cghillFrom 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 on other sites
That works perfectly!!! If only I knew it was that simple a while ago. Thanks a lot for your help!

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632633
• Total Posts
3007543
• ### Who's Online (See full list)

There are no registered users currently online

×