Jump to content
  • Advertisement
Sign in to follow this  

Matrix rotation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, maybe i am asking a silly question, but a doubt afflects me, i am working with matrices in XNA, i calculated my rotation matrix with Matrix.CreateFromYawPitchRoll but and then i defined camUp, camLook, camLeft using respectively the 2nd, the 3rd and the 1st row of my matrix. What i want to understand is why i use these values, i mean why should i use the 2nd row for the camUp, the 3rd for camLook and so on... What's the logic and the math rules behind this algorithm ? Thanks in advance for Your replies.

Share this post

Link to post
Share on other sites
When you deal with rotation matrices you get a special kind of matrix where each axis (row) is at 90 degrees to each other. The 3 axis are there for forward, up and right.

It depends on the implementation but in xna forward is the z axis (row 3), up is the y axis (row 2) and left/right is the x axis, row 1.

If you think of what a matrix with no rotation is you get the identity:


Which you can see row 2 being up/down, row 3 being forward/back and row 1 being left/right.

Share this post

Link to post
Share on other sites
The matrix is composed of 4 vectors, 3 basis vectors, XYZ, and a translation component, T. As the previous poster mentioned, for most cases in 3d graphics the 3 basis vectors are orthogonal, or perpindicular, or 90 degrees relative to one another. Using orthogonal matrices makes life a whole lot easier, not sure i could explain why though.

I like to think of the rotation bit as, "what would happen to each of my components in this rotation?"

For example, identity, no rotation, we have the following basis vectors:

X(1 0 0) Y(0 1 0) Z(0 0 1)

So to answer the question you use matrix multiplication to see the result.

Given point P(x y z)
Result(P * X, P * Y, P * Z) which is just (x y z) again.

Or a 90 degree rotation
X(0 0 -1) Y(0 1 0) Z(1 0 0)
Result(P * X, P * Y, P * Z) now equals (-z y x).

You'll also want to understand the right and left handed rules to see where these vectors came from. It will come in handy when trying to do this math in your head. It is also very handy to be able to visualize basis vectors kind of like this: http://www.cs.umbc.edu/~rheingan/435/pages/res/view/view19.gif or this http://www.euclideanspace.com/maths/algebra/matrix/orthogonal

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!