mat4.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. .. default-domain:: C
  2. mat4
  3. ====
  4. Header: cglm/mat4.h
  5. Important: :c:func:`glm_mat4_scale` multiplies mat4 with scalar, if you need to
  6. apply scale transform use :c:func:`glm_scale` functions.
  7. Table of contents (click to go):
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. Macros:
  10. 1. GLM_MAT4_IDENTITY_INIT
  11. #. GLM_MAT4_ZERO_INIT
  12. #. GLM_MAT4_IDENTITY
  13. #. GLM_MAT4_ZERO
  14. #. glm_mat4_udup(mat, dest)
  15. #. glm_mat4_dup(mat, dest)
  16. Functions:
  17. 1. :c:func:`glm_mat4_ucopy`
  18. #. :c:func:`glm_mat4_copy`
  19. #. :c:func:`glm_mat4_identity`
  20. #. :c:func:`glm_mat4_pick3`
  21. #. :c:func:`glm_mat4_pick3t`
  22. #. :c:func:`glm_mat4_ins3`
  23. #. :c:func:`glm_mat4_mul`
  24. #. :c:func:`glm_mat4_mulN`
  25. #. :c:func:`glm_mat4_mulv`
  26. #. :c:func:`glm_mat4_mulv3`
  27. #. :c:func:`glm_mat4_quat`
  28. #. :c:func:`glm_mat4_transpose_to`
  29. #. :c:func:`glm_mat4_transpose`
  30. #. :c:func:`glm_mat4_scale_p`
  31. #. :c:func:`glm_mat4_scale`
  32. #. :c:func:`glm_mat4_det`
  33. #. :c:func:`glm_mat4_inv`
  34. #. :c:func:`glm_mat4_inv_fast`
  35. #. :c:func:`glm_mat4_swap_col`
  36. #. :c:func:`glm_mat4_swap_row`
  37. Functions documentation
  38. ~~~~~~~~~~~~~~~~~~~~~~~
  39. .. c:function:: void glm_mat4_ucopy(mat4 mat, mat4 dest)
  40. copy mat4 to another one (dest). u means align is not required for dest
  41. Parameters:
  42. | *[in]* **mat** source
  43. | *[out]* **dest** destination
  44. .. c:function:: void glm_mat4_copy(mat4 mat, mat4 dest)
  45. copy mat4 to another one (dest).
  46. Parameters:
  47. | *[in]* **mat** source
  48. | *[out]* **dest** destination
  49. .. c:function:: void glm_mat4_identity(mat4 mat)
  50. copy identity mat4 to mat, or makes mat to identiy
  51. Parameters:
  52. | *[out]* **mat** matrix
  53. .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest)
  54. copy upper-left of mat4 to mat3
  55. Parameters:
  56. | *[in]* **mat** source
  57. | *[out]* **dest** destination
  58. .. c:function:: void glm_mat4_pick3t(mat4 mat, mat4 dest)
  59. copy upper-left of mat4 to mat3 (transposed)
  60. the postfix t stands for transpose
  61. Parameters:
  62. | *[in]* **mat** source
  63. | *[out]* **dest** destination
  64. .. c:function:: void glm_mat4_ins3(mat3 mat, mat4 dest)
  65. copy mat3 to mat4's upper-left. this function does not fill mat4's other
  66. elements. To do that use glm_mat4.
  67. Parameters:
  68. | *[in]* **mat** source
  69. | *[out]* **dest** destination
  70. .. c:function:: void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest)
  71. multiply m1 and m2 to dest
  72. m1, m2 and dest matrices can be same matrix, it is possible to write this:
  73. .. code-block:: c
  74. mat4 m = GLM_MAT4_IDENTITY_INIT;
  75. glm_mat4_mul(m, m, m);
  76. Parameters:
  77. | *[in]* **m1** left matrix
  78. | *[in]* **m2** right matrix
  79. | *[out]* **dest** destination matrix
  80. .. c:function:: void glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest)
  81. mupliply N mat4 matrices and store result in dest
  82. | this function lets you multiply multiple (more than two or more...)
  83. | matrices
  84. | multiplication will be done in loop, this may reduce instructions
  85. | size but if **len** is too small then compiler may unroll whole loop
  86. .. code-block:: c
  87. mat m1, m2, m3, m4, res;
  88. glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res);
  89. Parameters:
  90. | *[in]* **matrices** array of mat4
  91. | *[in]* **len** matrices count
  92. | *[out]* **dest** destination matrix
  93. .. c:function:: void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest)
  94. multiply mat4 with vec4 (column vector) and store in dest vector
  95. Parameters:
  96. | *[in]* **m** mat4 (left)
  97. | *[in]* **v** vec4 (right, column vector)
  98. | *[out]* **dest** vec4 (result, column vector)
  99. .. c:function:: void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest)
  100. multiply vector with mat4's mat3 part(rotation)
  101. Parameters:
  102. | *[in]* **m** mat4 (left)
  103. | *[in]* **v** vec3 (right, column vector)
  104. | *[out]* **dest** vec3 (result, column vector)
  105. .. c:function:: void glm_mat4_quat(mat4 m, versor dest)
  106. convert mat4's rotation part to quaternion
  107. Parameters:
  108. | *[in]* **m** affine matrix
  109. | *[out]* **dest** destination quaternion
  110. .. c:function:: void glm_mat4_transpose_to(mat4 m, mat4 dest)
  111. transpose mat4 and store in dest
  112. source matrix will not be transposed unless dest is m
  113. Parameters:
  114. | *[in]* **m** matrix
  115. | *[out]* **dest** destination matrix
  116. .. c:function:: void glm_mat4_transpose(mat4 m)
  117. tranpose mat4 and store result in same matrix
  118. Parameters:
  119. | *[in]* **m** source
  120. | *[out]* **dest** destination matrix
  121. .. c:function:: void glm_mat4_scale_p(mat4 m, float s)
  122. scale (multiply with scalar) matrix without simd optimization
  123. Parameters:
  124. | *[in, out]* **m** matrix
  125. | *[in]* **s** scalar
  126. .. c:function:: void glm_mat4_scale(mat4 m, float s)
  127. scale (multiply with scalar) matrix
  128. THIS IS NOT SCALE TRANSFORM, use glm_scale for that.
  129. Parameters:
  130. | *[in, out]* **m** matrix
  131. | *[in]* **s** scalar
  132. .. c:function:: float glm_mat4_det(mat4 mat)
  133. mat4 determinant
  134. Parameters:
  135. | *[in]* **mat** matrix
  136. Return:
  137. | determinant
  138. .. c:function:: void glm_mat4_inv(mat4 mat, mat4 dest)
  139. inverse mat4 and store in dest
  140. Parameters:
  141. | *[in]* **mat** source
  142. | *[out]* **dest** destination matrix (inverse matrix)
  143. .. c:function:: void glm_mat4_inv_fast(mat4 mat, mat4 dest)
  144. inverse mat4 and store in dest
  145. | this func uses reciprocal approximation without extra corrections
  146. | e.g Newton-Raphson. this should work faster than normal,
  147. | to get more precise use glm_mat4_inv version.
  148. | NOTE: You will lose precision, glm_mat4_inv is more accurate
  149. Parameters:
  150. | *[in]* **mat** source
  151. | *[out]* **dest** destination
  152. .. c:function:: void glm_mat4_swap_col(mat4 mat, int col1, int col2)
  153. swap two matrix columns
  154. Parameters:
  155. | *[in, out]* **mat** matrix
  156. | *[in]* **col1** col1
  157. | *[in]* **col2** col2
  158. .. c:function:: void glm_mat4_swap_row(mat4 mat, int row1, int row2)
  159. swap two matrix rows
  160. Parameters:
  161. | *[in, out]* **mat** matrix
  162. | *[in]* **row1** row1
  163. | *[in]* **row2** row2