RMathUtils progress

This commit is contained in:
Phillip Stephens 2025-04-22 14:54:28 -07:00
parent d53f80e881
commit 3f85b60b58
3 changed files with 44 additions and 2 deletions

View File

@ -954,7 +954,7 @@ config.libs = [
Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/Graphics/DolphinCTexture.cpp"), Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/Graphics/DolphinCTexture.cpp"),
Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/Math/CloseEnough.cpp"), Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/Math/CloseEnough.cpp"),
Object(NonMatching, "Kyoto/Math/CMatrix3f.cpp"), Object(NonMatching, "Kyoto/Math/CMatrix3f.cpp"),
Object(NonMatching, "Kyoto/Math/CMatrix4f.cpp"), Object(Equivalent, "Kyoto/Math/CMatrix4f.cpp"),
Object(NonMatching, "Kyoto/Math/CQuaternion.cpp"), Object(NonMatching, "Kyoto/Math/CQuaternion.cpp"),
Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/CRandom16.cpp"), Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/CRandom16.cpp"),
Object(NonMatching, "Kyoto/Math/CTransform4f.cpp"), Object(NonMatching, "Kyoto/Math/CTransform4f.cpp"),

View File

@ -4,9 +4,11 @@
#include "types.h" #include "types.h"
#include "math.h" #include "math.h"
#include "float.h"
#include <Kyoto/Math/CVector3f.hpp> #include <Kyoto/Math/CVector3f.hpp>
#define M_PI 3.14159265358979323846
#define M_PIF 3.14159265358979323846f #define M_PIF 3.14159265358979323846f
#define M_2PIF 6.28318530718f #define M_2PIF 6.28318530718f

View File

@ -70,4 +70,44 @@ CVector3f CMath::BaryToWorld(const CVector3f& p0, const CVector3f& p1, const CVe
return bary.GetX() * p0 + bary.GetY() * p1 + bary.GetZ() * p2; return bary.GetX() * p0 + bary.GetY() * p1 + bary.GetZ() * p2;
} }
float CMath::FastSinR(float x) {} float CMath::FastSinR(float x) {
if (fabs(x) > M_PI) {
x = -((float)(int)(x * (1 / M_2PIF)) * M_2PIF - x);
if (x > M_PIF) {
x -= M_2PIF;
} else if (x < -M_PIF) {
x = M_2PIF + x;
}
}
float f4 = x * x;
float f5 = x * 0.9998508f;
x *= f4;
f5 += -0.16621658f * x;
x *= f4;
f5 += 0.008087108f * x;
x *= f4;
f5 += -0.000152977f * x;
return f5;
}
float CMath::FastCosR(float x) {}
float CMath::FastArcCosR(float x) {}
int CMath::FloorPowerOfTwo(int v) {
if (v == 0) {
return 0;
}
uint s1 = (0xffffU - v) >> 0x1b & 0x10;
uint sb1 = (uint)v >> s1 & 0xffff;
uint s2 = (0xff - sb1) >> 0x1c & 8;
uint sb2 = sb1 >> s2 & 0xff;
uint s3 = ((0xf - sb2) >> 0x1d) & 4;
uint sb3 = (sb2 >> s3) & 0xf;
uint s4 = (3 - sb3) >> 0x1e & 2;
uint totalShift = s1 + s2 + s3 + s4;
uint finalSig = sb3 >> s4 & 3;
uint finalShift = (((uint)(1 - finalSig) >> 0x1f)) + totalShift;
return 1 << finalShift;
}