From 107d688e7262db5731041294df3d57b0cfd89566 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 6 May 2019 19:04:04 -0700 Subject: v3f: add bi-linear interpolation: v3f_bilerp() --- v3f.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'v3f.h') diff --git a/v3f.h b/v3f.h index ad6e373..aca6e1f 100644 --- a/v3f.h +++ b/v3f.h @@ -209,6 +209,34 @@ static inline v3f_t * v3f_nlerp(v3f_t *res, const v3f_t *a, const v3f_t *b, floa } +/* + * 1 ab-------bb + * | | | + * | | | + * | | | + * 0 aa-------ba + * t_x: 0---------1 + * ^ + * t_y + */ +static inline v3f_t _v3f_bilerp(const v3f_t *aa, const v3f_t *ab, const v3f_t *ba, const v3f_t *bb, float t_x, float t_y) +{ + v3f_t xa = _v3f_lerp(aa, ba, t_x); + v3f_t xb = _v3f_lerp(ab, bb, t_x); + + return _v3f_lerp(&xa, &xb, t_y); +} + + +static inline v3f_t * v3f_bilerp(v3f_t *res, const v3f_t *aa, const v3f_t *ab, const v3f_t *ba, const v3f_t *bb, float t_x, float t_y) +{ + if (_v3f_allocated(&res)) + *res = _v3f_bilerp(aa, ab, ba, bb, t_x, t_y); + + return res; +} + + static inline v3f_t _v3f_cross(const v3f_t *a, const v3f_t *b) { return (v3f_t){ -- cgit v1.2.3