Mesh rotation from direction, up, and side vectors

Started by
3 comments, last by cghill 17 years, 6 months ago
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!
Advertisement
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.
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!
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.
That works perfectly!!! If only I knew it was that simple a while ago. Thanks a lot for your help!

This topic is closed to new replies.

Advertisement