diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2019-05-06 18:54:19 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2019-05-06 19:07:21 -0700 |
commit | a1be48106253be3644148d56dae122a67958c4ff (patch) | |
tree | f0eeeb506c77a40f5a2eb8adccde58d3d73f1ffa /v3f.h | |
parent | f4cc590a4896b0a1159f13f3c367d90b7b28ade2 (diff) |
v3f: add cross product: v3f_cross()
Diffstat (limited to 'v3f.h')
-rw-r--r-- | v3f.h | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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 |