vec2.rst 11 KB

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