vec4.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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_isnan`
  55. #. :c:func:`glm_vec4_isinf`
  56. #. :c:func:`glm_vec4_isvalid`
  57. #. :c:func:`glm_vec4_sign`
  58. #. :c:func:`glm_vec4_sqrt`
  59. Functions documentation
  60. ~~~~~~~~~~~~~~~~~~~~~~~
  61. .. c:function:: void glm_vec4(vec3 v3, float last, vec4 dest)
  62. init vec4 using vec3, since you are initializing vec4 with vec3
  63. you need to set last item. cglm could set it zero but making it parameter
  64. gives more control
  65. Parameters:
  66. | *[in]* **v3** vector4
  67. | *[in]* **last** last item of vec4
  68. | *[out]* **dest** destination
  69. .. c:function:: void glm_vec4_copy3(vec4 a, vec3 dest)
  70. copy first 3 members of [a] to [dest]
  71. Parameters:
  72. | *[in]* **a** source
  73. | *[out]* **dest** destination
  74. .. c:function:: void glm_vec4_copy(vec4 v, vec4 dest)
  75. copy all members of [a] to [dest]
  76. Parameters:
  77. | *[in]* **v** source
  78. | *[in]* **dest** destination
  79. .. c:function:: void glm_vec4_ucopy(vec4 v, vec4 dest)
  80. copy all members of [a] to [dest]
  81. | alignment is not required
  82. Parameters:
  83. | *[in]* **v** source
  84. | *[in]* **dest** destination
  85. .. c:function:: void glm_vec4_zero(vec4 v)
  86. makes all members zero
  87. Parameters:
  88. | *[in, out]* **v** vector
  89. .. c:function:: float glm_vec4_dot(vec4 a, vec4 b)
  90. dot product of vec4
  91. Parameters:
  92. | *[in]* **a** vector1
  93. | *[in]* **b** vector2
  94. Returns:
  95. dot product
  96. .. c:function:: float glm_vec4_norm2(vec4 v)
  97. norm * norm (magnitude) of vector
  98. we can use this func instead of calling norm * norm, because it would call
  99. sqrtf fuction twice but with this func we can avoid func call, maybe this is
  100. not good name for this func
  101. Parameters:
  102. | *[in]* **v** vector
  103. Returns:
  104. square of norm / magnitude
  105. .. c:function:: float glm_vec4_norm(vec4 vec)
  106. norm (magnitude) of vec4
  107. Parameters:
  108. | *[in]* **vec** vector
  109. .. c:function:: void glm_vec4_add(vec4 a, vec4 b, vec4 dest)
  110. add a vector to b vector store result in dest
  111. Parameters:
  112. | *[in]* **a** vector1
  113. | *[in]* **b** vector2
  114. | *[out]* **dest** destination vector
  115. .. c:function:: void glm_vec4_adds(vec4 v, float s, vec4 dest)
  116. add scalar to 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_vec4_sub(vec4 a, vec4 b, vec4 dest)
  122. subtract b vector from a vector store result in dest (d = v1 - v2)
  123. Parameters:
  124. | *[in]* **a** vector1
  125. | *[in]* **b** vector2
  126. | *[out]* **dest** destination vector
  127. .. c:function:: void glm_vec4_subs(vec4 v, float s, vec4 dest)
  128. subtract scalar from v vector store result in dest (d = v - vec(s))
  129. Parameters:
  130. | *[in]* **v** vector
  131. | *[in]* **s** scalar
  132. | *[out]* **dest** destination vector
  133. .. c:function:: void glm_vec4_mul(vec4 a, vec4 b, vec4 d)
  134. multiply two vector (component-wise multiplication)
  135. Parameters:
  136. | *[in]* **a** vector1
  137. | *[in]* **b** vector2
  138. | *[out]* **dest** result = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3])
  139. .. c:function:: void glm_vec4_scale(vec4 v, float s, vec4 dest)
  140. multiply/scale vec4 vector with scalar: result = v * s
  141. Parameters:
  142. | *[in]* **v** vector
  143. | *[in]* **s** scalar
  144. | *[out]* **dest** destination vector
  145. .. c:function:: void glm_vec4_scale_as(vec4 v, float s, vec4 dest)
  146. make vec4 vector scale as specified: result = unit(v) * s
  147. Parameters:
  148. | *[in]* **v** vector
  149. | *[in]* **s** scalar
  150. | *[out]* **dest** destination vector
  151. .. c:function:: void glm_vec4_div(vec4 a, vec4 b, vec4 dest)
  152. div vector with another component-wise division: d = v1 / v2
  153. Parameters:
  154. | *[in]* **a** vector1
  155. | *[in]* **b** vector2
  156. | *[out]* **dest** result = (a[0] / b[0], a[1] / b[1], a[2] / b[2], a[3] / b[3])
  157. .. c:function:: void glm_vec4_divs(vec4 v, float s, vec4 dest)
  158. div vector with scalar: d = v / s
  159. Parameters:
  160. | *[in]* **v** vector
  161. | *[in]* **s** scalar
  162. | *[out]* **dest** result = (a[0] / s, a[1] / s, a[2] / s, a[3] / s)
  163. .. c:function:: void glm_vec4_addadd(vec4 a, vec4 b, vec4 dest)
  164. | add two vectors and add result to sum
  165. | it applies += operator so dest must be initialized
  166. Parameters:
  167. | *[in]* **a** vector 1
  168. | *[in]* **b** vector 2
  169. | *[out]* **dest** dest += (a + b)
  170. .. c:function:: void glm_vec4_subadd(vec4 a, vec4 b, vec4 dest)
  171. | sub two vectors and add result to sum
  172. | it applies += operator so dest must be initialized
  173. Parameters:
  174. | *[in]* **a** vector 1
  175. | *[in]* **b** vector 2
  176. | *[out]* **dest** dest += (a - b)
  177. .. c:function:: void glm_vec4_muladd(vec4 a, vec4 b, vec4 dest)
  178. | mul two vectors and add result to sum
  179. | it applies += operator so dest must be initialized
  180. Parameters:
  181. | *[in]* **a** vector 1
  182. | *[in]* **b** vector 2
  183. | *[out]* **dest** dest += (a * b)
  184. .. c:function:: void glm_vec4_muladds(vec4 a, float s, vec4 dest)
  185. | mul vector with scalar and add result to sum
  186. | it applies += operator so dest must be initialized
  187. Parameters:
  188. | *[in]* **a** vector
  189. | *[in]* **s** scalar
  190. | *[out]* **dest** dest += (a * b)
  191. .. c:function:: void glm_vec4_maxadd(vec4 a, vec4 b, vec4 dest)
  192. | add max of two vector to result/dest
  193. | it applies += operator so dest must be initialized
  194. Parameters:
  195. | *[in]* **a** vector 1
  196. | *[in]* **b** vector 2
  197. | *[out]* **dest** dest += (a * b)
  198. .. c:function:: void glm_vec4_minadd(vec4 a, vec4 b, vec4 dest)
  199. | add min of two vector to result/dest
  200. | it applies += operator so dest must be initialized
  201. Parameters:
  202. | *[in]* **a** vector 1
  203. | *[in]* **b** vector 2
  204. | *[out]* **dest** dest += (a * b)
  205. .. c:function:: void glm_vec4_flipsign(vec4 v)
  206. **DEPRACATED!**
  207. use :c:func:`glm_vec4_negate`
  208. Parameters:
  209. | *[in, out]* **v** vector
  210. .. c:function:: void glm_vec4_flipsign_to(vec4 v, vec4 dest)
  211. **DEPRACATED!**
  212. use :c:func:`glm_vec4_negate_to`
  213. Parameters:
  214. | *[in]* **v** vector
  215. | *[out]* **dest** negated vector
  216. .. c:function:: void glm_vec4_inv(vec4 v)
  217. **DEPRACATED!**
  218. use :c:func:`glm_vec4_negate`
  219. Parameters:
  220. | *[in, out]* **v** vector
  221. .. c:function:: void glm_vec4_inv_to(vec4 v, vec4 dest)
  222. **DEPRACATED!**
  223. use :c:func:`glm_vec4_negate_to`
  224. Parameters:
  225. | *[in]* **v** source
  226. | *[out]* **dest** destination
  227. .. c:function:: void glm_vec4_negate(vec4 v)
  228. negate vector components
  229. Parameters:
  230. | *[in, out]* **v** vector
  231. .. c:function:: void glm_vec4_negate_to(vec4 v, vec4 dest)
  232. negate vector components and store result in dest
  233. Parameters:
  234. | *[in]* **v** vector
  235. | *[out]* **dest** negated vector
  236. .. c:function:: void glm_vec4_normalize(vec4 v)
  237. normalize vec4 and store result in same vec
  238. Parameters:
  239. | *[in, out]* **v** vector
  240. .. c:function:: void glm_vec4_normalize_to(vec4 vec, vec4 dest)
  241. normalize vec4 to dest
  242. Parameters:
  243. | *[in]* **vec** source
  244. | *[out]* **dest** destination
  245. .. c:function:: float glm_vec4_distance(vec4 v1, vec4 v2)
  246. distance between two vectors
  247. Parameters:
  248. | *[in]* **mat** vector1
  249. | *[in]* **row1** vector2
  250. Returns:
  251. | distance
  252. .. c:function:: void glm_vec4_maxv(vec4 v1, vec4 v2, vec4 dest)
  253. max values of vectors
  254. Parameters:
  255. | *[in]* **v1** vector1
  256. | *[in]* **v2** vector2
  257. | *[out]* **dest** destination
  258. .. c:function:: void glm_vec4_minv(vec4 v1, vec4 v2, vec4 dest)
  259. min values of vectors
  260. Parameters:
  261. | *[in]* **v1** vector1
  262. | *[in]* **v2** vector2
  263. | *[out]* **dest** destination
  264. .. c:function:: void glm_vec4_clamp(vec4 v, float minVal, float maxVal)
  265. constrain a value to lie between two further values
  266. Parameters:
  267. | *[in, out]* **v** vector
  268. | *[in]* **minVal** minimum value
  269. | *[in]* **maxVal** maximum value
  270. .. c:function:: void glm_vec4_lerp(vec4 from, vec4 to, float t, vec4 dest)
  271. linear interpolation between two vector
  272. | formula: from + s * (to - from)
  273. Parameters:
  274. | *[in]* **from** from value
  275. | *[in]* **to** to value
  276. | *[in]* **t** interpolant (amount) clamped between 0 and 1
  277. | *[out]* **dest** destination