vec2.rst 9.7 KB

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