# Getting a rotation matrix from up, right and forward vectors

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

## Recommended Posts

I've been following this tutorial to make a space sim style camera http://www.toymaker.info/Games/html/camera.html I have made a few changes to this. I don't reset the up, right and forward each time. That way rotations are done based on the local axes rather than the world axes (correct? It seems to work right), and I rotate by the change in the angle rather than the cumulative value (after all now it's a series of rotations in different directions so a cumulative value wouldn't make sense). Now that works fine for orienting the camera in the right way, but I don't know how to turn these three vectors into a suitable rotation matrix so I can rotate my ship model in world space. I've tried building the matrix in the same way as the view matrix (as described in that tutorial), but that doesn't seem to work at all. Can anyone point me in the right direction here? P.S. I assure you that pun was entirely unintentional.

##### Share on other sites
(Assuming a Direct3D style left-handed coordinate frame): If you have three world space vectors, Right (x), Forward (z), and Up (y) that define a coordinate system, and you want to transform from that coordinate system into world space (e.g. the Model->World transform), you just need to place those vectors as the rows in your transformation matrix. If, on the other hand, you need to transform from world space *into* this new coordinate system (such as with the World->View transform), you need the inverse of this matrix, which for a rotation matrix is just the transpose.

So the rotation matrix you're looking for is the transpose of the upper 3x3 portion of the matrix given in that tutorial.

##### Share on other sites
Thanks that works great.

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633269
• Total Posts
3011145
• ### Who's Online (See full list)

There are no registered users currently online

×