vec3.rst 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. .. default-domain:: C
  2. vec3
  3. ====
  4. Header: cglm/vec3.h
  5. We mostly use vectors in graphics math, to make writing code faster
  6. and easy to read, some *vec3* functions are aliased in global namespace.
  7. For instance :c:func:`glm_dot` is alias of :c:func:`glm_vec_dot`,
  8. alias means inline wrapper here. There is no call verison of alias functions
  9. There are also functions for rotating *vec3* vector. **_m4**, **_m3** prefixes
  10. rotate *vec3* with matrix.
  11. Table of contents (click to go):
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. Macros:
  14. 1. glm_vec_dup(v, dest)
  15. #. GLM_VEC3_ONE_INIT
  16. #. GLM_VEC3_ZERO_INIT
  17. #. GLM_VEC3_ONE
  18. #. GLM_VEC3_ZERO
  19. #. GLM_YUP
  20. #. GLM_ZUP
  21. #. GLM_XUP
  22. Functions:
  23. 1. :c:func:`glm_vec3`
  24. #. :c:func:`glm_vec_copy`
  25. #. :c:func:`glm_vec_dot`
  26. #. :c:func:`glm_vec_cross`
  27. #. :c:func:`glm_vec_norm2`
  28. #. :c:func:`glm_vec_norm`
  29. #. :c:func:`glm_vec_add`
  30. #. :c:func:`glm_vec_sub`
  31. #. :c:func:`glm_vec_scale`
  32. #. :c:func:`glm_vec_scale_as`
  33. #. :c:func:`glm_vec_flipsign`
  34. #. :c:func:`glm_vec_inv`
  35. #. :c:func:`glm_vec_inv_to`
  36. #. :c:func:`glm_vec_normalize`
  37. #. :c:func:`glm_vec_normalize_to`
  38. #. :c:func:`glm_vec_distance`
  39. #. :c:func:`glm_vec_angle`
  40. #. :c:func:`glm_vec_rotate`
  41. #. :c:func:`glm_vec_rotate_m4`
  42. #. :c:func:`glm_vec_proj`
  43. #. :c:func:`glm_vec_center`
  44. #. :c:func:`glm_vec_maxv`
  45. #. :c:func:`glm_vec_minv`
  46. #. :c:func:`glm_vec_ortho`
  47. Functions documentation
  48. ~~~~~~~~~~~~~~~~~~~~~~~
  49. .. c:function:: void glm_vec3(vec4 v4, vec3 dest)
  50. init vec3 using vec4
  51. Parameters:
  52. | *[in]* **v4** vector4
  53. | *[out]* **dest** destination
  54. .. c:function:: void glm_vec_copy(vec3 a, vec3 dest)
  55. copy all members of [a] to [dest]
  56. Parameters:
  57. | *[in]* **a** source
  58. | *[out]* **dest** destination
  59. .. c:function:: float glm_vec_dot(vec3 a, vec3 b)
  60. dot product of vec3
  61. Parameters:
  62. | *[in]* **a** vector1
  63. | *[in]* **b** vector2
  64. Returns:
  65. dot product
  66. .. c:function:: void glm_vec_cross(vec3 a, vec3 b, vec3 d)
  67. cross product
  68. Parameters:
  69. | *[in]* **a** source 1
  70. | *[in]* **b** source 2
  71. | *[out]* **d** destination
  72. .. c:function:: float glm_vec_norm2(vec3 v)
  73. norm * norm (magnitude) of vector
  74. we can use this func instead of calling norm * norm, because it would call
  75. sqrtf fuction twice but with this func we can avoid func call, maybe this is
  76. not good name for this func
  77. Parameters:
  78. | *[in]* **v** vector
  79. Returns:
  80. square of norm / magnitude
  81. .. c:function:: float glm_vec_norm(vec3 vec)
  82. norm (magnitude) of vec3
  83. Parameters:
  84. | *[in]* **vec** vector
  85. .. c:function:: void glm_vec_add(vec3 v1, vec3 v2, vec3 dest)
  86. add v2 vector to v1 vector store result in dest
  87. Parameters:
  88. | *[in]* **v1** vector1
  89. | *[in]* **v2** vector2
  90. | *[out]* **dest** destination vector
  91. .. c:function:: void glm_vec_sub(vec3 v1, vec3 v2, vec3 dest)
  92. subtract v2 vector from v1 vector store result in dest
  93. Parameters:
  94. | *[in]* **v1** vector1
  95. | *[in]* **v2** vector2
  96. | *[out]* **dest** destination vector
  97. .. c:function:: void glm_vec_scale(vec3 v, float s, vec3 dest)
  98. multiply/scale vec3 vector with scalar: result = v * s
  99. Parameters:
  100. | *[in]* **v** vector
  101. | *[in]* **s** scalar
  102. | *[out]* **dest** destination vector
  103. .. c:function:: void glm_vec_scale_as(vec3 v, float s, vec3 dest)
  104. make vec3 vector scale as specified: result = unit(v) * s
  105. Parameters:
  106. | *[in]* **v** vector
  107. | *[in]* **s** scalar
  108. | *[out]* **dest** destination vector
  109. .. c:function:: void glm_vec_flipsign(vec3 v)
  110. flip sign of all vec3 members
  111. Parameters:
  112. | *[in, out]* **v** vector
  113. .. c:function:: void glm_vec_inv(vec3 v)
  114. make vector as inverse/opposite of itself
  115. Parameters:
  116. | *[in, out]* **v** vector
  117. .. c:function:: void glm_vec_inv_to(vec3 v, vec3 dest)
  118. inverse/opposite vector
  119. Parameters:
  120. | *[in]* **v** source
  121. | *[out]* **dest** destination
  122. .. c:function:: void glm_vec_normalize(vec3 v)
  123. normalize vec3 and store result in same vec
  124. Parameters:
  125. | *[in, out]* **v** vector
  126. .. c:function:: void glm_vec_normalize_to(vec3 vec, vec3 dest)
  127. normalize vec3 to dest
  128. Parameters:
  129. | *[in]* **vec** source
  130. | *[out]* **dest** destination
  131. .. c:function:: float glm_vec_angle(vec3 v1, vec3 v2)
  132. angle betwen two vector
  133. Parameters:
  134. | *[in]* **v1** vector1
  135. | *[in]* **v2** vector2
  136. Return:
  137. | angle as radians
  138. .. c:function:: void glm_vec_rotate(vec3 v, float angle, vec3 axis)
  139. rotate vec3 around axis by angle using Rodrigues' rotation formula
  140. Parameters:
  141. | *[in, out]* **v** vector
  142. | *[in]* **axis** axis vector (must be unit vector)
  143. | *[out]* **angle** angle (radians)
  144. .. c:function:: void glm_vec_rotate_m4(mat4 m, vec3 v, vec3 dest)
  145. apply rotation matrix to vector
  146. Parameters:
  147. | *[in]* **m** affine matrix or rot matrix
  148. | *[in]* **v** vector
  149. | *[out]* **dest** rotated vector
  150. .. c:function:: void glm_vec_proj(vec3 a, vec3 b, vec3 dest)
  151. project a vector onto b vector
  152. Parameters:
  153. | *[in]* **a** vector1
  154. | *[in]* **b** vector2
  155. | *[out]* **dest** projected vector
  156. .. c:function:: void glm_vec_center(vec3 v1, vec3 v2, vec3 dest)
  157. find center point of two vector
  158. Parameters:
  159. | *[in]* **v1** vector1
  160. | *[in]* **v2** vector2
  161. | *[out]* **dest** center point
  162. .. c:function:: float glm_vec_distance(vec3 v1, vec3 v2)
  163. distance between two vectors
  164. Parameters:
  165. | *[in]* **mat** vector1
  166. | *[in]* **row1** vector2
  167. Returns:
  168. | distance
  169. .. c:function:: void glm_vec_maxv(vec3 v1, vec3 v2, vec3 dest)
  170. max values of vectors
  171. Parameters:
  172. | *[in]* **v1** vector1
  173. | *[in]* **v2** vector2
  174. | *[out]* **dest** destination
  175. .. c:function:: void glm_vec_minv(vec3 v1, vec3 v2, vec3 dest)
  176. min values of vectors
  177. Parameters:
  178. | *[in]* **v1** vector1
  179. | *[in]* **v2** vector2
  180. | *[out]* **dest** destination
  181. .. c:function:: void glm_vec_ortho(vec3 v, vec3 dest)
  182. possible orthogonal/perpendicular vector
  183. Parameters:
  184. | *[in]* **mat** vector
  185. | *[out]* **dest** orthogonal/perpendicular vector