Jump to content
  • Advertisement
Sign in to follow this  

Another Matrix Order Question :)

This topic is 2381 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

I'm trying to get my head around row/column major matrices and row/column vectors. Mostly, I'm using the following for reference:

So, trying to write a 4x4 matrix class, I have a class with an array of values:

float m_Values[16];

Now, I'm going to be using column vectors, so:

1) Am I right in saying the following:

Multiplication should be written like so: Matrix * Vector
Combining rotation matrices should be written (for example): Projection * View * World

2) Row/Column major matrices refers to the order the data is stored in memory, NOT whether or not the translation component should be down the right hand side / along the bottom.

The translation is down the right hand side of the matrix when using column vectors, and across the bottom when using row vectors. Is this correct?

3) OpenGL uses column vectors, and uses column major matrices, and we want to upload the matrices to OpenGL using glUniformMatrix4fv

I'm pretty sure this is right, so does that mean that the translation component should be in m_Values[12], m_Values[13] and m_Values[14]?

4) When multiplying two matrices together, the operator* should have something like the following

final.m_Values[0] = (this.m_Values[0] * other.m_Values[0]) + (this.m_Values[1] * other.m_Values[4]) + (this.m_Values[2] * other.m_Values[8]) + (this.m_Values[3] * other.m_Values[12]);

final.m_Values[1] = (this.m_Values[0] * other.m_Values[1]) + (this.m_Values[1] * other.m_Values[5]) + (this.m_Values[2] * other.m_Values[9]) + (this.m_Values[3] * other.m_Values[13]);

final.m_Values[2] = (this.m_Values[0] * other.m_Values[2]) + (this.m_Values[1] * other.m_Values[6]) + (this.m_Values[2] * other.m_Values[10]) + (this.m_Values[3] * other.m_Values[14]);

I'm not sure if this order is right, or if I need to multiply a different way because the matrices are stored in column major order in memory. Can anyone clarify if this is the right way or not?

5) The Matrix Quaternion FAQ I linked to at the top seems to be using column vectors, so vectors are multiplied on the right, as shown in Q13 of the FAQ. Q35 appears to suggest that matrices should be multiplied the other way though.

Q35 states that in order to get an X rotation, followed by a Y rotation, followed by a Z rotation, you multiply:

M = X.Y.Z

But I thought that, because it is using column vectors, the first transformation should be at the right hand side. I.e.:

M = Z.Y.X

In fact, looking at the function calls listed at the start of Q36, it seems to be multiplying in the order I'd think was correct (i.e. Z * Y * X), but still goes on to state that M = X.Y.Z.

Are Qs 35 & 36 wrong, or is it just a difference in notation for multiplying matrices instead of vectors (as Q13 says that V' = M.V, which seems like the right way round to me). Or is it just that I'm very confused? ;)

Hopefully someone can help me out on this, it would be very useful. Thanks :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!