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

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

100
010
001

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

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

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013603
×