Start RMathUtils

Former-commit-id: 4b9f690e10897f18eacd88fedfdaec4ae8968127
This commit is contained in:
2023-10-17 17:54:00 -07:00
parent fcf90460e9
commit eb50706b1e
3 changed files with 68 additions and 15 deletions

View File

@@ -5,20 +5,19 @@
#include "math.h"
#include <Kyoto/Math/CVector3f.hpp>
#define M_PIF 3.14159265358979323846f
#define M_2PIF 6.28318530718f
class CMath {
public:
static float FastCosR(float v);
static float FastSinR(float v);
static float FastArcCosR(float v);
static inline float FastFmod(float x, float y) {
int v = static_cast< int >(x * (1.f / y));
return x - v * y;
}
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 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); }
@@ -31,9 +30,7 @@ public:
return out;
}
#else
static inline float FastFSel(float v, float h, float l) {
return v >= 0.f ? h : l;
}
static inline float FastFSel(float v, float h, float l) { return v >= 0.f ? h : l; }
#endif
static inline float AbsF(float 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);
template < typename T >
static const T& Max(const T& a, const T& b);
// InvSqrtF__5CMathFf global
// FastArcCosR__5CMathFf global
// SlowCosineR__5CMathFf global
// SlowSineR__5CMathFf global
// FastCosR__5CMathFf global
// GetBezierPoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global
static float InvSqrtF(float x);
static float FastArcCosR(float x);
static float SlowCosineR(float x);
static float SlowSineR(float x);
static float SlowTangentR(float x);
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) {
float value = FastFmod(rad, M_2PIF);
if (value < 0.f) {
@@ -60,8 +60,12 @@ public:
// ModF__5CMathFff weak
static float Deg2Rad(float deg) { return Deg2Rev(deg) * M_2PIF; }
static float Deg2Rev(float deg) { return deg * (1.f / 360.f); }
static float ArcSineR(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
// GetCatmullRomSplinePoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global
// FastSqrtF__5CMathFf weak
@@ -77,8 +81,18 @@ public:
static float Rad2Rev(float rad) { return rad * (1.f / M_2PIF); }
// CeilingF__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);
};
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