From 2f85ae6d0af893fcba2a82cf3f925cf3c42608e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Wed, 29 Aug 2012 20:27:53 +0000 Subject: [PATCH] --- src/lol/math/math.h | 10 ++++++++++ src/lol/math/vector.h | 8 ++++++++ src/numeric.h | 8 ++++++++ 3 files changed, 26 insertions(+) diff --git a/src/lol/math/math.h b/src/lol/math/math.h index 793cd2e5..8fe3ad7c 100644 --- a/src/lol/math/math.h +++ b/src/lol/math/math.h @@ -64,6 +64,16 @@ static inline void sincos(float const &x, float *s, float *c) *c = std::cos(x); } +static inline double lerp(double const &a, double const &b, double const &x) +{ + return a + (b - a) * x; +} +static inline float lerp(float const &a, float const &b, float const &x) +{ + return a + (b - a) * x; +} + + /* These accelerated functions will be merged into the above, one day */ double lol_sin(double); double lol_cos(double); diff --git a/src/lol/math/vector.h b/src/lol/math/vector.h index 9d9ce076..ef266205 100644 --- a/src/lol/math/vector.h +++ b/src/lol/math/vector.h @@ -1229,6 +1229,14 @@ extern Quat slerp(Quat const &qa, Quat const &qb, T f); for (size_t n = 0; n < sizeof(a) / sizeof(t1); n++) \ ret += a[n] * b[n]; \ return ret; \ + } \ + tprefix \ + inline tname lerp(tname const &a, tname const &b, tf x) \ + { \ + tname ret; \ + for (size_t n = 0; n < sizeof(a) / sizeof(t1); n++) \ + ret[n] = a[n] + (a[n] - b[n]) * x; \ + return ret; \ } #define DECLARE_BINARY_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \ diff --git a/src/numeric.h b/src/numeric.h index 9c2211aa..5bf2f565 100644 --- a/src/numeric.h +++ b/src/numeric.h @@ -52,6 +52,14 @@ template static inline T PotUp(T val) return val + 1; } +//Lerp for float +template static inline T1 damp(const T1 &a, const T2 &b, const Tf &x, const Tf &dt) +{ + if (dt <= .0f) + return a; + return lol::lerp(a, b, dt / (dt + x)); +} + } /* namespace lol */ #endif // __LOL_NUMERIC_H__