3D Affine Transforms (pre)

Pre transform functions which are regular transform functions.

Table of contents (click to go):

Functions:

  1. glm_translate_to()

  2. glm_translate()

  3. glm_translate_x()

  4. glm_translate_y()

  5. glm_translate_z()

  6. glm_translate_make()

  7. glm_scale_to()

  8. glm_scale_make()

  9. glm_scale()

  10. glm_scale_uni()

  11. glm_rotate_x()

  12. glm_rotate_y()

  13. glm_rotate_z()

  14. glm_rotate_make()

  15. glm_rotate()

  16. glm_rotate_at()

  17. glm_rotate_atm()

  18. glm_decompose_scalev()

  19. glm_uniscaled()

  20. glm_decompose_rs()

  21. glm_decompose()

  22. glm_spin()

Functions documentation

void glm_translate_to(mat4 m, vec3 v, mat4 dest)

translate existing transform matrix by v vector and store result in dest

Parameters:
[in] m affine transform
[in] v translate vector [x, y, z]
[out] dest translated matrix
void glm_translate(mat4 m, vec3 v)

translate existing transform matrix by v vector and stores result in same matrix

Parameters:
[in, out] m affine transform
[in] v translate vector [x, y, z]
void glm_translate_x(mat4 m, float x)

translate existing transform matrix by x factor

Parameters:
[in, out] m affine transform
[in] v x factor
void glm_translate_y(mat4 m, float y)

translate existing transform matrix by y factor

Parameters:
[in, out] m affine transform
[in] v y factor
void glm_translate_z(mat4 m, float z)

translate existing transform matrix by z factor

Parameters:
[in, out] m affine transform
[in] v z factor
void glm_rotate_x(mat4 m, float angle, mat4 dest)

rotate existing transform matrix around X axis by angle and store result in dest

Parameters:
[in] m affine transform
[in] angle angle (radians)
[out] dest rotated matrix
void glm_rotate_y(mat4 m, float angle, mat4 dest)

rotate existing transform matrix around Y axis by angle and store result in dest

Parameters:
[in] m affine transform
[in] angle angle (radians)
[out] dest rotated matrix
void glm_rotate_z(mat4 m, float angle, mat4 dest)

rotate existing transform matrix around Z axis by angle and store result in dest

Parameters:
[in] m affine transform
[in] angle angle (radians)
[out] dest rotated matrix
void glm_rotate(mat4 m, float angle, vec3 axis)

rotate existing transform matrix around given axis by angle at ORIGIN (0,0,0)

❗️IMPORTANT ❗️

If you need to rotate object around itself e.g. center of object or at some point [of object] then glm_rotate_at() would be better choice to do so.

Even if object’s model transform is identiy, rotation may not be around center of object if object does not lay out at ORIGIN perfectly.

Using glm_rotate_at() with center of bounding shape ( AABB, Sphere … ) would be an easy option to rotate around object if object is not at origin.

One another option to rotate around itself at any point is glm_spin() which is perfect if only rotating around model position is desired e.g. not specific point on model for instance center of geometry or center of mass, again if geometry is not perfectly centered at origin at identity transform, rotation may not be around geometry.

Parameters:
[in, out] m affine transform
[in] angle angle (radians)
[in] axis axis
void glm_rotate_at(mat4 m, vec3 pivot, float angle, vec3 axis)

rotate existing transform around given axis by angle at given pivot point (rotation center)

Parameters:
[in, out] m affine transform
[in] pivot pivot, anchor point, rotation center
[in] angle angle (radians)
[in] axis axis
void glm_spin(mat4 m, float angle, vec3 axis)
rotate existing transform matrix around given axis by angle around self (doesn’t affected by position)
Parameters:
[in, out] m affine transform
[in] angle angle (radians)
[in] axis axis