diff options
author | chai <chaifix@163.com> | 2019-01-07 09:53:21 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-01-07 09:53:21 +0800 |
commit | 909e544ed322b28a6f59febf3213e05068e9e93c (patch) | |
tree | 683d08d89229c4f1be0e09a36d645a8add04f61f /src | |
parent | c42eb2529eead4b17c0c7f9da7ac9c41563a13fa (diff) |
*slerp
Diffstat (limited to 'src')
-rw-r--r-- | src/libjin/math/je_math.h | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/libjin/math/je_math.h b/src/libjin/math/je_math.h index f0a0a4c..4036696 100644 --- a/src/libjin/math/je_math.h +++ b/src/libjin/math/je_math.h @@ -59,12 +59,6 @@ namespace JinEngine return a > upper ? upper : a; } - template<typename T> - inline T lerp(T a, T b, float t) - { - return a + t * (b - a); - } - inline float lerp(float a, float b, float f) { f = clamp<float>(f, 0, 1); @@ -83,6 +77,38 @@ namespace JinEngine return -a; } + template<typename T> + inline T lerp(T a, T b, float t) + { + return a + t * (b - a); + } + + template<typename T> + inline T slerp(T start, T end, float percent) + { + // Dot product - the cosine of the angle between 2 vectors. + float dot = start * end; + // Clamp it to be in the range of Acos() + // This may be unnecessary, but floating point + // precision can be a fickle mistress. + dot = clamp<float>(dot, -1.0f, 1.0f); + // Acos(dot) returns the angle between start and end, + // And multiplying that by percent returns the angle between + // start and the final result. + float theta = Mathf.Acos(dot)*percent; + Vector3 RelativeVec = end - start * dot; + RelativeVec.Normalize(); + // Orthonormal basis + // The final result. + return ((start*Mathf.Cos(theta)) + (RelativeVec*Mathf.Sin(theta))); + } + + template<typename T> + inline T nlerp(T a, T b, float t) + { + + } + } // namespace Math } // namespace JinEngine |