From f66c8adf48a95897f3a73132c64659cb0fc6075b Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 22:21:22 -0700 Subject: v2f: add tri-linear interpolation: v2f_trilerp() --- v2f.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/v2f.h b/v2f.h index 382b5b0..93175a2 100644 --- a/v2f.h +++ b/v2f.h @@ -250,4 +250,31 @@ static inline v2f_t * v2f_bilerp(v2f_t *res, const v2f_t *aa, const v2f_t *ab, c return res; } + +/* + * abb-------bbb + * /| /| + * aba-------bba| + * | | | | + * |aab------|bab + * |/ |/ + * aaa-------baa + */ +static inline v2f_t _v2f_trilerp(const v2f_t *aaa, const v2f_t *aba, const v2f_t *aab, const v2f_t *abb, const v2f_t *baa, const v2f_t *bba, const v2f_t *bab, const v2f_t *bbb, float t_x, float t_y, float t_z) +{ + v2f_t xya = _v2f_bilerp(aaa, aba, baa, bba, t_x, t_y); + v2f_t xyb = _v2f_bilerp(aab, abb, bab, bbb, t_x, t_y); + + return _v2f_lerp(&xya, &xyb, t_z); +} + + +static inline v2f_t * v2f_trilerp(v2f_t *res, const v2f_t *aaa, const v2f_t *aba, const v2f_t *aab, const v2f_t *abb, const v2f_t *baa, const v2f_t *bba, const v2f_t *bab, const v2f_t *bbb, float t_x, float t_y, float t_z) +{ + if (_v2f_allocated(&res)) + *res = _v2f_trilerp(aaa, aba, aab, abb, baa, bba, bab, bbb, t_x, t_y, t_z); + + return res; +} + #endif -- cgit v1.2.3