# Vector matrix orientation

Posted Monday, 16 April, 2012 - 08:08 by phq inThis 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

## Re: Vector matrix orientation

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

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

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.

## Re: Vector matrix orientation

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

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

## Re: Vector matrix orientation

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?

## Re: Vector matrix orientation

Yes the translation components are on the bottom row.