mat4.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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_identity_array`
  21. #. :c:func:`glm_mat4_zero`
  22. #. :c:func:`glm_mat4_pick3`
  23. #. :c:func:`glm_mat4_pick3t`
  24. #. :c:func:`glm_mat4_ins3`
  25. #. :c:func:`glm_mat4_mul`
  26. #. :c:func:`glm_mat4_mulN`
  27. #. :c:func:`glm_mat4_mulv`
  28. #. :c:func:`glm_mat4_mulv3`
  29. #. :c:func:`glm_mat3_trace`
  30. #. :c:func:`glm_mat3_trace3`
  31. #. :c:func:`glm_mat4_quat`
  32. #. :c:func:`glm_mat4_transpose_to`
  33. #. :c:func:`glm_mat4_transpose`
  34. #. :c:func:`glm_mat4_scale_p`
  35. #. :c:func:`glm_mat4_scale`
  36. #. :c:func:`glm_mat4_det`
  37. #. :c:func:`glm_mat4_inv`
  38. #. :c:func:`glm_mat4_inv_fast`
  39. #. :c:func:`glm_mat4_swap_col`
  40. #. :c:func:`glm_mat4_swap_row`
  41. #. :c:func:`glm_mat4_rmc`
  42. Functions documentation
  43. ~~~~~~~~~~~~~~~~~~~~~~~
  44. .. c:function:: void glm_mat4_ucopy(mat4 mat, mat4 dest)
  45. copy mat4 to another one (dest). u means align is not required for dest
  46. Parameters:
  47. | *[in]* **mat** source
  48. | *[out]* **dest** destination
  49. .. c:function:: void glm_mat4_copy(mat4 mat, mat4 dest)
  50. copy mat4 to another one (dest).
  51. Parameters:
  52. | *[in]* **mat** source
  53. | *[out]* **dest** destination
  54. .. c:function:: void glm_mat4_identity(mat4 mat)
  55. copy identity mat4 to mat, or makes mat to identiy
  56. Parameters:
  57. | *[out]* **mat** matrix
  58. .. c:function:: void glm_mat4_identity_array(mat4 * __restrict mat, size_t count)
  59. make given matrix array's each element identity matrix
  60. Parameters:
  61. | *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
  62. | *[in]* **count** count of matrices
  63. .. c:function:: void glm_mat4_zero(mat4 mat)
  64. make given matrix zero
  65. Parameters:
  66. | *[in,out]* **mat** matrix to
  67. .. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest)
  68. copy upper-left of mat4 to mat3
  69. Parameters:
  70. | *[in]* **mat** source
  71. | *[out]* **dest** destination
  72. .. c:function:: void glm_mat4_pick3t(mat4 mat, mat4 dest)
  73. copy upper-left of mat4 to mat3 (transposed)
  74. the postfix t stands for transpose
  75. Parameters:
  76. | *[in]* **mat** source
  77. | *[out]* **dest** destination
  78. .. c:function:: void glm_mat4_ins3(mat3 mat, mat4 dest)
  79. copy mat3 to mat4's upper-left. this function does not fill mat4's other
  80. elements. To do that use glm_mat4.
  81. Parameters:
  82. | *[in]* **mat** source
  83. | *[out]* **dest** destination
  84. .. c:function:: void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest)
  85. multiply m1 and m2 to dest
  86. m1, m2 and dest matrices can be same matrix, it is possible to write this:
  87. .. code-block:: c
  88. mat4 m = GLM_MAT4_IDENTITY_INIT;
  89. glm_mat4_mul(m, m, m);
  90. Parameters:
  91. | *[in]* **m1** left matrix
  92. | *[in]* **m2** right matrix
  93. | *[out]* **dest** destination matrix
  94. .. c:function:: void glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest)
  95. mupliply N mat4 matrices and store result in dest
  96. | this function lets you multiply multiple (more than two or more...)
  97. | matrices
  98. | multiplication will be done in loop, this may reduce instructions
  99. | size but if **len** is too small then compiler may unroll whole loop
  100. .. code-block:: c
  101. mat m1, m2, m3, m4, res;
  102. glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res);
  103. Parameters:
  104. | *[in]* **matrices** array of mat4
  105. | *[in]* **len** matrices count
  106. | *[out]* **dest** destination matrix
  107. .. c:function:: void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest)
  108. multiply mat4 with vec4 (column vector) and store in dest vector
  109. Parameters:
  110. | *[in]* **m** mat4 (left)
  111. | *[in]* **v** vec4 (right, column vector)
  112. | *[out]* **dest** vec4 (result, column vector)
  113. .. c:function:: void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest)
  114. multiply vector with mat4's mat3 part(rotation)
  115. Parameters:
  116. | *[in]* **m** mat4 (left)
  117. | *[in]* **v** vec3 (right, column vector)
  118. | *[out]* **dest** vec3 (result, column vector)
  119. .. c:function:: void glm_mat4_trace(mat4 m)
  120. | sum of the elements on the main diagonal from upper left to the lower right
  121. Parameters:
  122. | *[in]* **m** matrix
  123. Returns:
  124. trace of matrix
  125. .. c:function:: void glm_mat4_trace3(mat4 m)
  126. | trace of matrix (rotation part)
  127. | sum of the elements on the main diagonal from upper left to the lower right
  128. Parameters:
  129. | *[in]* **m** matrix
  130. Returns:
  131. trace of matrix
  132. .. c:function:: void glm_mat4_quat(mat4 m, versor dest)
  133. convert mat4's rotation part to quaternion
  134. Parameters:
  135. | *[in]* **m** affine matrix
  136. | *[out]* **dest** destination quaternion
  137. .. c:function:: void glm_mat4_transpose_to(mat4 m, mat4 dest)
  138. transpose mat4 and store in dest
  139. source matrix will not be transposed unless dest is m
  140. Parameters:
  141. | *[in]* **m** matrix
  142. | *[out]* **dest** destination matrix
  143. .. c:function:: void glm_mat4_transpose(mat4 m)
  144. tranpose mat4 and store result in same matrix
  145. Parameters:
  146. | *[in]* **m** source
  147. | *[out]* **dest** destination matrix
  148. .. c:function:: void glm_mat4_scale_p(mat4 m, float s)
  149. scale (multiply with scalar) matrix without simd optimization
  150. Parameters:
  151. | *[in, out]* **m** matrix
  152. | *[in]* **s** scalar
  153. .. c:function:: void glm_mat4_scale(mat4 m, float s)
  154. scale (multiply with scalar) matrix
  155. THIS IS NOT SCALE TRANSFORM, use glm_scale for that.
  156. Parameters:
  157. | *[in, out]* **m** matrix
  158. | *[in]* **s** scalar
  159. .. c:function:: float glm_mat4_det(mat4 mat)
  160. mat4 determinant
  161. Parameters:
  162. | *[in]* **mat** matrix
  163. Return:
  164. | determinant
  165. .. c:function:: void glm_mat4_inv(mat4 mat, mat4 dest)
  166. inverse mat4 and store in dest
  167. Parameters:
  168. | *[in]* **mat** source
  169. | *[out]* **dest** destination matrix (inverse matrix)
  170. .. c:function:: void glm_mat4_inv_fast(mat4 mat, mat4 dest)
  171. inverse mat4 and store in dest
  172. | this func uses reciprocal approximation without extra corrections
  173. | e.g Newton-Raphson. this should work faster than normal,
  174. | to get more precise use glm_mat4_inv version.
  175. | NOTE: You will lose precision, glm_mat4_inv is more accurate
  176. Parameters:
  177. | *[in]* **mat** source
  178. | *[out]* **dest** destination
  179. .. c:function:: void glm_mat4_swap_col(mat4 mat, int col1, int col2)
  180. swap two matrix columns
  181. Parameters:
  182. | *[in, out]* **mat** matrix
  183. | *[in]* **col1** col1
  184. | *[in]* **col2** col2
  185. .. c:function:: void glm_mat4_swap_row(mat4 mat, int row1, int row2)
  186. swap two matrix rows
  187. Parameters:
  188. | *[in, out]* **mat** matrix
  189. | *[in]* **row1** row1
  190. | *[in]* **row2** row2
  191. .. c:function:: float glm_mat4_rmc(vec4 r, mat4 m, vec4 c)
  192. | **rmc** stands for **Row** * **Matrix** * **Column**
  193. | helper for R (row vector) * M (matrix) * C (column vector)
  194. | the result is scalar because R * M = Matrix1x4 (row vector),
  195. | then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar)
  196. Parameters:
  197. | *[in]* **r** row vector or matrix1x4
  198. | *[in]* **m** matrix4x4
  199. | *[in]* **c** column vector or matrix4x1
  200. Returns:
  201. scalar value e.g. Matrix1x1