affine.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. .. default-domain:: C
  2. affine transforms
  3. ================================================================================
  4. Header: cglm/affine.h
  5. Functions with **_make** prefix expect you don't have a matrix and they create
  6. a matrix for you. You don't need to pass identity matrix.
  7. But other functions expect you have a matrix and you want to transform them. If
  8. you didn't have any existing matrix you have to initialize matrix to identity
  9. before sending to transfrom functions.
  10. There are also functions to decompose transform matrix. These functions can't
  11. decompose matrix after projected.
  12. Table of contents (click to go):
  13. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. Functions:
  15. 1. :c:func:`glm_translate_to`
  16. #. :c:func:`glm_translate`
  17. #. :c:func:`glm_translate_x`
  18. #. :c:func:`glm_translate_y`
  19. #. :c:func:`glm_translate_z`
  20. #. :c:func:`glm_translate_make`
  21. #. :c:func:`glm_scale_to`
  22. #. :c:func:`glm_scale_make`
  23. #. :c:func:`glm_scale`
  24. #. :c:func:`glm_scale1`
  25. #. :c:func:`glm_scale_uni`
  26. #. :c:func:`glm_rotate_x`
  27. #. :c:func:`glm_rotate_y`
  28. #. :c:func:`glm_rotate_z`
  29. #. :c:func:`glm_rotate_ndc_make`
  30. #. :c:func:`glm_rotate_make`
  31. #. :c:func:`glm_rotate_ndc`
  32. #. :c:func:`glm_rotate`
  33. #. :c:func:`glm_decompose_scalev`
  34. #. :c:func:`glm_uniscaled`
  35. #. :c:func:`glm_decompose_rs`
  36. #. :c:func:`glm_decompose`
  37. Functions documentation
  38. ~~~~~~~~~~~~~~~~~~~~~~~
  39. .. c:function:: void glm_translate_to(mat4 m, vec3 v, mat4 dest)
  40. translate existing transform matrix by *v* vector and store result in dest
  41. Parameters:
  42. | *[in]* **m** affine transfrom
  43. | *[in]* **v** translate vector [x, y, z]
  44. | *[out]* **dest** translated matrix
  45. .. c:function:: void glm_translate(mat4 m, vec3 v)
  46. translate existing transform matrix by *v* vector
  47. and stores result in same matrix
  48. Parameters:
  49. | *[in, out]* **m** affine transfrom
  50. | *[in]* **v** translate vector [x, y, z]
  51. .. c:function:: void glm_translate_x(mat4 m, float x)
  52. translate existing transform matrix by x factor
  53. Parameters:
  54. | *[in, out]* **m** affine transfrom
  55. | *[in]* **v** x factor
  56. .. c:function:: void glm_translate_y(mat4 m, float y)
  57. translate existing transform matrix by *y* factor
  58. Parameters:
  59. | *[in, out]* **m** affine transfrom
  60. | *[in]* **v** y factor
  61. .. c:function:: void glm_translate_z(mat4 m, float z)
  62. translate existing transform matrix by *z* factor
  63. Parameters:
  64. | *[in, out]* **m** affine transfrom
  65. | *[in]* **v** z factor
  66. .. c:function:: void glm_translate_make(mat4 m, vec3 v)
  67. creates NEW translate transform matrix by *v* vector.
  68. Parameters:
  69. | *[in, out]* **m** affine transfrom
  70. | *[in]* **v** translate vector [x, y, z]
  71. .. c:function:: void glm_scale_to(mat4 m, vec3 v, mat4 dest)
  72. scale existing transform matrix by *v* vector and store result in dest
  73. Parameters:
  74. | *[in]* **m** affine transfrom
  75. | *[in]* **v** scale vector [x, y, z]
  76. | *[out]* **dest** scaled matrix
  77. .. c:function:: void glm_scale_make(mat4 m, vec3 v)
  78. creates NEW scale matrix by v vector
  79. Parameters:
  80. | *[out]* **m** affine transfrom
  81. | *[in]* **v** scale vector [x, y, z]
  82. .. c:function:: void glm_scale(mat4 m, vec3 v)
  83. scales existing transform matrix by v vector
  84. and stores result in same matrix
  85. Parameters:
  86. | *[in, out]* **m** affine transfrom
  87. | *[in]* **v** scale vector [x, y, z]
  88. .. c:function:: void glm_scale1(mat4 m, float s)
  89. DEPRECATED! Use glm_scale_uni
  90. .. c:function:: void glm_scale_uni(mat4 m, float s)
  91. applies uniform scale to existing transform matrix v = [s, s, s]
  92. and stores result in same matrix
  93. Parameters:
  94. | *[in, out]* **m** affine transfrom
  95. | *[in]* **v** scale factor
  96. .. c:function:: void glm_rotate_x(mat4 m, float angle, mat4 dest)
  97. rotate existing transform matrix around X axis by angle
  98. and store result in dest
  99. Parameters:
  100. | *[in]* **m** affine transfrom
  101. | *[in]* **angle** angle (radians)
  102. | *[out]* **dest** rotated matrix
  103. .. c:function:: void glm_rotate_y(mat4 m, float angle, mat4 dest)
  104. rotate existing transform matrix around Y axis by angle
  105. and store result in dest
  106. Parameters:
  107. | *[in]* **m** affine transfrom
  108. | *[in]* **angle** angle (radians)
  109. | *[out]* **dest** rotated matrix
  110. .. c:function:: void glm_rotate_z(mat4 m, float angle, mat4 dest)
  111. rotate existing transform matrix around Z axis by angle
  112. and store result in dest
  113. Parameters:
  114. | *[in]* **m** affine transfrom
  115. | *[in]* **angle** angle (radians)
  116. | *[out]* **dest** rotated matrix
  117. .. c:function:: void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc)
  118. creates NEW rotation matrix by angle and axis
  119. this name may change in the future. axis must be is normalized
  120. Parameters:
  121. | *[out]* **m** affine transfrom
  122. | *[in]* **angle** angle (radians)
  123. | *[in]* **axis_ndc** normalized axis
  124. .. c:function:: void glm_rotate_make(mat4 m, float angle, vec3 axis)
  125. creates NEW rotation matrix by angle and axis,
  126. axis will be normalized so you don't need to normalize it
  127. Parameters:
  128. | *[out]* **m** affine transfrom
  129. | *[in]* **axis** angle (radians)
  130. | *[in]* **axis** axis
  131. .. c:function:: void glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc)
  132. rotate existing transform matrix around Z axis by angle and axis
  133. this name may change in the future, axis must be normalized.
  134. Parameters:
  135. | *[out]* **m** affine transfrom
  136. | *[in]* **angle** angle (radians)
  137. | *[in]* **axis_ndc** normalized axis
  138. .. c:function:: void glm_rotate(mat4 m, float angle, vec3 axis)
  139. rotate existing transform matrix around Z axis by angle and axis
  140. Parameters:
  141. | *[in, out]* **m** affine transfrom
  142. | *[in]* **angle** angle (radians)
  143. | *[in]* **axis** axis
  144. .. c:function:: void glm_decompose_scalev(mat4 m, vec3 s)
  145. decompose scale vector
  146. Parameters:
  147. | *[in]* **m** affine transform
  148. | *[out]* **s** scale vector (Sx, Sy, Sz)
  149. .. c:function:: bool glm_uniscaled(mat4 m)
  150. returns true if matrix is uniform scaled.
  151. This is helpful for creating normal matrix.
  152. Parameters:
  153. | *[in]* **m** matrix
  154. .. c:function:: void glm_decompose_rs(mat4 m, mat4 r, vec3 s)
  155. decompose rotation matrix (mat4) and scale vector [Sx, Sy, Sz]
  156. DON'T pass projected matrix here
  157. Parameters:
  158. | *[in]* **m** affine transform
  159. | *[out]* **r** rotation matrix
  160. | *[out]* **s** scale matrix
  161. .. c:function:: void glm_decompose(mat4 m, vec4 t, mat4 r, vec3 s)
  162. decompose affine transform, TODO: extract shear factors.
  163. DON'T pass projected matrix here
  164. Parameters:
  165. | *[in]* **m** affine transfrom
  166. | *[out]* **t** translation vector
  167. | *[out]* **r** rotation matrix (mat4)
  168. | *[out]* **s** scaling vector [X, Y, Z]