|
|
@@ -14,10 +14,10 @@ namespace crown
|
|
|
|
|
|
/// @addtogroup Math
|
|
|
/// @{
|
|
|
-const float PI = 3.1415926535897932f;
|
|
|
-const float TWO_PI = PI * 2.0f;
|
|
|
-const float HALF_PI = PI * 0.5f;
|
|
|
-const float FLOAT_PRECISION = 1.0e-7f;
|
|
|
+const float PI = 3.1415926535897932f;
|
|
|
+const float TWO_PI = PI * 2.0f;
|
|
|
+const float HALF_PI = PI * 0.5f;
|
|
|
+const float FLOAT_PRECISION = 1.0e-7f;
|
|
|
|
|
|
inline bool fequal(float a, float b, float precision = FLOAT_PRECISION)
|
|
|
{
|
|
|
@@ -72,61 +72,56 @@ inline bool is_pow_2(uint32_t x)
|
|
|
}
|
|
|
|
|
|
/// Returns the linear interpolated value between @a p0 and @a p1 at time @a t
|
|
|
-template <typename T>
|
|
|
-inline T linear(const T& p0, const T& p1, float t)
|
|
|
+inline float linear(const float p0, const float p1, float t)
|
|
|
{
|
|
|
- return p0 + (t * (p1 - p0));
|
|
|
+ return p0 + t * (p1 - p0);
|
|
|
}
|
|
|
|
|
|
/// Returns the cosine interpolated value between @a p0 and @a p1 at time @a t
|
|
|
-template <typename T>
|
|
|
-inline T cosine(const T& p0, const T& p1, float t)
|
|
|
+inline float cosine(const float p0, const float p1, float t)
|
|
|
{
|
|
|
const float f = t * PI;
|
|
|
const float g = (1.0f - cosf(f)) * 0.5f;
|
|
|
|
|
|
- return p0 + (g * (p1 - p0));
|
|
|
+ return p0 + g * (p1 - p0);
|
|
|
}
|
|
|
|
|
|
/// Returns the cubic interpolated value between @a p0 and @a p1 at time @a t
|
|
|
-template <typename T>
|
|
|
-inline T cubic(const T& p0, const T& p1, float t)
|
|
|
+inline float cubic(const float p0, const float p1, float t)
|
|
|
{
|
|
|
- const float tt = t * t;
|
|
|
+ const float tt = t * t;
|
|
|
const float ttt = tt * t;
|
|
|
|
|
|
return p0 * (2.0f * ttt - 3.0f * tt + 1.0f) + p1 * (3.0f * tt - 2.0f * ttt);
|
|
|
}
|
|
|
|
|
|
/// Bezier interpolation
|
|
|
-template <typename T>
|
|
|
-inline T bezier(const T& p0, const T& p1, const T& p2, const T& p3, float t)
|
|
|
+inline float bezier(const float p0, const float p1, const float p2, const float p3, float t)
|
|
|
{
|
|
|
- const float u = 1.0f - t;
|
|
|
- const float tt = t * t ;
|
|
|
- const float uu = u * u;
|
|
|
+ const float u = 1.0f - t;
|
|
|
+ const float tt = t * t ;
|
|
|
+ const float uu = u * u;
|
|
|
const float uuu = uu * u;
|
|
|
const float ttt = tt * t;
|
|
|
|
|
|
- T tmp = (uuu * p0) +
|
|
|
- (3.0f * uu * t * p1) +
|
|
|
- (3.0f * u * tt * p2) +
|
|
|
- (ttt * p3);
|
|
|
+ const float tmp = (uuu * p0)
|
|
|
+ + (3.0f * uu * t * p1)
|
|
|
+ + (3.0f * u * tt * p2)
|
|
|
+ + (ttt * p3);
|
|
|
|
|
|
return tmp;
|
|
|
}
|
|
|
|
|
|
/// Catmull-Rom interpolation
|
|
|
-template <typename T>
|
|
|
-inline T catmull_rom(const T& p0, const T& p1, const T& p2, const T& p3, float t)
|
|
|
+inline float catmull_rom(const float p0, const float p1, const float p2, const float p3, float t)
|
|
|
{
|
|
|
- const float tt = t * t;
|
|
|
+ const float tt = t * t;
|
|
|
const float ttt = tt * t;
|
|
|
|
|
|
- T tmp = (2.0f * p1) +
|
|
|
- ((-p0 + p2) * t) +
|
|
|
- (((2.0f * p0) - (5.0f * p1) + (4.0f * p2) - p3) * tt) +
|
|
|
- ((-p0 + (3.0f * p1) + (-3.0f * p2) + p3) * ttt);
|
|
|
+ const float tmp = (2.0f * p1)
|
|
|
+ + (-p0 + p2) * t
|
|
|
+ + ((2.0f * p0) - (5.0f * p1) + (4.0f * p2) - p3) * tt
|
|
|
+ + (-p0 + (3.0f * p1) + (-3.0f * p2) + p3) * ttt;
|
|
|
|
|
|
return tmp * 0.5f;
|
|
|
}
|