| @@ -64,6 +64,16 @@ static inline void sincos(float const &x, float *s, float *c) | |||||
| *c = std::cos(x); | *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 */ | /* These accelerated functions will be merged into the above, one day */ | ||||
| double lol_sin(double); | double lol_sin(double); | ||||
| double lol_cos(double); | double lol_cos(double); | ||||
| @@ -1229,6 +1229,14 @@ extern Quat<T> slerp(Quat<T> const &qa, Quat<T> const &qb, T f); | |||||
| for (size_t n = 0; n < sizeof(a) / sizeof(t1); n++) \ | for (size_t n = 0; n < sizeof(a) / sizeof(t1); n++) \ | ||||
| ret += a[n] * b[n]; \ | ret += a[n] * b[n]; \ | ||||
| return ret; \ | return ret; \ | ||||
| } \ | |||||
| tprefix \ | |||||
| inline tname<tf> lerp(tname<t1> const &a, tname<t2> const &b, tf x) \ | |||||
| { \ | |||||
| tname<tf> 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) \ | #define DECLARE_BINARY_VECTOR_COERCE_OPS(tname, tprefix, t1, t2, tf) \ | ||||
| @@ -52,6 +52,14 @@ template <typename T> static inline T PotUp(T val) | |||||
| return val + 1; | return val + 1; | ||||
| } | } | ||||
| //Lerp for float | |||||
| template <typename T1, typename T2, typename Tf> 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 */ | } /* namespace lol */ | ||||
| #endif // __LOL_NUMERIC_H__ | #endif // __LOL_NUMERIC_H__ | ||||