diff options
author | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-02-11 11:29:07 +0800 |
commit | 160e1299ef3d95f8e8c48706d7f61dd3dc6c6b60 (patch) | |
tree | abe5ae5242d9cc6caf6edf103e662c44e978fca0 /src/libjin/math/math.h | |
parent | e095043485d1d298571af6d9eca7f0db9009ea7a (diff) |
Diffstat (limited to 'src/libjin/math/math.h')
-rw-r--r-- | src/libjin/math/math.h | 206 |
1 files changed, 103 insertions, 103 deletions
diff --git a/src/libjin/math/math.h b/src/libjin/math/math.h index 79ed4c8..5197f6d 100644 --- a/src/libjin/math/math.h +++ b/src/libjin/math/math.h @@ -7,109 +7,109 @@ namespace JinEngine { - namespace Math - { - - #ifdef min - #undef min - #endif // min - #ifdef max - #undef max - #endif // max - - template<typename T> - inline T min(T a, T b) - { - return a < b ? a : b; - } - - template<typename T> - inline T max(T a, T b) - { - return a > b ? a : b; - } - - template<typename T> - inline T clamp(T a, T mi, T ma) - { - return min<T>(max<T>(a, mi), ma); - } - - template<typename T> - inline bool within(T a, T mi, T ma) - { - return a >= mi && a <= ma; - } - - template<typename T> - inline bool without(T a, T mi, T ma) - { - return a < mi || a > ma; - } - - template<typename T> - inline T lowerBound(T a, T lower) - { - return a < lower ? lower : a; - } - - template<typename T> - inline T upperBound(T a, T upper) - { - return a > upper ? upper : a; - } - - inline float lerp(float a, float b, float f) - { - f = clamp<float>(f, 0, 1); - return a + f * (b - a); - } - - template<typename T> - inline T abs(T a) - { - return a > 0 ? a : -a; - } - - template<typename T> - inline T reverse(T a) - { - 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 Math + { + + #ifdef min + #undef min + #endif // min + #ifdef max + #undef max + #endif // max + + template<typename T> + inline T min(T a, T b) + { + return a < b ? a : b; + } + + template<typename T> + inline T max(T a, T b) + { + return a > b ? a : b; + } + + template<typename T> + inline T clamp(T a, T mi, T ma) + { + return min<T>(max<T>(a, mi), ma); + } + + template<typename T> + inline bool within(T a, T mi, T ma) + { + return a >= mi && a <= ma; + } + + template<typename T> + inline bool without(T a, T mi, T ma) + { + return a < mi || a > ma; + } + + template<typename T> + inline T lowerBound(T a, T lower) + { + return a < lower ? lower : a; + } + + template<typename T> + inline T upperBound(T a, T upper) + { + return a > upper ? upper : a; + } + + inline float lerp(float a, float b, float f) + { + f = clamp<float>(f, 0, 1); + return a + f * (b - a); + } + + template<typename T> + inline T abs(T a) + { + return a > 0 ? a : -a; + } + + template<typename T> + inline T reverse(T a) + { + 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 #endif // __JE_UTILS_MATH_H__
\ No newline at end of file |