mat4.rst 6.5 KB

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