diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2018-10-02 00:17:51 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2018-10-02 00:17:51 -0700 |
commit | 2bd54dfc3ba57f11281d8943921b8a92c61b1fee (patch) | |
tree | fad0defea500eaa13f0646d68ca27dc15a5ac545 | |
parent | 9786a5e3c03c5e45d064a10fcd13f5ebffc32017 (diff) |
v3f: add pointer result variants
It can be convenient to supply and return a result pointer, making
for more composable vector operations.
-rw-r--r-- | v3f.h | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -30,24 +30,56 @@ static inline v3f_t v3f_add(const v3f_t *a, const v3f_t *b) } +static inline v3f_t * pv3f_add(const v3f_t *a, const v3f_t *b, v3f_t *res) +{ + *res = v3f_add(a, b); + + return res; +} + + static inline v3f_t v3f_sub(const v3f_t *a, const v3f_t *b) { return (v3f_t){a->x - b->x, a->y - b->y, a->z - b->z}; } +static inline v3f_t * pv3f_sub(const v3f_t *a, const v3f_t *b, v3f_t *res) +{ + *res = v3f_sub(a, b); + + return res; +} + + static inline v3f_t v3f_mult(const v3f_t *a, const v3f_t *b) { return (v3f_t){a->x * b->x, a->y * b->y, a->z * b->z}; } +static inline v3f_t * pv3f_mult(const v3f_t *a, const v3f_t *b, v3f_t *res) +{ + *res = v3f_mult(a, b); + + return res; +} + + static inline v3f_t v3f_mult_scalar(const v3f_t *v, float scalar) { return (v3f_t){v->x * scalar, v->y * scalar, v->z * scalar}; } +static inline v3f_t * pv3f_mult_scalar(const v3f_t *v, float scalar, v3f_t *res) +{ + *res = v3f_mult_scalar(v, scalar); + + return res; +} + + static inline float v3f_dot(const v3f_t *a, const v3f_t *b) { return a->x * b->x + a->y * b->y + a->z * b->z; @@ -66,6 +98,14 @@ static inline v3f_t v3f_normalize(const v3f_t *v) } +static inline v3f_t * pv3f_normalize(const v3f_t *v, v3f_t *res) +{ + *res = v3f_normalize(v); + + return res; +} + + static inline v3f_t v3f_lerp(const v3f_t *a, const v3f_t *b, float t) { v3f_t lerp_a, lerp_b; @@ -77,6 +117,14 @@ static inline v3f_t v3f_lerp(const v3f_t *a, const v3f_t *b, float t) } +static inline v3f_t * pv3f_lerp(const v3f_t *a, const v3f_t *b, float t, v3f_t *res) +{ + *res = v3f_lerp(a, b, t); + + return res; +} + + static inline v3f_t v3f_nlerp(const v3f_t *a, const v3f_t *b, float t) { v3f_t lerp = v3f_lerp(a, b, t); @@ -84,4 +132,12 @@ static inline v3f_t v3f_nlerp(const v3f_t *a, const v3f_t *b, float t) return v3f_normalize(&lerp); } + +static inline v3f_t * pv3f_nlerp(const v3f_t *a, const v3f_t *b, float t, v3f_t *res) +{ + *res = v3f_nlerp(a, b, t); + + return res; +} + #endif |