phq's picture

Vector matrix orientation

This row-major/column-major has been a big issue of mine, especially since I understand the basics which has nothing to do with the actual issue.
Now when I realized that row-major in graphics also means that vectors are row-vectors it has become much clearer to me.

So I have made a few observations of which I would like a better understanding behind the choices.

1. OpenGL uses by default column-major matrix indexing, why is OpenTK.Math.Matrix4 using a row-major representation.

2. OpenGL is designed for column-vectors and thus calculate like this: M.v (Matrix * vector), rather than v.M
This is also the way the OpenGL online tutorials and books do, as well as how the shader code is written.
But I found out that the Matrix.Create.. functions generates matrices that assume row-vectors.

3. When I almost had got it, I tried to verify whether OpenTK was using row or column vectors. I tried to find that perhaps only M.v or v.M code was written but I found none.
The only indicator was the matrix create... methods, or rather the output they generated.
Why is there no Mult(Vector4, Matrix4) in the OpenTK.Math namespace?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mOfl's picture
phq wrote:

This row-major/column-major has been a big issue of mine, especially since I understand the basics which has nothing to do with the actual issue. Now when I realized that row-major in graphics also means that vectors are row-vectors it has become much clearer to me.

There's been a thread on this matter already, http://www.opentk.com/node/2794, maybe some of the information in this thread will help to resolve your troubles.

Quote:

1. OpenGL uses by default column-major matrix indexing, why is OpenTK.Math.Matrix4 using a row-major representation.

The correct question is: "CPU-based libraries like OpenTK.Math, GLM, IMath, ... are using row-major representation, then why does OpenGL use column-major matrices?" It is common to use the row-major representation, only in OpenGL column-major matrices are used for some reason (I think they state it's more intuitive). As already explained in the other thread, in the end, the two representations are nothing but different conventions for how to align the 16 (float) values of a matrix in memory. A row-major matrix has the same memory alignment as its transpose in column-major form, which also explains the difference of M * v vs. v * M.

Robmaister's picture
phq wrote:

Why is there no Mult(Vector4, Matrix4) in the OpenTK.Math namespace?

It's called Vector4.Transform(Vector4, Matrix4)

lid6j86's picture

so i'm gonna sound stupid, but this means that it is set up like:

[x1 , x2, x2, 0
y1, y2, y3, 0
z1, z2, z3, 0
T1, T2, T3, 1]

instead of

[x1, y1, z1, T1
x2, y2, z2, T2
x3, y3, z3, T3
0 , 0 , 0 , 1

is this correct?

phq's picture

Yes the translation components are on the bottom row.