diff --git a/configure.py b/configure.py index cb32bba3..b9e729a9 100755 --- a/configure.py +++ b/configure.py @@ -954,7 +954,7 @@ config.libs = [ Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/Graphics/DolphinCTexture.cpp"), Object(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/Math/CloseEnough.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(MatchingFor("GM8E01_00", "GM8E01_01"), "Kyoto/CRandom16.cpp"), Object(NonMatching, "Kyoto/Math/CTransform4f.cpp"), diff --git a/include/Kyoto/Math/CMath.hpp b/include/Kyoto/Math/CMath.hpp index 8a7e2810..bffac847 100644 --- a/include/Kyoto/Math/CMath.hpp +++ b/include/Kyoto/Math/CMath.hpp @@ -4,9 +4,11 @@ #include "types.h" #include "math.h" +#include "float.h" #include +#define M_PI 3.14159265358979323846 #define M_PIF 3.14159265358979323846f #define M_2PIF 6.28318530718f diff --git a/src/Kyoto/Math/RMathUtils.cpp b/src/Kyoto/Math/RMathUtils.cpp index 62fc7e91..56221249 100644 --- a/src/Kyoto/Math/RMathUtils.cpp +++ b/src/Kyoto/Math/RMathUtils.cpp @@ -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; } -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; +}