mat4.rst 7.0 KB

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