2015-04-19 20:39:16 +00:00
|
|
|
#ifndef MATH_HPP
|
|
|
|
#define MATH_HPP
|
|
|
|
|
2015-10-12 04:40:59 +00:00
|
|
|
#ifndef NOMINMAX
|
|
|
|
#define NOMINMAX 1
|
|
|
|
#endif
|
|
|
|
#ifndef _USE_MATH_DEFINES
|
2015-04-19 20:39:16 +00:00
|
|
|
#define _USE_MATH_DEFINES 1
|
2015-10-12 08:46:45 +00:00
|
|
|
#include <cmath>
|
2015-10-12 04:40:59 +00:00
|
|
|
#endif
|
2015-10-12 08:49:33 +00:00
|
|
|
|
2015-04-19 20:39:16 +00:00
|
|
|
#include "CVector3f.hpp"
|
|
|
|
#include "CTransform.hpp"
|
|
|
|
|
2015-10-08 00:21:38 +00:00
|
|
|
namespace Zeus
|
|
|
|
{
|
2015-04-19 20:39:16 +00:00
|
|
|
namespace Math
|
|
|
|
{
|
2015-08-29 01:29:17 +00:00
|
|
|
template<typename T>
|
2015-10-12 08:46:45 +00:00
|
|
|
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 val, T b) {return max<T>(a, min<T>(b, val));}
|
2015-04-19 20:39:16 +00:00
|
|
|
inline float radToDeg(float rad) {return rad * 180.f / M_PI;}
|
|
|
|
inline float degToRad(float deg) {return deg * M_PI / 180;}
|
2015-08-29 04:49:19 +00:00
|
|
|
|
2015-04-19 20:39:16 +00:00
|
|
|
extern const CVector3f kRadToDegVec;
|
|
|
|
extern const CVector3f kDegToRadVec;
|
|
|
|
inline CVector3f radToDeg(CVector3f rad) {return rad * kRadToDegVec;}
|
|
|
|
inline CVector3f degToRad(CVector3f deg) {return deg * kDegToRadVec;}
|
2015-08-29 04:49:19 +00:00
|
|
|
|
2015-04-19 20:39:16 +00:00
|
|
|
extern const CVector3f kUpVec;
|
|
|
|
CTransform lookAt(const CVector3f& pos, const CVector3f& lookPos, const CVector3f& up=kUpVec);
|
2015-08-12 01:41:28 +00:00
|
|
|
inline CVector3f baryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, const CVector3f& bary)
|
|
|
|
{ return bary.x * p0 + bary.y * p1 + bary.z * p2; }
|
2015-10-08 00:21:38 +00:00
|
|
|
|
2015-10-12 09:38:34 +00:00
|
|
|
CVector3f getBezierPoint(const CVector3f& a, const CVector3f& b,
|
|
|
|
const CVector3f& c, const CVector3f& d, float t);
|
2015-10-12 08:46:45 +00:00
|
|
|
float getCatmullRomSplinePoint(float a, float b,
|
|
|
|
float c, float d, float t);
|
|
|
|
CVector3f getCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
|
|
|
const CVector3f& c, const CVector3f& d, float t);
|
2015-10-12 09:38:34 +00:00
|
|
|
CVector3f getRoundCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b,
|
|
|
|
const CVector3f& c, const CVector3f& d, float t);
|
2015-10-12 00:33:42 +00:00
|
|
|
|
2015-10-12 08:46:45 +00:00
|
|
|
inline float slowCosineR(float val) { return float(cos(val)); }
|
|
|
|
inline float slowSineR(float val) { return float(sin(val)); }
|
|
|
|
inline float slowTangentR(float val) { return float(tan(val)); }
|
|
|
|
inline float arcSineR(float val) { return float(asin(val)); }
|
|
|
|
inline float arcTangentR(float val) { return float(atan(val)); }
|
|
|
|
inline float arcCosineR(float val) { return float(acos(val)); }
|
|
|
|
inline float powF(float a, float b) { return float(exp(b * log(a))); }
|
|
|
|
inline float floorF(float val) { return float(floor(val)); }
|
|
|
|
inline float ceilingF(float val)
|
2015-10-12 00:33:42 +00:00
|
|
|
{
|
2015-10-12 08:46:45 +00:00
|
|
|
float tmp = floorF(val);
|
|
|
|
return (tmp == val ? tmp : tmp + 1.0);
|
2015-10-12 00:33:42 +00:00
|
|
|
}
|
|
|
|
|
2015-10-12 08:46:45 +00:00
|
|
|
// Since round(double) doesn't exist in some <cmath> implementations
|
|
|
|
// we'll define our own
|
2015-10-12 09:19:19 +00:00
|
|
|
inline double round(double val) { return (val < 0.0 ? ceilingF(val - 0.5) : floorF(val + 0.5)); }
|
2015-10-12 08:46:45 +00:00
|
|
|
inline double powD(float a, float b) { return exp(a * log(b)); }
|
|
|
|
|
|
|
|
double sqrtD(double val);
|
|
|
|
inline double invSqrtD(double val) { return 1.0 / sqrtD(val); }
|
|
|
|
inline float invSqrtF(float val) { return float(1.0 / sqrtD(val)); }
|
|
|
|
inline float sqrtF(float val) { return float(sqrtD(val)); }
|
|
|
|
float fastArcCosR(float val);
|
|
|
|
float fastCosR(float val);
|
|
|
|
float fastSinR(float val);
|
|
|
|
int floorPowerOfTwo(int x);
|
2015-10-08 00:21:38 +00:00
|
|
|
}
|
2015-04-19 20:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MATH_HPP
|