X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Flib%2Fmath.qh;fp=qcsrc%2Flib%2Fmath.qh;h=8ba31516dda7fecffca459d112cbb4affaa92a76;hb=fdbfb6f9364d8aeae67e108400a6bd1dd37dc0b7;hp=06994887c58ad6bbaeb7a46855052f300561279b;hpb=0f2e3cd6c6554bda254111dee0746fea05aac047;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/lib/math.qh b/qcsrc/lib/math.qh index 06994887c..8ba31516d 100644 --- a/qcsrc/lib/math.qh +++ b/qcsrc/lib/math.qh @@ -2,6 +2,7 @@ #include "lib/float.qh" +ERASEABLE void mean_accumulate(entity e, .float a, .float c, float mean, float value, float weight) { if (weight == 0) return; @@ -10,6 +11,7 @@ void mean_accumulate(entity e, .float a, .float c, float mean, float value, floa e.(c) += weight; } +ERASEABLE float mean_evaluate(entity e, .float a, .float c, float mean) { if (e.(c) == 0) return 0; @@ -32,6 +34,7 @@ Angc used for animations */ +ERASEABLE float angc(float a1, float a2) { while (a1 > 180) @@ -50,11 +53,13 @@ float angc(float a1, float a2) return a; } +ERASEABLE float fsnap(float val, float fsize) { return rint(val / fsize) * fsize; } +ERASEABLE vector vsnap(vector point, float fsize) { vector vret; @@ -66,11 +71,13 @@ vector vsnap(vector point, float fsize) return vret; } +ERASEABLE vector lerpv(float t0, vector v0, float t1, vector v1, float t) { return v0 + (v1 - v0) * ((t - t0) / (t1 - t0)); } +ERASEABLE vector bezier_quadratic_getpoint(vector a, vector b, vector c, float t) { return (c - 2 * b + a) * (t * t) @@ -78,12 +85,14 @@ vector bezier_quadratic_getpoint(vector a, vector b, vector c, float t) + a; } +ERASEABLE vector bezier_quadratic_getderivative(vector a, vector b, vector c, float t) { return (c - 2 * b + a) * (2 * t) + (b - a) * 2; } +ERASEABLE float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float spd) { return (((startspeedfactor + endspeedfactor - 2 @@ -92,6 +101,7 @@ float cubic_speedfunc(float startspeedfactor, float endspeedfactor, float spd) ) * spd; } +ERASEABLE bool cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor) { if (startspeedfactor < 0 || endspeedfactor < 0) return false; @@ -156,34 +166,40 @@ bool cubic_speedfunc_is_sane(float startspeedfactor, float endspeedfactor) } /** continuous function mapping all reals into -1..1 */ +ERASEABLE float float2range11(float f) { return f / (fabs(f) + 1); } /** continuous function mapping all reals into 0..1 */ +ERASEABLE float float2range01(float f) { return 0.5 + 0.5 * float2range11(f); } +ERASEABLE float median(float a, float b, float c) { return (a < c) ? bound(a, b, c) : bound(c, b, a); } +ERASEABLE float almost_equals(float a, float b) { float eps = (max(a, -a) + max(b, -b)) * 0.001; return a - b < eps && b - a < eps; } +ERASEABLE float almost_equals_eps(float a, float b, float times_eps) { float eps = max(fabs(a), fabs(b)) * FLOAT_EPSILON * times_eps; return a - b < eps && b - a < eps; } +ERASEABLE float almost_in_bounds(float a, float b, float c) { float eps = (max(a, -a) + max(c, -c)) * 0.001; @@ -191,6 +207,7 @@ float almost_in_bounds(float a, float b, float c) return b == median(a - eps, b, c + eps); } +ERASEABLE float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float d) { if (halflifedist > 0) return (0.5 ** ((bound(mindist, d, maxdist) - mindist) / halflifedist)); @@ -198,11 +215,9 @@ float ExponentialFalloff(float mindist, float maxdist, float halflifedist, float else return 1; } -float power2of(float e) -{ - return (2 ** e); -} +#define power2of(e) (2 ** e) +ERASEABLE float log2of(float e) { // NOTE: generated code @@ -255,6 +270,7 @@ float log2of(float e) } /** ax^2 + bx + c = 0 */ +ERASEABLE vector solve_quadratic(float a, float b, float c) { vector v;