From: Mario Date: Sat, 30 May 2020 09:51:00 +0000 (+1000) Subject: Add some useful lerp lib functions made use of in the polytrails branch and in mods X-Git-Tag: xonotic-v0.8.5~995 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4db2ff8fdd5f9db3f74362e9fb6ce67e16fa65a4;p=xonotic%2Fxonotic-data.pk3dir.git Add some useful lerp lib functions made use of in the polytrails branch and in mods --- diff --git a/qcsrc/lib/math.qh b/qcsrc/lib/math.qh index d8f19906a..ac2332500 100644 --- a/qcsrc/lib/math.qh +++ b/qcsrc/lib/math.qh @@ -71,6 +71,39 @@ vector vsnap(vector point, float fsize) return vret; } +ERASEABLE +float lerpratio(float f0, float f1, float ratio) +{ + return f0 * (1 - ratio) + f1 * ratio; +} + +ERASEABLE +float lerp(float t0, float f0, float t1, float f1, float t) +{ + return lerpratio(f0, f1, (t - t0) / (t1 - t0)); +} + +ERASEABLE +float lerp3ratio(float f0, float f1, float f2, float ratio) +{ + float mid = 0.5; + return ratio < mid ? lerpratio(f0, f1, ratio / mid) : ratio > mid ? lerpratio(f1, f2, (ratio - mid) / mid) : f1; +} + + +ERASEABLE +vector lerpvratio(vector f0, vector f1, float ratio) +{ + return f0 * (1 - ratio) + f1 * ratio; +} + +ERASEABLE +vector lerpv3ratio(vector f0, vector f1, vector f2, float ratio) +{ + float mid = 0.5; + return ratio < mid ? lerpvratio(f0, f1, ratio / mid) : ratio > mid ? lerpvratio(f1, f2, (ratio - mid) / mid) : f1; +} + ERASEABLE vector lerpv(float t0, vector v0, float t1, vector v1, float t) {