# Matrices

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

## Recommended Posts

Hi, guys. I'm trying to get into 3D graphics, but I'm a little confused. I think I got the notion of transformation matrices somewhat down, but I'm a little confused. However, through all my Googling, I couldn't find anything on position matrices. Everywhere I read, position is represented as a vector. However, I'm working on a billiards simulation, and it seems like I could use a matrix to represent both the ball position and rotation at the same time. I kinda half-guessed at what this matrix would look like: [rx 0 0 0] [0 ry 0 0] [0 0 rz 0] [x y z 1] Is this right? Is that kinda thing even possible? Thanks in advance for helping a 3D newb out.

##### Share on other sites
Recommend:

1. Reading all the articles on matrices in the articles section of this site.

2. Getting a book such as '3D Math Primer', which goes over all of this stuff in detail.

I'm not sure what the rx, ry and rz mean in your example. If those are Euler rotation values, then no, that's not right. Otherwise you're on the right track. With a 4x4 matrix, you can store the three orthonormal axes of the coordinate system in the rows of the upper-left 3x3 matrix, and translation at the bottom, as you have done. Alternately, you can use a transposed version of the matrix (column-major). Finally, if you don't need the last row/column (0 0 0 1), you can strip it away and just use a 4x3 or 3x4 matrix.

##### Share on other sites
I did read everything in the articles section. However, I am still confused as matrices are not an easy subject to grasp. As for rx, I was thinking that it would be the number of radians the ball turned around the x-axis.

##### Share on other sites
You are right, matrices can be difficult to grasp - it takes some time, and repeated exposure to the material.

I'm not aware of any useful matrix formulation that incorporates the actual angle in radians. Did you get that from somewhere? Perhaps you misunderstood - re-reading the material might clear things up for you.

Otherwise, maybe ask some more specific questions. I'm sure someone here can help you get it sorted.

##### Share on other sites
The rotation portion of a transformation matrix will never contain the actual angle, in radians or any other measurement. In terms of angle, the rotation matrix components boil down to the product of sines and cosines of various angles, with scale factors also multiplied in there in the most general case. The OpenGL red book has some insight into this:

OpenGL Red Book v1.1, Appendix G

Nate Robins wrote some very cool OpenGL demos that serve as interactive tutorials to some aspects of 3D graphics, including transformation matrix. I highly recommend downloading these and running them. They can help you to understand some of this better, although the tutorials do specifically illustrate OpenGL function call syntax. (Looking at the Red Book can help to map the OpenGL syntax shown in the tutorials back to general math.)

Nate Robins OpenGL Tutorials

Look specifically at the "transformation" tutorial.

The Nehe tutorials here at gamedev also can be useful. Sometimes, I think, actual working code that is crafted to demonstrate an idea can be easier to follow than math equations and text. Eventually you get back to the math, but the demos can help get past a sticking point.

Nehe

##### Share on other sites
Well, I think I understand the transformation matrix pretty well. My question is, is there such a thing as a POSITION matrix? Or does that have to be a vector?

##### Share on other sites
Well, I'm sure Graham or one of the other math gurus here would be able to give you a more rigorous answer, but I'm not aware of any 'position matrix' per se. In n-dimensional space, a position is uniquely identified by n scalar displacements along n basis vectors. In English that means that yes, your position is a vector, not a matrix.

Perhaps you're confusing the idea of a 'position matrix' with a 4x4 matrix that represents translation only? Such a matrix would have a translation vector in the appropriate place, but the 'rotation' portion would be the identiy matrix, like this:

1 0 0 0
0 1 0 0
0 0 1 0
x y z 1

Multiplying this by another matrix would incorporate the translational element while leaving the orientation unchanged.

Anyway, that's my best guess as to what you might mean by a 'position matrix'.

##### Share on other sites
Once you understand the basic concept of matrices, then they are quite easy to understand.

For the rotation part of a matrix - there isn't actually a rotation stored as such. If you picture the axis on a graph - the directional vectors describing which way the different axis are pointing are called 'basis' vectors.

For example, on a none rotated graph - the x-basis vector will be [1,0,0]. The y-basis vector will be [0,1,0]. And the z-basis vector will be [0,0,1]. On a matrix, the first row is the x-basis vector, the second row is the y-basis vector, and the 3rd row is the z-basis vector. This explains why a matrix without rotation looks like this:

1, 0, 0
0, 1, 0
0, 0, 1

As for your question about the position of the matrix. This is stored in the fourth row. Note that the 4th column is only not [0, 0, 1] (going downwards), when you're doing more advanced stuff that translation and rotation. Ignore the 4th column for now.

Hope this helps.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 9
• 31
• 16
• 11
• 10
• ### Forum Statistics

• Total Topics
634121
• Total Posts
3015613
×