Here are two codes.

glm::mat4 proj = glm::ortho ( 0.0, 1920.0, 0.0, 1080.0, -1.0, 1.0 ); glm::mat4 view = glm::translate ( glm::mat4(1.0f), glm::vec3 ( 2.0, 3.0f, 2.0f ) ); glm::mat4 result = proj * view; 

Here is the conclusion.

  0.001042 0.000000 0.000000 0.000000 0.000000 0.001852 0.000000 0.000000 0.000000 0.000000 -1.000000 0.000000 -1.000000 -1.000000 -0.000000 1.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 0.000000 0.000000 0.000000 1.000000 0.000000 2.000000 3.000000 2.000000 1.000000 ======================================== 0.001042 0.000000 0.000000 0.000000 0.000000 0.001852 0.000000 0.000000 0.000000 0.000000 -1.000000 0.000000 -0.997917 -0.994444 -2.000000 1.000000 

How are these numbers, -0.997917 and -0.994444, how are they calculated? How do they multiply there? For example, from 2 to become -2, but how? And I’m looking for everything in glm, but I’ll not find it, looking for operator * for mat4.

  • The first block of code where 0.001042 is the ortho matrix, the second block of the matrix is ​​translate. The third block is the multiplication of something. - xverizex
  • one
    So this is the usual multiplication of matrices. Try googling it. - HolyBlackCat

1 answer 1

Multiplication matrices for dummies

A little help:

Just as the multiplication of ordinary numbers, the multiplication of matrices is associative , i.e.
(a * b) * c == a * (b * c) .

But, unlike multiplication of numbers, multiplication of matrices is not commutative , i.e.
a * b != b * a .

In order for the two matrices to be multiplied, the width of the first matrix must coincide with the height of the second matrix.

The matrix that is obtained as a result coincides in height with the first matrix, and in width with the second.

How to count:

Each cell in the new matrix is ​​calculated as follows:

 c[x][y] = a[0][y] * b[x][0] + a[1][y] * b[x][1] + ... + a[n-1][y] * b[x][n-1]; 

Where: a is the first matrix, b is the second matrix, c is the result, n is the width of the first matrix and the height of the second one at the same time.
It is assumed that [0][0] is the upper-left corner of the matrix. The first bracket is x , the second is y .

If you need to program it, then the easiest way is three nested for : Two to go through all the cells of the new matrix, and the third to sum up n works for this cell.