mat4.rst 6.0 KB

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