5 #include "EegeoPlatformMacros.h"
7 #if defined (EEGEO_WIN)
8 #define _USE_MATH_DEFINES
15 #define ARC4RANDOM_MAX 0x100000000
16 #define ARC4RANDOM_INVMAX (1.0f/(float)ARC4RANDOM_MAX)
21 T Min(
const T in1,
const T in2)
34 T Max(
const T in1,
const T in2)
47 T Clamp(
const T in,
const T min,
const T max)
66 const float kPI =
static_cast<float>(M_PI);
67 const float kFloatMax = FLT_MAX;
68 const float kEpsilon = 0.0001f;
70 inline double Deg2Rad (
double deg ) {
return (deg * M_PI) / 180.0;}
71 inline double Rad2Deg (
double rad ) {
return (rad * 180.0) / M_PI;}
73 inline float Deg2Rad (
float deg ) {
return (deg * kPI) / 180.0f;}
74 inline float Rad2Deg (
float rad ) {
return (rad * 180.0f) / kPI;}
75 inline float Abs (
float x ) {
return fabsf(x); }
76 inline float Sin (
float theta ) {
return sinf(theta); }
77 inline float Cos (
float theta ) {
return cosf(theta); }
78 inline float Tan (
float theta ) {
return tanf(theta); }
79 inline float ASin (
float theta ) {
return asinf(theta); }
80 inline float ACos (
float theta ) {
return acosf(theta); }
81 inline float ATan (
float theta ) {
return atanf(theta); }
82 inline float ATan2 (
float y,
float x ) {
return atan2f(y, x); }
84 inline float Pow (
float x,
float y ) {
return powf(x, y); }
86 inline float Log (
float x ) {
return logf(x); }
87 inline float Exp (
float x ) {
return expf(x); }
89 inline float Sqrtf (
float x ) {
return sqrtf(x); }
90 inline double Sqrtd (
double x ) {
return sqrt(x); }
92 inline float Modf (
float x,
float* pI ) {
return modff(x, pI); }
94 float SmoothStep (
float in );
95 float SmoothStep (
float min,
float max,
float in );
97 float SmootherStep(
float in );
98 float SmootherStep(
float min,
float max,
float in );
100 inline float Clamp01(
float x);
101 inline double Clamp01(
double x);
103 inline float SinEaseInOut(
float t);
105 template <
typename T>
106 T Clamp(
const T in,
const T min,
const T max)
108 return Eegeo::Clamp(in, min, max);
111 template <
typename T>
112 T Lerp(
const T x,
const T y,
const T t);
115 inline float Lerp(
const float x,
const float y,
const float t)
117 return x * (1.0f - t) + y * t;
121 inline double Lerp(
const double x,
const double y,
const double t)
123 return x * (1.0 - t) + y * t;
127 inline float Math::SmoothStep(
float in)
129 return in * in * (3.0f - 2.0f * in);
132 inline float Math::SmoothStep(
float min,
float max,
float in)
134 in = ((in - min)/(max - min));
145 return in * in * (3.0f - 2.0f * in);
148 inline float Math::SmootherStep(
float in)
150 return in * in * in * (in * (in * 6 - 15) + 10);
153 inline float Math::SmootherStep(
float min,
float max,
float in)
155 in = ((in - min)/(max - min));
166 return in * in * in * (in * (in * 6 - 15) + 10);
169 inline float Math::Clamp01(
float x)
171 return Clamp(x, 0.f, 1.f);
174 inline double Math::Clamp01(
double x)
176 return Clamp(x, 0.0, 1.0);
179 inline float Math::SinEaseInOut(
float t)
181 return 1.0f - 0.5f * (1.0f + Cos(t * kPI));