| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961 |
- /*
- * Copyright (c), Recep Aslantas.
- *
- * MIT License (MIT), http://opensource.org/licenses/MIT
- * Full license can be found in the LICENSE file
- */
- /*
- Macros:
- GLMS_VEC4_ONE_INIT
- GLMS_VEC4_BLACK_INIT
- GLMS_VEC4_ZERO_INIT
- GLMS_VEC4_ONE
- GLMS_VEC4_BLACK
- GLMS_VEC4_ZERO
- Functions:
- CGLM_INLINE vec4s glms_vec4(vec3s v3, float last);
- CGLM_INLINE vec3s glms_vec4_copy3(vec4s v);
- CGLM_INLINE vec4s glms_vec4_copy(vec4s v);
- CGLM_INLINE vec4s glms_vec4_ucopy(vec4s v);
- CGLM_INLINE void glms_vec4_pack(vec4s dst[], vec4 src[], size_t len);
- CGLM_INLINE void glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len);
- CGLM_INLINE float glms_vec4_dot(vec4s a, vec4s b);
- CGLM_INLINE float glms_vec4_norm2(vec4s v);
- CGLM_INLINE float glms_vec4_norm(vec4s v);
- CGLM_INLINE float glms_vec4_norm_one(vec4s v);
- CGLM_INLINE float glms_vec4_norm_inf(vec4s v);
- CGLM_INLINE vec4s glms_vec4_add(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_adds(vec4s v, float s);
- CGLM_INLINE vec4s glms_vec4_sub(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_subs(vec4s v, float s);
- CGLM_INLINE vec4s glms_vec4_mul(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_scale(vec4s v, float s);
- CGLM_INLINE vec4s glms_vec4_scale_as(vec4s v, float s);
- CGLM_INLINE vec4s glms_vec4_div(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_divs(vec4s v, float s);
- CGLM_INLINE vec4s glms_vec4_addadd(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_subadd(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_muladd(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_muladds(vec4s a, float s, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_maxadd(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_minadd(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_subsub(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_addsub(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_mulsub(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_mulsubs(vec4s a, float s, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_maxsub(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_minsub(vec4s a, vec4s b, vec4s dest);
- CGLM_INLINE vec4s glms_vec4_negate(vec4s v);
- CGLM_INLINE vec4s glms_vec4_normalize(vec4s v);
- CGLM_INLINE float glms_vec4_distance(vec4s a, vec4s b);
- CGLM_INLINE float glms_vec4_distance2(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_maxv(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_minv(vec4s a, vec4s b);
- CGLM_INLINE vec4s glms_vec4_clamp(vec4s v, float minVal, float maxVal);
- CGLM_INLINE vec4s glms_vec4_lerp(vec4s from, vec4s to, float t);
- CGLM_INLINE vec4s glms_vec4_lerpc(vec4s from, vec4s to, float t);
- CGLM_INLINE vec4s glms_vec4_mix(vec4s from, vec4s to, float t);
- CGLM_INLINE vec4s glms_vec4_mixc(vec4s from, vec4s to, float t);
- CGLM_INLINE vec4s glms_vec4_step(vec4s edge, vec4s x);
- CGLM_INLINE vec4s glms_vec4_smoothstep_uni(float edge0, float edge1, vec4s x);
- CGLM_INLINE vec4s glms_vec4_smoothstep(vec4s edge0, vec4s edge1, vec4s x);
- CGLM_INLINE vec4s glms_vec4_smoothinterp(vec4s from, vec4s to, float t);
- CGLM_INLINE vec4s glms_vec4_smoothinterpc(vec4s from, vec4s to, float t);
- CGLM_INLINE vec4s glms_vec4_cubic(float s);
- CGLM_INLINE vec4s glms_vec4_swizzle(vec4s v, int mask);
- CGLM_INLINE vec4s glms_vec4_make(float * restrict src);
- CGLM_INLINE vec4s glms_vec4_reflect(vec4s v, vec4s n);
- CGLM_INLINE bool glms_vec4_refract(vec4s v, vec4s n, float eta, vec4s *dest)
- Deprecated:
- glms_vec4_step_uni --> use glms_vec4_steps
- */
- #ifndef cglms_vec4s_h
- #define cglms_vec4s_h
- #include "../common.h"
- #include "../types-struct.h"
- #include "../util.h"
- #include "../vec4.h"
- #include "vec4-ext.h"
- /* DEPRECATED! */
- #define glms_vec4_step_uni(edge, x) glms_vec4_steps(edge, x)
- #define GLMS_VEC4_ONE_INIT {GLM_VEC4_ONE_INIT}
- #define GLMS_VEC4_BLACK_INIT {GLM_VEC4_BLACK_INIT}
- #define GLMS_VEC4_ZERO_INIT {GLM_VEC4_ZERO_INIT}
- #define GLMS_VEC4_ONE ((vec4s)GLM_VEC4_ONE_INIT)
- #define GLMS_VEC4_BLACK ((vec4s)GLM_VEC4_BLACK_INIT)
- #define GLMS_VEC4_ZERO ((vec4s)GLM_VEC4_ZERO_INIT)
- /*!
- * @brief init vec4 using vec3
- *
- * @param[in] v3 vector3
- * @param[in] last last item
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4(vec3s v3, float last) {
- vec4s r;
- glm_vec4(v3.raw, last, r.raw);
- return r;
- }
- /*!
- * @brief copy first 3 members of [a] to [dest]
- *
- * @param[in] v source
- * @returns vec3
- */
- CGLM_INLINE
- vec3s
- glms_vec4_(copy3)(vec4s v) {
- vec3s r;
- glm_vec4_copy3(v.raw, r.raw);
- return r;
- }
- /*!
- * @brief copy all members of [a] to [dest]
- *
- * @param[in] v source
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(copy)(vec4s v) {
- vec4s r;
- glm_vec4_copy(v.raw, r.raw);
- return r;
- }
- /*!
- * @brief copy all members of [a] to [dest]
- *
- * alignment is not required
- *
- * @param[in] v source
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(ucopy)(vec4s v) {
- vec4s r;
- glm_vec4_ucopy(v.raw, r.raw);
- return r;
- }
- /*!
- * @brief pack an array of vec4 into an array of vec4s
- *
- * @param[out] dst array of vec4
- * @param[in] src array of vec4s
- * @param[in] len number of elements
- */
- CGLM_INLINE
- void
- glms_vec4_(pack)(vec4s dst[], vec4 src[], size_t len) {
- size_t i;
- for (i = 0; i < len; i++) {
- glm_vec4_copy(src[i], dst[i].raw);
- }
- }
- /*!
- * @brief unpack an array of vec4s into an array of vec4
- *
- * @param[out] dst array of vec4s
- * @param[in] src array of vec4
- * @param[in] len number of elements
- */
- CGLM_INLINE
- void
- glms_vec4_(unpack)(vec4 dst[], vec4s src[], size_t len) {
- size_t i;
- for (i = 0; i < len; i++) {
- glm_vec4_copy(src[i].raw, dst[i]);
- }
- }
- /*!
- * @brief make vector zero
- *
- * @returns zero vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(zero)(void) {
- vec4s r;
- glm_vec4_zero(r.raw);
- return r;
- }
- /*!
- * @brief make vector one
- *
- * @returns one vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(one)(void) {
- vec4s r;
- glm_vec4_one(r.raw);
- return r;
- }
- /*!
- * @brief vec4 dot product
- *
- * @param[in] a vector1
- * @param[in] b vector2
- *
- * @return dot product
- */
- CGLM_INLINE
- float
- glms_vec4_(dot)(vec4s a, vec4s b) {
- return glm_vec4_dot(a.raw, b.raw);
- }
- /*!
- * @brief norm * norm (magnitude) of vec
- *
- * we can use this func instead of calling norm * norm, because it would call
- * sqrtf function twice but with this func we can avoid func call, maybe this is
- * not good name for this func
- *
- * @param[in] v vec4
- *
- * @return norm * norm
- */
- CGLM_INLINE
- float
- glms_vec4_(norm2)(vec4s v) {
- return glm_vec4_norm2(v.raw);
- }
- /*!
- * @brief norm (magnitude) of vec4
- *
- * @param[in] v vector
- *
- * @return norm
- */
- CGLM_INLINE
- float
- glms_vec4_(norm)(vec4s v) {
- return glm_vec4_norm(v.raw);
- }
- /*!
- * @brief L1 norm of vec4
- * Also known as Manhattan Distance or Taxicab norm.
- * L1 Norm is the sum of the magnitudes of the vectors in a space.
- * It is calculated as the sum of the absolute values of the vector components.
- * In this norm, all the components of the vector are weighted equally.
- *
- * This computes:
- * R = |v[0]| + |v[1]| + |v[2]| + |v[3]|
- *
- * @param[in] v vector
- *
- * @return L1 norm
- */
- CGLM_INLINE
- float
- glms_vec4_(norm_one)(vec4s v) {
- return glm_vec4_norm_one(v.raw);
- }
- /*!
- * @brief Infinity norm of vec4
- * Also known as Maximum norm.
- * Infinity Norm is the largest magnitude among each element of a vector.
- * It is calculated as the maximum of the absolute values of the vector components.
- *
- * This computes:
- * inf norm = max(|v[0]|, |v[1]|, |v[2]|, |v[3]|)
- *
- * @param[in] v vector
- *
- * @return Infinity norm
- */
- CGLM_INLINE
- float
- glms_vec4_(norm_inf)(vec4s v) {
- return glm_vec4_norm_inf(v.raw);
- }
- /*!
- * @brief add b vector to a vector store result in dest
- *
- * @param[in] a vector1
- * @param[in] b vector2
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(add)(vec4s a, vec4s b) {
- vec4s r;
- glm_vec4_add(a.raw, b.raw, r.raw);
- return r;
- }
- /*!
- * @brief add scalar to v vector store result in dest (d = v + vec(s))
- *
- * @param[in] v vector
- * @param[in] s scalar
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(adds)(vec4s v, float s) {
- vec4s r;
- glm_vec4_adds(v.raw, s, r.raw);
- return r;
- }
- /*!
- * @brief subtract b vector from a vector store result in dest (d = a - b)
- *
- * @param[in] a vector1
- * @param[in] b vector2
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(sub)(vec4s a, vec4s b) {
- vec4s r;
- glm_vec4_sub(a.raw, b.raw, r.raw);
- return r;
- }
- /*!
- * @brief subtract scalar from v vector store result in dest (d = v - vec(s))
- *
- * @param[in] v vector
- * @param[in] s scalar
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(subs)(vec4s v, float s) {
- vec4s r;
- glm_vec4_subs(v.raw, s, r.raw);
- return r;
- }
- /*!
- * @brief multiply two vectors (component-wise multiplication)
- *
- * @param a vector1
- * @param b vector2
- * @returns dest = (a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3])
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(mul)(vec4s a, vec4s b) {
- vec4s r;
- glm_vec4_mul(a.raw, b.raw, r.raw);
- return r;
- }
- /*!
- * @brief multiply/scale vec4 vector with scalar: result = v * s
- *
- * @param[in] v vector
- * @param[in] s scalar
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(scale)(vec4s v, float s) {
- vec4s r;
- glm_vec4_scale(v.raw, s, r.raw);
- return r;
- }
- /*!
- * @brief make vec4 vector scale as specified: result = unit(v) * s
- *
- * @param[in] v vector
- * @param[in] s scalar
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(scale_as)(vec4s v, float s) {
- vec4s r;
- glm_vec4_scale_as(v.raw, s, r.raw);
- return r;
- }
- /*!
- * @brief div vector with another component-wise division: d = a / b
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns result = (a[0]/b[0], a[1]/b[1], a[2]/b[2], a[3]/b[3])
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(div)(vec4s a, vec4s b) {
- vec4s r;
- glm_vec4_div(a.raw, b.raw, r.raw);
- return r;
- }
- /*!
- * @brief div vec4 vector with scalar: d = v / s
- *
- * @param[in] v vector
- * @param[in] s scalar
- * @returns destination vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(divs)(vec4s v, float s) {
- vec4s r;
- glm_vec4_divs(v.raw, s, r.raw);
- return r;
- }
- /*!
- * @brief add two vectors and add result to sum
- *
- * it applies += operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest += (a + b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(addadd)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_addadd(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief sub two vectors and add result to dest
- *
- * it applies += operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest += (a - b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(subadd)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_subadd(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief mul two vectors and add result to dest
- *
- * it applies += operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest += (a * b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(muladd)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_muladd(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief mul vector with scalar and add result to sum
- *
- * it applies += operator so dest must be initialized
- *
- * @param[in] a vector
- * @param[in] s scalar
- * @returns dest += (a * b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(muladds)(vec4s a, float s, vec4s dest) {
- glm_vec4_muladds(a.raw, s, dest.raw);
- return dest;
- }
- /*!
- * @brief add max of two vectors to result/dest
- *
- * it applies += operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest += max(a, b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(maxadd)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_maxadd(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief add min of two vectors to result/dest
- *
- * it applies += operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest += min(a, b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(minadd)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_minadd(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief sub two vectors and sub result to dest
- *
- * it applies -= operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest -= (a + b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(subsub)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_subsub(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief add two vectors and sub result to dest
- *
- * it applies -= operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest -= (a + b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(addsub)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_addsub(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief mul two vectors and sub result to dest
- *
- * it applies -= operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest -= (a * b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(mulsub)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_mulsub(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief mul vector with scalar and sub result to dest
- *
- * it applies -= operator so dest must be initialized
- *
- * @param[in] a vector
- * @param[in] s scalar
- * @returns dest -= (a * b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(mulsubs)(vec4s a, float s, vec4s dest) {
- glm_vec4_mulsubs(a.raw, s, dest.raw);
- return dest;
- }
- /*!
- * @brief sub max of two vectors to dest
- *
- * it applies -= operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest -= max(a, b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(maxsub)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_maxsub(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief sub min of two vectors to dest
- *
- * it applies -= operator so dest must be initialized
- *
- * @param[in] a vector 1
- * @param[in] b vector 2
- * @returns dest -= min(a, b)
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(minsub)(vec4s a, vec4s b, vec4s dest) {
- glm_vec4_minsub(a.raw, b.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief negate vector components and store result in dest
- *
- * @param[in] v vector
- * @returns result vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(negate)(vec4s v) {
- glm_vec4_negate(v.raw);
- return v;
- }
- /*!
- * @brief normalize vec4 and store result in same vec
- *
- * @param[in] v vector
- * @returns normalized vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(normalize)(vec4s v) {
- glm_vec4_normalize(v.raw);
- return v;
- }
- /**
- * @brief distance between two vectors
- *
- * @param[in] a vector1
- * @param[in] b vector2
- * @return returns distance
- */
- CGLM_INLINE
- float
- glms_vec4_(distance)(vec4s a, vec4s b) {
- return glm_vec4_distance(a.raw, b.raw);
- }
- /**
- * @brief squared distance between two vectors
- *
- * @param[in] a vector1
- * @param[in] b vector2
- * @return returns squared distance
- */
- CGLM_INLINE
- float
- glms_vec4_(distance2)(vec4s a, vec4s b) {
- return glm_vec4_distance2(a.raw, b.raw);
- }
- /*!
- * @brief max values of vectors
- *
- * @param[in] a vector1
- * @param[in] b vector2
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(maxv)(vec4s a, vec4s b) {
- vec4s r;
- glm_vec4_maxv(a.raw, b.raw, r.raw);
- return r;
- }
- /*!
- * @brief min values of vectors
- *
- * @param[in] a vector1
- * @param[in] b vector2
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(minv)(vec4s a, vec4s b) {
- vec4s r;
- glm_vec4_minv(a.raw, b.raw, r.raw);
- return r;
- }
- /*!
- * @brief clamp vector's individual members between min and max values
- *
- * @param[in] v vector
- * @param[in] minVal minimum value
- * @param[in] maxVal maximum value
- * @returns clamped vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(clamp)(vec4s v, float minVal, float maxVal) {
- glm_vec4_clamp(v.raw, minVal, maxVal);
- return v;
- }
- /*!
- * @brief linear interpolation between two vectors
- *
- * formula: from + s * (to - from)
- *
- * @param[in] from from value
- * @param[in] to to value
- * @param[in] t interpolant (amount)
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(lerp)(vec4s from, vec4s to, float t) {
- vec4s r;
- glm_vec4_lerp(from.raw, to.raw, t, r.raw);
- return r;
- }
- /*!
- * @brief linear interpolation between two vectors (clamped)
- *
- * formula: from + s * (to - from)
- *
- * @param[in] from from value
- * @param[in] to to value
- * @param[in] t interpolant (amount) clamped between 0 and 1
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(lerpc)(vec4s from, vec4s to, float t) {
- vec4s r;
- glm_vec4_lerpc(from.raw, to.raw, t, r.raw);
- return r;
- }
- /*!
- * @brief linear interpolation between two vectors
- *
- * formula: from + s * (to - from)
- *
- * @param[in] from from value
- * @param[in] to to value
- * @param[in] t interpolant (amount)
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(mix)(vec4s from, vec4s to, float t) {
- vec4s r;
- glm_vec4_mix(from.raw, to.raw, t, r.raw);
- return r;
- }
- /*!
- * @brief linear interpolation between two vectors (clamped)
- *
- * formula: from + s * (to - from)
- *
- * @param[in] from from value
- * @param[in] to to value
- * @param[in] t interpolant (amount) clamped between 0 and 1
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(mixc)(vec4s from, vec4s to, float t) {
- vec4s r;
- glm_vec4_mixc(from.raw, to.raw, t, r.raw);
- return r;
- }
- /*!
- * @brief threshold function
- *
- * @param[in] edge threshold
- * @param[in] x value to test against threshold
- * @returns 0.0 if x < edge, else 1.0
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(step)(vec4s edge, vec4s x) {
- vec4s r;
- glm_vec4_step(edge.raw, x.raw, r.raw);
- return r;
- }
- /*!
- * @brief threshold function with a smooth transition (unidimensional)
- *
- * @param[in] edge0 low threshold
- * @param[in] edge1 high threshold
- * @param[in] x value to test against threshold
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(smoothstep_uni)(float edge0, float edge1, vec4s x) {
- vec4s r;
- glm_vec4_smoothstep_uni(edge0, edge1, x.raw, r.raw);
- return r;
- }
- /*!
- * @brief threshold function with a smooth transition
- *
- * @param[in] edge0 low threshold
- * @param[in] edge1 high threshold
- * @param[in] x value to test against threshold
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(smoothstep)(vec4s edge0, vec4s edge1, vec4s x) {
- vec4s r;
- glm_vec4_smoothstep(edge0.raw, edge1.raw, x.raw, r.raw);
- return r;
- }
- /*!
- * @brief smooth Hermite interpolation between two vectors
- *
- * formula: from + s * (to - from)
- *
- * @param[in] from from value
- * @param[in] to to value
- * @param[in] t interpolant (amount)
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(smoothinterp)(vec4s from, vec4s to, float t) {
- vec4s r;
- glm_vec4_smoothinterp(from.raw, to.raw, t, r.raw);
- return r;
- }
- /*!
- * @brief smooth Hermite interpolation between two vectors (clamped)
- *
- * formula: from + s * (to - from)
- *
- * @param[in] from from value
- * @param[in] to to value
- * @param[in] t interpolant (amount) clamped between 0 and 1
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(smoothinterpc)(vec4s from, vec4s to, float t) {
- vec4s r;
- glm_vec4_smoothinterpc(from.raw, to.raw, t, r.raw);
- return r;
- }
- /*!
- * @brief helper to fill vec4 as [S^3, S^2, S, 1]
- *
- * @param[in] s parameter
- * @returns destination
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(cubic)(float s) {
- vec4s r;
- glm_vec4_cubic(s, r.raw);
- return r;
- }
- /*!
- * @brief swizzle vector components
- *
- * you can use existing masks e.g. GLM_XXXX, GLM_WZYX
- *
- * @param[in] v source
- * @param[in] mask mask
- * @returns swizzled vector
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(swizzle)(vec4s v, int mask) {
- vec4s dest;
- glm_vec4_swizzle(v.raw, mask, dest.raw);
- return dest;
- }
- /*!
- * @brief Create four dimensional vector from pointer
- *
- * @param[in] src pointer to an array of floats
- * @returns constructed 4D vector from raw pointer
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(make)(const float * __restrict src) {
- vec4s dest;
- glm_vec4_make(src, dest.raw);
- return dest;
- }
- /*!
- * @brief reflection vector using an incident ray and a surface normal
- *
- * @param[in] v incident vector
- * @param[in] n normalized normal vector
- * @returns reflection result
- */
- CGLM_INLINE
- vec4s
- glms_vec4_(reflect)(vec4s v, vec4s n) {
- vec4s dest;
- glm_vec4_reflect(v.raw, n.raw, dest.raw);
- return dest;
- }
- /*!
- * @brief computes refraction vector for an incident vector and a surface normal.
- *
- * calculates the refraction vector based on Snell's law. If total internal reflection
- * occurs (angle too great given eta), dest is set to zero and returns false.
- * Otherwise, computes refraction vector, stores it in dest, and returns true.
- *
- * this implementation does not explicitly preserve the 'w' component of the
- * incident vector 'I' in the output 'dest', users requiring the preservation of
- * the 'w' component should manually adjust 'dest' after calling this function.
- *
- * @param[in] v normalized incident vector
- * @param[in] n normalized normal vector
- * @param[in] eta ratio of indices of refraction (incident/transmitted)
- * @param[out] dest refraction vector if refraction occurs; zero vector otherwise
- *
- * @returns true if refraction occurs; false if total internal reflection occurs.
- */
- CGLM_INLINE
- bool
- glms_vec4_(refract)(vec4s v, vec4s n, float eta, vec4s * __restrict dest) {
- return glm_vec4_refract(v.raw, n.raw, eta, dest->raw);
- }
- #endif /* cglms_vec4s_h */
|