diff --git a/config/GM8E01_00/symbols.txt b/config/GM8E01_00/symbols.txt index 814b3a3d..6d2bb95a 100644 --- a/config/GM8E01_00/symbols.txt +++ b/config/GM8E01_00/symbols.txt @@ -14518,11 +14518,11 @@ __sinit_CARAMManager_cpp = .text:0x80344F00; // type:function size:0x54 scope:lo __dt__Q24rstl67listFv = .text:0x80344F54; // type:function size:0x78 scope:weak PointInFrustumPlanes__14CFrustumPlanesCFRC9CVector3f = .text:0x80344FCC; // type:function size:0x60 scope:global SphereInFrustumPlanes__14CFrustumPlanesCFRC7CSphere = .text:0x8034502C; // type:function size:0x6C scope:global -fn_80345098 = .text:0x80345098; // type:function size:0xF0 +BoxFrustumPlanesCheck__14CFrustumPlanesCFRC6CAABox = .text:0x80345098; // type:function size:0xF0 BoxInFrustumPlanes__14CFrustumPlanesCFRCQ24rstl24optional_object<6CAABox> = .text:0x80345188; // type:function size:0x48 scope:global BoxInFrustumPlanes__14CFrustumPlanesCFRC6CAABox = .text:0x803451D0; // type:function size:0x84 scope:global __ct__14CFrustumPlanesFRC12CTransform4ffffbf = .text:0x80345254; // type:function size:0x45C scope:global -fn_803456B0 = .text:0x803456B0; // type:function size:0x9C +fn_803456B0__FRC9CVector3fRC9CVector3fRC9CVector3f = .text:0x803456B0; // type:function size:0x9C GetCompressedBlend__13CCubeMaterialCFv = .text:0x8034574C; // type:function size:0x38 scope:global DisableShadowMaps__10CCubeModelFv = .text:0x80345784; // type:function size:0xC scope:global EnableShadowMaps__10CCubeModelFPC8CTextureRC12CTransform4fUcUc = .text:0x80345790; // type:function size:0x58 scope:global diff --git a/config/GM8E01_01/symbols.txt b/config/GM8E01_01/symbols.txt index 5ec8bc38..7d279ee3 100644 --- a/config/GM8E01_01/symbols.txt +++ b/config/GM8E01_01/symbols.txt @@ -14533,11 +14533,11 @@ __sinit_CARAMManager_cpp = .text:0x80344FE0; // type:function size:0x54 scope:gl __dt__Q24rstl67listFv = .text:0x80345034; // type:function size:0x78 scope:global PointInFrustumPlanes__14CFrustumPlanesCFRC9CVector3f = .text:0x803450AC; // type:function size:0x60 scope:global SphereInFrustumPlanes__14CFrustumPlanesCFRC7CSphere = .text:0x8034510C; // type:function size:0x6C scope:global -fn_80345098 = .text:0x80345178; // type:function size:0xF0 scope:global +BoxFrustumPlanesCheck__14CFrustumPlanesCFRC6CAABox = .text:0x80345178; // type:function size:0xF0 scope:global BoxInFrustumPlanes__14CFrustumPlanesCFRCQ24rstl24optional_object<6CAABox> = .text:0x80345268; // type:function size:0x48 scope:global BoxInFrustumPlanes__14CFrustumPlanesCFRC6CAABox = .text:0x803452B0; // type:function size:0x84 scope:global __ct__14CFrustumPlanesFRC12CTransform4ffffbf = .text:0x80345334; // type:function size:0x45C scope:global -fn_803456B0 = .text:0x80345790; // type:function size:0x9C scope:global +fn_803456B0__FRC9CVector3fRC9CVector3fRC9CVector3f = .text:0x80345790; // type:function size:0x9C scope:global GetCompressedBlend__13CCubeMaterialCFv = .text:0x8034582C; // type:function size:0x38 scope:global DisableShadowMaps__10CCubeModelFv = .text:0x80345864; // type:function size:0xC scope:global EnableShadowMaps__10CCubeModelFPC8CTextureRC12CTransform4fUcUc = .text:0x80345870; // type:function size:0x58 scope:global diff --git a/include/Kyoto/Math/CFrustumPlanes.hpp b/include/Kyoto/Math/CFrustumPlanes.hpp index 047150b1..65f5b7f3 100644 --- a/include/Kyoto/Math/CFrustumPlanes.hpp +++ b/include/Kyoto/Math/CFrustumPlanes.hpp @@ -4,6 +4,7 @@ #include "types.h" #include "Kyoto/Math/CVector3f.hpp" +#include "Kyoto/Math/CPlane.hpp" #include "rstl/optional_object.hpp" #include "rstl/reserved_vector.hpp" @@ -14,22 +15,16 @@ class CTransform4f; class CFrustumPlanes { public: - class SPlane { - private: - float x; - float y; - float z; - float d; - }; CFrustumPlanes(const CTransform4f&, float, float, float, bool, float); bool BoxInFrustumPlanes(const CAABox& box) const; bool BoxInFrustumPlanes(const rstl::optional_object< CAABox >& box) const; + int BoxFrustumPlanesCheck(const CAABox& box) const; bool SphereInFrustumPlanes(const CSphere& sphere) const; bool PointInFrustumPlanes(const CVector3f& point) const; private: - rstl::reserved_vector< SPlane, 6 > x0_planes; + rstl::reserved_vector< CPlane, 6 > x0_planes; }; #endif // _CFRUSTUMPLANES diff --git a/include/Kyoto/Math/CMath.hpp b/include/Kyoto/Math/CMath.hpp index 3c4ef5cb..1c51f3b9 100644 --- a/include/Kyoto/Math/CMath.hpp +++ b/include/Kyoto/Math/CMath.hpp @@ -48,8 +48,6 @@ public: 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) { @@ -66,7 +64,13 @@ public: static float PowF(float x, float y); static const float FloorF(float x); static float CeilingF(float x); - // BaryToWorld__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3f global + static CVector3f GetCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, + const CVector3f& c, const CVector3f& d, float t); + static float GetCatmullRomSplinePoint(float a, float b, float c, float d, float t); + static CVector3f GetBezierPoint(const CVector3f&, const CVector3f&, const CVector3f&, + const CVector3f&, float); + static CVector3f BaryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, + const CVector3f& bary); // GetCatmullRomSplinePoint__5CMathFRC9CVector3fRC9CVector3fRC9CVector3fRC9CVector3ff global // FastSqrtF__5CMathFf weak static double SqrtD(double x); diff --git a/include/Kyoto/Math/CPlane.hpp b/include/Kyoto/Math/CPlane.hpp index b847a926..2261fd53 100644 --- a/include/Kyoto/Math/CPlane.hpp +++ b/include/Kyoto/Math/CPlane.hpp @@ -19,7 +19,10 @@ public: float GetHeight(const CVector3f& pos) const { return CVector3f::Dot(GetNormal(), pos) - GetConstant(); } - // IsFacing__6CPlaneCFRC9CVector3f + bool IsFacing(const CVector3f& vec) const { + return CVector3f::Dot(x0_normal, vec) >= GetConstant(); + } + float ClipLineSegment(const CVector3f& start, const CVector3f& end) const; private: diff --git a/src/Kyoto/Math/CFrustumPlanes.cpp b/src/Kyoto/Math/CFrustumPlanes.cpp new file mode 100644 index 00000000..ef435066 --- /dev/null +++ b/src/Kyoto/Math/CFrustumPlanes.cpp @@ -0,0 +1,117 @@ +#include "Kyoto/Math/CPlane.hpp" +#include + +#include +#include +#include +#include + +#pragma dont_inline on +static CUnitVector3f fn_803456B0(const CVector3f& a, const CVector3f& b, const CVector3f& c) { + return CVector3f::Cross(b - a, c - a); +} +#pragma dont_inline reset + +CFrustumPlanes::CFrustumPlanes(const CTransform4f& xf, float a, float b, float c, bool b1, + float d) { + + float dVar6 = cos(a * 0.5f); + float dVar7 = sin(a * 0.5f); + float fVar1 = (c / dVar6) * dVar7; + dVar6 = cos(a * 0.5f * b); + dVar7 = sin(a * 0.5f * b); + + CVector3f local_b8; + CVector3f local_c4; + CVector3f local_a0; + CVector3f local_ac; + + local_b8.SetY(c); + local_b8.SetX((c / dVar6) * dVar7); + local_b8.SetZ(-fVar1); + local_c4.SetX((c / dVar6) * dVar7); + local_ac.SetX(-(c / dVar6) * dVar7); + local_c4.SetY(c); + local_c4.SetZ(fVar1); + local_ac.SetY(c); + local_ac.SetZ(-fVar1); + local_a0.SetX(-(c / dVar6) * dVar7); + local_a0.SetY(c); + local_a0.SetZ(fVar1); + + CVector3f local_f4 = xf.Rotate(local_c4); + CVector3f local_e8 = xf.Rotate(local_b8); + CVector3f local_dc = xf.Rotate(local_ac); + CVector3f local_d0 = xf.Rotate(local_a0); + + CVector3f pos = xf.GetTranslation(); + + CVector3f local_138 = xf * CVector3f(0.f, c, 0.f); + x0_planes.push_back(CPlane(local_138, fn_803456B0(local_f4, local_dc, local_e8))); + x0_planes.push_back(CPlane(pos, fn_803456B0(CVector3f::Zero(), local_e8, local_f4))); + x0_planes.push_back(CPlane(pos, fn_803456B0(CVector3f::Zero(), local_d0, local_dc))); + x0_planes.push_back(CPlane(pos, fn_803456B0(CVector3f::Zero(), local_f4, local_d0))); + x0_planes.push_back(CPlane( pos, fn_803456B0(CVector3f::Zero(), local_dc, local_e8))); + x0_planes.push_back(CPlane(x0_planes[0].GetConstant(), -x0_planes[0].GetNormal())); +} + +bool CFrustumPlanes::BoxInFrustumPlanes(const CAABox& box) const { + for (int i = 0; i < x0_planes.size(); ++i) { + if (!box.InsidePlane(x0_planes[i])) { + return false; + } + } + return true; +} + +bool CFrustumPlanes::BoxInFrustumPlanes(const rstl::optional_object< CAABox >& box) const { + if (x0_planes.empty()) { + return true; + } + + if (!box.valid()) { + return false; + } + + return BoxInFrustumPlanes(*box); +} + +int CFrustumPlanes::BoxFrustumPlanesCheck(const CAABox& box) const { + int ret = 1; + + for (int i = 0; i < x0_planes.size(); ++i) { + CVector3f closestPoint = box.ClosestPointAlongVector(x0_planes[i].GetNormal()); + + if (x0_planes[i].IsFacing(closestPoint)) { + return 0; + } + + if (ret == 1) { + CVector3f furthestPoint = box.FurthestPointAlongVector(x0_planes[i].GetNormal()); + if (x0_planes[i].IsFacing(furthestPoint)) { + ret = 2; + } + } + } + return ret; +} + +bool CFrustumPlanes::SphereInFrustumPlanes(const CSphere& sphere) const { + float radius = sphere.GetRadius(); + CVector3f pos = sphere.GetCenter(); + for (int i = 0; i < x0_planes.size(); ++i) { + if (x0_planes[i].GetHeight(pos) - radius > 0.f) { + return false; + } + } + return true; +} + +bool CFrustumPlanes::PointInFrustumPlanes(const CVector3f& point) const { + for (int i = 0; i < x0_planes.size(); ++i) { + if (x0_planes[i].IsFacing(point)) { + return false; + } + } + return true; +} diff --git a/src/Kyoto/Math/RMathUtils.cpp b/src/Kyoto/Math/RMathUtils.cpp index 3aac4d49..6e083475 100644 --- a/src/Kyoto/Math/RMathUtils.cpp +++ b/src/Kyoto/Math/RMathUtils.cpp @@ -29,12 +29,46 @@ float CMath::CeilingF(float x) { } return tmp + 1.f; } +CVector3f CMath::GetCatmullRomSplinePoint(const CVector3f& a, const CVector3f& b, + const CVector3f& c, const CVector3f& d, float t) { + if (t <= 0.0f) + return b; + if (t >= 1.0f) + return c; + + const float t2 = t * t; + const float t3 = t2 * t; + + return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) + + c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) + d * (0.5f * t3 - 0.5f * t2)); +} + +float CMath::GetCatmullRomSplinePoint(float a, float b, float c, float d, float t) { + if (t <= 0.0f) + return b; + if (t >= 1.0f) + return c; + + const float t2 = t * t; + const float t3 = t2 * t; + + return (a * (-0.5f * t3 + t2 - 0.5f * t) + b * (1.5f * t3 + -2.5f * t2 + 1.0f) + + c * (-1.5f * t3 + 2.0f * t2 + 0.5f * t) + d * (0.5f * t3 - 0.5f * t2)); +} 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; + const CVector3f& d, const float t) { + const CVector3f ab = Lerp(a, b, t); + const CVector3f bc = Lerp(b, c, t); + const CVector3f cd = Lerp(c, d, t); + const CVector3f abbc = Lerp(ab, bc, t); + const CVector3f bccd = Lerp(bc, cd, t); + return Lerp(abbc, bccd, t); +} + +CVector3f CMath::BaryToWorld(const CVector3f& p0, const CVector3f& p1, const CVector3f& p2, + const CVector3f& bary) { + return bary.GetX() * p0 + bary.GetY() * p1 + bary.GetZ() * p2; } float CMath::FastSinR(float x) {}