1

Does anybody know what the order of a 4x4 GLfloat array matrix for transforming a 2D rectangle is? I don't want to use glm or cglm to make my life easy. I'm trying to use the least amount of libraries as possible. Is the order something like this:

{ px, sx, rx, 0, py, sy, ry, 0, pz, sz, rz, 0, 0, 0, 0, 1 } ?

If not what is it?

Thanks!

  • What are px,, sx,, rx, ...? OpenGL doesn't care whether your matrices are row major or column major, as long as you set the correct parameters in `glUniformMatrix4fv`. – BDL Apr 03 '22 at 10:21
  • px - position x ; sx - size x ; rx - rotation x – Kabajat2008 Apr 03 '22 at 10:27
  • Ok. That's not at all how transformation matrices work. A transformation matrix containing rotation, translation and scale is the result of a multiplication of at least three matrices, one for each of the primitive operations. If your rotations are rotations around the global axis (aka: Euler Angles), then you need a separate rotation matrix for each of them and you have to decide on the order. You really need to read up on the math: https://learnopengl.com/Getting-started/Transformations – BDL Apr 03 '22 at 10:34
  • 1
    see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) – Spektre Apr 03 '22 at 12:46

1 Answers1

0

4x4 matrix is for 3D.

Xx  Yx  Zx  Tx
Xy  Yy  Zy  Ty
Xz  Yz  Zz  Tz
0   0   0   1

(Xx, Xy, Xz) - left (or right) vector
(Yx, Yy, Yz) - up vector
(Zx, Zy, Zz) - forward vector
(Tx, Ty, Tz) - translation (position) vector

indices:
m00 m01 m02 m03
m10 m11 m12 m13
m20 m21 m22 m23
m30 m31 m32 m33

Order: m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33

If you need only 2D transformations you can use a 3x3 matrix.

Xx  Yx  Tx
Xy  Yy  Ty
0   0   1

Order: m00, m10, m20, m01, m11, m21, m02, m12, m22

Or you want this?

Xx  Yx  0  Tx
Xy  Yy  0  Ty
0   0   1  0
0   0   0  1
Zeganstyl
  • 11
  • 1
  • 3