X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fmath.qh;h=ac23325000995f50ef2e1fdde945686ff741401f;hb=9d5295bb4213f6c703d43d158605efe893514ee4;hp=f20b1c66e5bf120be7748737dabe8b9e8dec9f88;hpb=65b54b5967f0a152ff308a37196a583e816c1f72;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/math.qh b/qcsrc/lib/math.qh index f20b1c66e..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) { @@ -324,9 +357,9 @@ vector solve_quadratic(float a, float b, float c) } /// Maps values between the src and dest range: src_min to dest_min, src_max to dest_max, values between them -/// to the curresponding values between and extrapolates for values outside the range. +/// to the corresponding values between and extrapolates for values outside the range. /// -/// src_min and src_max must not be the same or division by zero accurs. +/// src_min and src_max must not be the same or division by zero occurs. /// /// dest_max can be smaller than dest_min if you want the resulting range to be inverted, all values can be negative. ERASEABLE