vec4.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. .. default-domain:: C
  2. vec4
  3. ====
  4. Header: cglm/vec4.h
  5. Table of contents (click to go):
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. Macros:
  8. 1. glm_vec4_dup3(v, dest)
  9. #. glm_vec4_dup(v, dest)
  10. #. GLM_VEC4_ONE_INIT
  11. #. GLM_VEC4_BLACK_INIT
  12. #. GLM_VEC4_ZERO_INIT
  13. #. GLM_VEC4_ONE
  14. #. GLM_VEC4_BLACK
  15. #. GLM_VEC4_ZERO
  16. Functions:
  17. 1. :c:func:`glm_vec4`
  18. #. :c:func:`glm_vec4_copy3`
  19. #. :c:func:`glm_vec4_copy`
  20. #. :c:func:`glm_vec4_ucopy`
  21. #. :c:func:`glm_vec4_zero`
  22. #. :c:func:`glm_vec4_one`
  23. #. :c:func:`glm_vec4_dot`
  24. #. :c:func:`glm_vec4_norm2`
  25. #. :c:func:`glm_vec4_norm`
  26. #. :c:func:`glm_vec4_add`
  27. #. :c:func:`glm_vec4_adds`
  28. #. :c:func:`glm_vec4_sub`
  29. #. :c:func:`glm_vec4_subs`
  30. #. :c:func:`glm_vec4_mul`
  31. #. :c:func:`glm_vec4_scale`
  32. #. :c:func:`glm_vec4_scale_as`
  33. #. :c:func:`glm_vec4_div`
  34. #. :c:func:`glm_vec4_divs`
  35. #. :c:func:`glm_vec4_addadd`
  36. #. :c:func:`glm_vec4_subadd`
  37. #. :c:func:`glm_vec4_muladd`
  38. #. :c:func:`glm_vec4_muladds`
  39. #. :c:func:`glm_vec4_maxadd`
  40. #. :c:func:`glm_vec4_minadd`
  41. #. :c:func:`glm_vec4_flipsign`
  42. #. :c:func:`glm_vec4_flipsign_to`
  43. #. :c:func:`glm_vec4_inv`
  44. #. :c:func:`glm_vec4_inv_to`
  45. #. :c:func:`glm_vec4_negate`
  46. #. :c:func:`glm_vec4_negate_to`
  47. #. :c:func:`glm_vec4_normalize`
  48. #. :c:func:`glm_vec4_normalize_to`
  49. #. :c:func:`glm_vec4_distance`
  50. #. :c:func:`glm_vec4_maxv`
  51. #. :c:func:`glm_vec4_minv`
  52. #. :c:func:`glm_vec4_clamp`
  53. #. :c:func:`glm_vec4_lerp`
  54. #. :c:func:`glm_vec4_cubic`
  55. #. :c:func:`glm_vec4_make`
  56. Functions documentation
  57. ~~~~~~~~~~~~~~~~~~~~~~~
  58. .. c:function:: void glm_vec4(vec3 v3, float last, vec4 dest)
  59. init vec4 using vec3, since you are initializing vec4 with vec3
  60. you need to set last item. cglm could set it zero but making it parameter
  61. gives more control
  62. Parameters:
  63. | *[in]* **v3** vector4
  64. | *[in]* **last** last item of vec4
  65. | *[out]* **dest** destination
  66. .. c:function:: void glm_vec4_copy3(vec4 a, vec3 dest)
  67. copy first 3 members of [a] to [dest]
  68. Parameters:
  69. | *[in]* **a** source
  70. | *[out]* **dest** destination
  71. .. c:function:: void glm_vec4_copy(vec4 v, vec4 dest)
  72. copy all members of [a] to [dest]
  73. Parameters:
  74. | *[in]* **v** source
  75. | *[in]* **dest** destination
  76. .. c:function:: void glm_vec4_ucopy(vec4 v, vec4 dest)
  77. copy all members of [a] to [dest]
  78. | alignment is not required
  79. Parameters:
  80. | *[in]* **v** source
  81. | *[in]* **dest** destination
  82. .. c:function:: void glm_vec4_zero(vec4 v)
  83. makes all members zero
  84. Parameters:
  85. | *[in, out]* **v** vector
  86. .. c:function:: float glm_vec4_dot(vec4 a, vec4 b)
  87. dot product of vec4
  88. Parameters:
  89. | *[in]* **a** vector1
  90. | *[in]* **b** vector2
  91. Returns:
  92. dot product
  93. .. c:function:: float glm_vec4_norm2(vec4 v)
  94. norm * norm (magnitude) of vector
  95. we can use this func instead of calling norm * norm, because it would call
  96. sqrtf fuction twice but with this func we can avoid func call, maybe this is
  97. not good name for this func
  98. Parameters:
  99. | *[in]* **v** vector
  100. Returns:
  101. square of norm / magnitude
  102. .. c:function:: float glm_vec4_norm(vec4 vec)
  103. | euclidean norm (magnitude), also called L2 norm
  104. | this will give magnitude of vector in euclidean space
  105. Parameters:
  106. | *[in]* **vec** vector
  107. .. c:function:: void glm_vec4_add(vec4 a, vec4 b, vec4 dest)
  108. add a vector to b vector store result in dest
  109. Parameters:
  110. | *[in]* **a** vector1
  111. | *[in]* **b** vector2
  112. | *[out]* **dest** destination vector
  113. .. c:function:: void glm_vec4_adds(vec4 v, float s, vec4 dest)
  114. add scalar to v vector store result in dest (d = v + vec(s))
  115. Parameters:
  116. | *[in]* **v** vector
  117. | *[in]* **s** scalar
  118. | *[out]* **dest** destination vector
  119. .. c:function:: void glm_vec4_sub(vec4 a, vec4 b, vec4 dest)
  120. subtract b vector from a vector store result in dest (d = v1 - v2)
  121. Parameters:
  122. | *[in]* **a** vector1
  123. | *[in]* **b** vector2
  124. | *[out]* **dest** destination vector
  125. .. c:function:: void glm_vec4_subs(vec4 v, float s, vec4 dest)
  126. subtract scalar from v vector store result in dest (d = v - vec(s))
  127. Parameters:
  128. | *[in]* **v** vector
  129. | *[in]* **s** scalar
  130. | *[out]* **dest** destination vector
  131. .. c:function:: void glm_vec4_mul(vec4 a, vec4 b, vec4 d)
  132. multiply two vector (component-wise multiplication)
  133. Parameters:
  134. | *[in]* **a** vector1
  135. | *[in]* **b** vector2
  136. | *[out]* **dest** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3])
  137. .. c:function:: void glm_vec4_scale(vec4 v, float s, vec4 dest)
  138. multiply/scale vec4 vector with scalar: result = v * s
  139. Parameters:
  140. | *[in]* **v** vector
  141. | *[in]* **s** scalar
  142. | *[out]* **dest** destination vector
  143. .. c:function:: void glm_vec4_scale_as(vec4 v, float s, vec4 dest)
  144. make vec4 vector scale as specified: result = unit(v) * s
  145. Parameters:
  146. | *[in]* **v** vector
  147. | *[in]* **s** scalar
  148. | *[out]* **dest** destination vector
  149. .. c:function:: void glm_vec4_div(vec4 a, vec4 b, vec4 dest)
  150. div vector with another component-wise division: d = v1 / v2
  151. Parameters:
  152. | *[in]* **a** vector1
  153. | *[in]* **b** vector2
  154. | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3])
  155. .. c:function:: void glm_vec4_divs(vec4 v, float s, vec4 dest)
  156. div vector with scalar: d = v / s
  157. Parameters:
  158. | *[in]* **v** vector
  159. | *[in]* **s** scalar
  160. | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s, a[3] / s)
  161. .. c:function:: void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest)
  162. | add two vectors and add result to sum
  163. | it applies += operator so dest must be initialized
  164. Parameters:
  165. | *[in]* **a** vector 1
  166. | *[in]* **b** vector 2
  167. | *[out]* **dest** dest += (a + b)
  168. .. c:function:: void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest)
  169. | sub two vectors and add result to sum
  170. | it applies += operator so dest must be initialized
  171. Parameters:
  172. | *[in]* **a** vector 1
  173. | *[in]* **b** vector 2
  174. | *[out]* **dest** dest += (a - b)
  175. .. c:function:: void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest)
  176. | mul two vectors and add result to sum
  177. | it applies += operator so dest must be initialized
  178. Parameters:
  179. | *[in]* **a** vector 1
  180. | *[in]* **b** vector 2
  181. | *[out]* **dest** dest += (a * b)
  182. .. c:function:: void glm_vec4_muladds(vec4 a, float s, vec4 dest)
  183. | mul vector with scalar and add result to sum
  184. | it applies += operator so dest must be initialized
  185. Parameters:
  186. | *[in]* **a** vector
  187. | *[in]* **s** scalar
  188. | *[out]* **dest** dest += (a * b)
  189. .. c:function:: void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest)
  190. | add max of two vector to result/dest
  191. | it applies += operator so dest must be initialized
  192. Parameters:
  193. | *[in]* **a** vector 1
  194. | *[in]* **b** vector 2
  195. | *[out]* **dest** dest += (a * b)
  196. .. c:function:: void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest)
  197. | add min of two vector to result/dest
  198. | it applies += operator so dest must be initialized
  199. Parameters:
  200. | *[in]* **a** vector 1
  201. | *[in]* **b** vector 2
  202. | *[out]* **dest** dest += (a * b)
  203. .. c:function:: void glm_vec4_flipsign(vec4 v)
  204. **DEPRACATED!**
  205. use :c:func:`glm_vec4_negate`
  206. Parameters:
  207. | *[in, out]* **v** vector
  208. .. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest)
  209. **DEPRACATED!**
  210. use :c:func:`glm_vec4_negate_to`
  211. Parameters:
  212. | *[in]* **v** vector
  213. | *[out]* **dest** negated vector
  214. .. c:function:: void glm_vec4_inv(vec4 v)
  215. **DEPRACATED!**
  216. use :c:func:`glm_vec4_negate`
  217. Parameters:
  218. | *[in, out]* **v** vector
  219. .. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest)
  220. **DEPRACATED!**
  221. use :c:func:`glm_vec4_negate_to`
  222. Parameters:
  223. | *[in]* **v** source
  224. | *[out]* **dest** destination
  225. .. c:function:: void glm_vec4_negate(vec4 v)
  226. negate vector components
  227. Parameters:
  228. | *[in, out]* **v** vector
  229. .. c:function:: void glm_vec4_negate_to(vec4 v, vec4 dest)
  230. negate vector components and store result in dest
  231. Parameters:
  232. | *[in]* **v** vector
  233. | *[out]* **dest** negated vector
  234. .. c:function:: void glm_vec4_normalize(vec4 v)
  235. normalize vec4 and store result in same vec
  236. Parameters:
  237. | *[in, out]* **v** vector
  238. .. c:function:: void glm_vec4_normalize_to(vec4 vec, vec4 dest)
  239. normalize vec4 to dest
  240. Parameters:
  241. | *[in]* **vec** source
  242. | *[out]* **dest** destination
  243. .. c:function:: float glm_vec4_distance(vec4 v1, vec4 v2)
  244. distance between two vectors
  245. Parameters:
  246. | *[in]* **mat** vector1
  247. | *[in]* **row1** vector2
  248. Returns:
  249. | distance
  250. .. c:function:: void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest)
  251. max values of vectors
  252. Parameters:
  253. | *[in]* **v1** vector1
  254. | *[in]* **v2** vector2
  255. | *[out]* **dest** destination
  256. .. c:function:: void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest)
  257. min values of vectors
  258. Parameters:
  259. | *[in]* **v1** vector1
  260. | *[in]* **v2** vector2
  261. | *[out]* **dest** destination
  262. .. c:function:: void glm_vec4_clamp(vec4 v, float minVal, float maxVal)
  263. constrain a value to lie between two further values
  264. Parameters:
  265. | *[in, out]* **v** vector
  266. | *[in]* **minVal** minimum value
  267. | *[in]* **maxVal** maximum value
  268. .. c:function:: void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest)
  269. linear interpolation between two vector
  270. | formula: from + s * (to - from)
  271. Parameters:
  272. | *[in]* **from** from value
  273. | *[in]* **to** to value
  274. | *[in]* **t** interpolant (amount) clamped between 0 and 1
  275. | *[out]* **dest** destination
  276. .. c:function:: void glm_vec4_cubic(float s, vec4 dest)
  277. helper to fill vec4 as [S^3, S^2, S, 1]
  278. Parameters:
  279. | *[in]* **s** parameter
  280. | *[out]* **dest** destination
  281. .. c:function:: void glm_vec4_make(float * __restrict src, vec4 dest)
  282. Create four dimensional vector from pointer
  283. | NOTE: **@src** must contain at least 4 elements.
  284. Parameters:
  285. | *[in]* **src** pointer to an array of floats
  286. | *[out]* **dest** destination vector