summaryrefslogtreecommitdiff
path: root/libs/cglm/docs/source/affine-mat.rst
blob: d0065e9232d06b1893a2cc887ee06c1d89224bd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.. default-domain:: C

3D 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 :c:func:`glm_mul`
assumes matrix will be this format:

.. code-block:: text

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

if you override zero values here then use :c:func:`glm_mat4_mul` version.
You cannot use :c:func:`glm_mul` anymore.

Same is also true for :c:func:`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. :c:func:`glm_mul`
#. :c:func:`glm_mul_rot`
#. :c:func:`glm_inv_tr`

Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~

.. c:function:: 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:

    .. code-block:: text

       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

.. c:function:: 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):

    .. code-block:: text

       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

.. c:function:: void  glm_inv_tr(mat4 mat)

    | inverse orthonormal rotation + translation matrix (ridig-body)

    .. code-block:: text

       X = | R  T |   X' = | R' -R'T |
           | 0  1 |        | 0     1 |

    use this if you only have rotation + translation, this should work faster
    than :c:func:`glm_mat4_inv`

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

    Parameters:
      | *[in,out]*  **mat**  affine matrix