Column Major?

Is Matrix4 (the float version) column major?


Comments

Re: Column Major?
posted by Inertia
Re: Column Major?
posted by Kamujin

I think less efficiently when I am tired. I think I see my mistake now.

Can you check my order here?

In row major, modelViewProjection = projection * modelView? (not modelView * projection)

Is this right?

Re: Column Major?
posted by Inertia

ModelView * Projection if memory serves right. There's a whole chapter dedicated to matrix operation at http://www.glprogramming.com/red/chapter03.html

in OpenTK.Math matrices are concatenated like this

C = A * B; // results in C containing matrix A transformed by B

// should be the same operation as:

GL.Matrixmode( ModelViewMatrix );
GL.LoadTransposedMatrix( A );
GL.MultTransposedMatrix( B );
GL.GetFloat( TransposedModelViewMatrix, out C.row0.X );

Re: Column Major?
posted by Kamujin

Yeah, I'm not using immediate mode though. I'm sending it to the shader as a uniform.

I wasn't confused until I started using the OpenTK math libraries with OpenGL via shaders. I just have to get it all sorted out in my head.

Thanks for the link. Its been a while since I've played with matrix ordering, so I am trying to get it straight in my head again.

Re: Column Major?
posted by objarni

I use this "mind model" when thinking of matrix ordering:

newVec = matrix1*matrix2*...*matrixN*oldVec

.. so matrix1 is applied 'last' and matrixN 'first', on the oldVec-vector.

Re: Column Major?
posted by Kamujin

Objarni, your "mind model" is row major, correct?

Re: Column Major?
posted by objarni

My mind model comes from linear algebra.

To me multiplication between matrices is mathematically defined something like:

R(r,c) = (A*B)(r,c) = A(r,:)*B(:,c)    // for relevant r, c

.. where

  • R is the result matrix
  • A(r,c) means element on row r, column c of matrix A
  • A(r,:) means row r of A (a.k.a. row-vector)
  • B(:,c) means column c of B (a.k.a. column-vector)

The definition could be read aloud something like "the element on row r column c of the result matrix equals the scalar product of row vector r of A and column vector c of B".

Multiplying a row and a column vector means:

             |b1|
|a1 a2 a3| * |b2|  =  a1b1 + a2b2 + a3b3   // similar to scalar-product of two vectors
             |b3|

I'm not entirely sure what you mean by row-major; does it have anything to do with the ordering of the elements in a computer representation of a matrix using an array?

Re: Column Major?
posted by Kamujin

I think thats row-major notation.

There is information on row-major vs column-major matrices at the following link.

http://lists.apple.com/archives/Mac-opengl/2000/Dec/msg00045.html