vec2.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. .. default-domain:: C
  2. vec2
  3. ====
  4. Header: cglm/vec2.h
  5. Table of contents (click to go):
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. Macros:
  8. 1. GLM_vec2_ONE_INIT
  9. #. GLM_vec2_ZERO_INIT
  10. #. GLM_vec2_ONE
  11. #. GLM_vec2_ZERO
  12. Functions:
  13. 1. :c:func:`glm_vec2`
  14. #. :c:func:`glm_vec2_copy`
  15. #. :c:func:`glm_vec2_zero`
  16. #. :c:func:`glm_vec2_one`
  17. #. :c:func:`glm_vec2_dot`
  18. #. :c:func:`glm_vec2_cross`
  19. #. :c:func:`glm_vec2_norm2`
  20. #. :c:func:`glm_vec2_norm`
  21. #. :c:func:`glm_vec2_add`
  22. #. :c:func:`glm_vec2_adds`
  23. #. :c:func:`glm_vec2_sub`
  24. #. :c:func:`glm_vec2_subs`
  25. #. :c:func:`glm_vec2_mul`
  26. #. :c:func:`glm_vec2_scale`
  27. #. :c:func:`glm_vec2_scale_as`
  28. #. :c:func:`glm_vec2_div`
  29. #. :c:func:`glm_vec2_divs`
  30. #. :c:func:`glm_vec2_addadd`
  31. #. :c:func:`glm_vec2_subadd`
  32. #. :c:func:`glm_vec2_muladd`
  33. #. :c:func:`glm_vec2_muladds`
  34. #. :c:func:`glm_vec2_maxadd`
  35. #. :c:func:`glm_vec2_minadd`
  36. #. :c:func:`glm_vec2_negate`
  37. #. :c:func:`glm_vec2_negate_to`
  38. #. :c:func:`glm_vec2_normalize`
  39. #. :c:func:`glm_vec2_normalize_to`
  40. #. :c:func:`glm_vec2_rotate`
  41. #. :c:func:`glm_vec2_distance2`
  42. #. :c:func:`glm_vec2_distance`
  43. #. :c:func:`glm_vec2_maxv`
  44. #. :c:func:`glm_vec2_minv`
  45. #. :c:func:`glm_vec2_clamp`
  46. #. :c:func:`glm_vec2_lerp`
  47. Functions documentation
  48. ~~~~~~~~~~~~~~~~~~~~~~~
  49. .. c:function:: void glm_vec2(float * v, vec2 dest)
  50. init vec2 using vec3 or vec4
  51. Parameters:
  52. | *[in]* **v** vector
  53. | *[out]* **dest** destination
  54. .. c:function:: void glm_vec2_copy(vec2 a, vec2 dest)
  55. copy all members of [a] to [dest]
  56. Parameters:
  57. | *[in]* **a** source
  58. | *[out]* **dest** destination
  59. .. c:function:: void glm_vec2_zero(vec2 v)
  60. makes all members 0.0f (zero)
  61. Parameters:
  62. | *[in, out]* **v** vector
  63. .. c:function:: void glm_vec2_one(vec2 v)
  64. makes all members 1.0f (one)
  65. Parameters:
  66. | *[in, out]* **v** vector
  67. .. c:function:: float glm_vec2_dot(vec2 a, vec2 b)
  68. dot product of vec2
  69. Parameters:
  70. | *[in]* **a** vector1
  71. | *[in]* **b** vector2
  72. Returns:
  73. dot product
  74. .. c:function:: void glm_vec2_cross(vec2 a, vec2 b, vec2 d)
  75. cross product of two vector (RH)
  76. | ref: http://allenchou.net/2013/07/cross-product-of-2d-vectors/
  77. Parameters:
  78. | *[in]* **a** vector 1
  79. | *[in]* **b** vector 2
  80. | *[out]* **dest** destination
  81. Returns:
  82. Z component of cross product
  83. .. c:function:: float glm_vec2_norm2(vec2 v)
  84. norm * norm (magnitude) of vector
  85. we can use this func instead of calling norm * norm, because it would call
  86. sqrtf fuction twice but with this func we can avoid func call, maybe this is
  87. not good name for this func
  88. Parameters:
  89. | *[in]* **v** vector
  90. Returns:
  91. square of norm / magnitude
  92. .. c:function:: float glm_vec2_norm(vec2 vec)
  93. | euclidean norm (magnitude), also called L2 norm
  94. | this will give magnitude of vector in euclidean space
  95. Parameters:
  96. | *[in]* **vec** vector
  97. .. c:function:: void glm_vec2_add(vec2 a, vec2 b, vec2 dest)
  98. add a vector to b vector store result in dest
  99. Parameters:
  100. | *[in]* **a** vector1
  101. | *[in]* **b** vector2
  102. | *[out]* **dest** destination vector
  103. .. c:function:: void glm_vec2_adds(vec2 a, float s, vec2 dest)
  104. add scalar to v vector store result in dest (d = v + vec(s))
  105. Parameters:
  106. | *[in]* **v** vector
  107. | *[in]* **s** scalar
  108. | *[out]* **dest** destination vector
  109. .. c:function:: void glm_vec2_sub(vec2 v1, vec2 v2, vec2 dest)
  110. subtract b vector from a vector store result in dest (d = v1 - v2)
  111. Parameters:
  112. | *[in]* **a** vector1
  113. | *[in]* **b** vector2
  114. | *[out]* **dest** destination vector
  115. .. c:function:: void glm_vec2_subs(vec2 v, float s, vec2 dest)
  116. subtract scalar from v vector store result in dest (d = v - vec(s))
  117. Parameters:
  118. | *[in]* **v** vector
  119. | *[in]* **s** scalar
  120. | *[out]* **dest** destination vector
  121. .. c:function:: void glm_vec2_mul(vec2 a, vec2 b, vec2 d)
  122. multiply two vector (component-wise multiplication)
  123. Parameters:
  124. | *[in]* **a** vector
  125. | *[in]* **b** scalar
  126. | *[out]* **d** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2])
  127. .. c:function:: void glm_vec2_scale(vec2 v, float s, vec2 dest)
  128. multiply/scale vec2 vector with scalar: result = v * s
  129. Parameters:
  130. | *[in]* **v** vector
  131. | *[in]* **s** scalar
  132. | *[out]* **dest** destination vector
  133. .. c:function:: void glm_vec2_scale_as(vec2 v, float s, vec2 dest)
  134. make vec2 vector scale as specified: result = unit(v) * s
  135. Parameters:
  136. | *[in]* **v** vector
  137. | *[in]* **s** scalar
  138. | *[out]* **dest** destination vector
  139. .. c:function:: void glm_vec2_div(vec2 a, vec2 b, vec2 dest)
  140. div vector with another component-wise division: d = a / b
  141. Parameters:
  142. | *[in]* **a** vector 1
  143. | *[in]* **b** vector 2
  144. | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2])
  145. .. c:function:: void glm_vec2_divs(vec2 v, float s, vec2 dest)
  146. div vector with scalar: d = v / s
  147. Parameters:
  148. | *[in]* **v** vector
  149. | *[in]* **s** scalar
  150. | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s])
  151. .. c:function:: void glm_vec2_addadd(vec2 a, vec2 b, vec2 dest)
  152. | add two vectors and add result to sum
  153. | it applies += operator so dest must be initialized
  154. Parameters:
  155. | *[in]* **a** vector 1
  156. | *[in]* **b** vector 2
  157. | *[out]* **dest** dest += (a + b)
  158. .. c:function:: void glm_vec2_subadd(vec2 a, vec2 b, vec2 dest)
  159. | sub two vectors and add result to sum
  160. | it applies += operator so dest must be initialized
  161. Parameters:
  162. | *[in]* **a** vector 1
  163. | *[in]* **b** vector 2
  164. | *[out]* **dest** dest += (a - b)
  165. .. c:function:: void glm_vec2_muladd(vec2 a, vec2 b, vec2 dest)
  166. | mul two vectors and add result to sum
  167. | it applies += operator so dest must be initialized
  168. Parameters:
  169. | *[in]* **a** vector 1
  170. | *[in]* **b** vector 2
  171. | *[out]* **dest** dest += (a * b)
  172. .. c:function:: void glm_vec2_muladds(vec2 a, float s, vec2 dest)
  173. | mul vector with scalar and add result to sum
  174. | it applies += operator so dest must be initialized
  175. Parameters:
  176. | *[in]* **a** vector
  177. | *[in]* **s** scalar
  178. | *[out]* **dest** dest += (a * b)
  179. .. c:function:: void glm_vec2_maxadd(vec2 a, vec2 b, vec2 dest)
  180. | add max of two vector to result/dest
  181. | it applies += operator so dest must be initialized
  182. Parameters:
  183. | *[in]* **a** vector 1
  184. | *[in]* **b** vector 2
  185. | *[out]* **dest** dest += (a * b)
  186. .. c:function:: void glm_vec2_minadd(vec2 a, vec2 b, vec2 dest)
  187. | add min of two vector to result/dest
  188. | it applies += operator so dest must be initialized
  189. Parameters:
  190. | *[in]* **a** vector 1
  191. | *[in]* **b** vector 2
  192. | *[out]* **dest** dest += (a * b)
  193. .. c:function:: void glm_vec2_negate(vec2 v)
  194. negate vector components
  195. Parameters:
  196. | *[in, out]* **v** vector
  197. .. c:function:: void glm_vec2_negate_to(vec2 v, vec2 dest)
  198. negate vector components and store result in dest
  199. Parameters:
  200. | *[in]* **v** vector
  201. | *[out]* **dest** negated vector
  202. .. c:function:: void glm_vec2_normalize(vec2 v)
  203. normalize vec2 and store result in same vec
  204. Parameters:
  205. | *[in, out]* **v** vector
  206. .. c:function:: void glm_vec2_normalize_to(vec2 vec, vec2 dest)
  207. normalize vec2 to dest
  208. Parameters:
  209. | *[in]* **vec** source
  210. | *[out]* **dest** destination
  211. .. c:function:: void glm_vec2_rotate(vec2 v, float angle, vec2 dest)
  212. rotate vec2 around axis by angle using Rodrigues' rotation formula
  213. Parameters:
  214. | *[in]* **v** vector
  215. | *[in]* **axis** axis vector
  216. | *[out]* **dest** destination
  217. .. c:function:: float glm_vec2_distance2(vec2 v1, vec2 v2)
  218. squared distance between two vectors
  219. Parameters:
  220. | *[in]* **mat** vector1
  221. | *[in]* **row1** vector2
  222. Returns:
  223. | squared distance (distance * distance)
  224. .. c:function:: float glm_vec2_distance(vec2 v1, vec2 v2)
  225. distance between two vectors
  226. Parameters:
  227. | *[in]* **mat** vector1
  228. | *[in]* **row1** vector2
  229. Returns:
  230. | distance
  231. .. c:function:: void glm_vec2_maxv(vec2 v1, vec2 v2, vec2 dest)
  232. max values of vectors
  233. Parameters:
  234. | *[in]* **v1** vector1
  235. | *[in]* **v2** vector2
  236. | *[out]* **dest** destination
  237. .. c:function:: void glm_vec2_minv(vec2 v1, vec2 v2, vec2 dest)
  238. min values of vectors
  239. Parameters:
  240. | *[in]* **v1** vector1
  241. | *[in]* **v2** vector2
  242. | *[out]* **dest** destination
  243. .. c:function:: void glm_vec2_clamp(vec2 v, float minVal, float maxVal)
  244. constrain a value to lie between two further values
  245. Parameters:
  246. | *[in, out]* **v** vector
  247. | *[in]* **minVal** minimum value
  248. | *[in]* **maxVal** maximum value
  249. .. c:function:: void glm_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest)
  250. linear interpolation between two vector
  251. | formula: from + s * (to - from)
  252. Parameters:
  253. | *[in]* **from** from value
  254. | *[in]* **to** to value
  255. | *[in]* **t** interpolant (amount) clamped between 0 and 1
  256. | *[out]* **dest** destination