mat4.rst 8.8 KB

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