1

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

Jochemspek
  • 321
  • 2
  • 9
  • So in `Matrix4[[a],[b],[c],[d]]`, are `a` to `d` rows or columns? This stuff can be flipped at so many points – derhass Mar 10 '20 at 20:52
  • row-major means that the outermost dimension (ie the first index in a multidimensional array) refers to a row and the innermost to a column. So [a] refers to the first row for a row-major matrix, first column for column-major. – Jochemspek Mar 11 '20 at 15:28

1 Answers1

1

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.

Erwan Daniel
  • 1,319
  • 11
  • 26
  • hence my confusion. The docs say it's row-major, but the translation part is stored in 12,13,14 (when flattened) which suggests column-major. – Jochemspek Mar 10 '20 at 14:12
  • 1
    "If it's row-major matrix, then the translation is stored in the 3, 7, and 11th indices." that is not true in the general case, it assumes the translation matrix are meant to be applied in the `Matrix * column_vector` order. For example, GL default conventions column major matrices have translation in 12,13,14, but DirectX's default convention row-major matrices have translation also in 12,13,14 - in fact the actual matrices sendtto the GPU are byte-for-byte identical for both, but all operations concerning them must be written in swapped order between them. – derhass Mar 10 '20 at 20:48
  • see also https://stackoverflow.com/questions/61061408/why-does-pyrr-matrix44-translation-appear-to-be-column-major-and-rotation-row-m?noredirect=1#comment108055414_61061408 – Jochemspek Apr 09 '20 at 04:14