From 5053382808960f3209b3fd217fd6b20b240f0d38 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Sun, 13 Jun 2021 12:59:45 +0200 Subject: Added image viewer and blerp scaling --- libs/libc/math.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'libs/libc/math.c') diff --git a/libs/libc/math.c b/libs/libc/math.c index 23b1ca4..606281c 100644 --- a/libs/libc/math.c +++ b/libs/libc/math.c @@ -32,7 +32,7 @@ f64 pow(f64 base, f64 exp) // TODO: More efficient sqrt? -f32 sqrtf(f64 num) +f32 sqrtf(f32 num) { return powf(num, .5); } @@ -42,6 +42,30 @@ f64 sqrt(f64 num) return pow(num, .5); } +/** + * Interpolations + */ + +f32 lerpf(f32 from, f32 to, f32 trans) +{ + return from + (to - from) * trans; +} + +f64 lerp(f64 from, f64 to, f64 trans) +{ + return from + (to - from) * trans; +} + +f32 blerpf(f32 a, f32 b, f32 c, f32 d, f32 transx, f32 transy) +{ + return lerpf(lerpf(a, b, transx), lerpf(c, d, transx), transy); +} + +f64 blerp(f64 a, f64 b, f64 c, f64 d, f64 transx, f64 transy) +{ + return lerp(lerp(a, b, transx), lerp(c, d, transx), transy); +} + /** * Trigonometric functions */ -- cgit v1.2.3