is pyrr.Matrix44 layout actually column-major?

275 views Asked by At

in the pyrr.Matrix docs it states:

Matrices are laid out in row-major format and can be loaded directly into OpenGL. To convert to column-major format, transpose the array using the numpy.array.T method.

creating a transformation matrix gives me:

Matrix44.from_translation( np.array([1,2,3]))                                                                                                        
Matrix44([[1, 0, 0, 0],
          [0, 1, 0, 0],
          [0, 0, 1, 0],
          [1, 2, 3, 1]])

If the layout is row-major, I would expect the output to be the transpose:

Matrix44([[1, 0, 0, 1],
          [0, 1, 0, 2],
          [0, 0, 1, 3],
          [0, 0, 0, 1]])

I'm most likely confused (I come from C/OpenGL background), but could anyone please enlighten me?

Jonathan

1

There are 1 answers

3
Erwan Daniel On

I was writing down a great answer. But I found this really interesting link I invite you to read it !

This is a small resume :

  • If it's row-major matrix, then the translation is stored in the 3, 7, and 11th indices.
  • If it's column-major, then the translation is stored in the 12, 13, and 14th indices.

The difference behind the scene is the way to store the data. As it is 16 float in memory, those floats are contiguous in the memory. So you have to define if you either store them in 4 float x 4 columns or 4 float x 4 rows. And then it change the way you access and use it.

You can look at this link too.