summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2019-05-06 19:04:04 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-05-06 20:22:19 -0700
commit107d688e7262db5731041294df3d57b0cfd89566 (patch)
tree31c0cba4ab4692bd26bdc6ead894f5994a6c746a
parenta1be48106253be3644148d56dae122a67958c4ff (diff)
v3f: add bi-linear interpolation: v3f_bilerp()
-rw-r--r--v3f.h28
1 files changed, 28 insertions, 0 deletions
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){
© All Rights Reserved