mirror of https://github.com/PrimeDecomp/prime.git
Start RMathUtils
Former-commit-id: 4b9f690e10897f18eacd88fedfdaec4ae8968127
This commit is contained in:
parent
fcf90460e9
commit
eb50706b1e
|
@ -5,20 +5,19 @@
|
||||||
|
|
||||||
#include "math.h"
|
#include "math.h"
|
||||||
|
|
||||||
|
#include <Kyoto/Math/CVector3f.hpp>
|
||||||
|
|
||||||
#define M_PIF 3.14159265358979323846f
|
#define M_PIF 3.14159265358979323846f
|
||||||
#define M_2PIF 6.28318530718f
|
#define M_2PIF 6.28318530718f
|
||||||
|
|
||||||
class CMath {
|
class CMath {
|
||||||
public:
|
public:
|
||||||
static float FastCosR(float v);
|
|
||||||
static float FastSinR(float v);
|
|
||||||
static float FastArcCosR(float v);
|
|
||||||
static inline float FastFmod(float x, float y) {
|
static inline float FastFmod(float x, float y) {
|
||||||
int v = static_cast< int >(x * (1.f / y));
|
int v = static_cast< int >(x * (1.f / y));
|
||||||
return x - v * y;
|
return x - v * y;
|
||||||
}
|
}
|
||||||
template < typename T >
|
template < typename T >
|
||||||
static const T& Clamp(const T& min, const T& val, const T& max); // TODO: weak
|
static const T& Clamp(const T& min, const T& val, const T& max);
|
||||||
static float SqrtF(float v);
|
static float SqrtF(float v);
|
||||||
static inline float Limit(float v, float h) { return fabs(v) > h ? h * Sign(v) : v; }
|
static inline float Limit(float v, float h) { return fabs(v) > h ? h * Sign(v) : v; }
|
||||||
static inline float Sign(float v) { return FastFSel(v, 1.f, -1.f); }
|
static inline float Sign(float v) { return FastFSel(v, 1.f, -1.f); }
|
||||||
|
@ -31,9 +30,7 @@ public:
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static inline float FastFSel(float v, float h, float l) {
|
static inline float FastFSel(float v, float h, float l) { return v >= 0.f ? h : l; }
|
||||||
return v >= 0.f ? h : l;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
static inline float AbsF(float v) { return fabs(v); }
|
static inline float AbsF(float v) { return fabs(v); }
|
||||||
static inline double AbsD(double v) { return fabs(v); }
|
static inline double AbsD(double v) { return fabs(v); }
|
||||||
|
@ -44,12 +41,15 @@ public:
|
||||||
static const T& Min(const T& a, const T& b);
|
static const T& Min(const T& a, const T& b);
|
||||||
template < typename T >
|
template < typename T >
|
||||||
static const T& Max(const T& a, const T& b);
|
static const T& Max(const T& a, const T& b);
|
||||||
// InvSqrtF__5CMathFf global
|
static float InvSqrtF(float x);
|
||||||
// FastArcCosR__5CMathFf global
|
static float FastArcCosR(float x);
|
||||||
// SlowCosineR__5CMathFf global
|
static float SlowCosineR(float x);
|
||||||
// SlowSineR__5CMathFf global
|
static float SlowSineR(float x);
|
||||||
// FastCosR__5CMathFf global
|
static float SlowTangentR(float x);
|
||||||
// GetBezierPoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global
|
static float FastSinR(float x);
|
||||||
|
static float FastCosR(float x);
|
||||||
|
static CVector3f GetBezierPoint(const CVector3f&, const CVector3f&, const CVector3f&,
|
||||||
|
const CVector3f&, float);
|
||||||
static float ClampRadians(float rad) {
|
static float ClampRadians(float rad) {
|
||||||
float value = FastFmod(rad, M_2PIF);
|
float value = FastFmod(rad, M_2PIF);
|
||||||
if (value < 0.f) {
|
if (value < 0.f) {
|
||||||
|
@ -60,8 +60,12 @@ public:
|
||||||
// ModF__5CMathFff weak
|
// ModF__5CMathFff weak
|
||||||
static float Deg2Rad(float deg) { return Deg2Rev(deg) * M_2PIF; }
|
static float Deg2Rad(float deg) { return Deg2Rev(deg) * M_2PIF; }
|
||||||
static float Deg2Rev(float deg) { return deg * (1.f / 360.f); }
|
static float Deg2Rev(float deg) { return deg * (1.f / 360.f); }
|
||||||
|
static float ArcSineR(float v);
|
||||||
static float ArcCosineR(float v);
|
static float ArcCosineR(float v);
|
||||||
// FloorF__5CMathFf global
|
static float ArcTangentR(float v);
|
||||||
|
static float PowF(float x, float y);
|
||||||
|
static const float FloorF(float x);
|
||||||
|
static float CeilingF(float x);
|
||||||
// BaryToWorld__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3f global
|
// BaryToWorld__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3f global
|
||||||
// GetCatmullRomSplinePoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global
|
// GetCatmullRomSplinePoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global
|
||||||
// FastSqrtF__5CMathFf weak
|
// FastSqrtF__5CMathFf weak
|
||||||
|
@ -77,8 +81,18 @@ public:
|
||||||
static float Rad2Rev(float rad) { return rad * (1.f / M_2PIF); }
|
static float Rad2Rev(float rad) { return rad * (1.f / M_2PIF); }
|
||||||
// CeilingF__5CMathFf global
|
// CeilingF__5CMathFf global
|
||||||
// ArcTangentR__5CMathFf global
|
// ArcTangentR__5CMathFf global
|
||||||
// Swap<f>__5CMathFRfRf weak
|
template < typename T >
|
||||||
|
static void Swap(T& a, T& b) {
|
||||||
|
T tmp = a;
|
||||||
|
a = b;
|
||||||
|
b = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
static int FloorPowerOfTwo(int v);
|
static int FloorPowerOfTwo(int v);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template < typename T >
|
||||||
|
const T& CMath::Clamp(const T& min, const T& val, const T& max) {
|
||||||
|
return min > val ? min : max < val ? max : val;
|
||||||
|
}
|
||||||
#endif // _CMATH
|
#endif // _CMATH
|
||||||
|
|
|
@ -73,6 +73,7 @@ double cos(double x);
|
||||||
double atan(double x);
|
double atan(double x);
|
||||||
double atan2(double y, double x);
|
double atan2(double y, double x);
|
||||||
double tan(double x);
|
double tan(double x);
|
||||||
|
double ceil(double x);
|
||||||
|
|
||||||
_MATH_INLINE float fabsf(float x) { return (float)fabs((double)x); }
|
_MATH_INLINE float fabsf(float x) { return (float)fabs((double)x); }
|
||||||
_MATH_INLINE float sinf(float x) { return (float)sin((double)x); }
|
_MATH_INLINE float sinf(float x) { return (float)sin((double)x); }
|
||||||
|
@ -80,8 +81,11 @@ _MATH_INLINE float cosf(float x) { return (float)cos((double)x); }
|
||||||
_MATH_INLINE float atan2f(float y, float x) { return (float)atan2((double)y, (double)x); }
|
_MATH_INLINE float atan2f(float y, float x) { return (float)atan2((double)y, (double)x); }
|
||||||
_MATH_INLINE float fmodf(float x, float m) { return (float)fmod((double)x, (double)m); }
|
_MATH_INLINE float fmodf(float x, float m) { return (float)fmod((double)x, (double)m); }
|
||||||
float tanf(float x);
|
float tanf(float x);
|
||||||
|
double asin(double x);
|
||||||
double acos(double x);
|
double acos(double x);
|
||||||
float acosf(float x);
|
float acosf(float x);
|
||||||
|
double log(double x);
|
||||||
|
double exp(double x);
|
||||||
|
|
||||||
double ldexp(double x, int exp);
|
double ldexp(double x, int exp);
|
||||||
|
|
||||||
|
|
|
@ -3,3 +3,38 @@
|
||||||
float CMath::SqrtF(float x) { return 0.f; }
|
float CMath::SqrtF(float x) { return 0.f; }
|
||||||
|
|
||||||
double CMath::SqrtD(double x) { return 0.0; }
|
double CMath::SqrtD(double x) { return 0.0; }
|
||||||
|
|
||||||
|
float CMath::InvSqrtF(float x) { return 0.f; }
|
||||||
|
|
||||||
|
float CMath::ArcSineR(float v) { return asin(v); }
|
||||||
|
|
||||||
|
float CMath::ArcCosineR(float v) { return acos(v); }
|
||||||
|
|
||||||
|
float CMath::ArcTangentR(float v) { return atan(v); }
|
||||||
|
|
||||||
|
float CMath::PowF(float x, float y) { return exp(log(x) * y); }
|
||||||
|
|
||||||
|
float CMath::SlowSineR(float x) { return sin(x); }
|
||||||
|
|
||||||
|
float CMath::SlowCosineR(float x) { return cos(x); }
|
||||||
|
|
||||||
|
float CMath::SlowTangentR(float x) { return tan(x); }
|
||||||
|
|
||||||
|
const float CMath::FloorF(float x) { return floor(x); }
|
||||||
|
|
||||||
|
float CMath::CeilingF(float x) {
|
||||||
|
float tmp = FloorF(x);
|
||||||
|
if (tmp == x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
return tmp + 1.f;
|
||||||
|
}
|
||||||
|
|
||||||
|
CVector3f CMath::GetBezierPoint(const CVector3f& a, const CVector3f& b, const CVector3f& c,
|
||||||
|
const CVector3f& d, float t) {
|
||||||
|
const float omt = 1.f - t;
|
||||||
|
return ((a * omt + b * t) * omt + (b * omt + c * t) * t) * omt +
|
||||||
|
((b * omt + c * t) * omt + (c * omt + d * t) * t) * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
float CMath::FastSinR(float x) {}
|
||||||
|
|
Loading…
Reference in New Issue