affine transform matrix (specialized functions)

Header: cglm/affine-mat.h

We mostly use glm_mat4_* for 4x4 general and transform matrices. cglm provides optimized version of some functions. Because affine transform matrix is a known format, for instance all last item of first three columns is zero.

You should be careful when using these functions. For instance glm_mul() assumes matrix will be this format:

R  R  R  X
R  R  R  Y
R  R  R  Z
0  0  0  W

if you override zero values here then use glm_mat4_mul() version. You cannot use glm_mul() anymore.

Same is also true for glm_inv_tr() if you only have rotation and translation then it will work as expected, otherwise you cannot use that.

In the future it may accept scale factors too but currectly it does not.

Table of contents (click func go):

Functions:

  1. glm_mul()
  2. glm_mul_rot()
  3. glm_inv_tr()

Functions documentation

void glm_mul(mat4 m1, mat4 m2, mat4 dest)
this is similar to glm_mat4_mul but specialized to affine transform

Matrix format should be:

R  R  R  X
R  R  R  Y
R  R  R  Z
0  0  0  W

this reduces some multiplications. It should be faster than mat4_mul. if you are not sure about matrix format then DON’T use this! use mat4_mul

Parameters:
[in] m1 affine matrix 1
[in] m2 affine matrix 2
[out] dest result matrix
void glm_mul_rot(mat4 m1, mat4 m2, mat4 dest)
this is similar to glm_mat4_mul but specialized to rotation matrix

Right Matrix format should be (left is free):

R  R  R  0
R  R  R  0
R  R  R  0
0  0  0  1

this reduces some multiplications. It should be faster than mat4_mul. if you are not sure about matrix format then DON’T use this! use mat4_mul

Parameters:
[in] m1 affine matrix 1
[in] m2 affine matrix 2
[out] dest result matrix
void glm_inv_tr(mat4 mat)
inverse orthonormal rotation + translation matrix (ridig-body)
X = | R  T |   X' = | R' -R'T |
    | 0  1 |        | 0     1 |

use this if you only have rotation + translation, this should work faster than glm_mat4_inv()

Don’t use this if your matrix includes other things e.g. scale, shear…

Parameters:
[in,out] mat affine matrix