Keithster

11-22-2015, 08:27 PM

I'm deeply confused about this whole row-major vs column-major business.

I asked the question on SO but I would love to hear answers from the opengl community as well. httpee://stackoverflow.com/questions/33862730/row-major-vs-column-major-confusion (sorry it didn't let me post the link so I had to modify it hence the 'pee')

I hope you can see how lost I am, I'm just mixing up a bunch of stuff but I can't seem to figure out what is it I'm mixing.

Take a translation matrix for example (the picture on my SO link edit), does row-major mean that we store the transformation vector in the last row? and column-major means we store it in the last column? or the opposite?

I'm gonna try and answer my own question: let's try to translate a vector with our row-major and column-major matrices:

First the translation values are stored in the last column (the way I have them stored in 'My Matrix' in the picture in SO link)

|1, 0, 0, x| |3| |3 + x|

|0, 1, 0, y| |5| |5 + y|

|0, 0, 1, z| |0| |0 + z|

|0, 0, 0, 1| |1| |1|

OK that makes sense to me. We got our translated vector!

Now let's try the other matrix, the way glm has it, where the values are stored in the last row:

|1, 0, 0, 0| |3| |3|

|0, 1, 0, 0| |5| |5|

|0, 0, 1, 0| |0| |0|

|x, y, z, 1| |1| |3x + 5y + 0 + 1|

That doesn't make sense, we didn't get the translated vector.

Let's try multiplying the vector from the left, transposed:

.....................|1, 0, 0, 0| |3 + x|

.....................|0, 1, 0, 0| |5 + y|

|3, 5, 0, 1|....|0, 0, 1, 0| |0 + z|

.....................|x, y, z, 1| |1|

We got our translated vector again!

But that doesn't really clear up the confusion. What did that result teach us? Well I've been reading and it seems that when you have a column-major matrix, you multiply the vector from the right. i.e. M x V which is what we did in the first example with my matrix, so does that mean that my matrix is in column-major? and glm's is in row major? but If that's really the case, then why is it that in glm, we always multiply the vector last, we never do V x M, so... there goes my theory :\

I hope you get the picture, and how much confused I am.

Any help is GREATLY appreciated!

I asked the question on SO but I would love to hear answers from the opengl community as well. httpee://stackoverflow.com/questions/33862730/row-major-vs-column-major-confusion (sorry it didn't let me post the link so I had to modify it hence the 'pee')

I hope you can see how lost I am, I'm just mixing up a bunch of stuff but I can't seem to figure out what is it I'm mixing.

Take a translation matrix for example (the picture on my SO link edit), does row-major mean that we store the transformation vector in the last row? and column-major means we store it in the last column? or the opposite?

I'm gonna try and answer my own question: let's try to translate a vector with our row-major and column-major matrices:

First the translation values are stored in the last column (the way I have them stored in 'My Matrix' in the picture in SO link)

|1, 0, 0, x| |3| |3 + x|

|0, 1, 0, y| |5| |5 + y|

|0, 0, 1, z| |0| |0 + z|

|0, 0, 0, 1| |1| |1|

OK that makes sense to me. We got our translated vector!

Now let's try the other matrix, the way glm has it, where the values are stored in the last row:

|1, 0, 0, 0| |3| |3|

|0, 1, 0, 0| |5| |5|

|0, 0, 1, 0| |0| |0|

|x, y, z, 1| |1| |3x + 5y + 0 + 1|

That doesn't make sense, we didn't get the translated vector.

Let's try multiplying the vector from the left, transposed:

.....................|1, 0, 0, 0| |3 + x|

.....................|0, 1, 0, 0| |5 + y|

|3, 5, 0, 1|....|0, 0, 1, 0| |0 + z|

.....................|x, y, z, 1| |1|

We got our translated vector again!

But that doesn't really clear up the confusion. What did that result teach us? Well I've been reading and it seems that when you have a column-major matrix, you multiply the vector from the right. i.e. M x V which is what we did in the first example with my matrix, so does that mean that my matrix is in column-major? and glm's is in row major? but If that's really the case, then why is it that in glm, we always multiply the vector last, we never do V x M, so... there goes my theory :\

I hope you get the picture, and how much confused I am.

Any help is GREATLY appreciated!