From a1be48106253be3644148d56dae122a67958c4ff Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 18:54:19 -0700 Subject: v3f: add cross product: v3f_cross() --- v3f.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'v3f.h') diff --git a/v3f.h b/v3f.h index 7996364..ad6e373 100644 --- a/v3f.h +++ b/v3f.h @@ -209,4 +209,23 @@ static inline v3f_t * v3f_nlerp(v3f_t *res, const v3f_t *a, const v3f_t *b, floa } +static inline v3f_t _v3f_cross(const v3f_t *a, const v3f_t *b) +{ + return (v3f_t){ + .x = a->y * b->z - a->z * b->y, + .y = a->z * b->x - a->x * b->z, + .z = a->x * b->y - a->y * b->x, + }; +} + + +static inline v3f_t * v3f_cross(v3f_t *res, const v3f_t *a, const v3f_t *b) +{ + if (_v3f_allocated(&res)) + *res = _v3f_cross(a, b); + + return res; +} + + #endif -- cgit v1.2.3