vec4.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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:: void glm_vec4_one(vec4 v)
  87. makes all members one
  88. Parameters:
  89. | *[in, out]* **v** vector
  90. .. c:function:: float glm_vec4_dot(vec4 a, vec4 b)
  91. dot product of vec4
  92. Parameters:
  93. | *[in]* **a** vector1
  94. | *[in]* **b** vector2
  95. Returns:
  96. dot product
  97. .. c:function:: float glm_vec4_norm2(vec4 v)
  98. norm * norm (magnitude) of vector
  99. we can use this func instead of calling norm * norm, because it would call
  100. sqrtf function twice but with this func we can avoid func call, maybe this is
  101. not good name for this func
  102. Parameters:
  103. | *[in]* **v** vector
  104. Returns:
  105. square of norm / magnitude
  106. .. c:function:: float glm_vec4_norm(vec4 vec)
  107. | euclidean norm (magnitude), also called L2 norm
  108. | this will give magnitude of vector in euclidean space
  109. Parameters:
  110. | *[in]* **vec** vector
  111. .. c:function:: void glm_vec4_add(vec4 a, vec4 b, vec4 dest)
  112. add a vector to b vector store result in dest
  113. Parameters:
  114. | *[in]* **a** vector1
  115. | *[in]* **b** vector2
  116. | *[out]* **dest** destination vector
  117. .. c:function:: void glm_vec4_adds(vec4 v, float s, vec4 dest)
  118. add scalar to v vector store result in dest (d = v + vec(s))
  119. Parameters:
  120. | *[in]* **v** vector
  121. | *[in]* **s** scalar
  122. | *[out]* **dest** destination vector
  123. .. c:function:: void glm_vec4_sub(vec4 a, vec4 b, vec4 dest)
  124. subtract b vector from a vector store result in dest (d = v1 - v2)
  125. Parameters:
  126. | *[in]* **a** vector1
  127. | *[in]* **b** vector2
  128. | *[out]* **dest** destination vector
  129. .. c:function:: void glm_vec4_subs(vec4 v, float s, vec4 dest)
  130. subtract scalar from v vector store result in dest (d = v - vec(s))
  131. Parameters:
  132. | *[in]* **v** vector
  133. | *[in]* **s** scalar
  134. | *[out]* **dest** destination vector
  135. .. c:function:: void glm_vec4_mul(vec4 a, vec4 b, vec4 d)
  136. multiply two vector (component-wise multiplication)
  137. Parameters:
  138. | *[in]* **a** vector1
  139. | *[in]* **b** vector2
  140. | *[out]* **dest** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3])
  141. .. c:function:: void glm_vec4_scale(vec4 v, float s, vec4 dest)
  142. multiply/scale vec4 vector with scalar: result = v * s
  143. Parameters:
  144. | *[in]* **v** vector
  145. | *[in]* **s** scalar
  146. | *[out]* **dest** destination vector
  147. .. c:function:: void glm_vec4_scale_as(vec4 v, float s, vec4 dest)
  148. make vec4 vector scale as specified: result = unit(v) * s
  149. Parameters:
  150. | *[in]* **v** vector
  151. | *[in]* **s** scalar
  152. | *[out]* **dest** destination vector
  153. .. c:function:: void glm_vec4_div(vec4 a, vec4 b, vec4 dest)
  154. div vector with another component-wise division: d = v1 / v2
  155. Parameters:
  156. | *[in]* **a** vector1
  157. | *[in]* **b** vector2
  158. | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3])
  159. .. c:function:: void glm_vec4_divs(vec4 v, float s, vec4 dest)
  160. div vector with scalar: d = v / s
  161. Parameters:
  162. | *[in]* **v** vector
  163. | *[in]* **s** scalar
  164. | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s, a[3] / s)
  165. .. c:function:: void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest)
  166. | add 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_vec4_subadd(vec4 a, vec4 b, vec4 dest)
  173. | sub two vectors and add result to sum
  174. | it applies += operator so dest must be initialized
  175. Parameters:
  176. | *[in]* **a** vector 1
  177. | *[in]* **b** vector 2
  178. | *[out]* **dest** dest += (a - b)
  179. .. c:function:: void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest)
  180. | mul two vectors and add result to sum
  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_vec4_muladds(vec4 a, float s, vec4 dest)
  187. | mul vector with scalar and add result to sum
  188. | it applies += operator so dest must be initialized
  189. Parameters:
  190. | *[in]* **a** vector
  191. | *[in]* **s** scalar
  192. | *[out]* **dest** dest += (a * b)
  193. .. c:function:: void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest)
  194. | add max of two vector to result/dest
  195. | it applies += operator so dest must be initialized
  196. Parameters:
  197. | *[in]* **a** vector 1
  198. | *[in]* **b** vector 2
  199. | *[out]* **dest** dest += (a * b)
  200. .. c:function:: void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest)
  201. | add min of two vector to result/dest
  202. | it applies += operator so dest must be initialized
  203. Parameters:
  204. | *[in]* **a** vector 1
  205. | *[in]* **b** vector 2
  206. | *[out]* **dest** dest += (a * b)
  207. .. c:function:: void glm_vec4_flipsign(vec4 v)
  208. **DEPRECATED!**
  209. use :c:func:`glm_vec4_negate`
  210. Parameters:
  211. | *[in, out]* **v** vector
  212. .. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest)
  213. **DEPRECATED!**
  214. use :c:func:`glm_vec4_negate_to`
  215. Parameters:
  216. | *[in]* **v** vector
  217. | *[out]* **dest** negated vector
  218. .. c:function:: void glm_vec4_inv(vec4 v)
  219. **DEPRECATED!**
  220. use :c:func:`glm_vec4_negate`
  221. Parameters:
  222. | *[in, out]* **v** vector
  223. .. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest)
  224. **DEPRECATED!**
  225. use :c:func:`glm_vec4_negate_to`
  226. Parameters:
  227. | *[in]* **v** source
  228. | *[out]* **dest** destination
  229. .. c:function:: void glm_vec4_negate(vec4 v)
  230. negate vector components
  231. Parameters:
  232. | *[in, out]* **v** vector
  233. .. c:function:: void glm_vec4_negate_to(vec4 v, vec4 dest)
  234. negate vector components and store result in dest
  235. Parameters:
  236. | *[in]* **v** vector
  237. | *[out]* **dest** negated vector
  238. .. c:function:: void glm_vec4_normalize(vec4 v)
  239. normalize vec4 and store result in same vec
  240. Parameters:
  241. | *[in, out]* **v** vector
  242. .. c:function:: void glm_vec4_normalize_to(vec4 vec, vec4 dest)
  243. normalize vec4 to dest
  244. Parameters:
  245. | *[in]* **vec** source
  246. | *[out]* **dest** destination
  247. .. c:function:: float glm_vec4_distance(vec4 v1, vec4 v2)
  248. distance between two vectors
  249. Parameters:
  250. | *[in]* **mat** vector1
  251. | *[in]* **row1** vector2
  252. Returns:
  253. | distance
  254. .. c:function:: void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest)
  255. max values of vectors
  256. Parameters:
  257. | *[in]* **v1** vector1
  258. | *[in]* **v2** vector2
  259. | *[out]* **dest** destination
  260. .. c:function:: void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest)
  261. min values of vectors
  262. Parameters:
  263. | *[in]* **v1** vector1
  264. | *[in]* **v2** vector2
  265. | *[out]* **dest** destination
  266. .. c:function:: void glm_vec4_clamp(vec4 v, float minVal, float maxVal)
  267. constrain a value to lie between two further values
  268. Parameters:
  269. | *[in, out]* **v** vector
  270. | *[in]* **minVal** minimum value
  271. | *[in]* **maxVal** maximum value
  272. .. c:function:: void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest)
  273. linear interpolation between two vector
  274. | formula: from + s * (to - from)
  275. Parameters:
  276. | *[in]* **from** from value
  277. | *[in]* **to** to value
  278. | *[in]* **t** interpolant (amount) clamped between 0 and 1
  279. | *[out]* **dest** destination
  280. .. c:function:: void glm_vec4_cubic(float s, vec4 dest)
  281. helper to fill vec4 as [S^3, S^2, S, 1]
  282. Parameters:
  283. | *[in]* **s** parameter
  284. | *[out]* **dest** destination
  285. .. c:function:: void glm_vec4_make(float * __restrict src, vec4 dest)
  286. Create four dimensional vector from pointer
  287. .. note:: **@src** must contain at least 4 elements.
  288. Parameters:
  289. | *[in]* **src** pointer to an array of floats
  290. | *[out]* **dest** destination vector