# Position, At, and Up to Rotation Matrix

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

## Recommended Posts

I have a position, an at, and an up vector for a model and I need to create a rotation matrix that will rotate my model so that it is oriented to those vectors. How do I do this? I'm thinking it has something to do with just putting the unit vectors straight into a matrix, but I'm not sure. Thanks

##### Share on other sites
Hi,

This should set you straight:

http://www.makegames.com/3drotation/

I found this extremely useful and well written. There's plenty of source code around to achieve this (included with the article too), but this article explains it nicely.

Cheers,

Martin.

##### Share on other sites
Your right, but it does depent what side you multiply from. this would be a general solution assuming z is up and x is left and your doing Mat = vec*Mat:

at_vector = at-position;
Left_vector = CrossProcuct(Up,at_vector);
Matrix = {
Left_vector.x, Left_vector.y, Left_vector.z
at_vector.x, at_vector.y, at_vector.z,
up.x, up.y, up.z,
};

try a few examples to see how it works. also to change back just take the inverse
(i.e. {Left as column | at as column | up as column } )

##### Share on other sites

Here's what I'm thinking. What if I used the same matrix that I'm using for my viewing matrix (I'm using Direct3D) for my world matrix too, except for I changed the viewing, position, and up that it was generated from?

I'm using a similar setup of position, looking, and up for my camera. Would this work? Thanks

##### Share on other sites
Thanks anonymous poster, I knew it was something to that effect.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 13
• 14
• 45