From a19a4d3378586218bb0c9ae2241029a272bfe067 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Fri, 5 Jan 2024 02:32:41 -0500 Subject: [PATCH] d_bg_s_acch almost --- include/SSystem/SComponent/c_m3d_g_pla.h | 20 ++++++++++++-------- src/SSystem/SComponent/c_bg_w.cpp | 2 +- src/d/d_bg_s_acch.cpp | 12 ++++++------ 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/SSystem/SComponent/c_m3d_g_pla.h b/include/SSystem/SComponent/c_m3d_g_pla.h index 8b8c562f2..995d90053 100644 --- a/include/SSystem/SComponent/c_m3d_g_pla.h +++ b/include/SSystem/SComponent/c_m3d_g_pla.h @@ -24,13 +24,20 @@ public: cXyz* GetNP() { return &mNormal; } const cXyz* GetNP() const { return &mNormal; } f32 GetD() const { return mD; } - float getCrossY(const cXyz& i_axis) const { // fake inline + void getCrossY(const cXyz& i_axis, f32* i_value) const { + if (!cM3d_IsZero(mNormal.y)) { + *i_value = (-mNormal.x * i_axis.x - mNormal.z * i_axis.z - mD) / mNormal.y; + } + } + f32 getCrossY_NonIsZero(const cXyz& i_axis) const { return (-mNormal.x * i_axis.x - mNormal.z * i_axis.z - mD) / mNormal.y; } - void getCrossY(const cXyz& i_axis, float* i_value) const { - if (!cM3d_IsZero(mNormal.y)) { - *i_value = getCrossY(i_axis); + bool getCrossYLessD(const Vec& i_axis, f32* i_value) const { + if (cM3d_IsZero(mNormal.y)) { + return false; } + *i_value = (-mNormal.x * i_axis.x - mNormal.z * i_axis.z) / mNormal.y; + return true; } f32 getSignedLenPos(const cXyz* param_1) const { return cM3d_SignedLenPlaAndPos(this, param_1); @@ -41,11 +48,8 @@ public: // TODO void Set(const cM3dGPla*) {} void SetupFrom3Vtx(const Vec*, const Vec*, const Vec*) {} - cM3dGPla(const cXyz*, float) {} + cM3dGPla(const cXyz*, f32) {} void cross(const cM3dGLin&, Vec&) const {} - void getCrossYLessD(const Vec&, float*) const {} - void getCrossY_NonIsZero(const cXyz&) const {} - void operator=(const cM3dGPla&) {} }; // Size: 0x14 #endif diff --git a/src/SSystem/SComponent/c_bg_w.cpp b/src/SSystem/SComponent/c_bg_w.cpp index 250aea6fe..5bfe65b65 100644 --- a/src/SSystem/SComponent/c_bg_w.cpp +++ b/src/SSystem/SComponent/c_bg_w.cpp @@ -177,7 +177,7 @@ bool cBgW::RwgGroundCheckGnd(u16 idx, cBgS_GndChk* chk) { while (true) { cBgW_RwgElm * rwg = &pm_rwg[idx]; cBgW_TriElm * tri = &pm_tri[idx]; - f32 y = tri->m_plane.getCrossY(*chk->GetPointP()); + f32 y = tri->m_plane.getCrossY_NonIsZero(*chk->GetPointP()); if (RwgGroundCheckCommon(y, (u16)idx, chk)) ret = true; idx = rwg->next; diff --git a/src/d/d_bg_s_acch.cpp b/src/d/d_bg_s_acch.cpp index ecab204b6..3887cbec5 100644 --- a/src/d/d_bg_s_acch.cpp +++ b/src/d/d_bg_s_acch.cpp @@ -116,7 +116,6 @@ void dBgS_Acch::GroundCheckInit(dBgS&) { /* 800A2EE8-800A305C .text GroundCheck__9dBgS_AcchFR4dBgS */ void dBgS_Acch::GroundCheck(dBgS& i_bgs) { - /* Nonmatching */ if (m_flags & GRND_NONE) return; @@ -446,11 +445,12 @@ bool dBgS_Acch::GetOnePolyInfo(cBgS_PolyInfo* dst) { /* 800A42B4-800A4348 .text GetWallAddY__9dBgS_AcchFR3Veci */ f32 dBgS_Acch::GetWallAddY(Vec& vec, int) { - /* Nonmatching */ - if (ChkGroundFind() && m_pla.GetNP()->y < 0.5f) { - f32 cross_y; - m_pla.getCrossY(vec, &cross_y); - if (cross_y < 0.0f) + if (!ChkGroundFind() || m_pla.mNormal.y < 0.5f) { + return 0.0f; + } + f32 cross_y; + if (m_pla.getCrossYLessD(vec, &cross_y)) { + if (cross_y > 0.0f) cross_y = 0.0f; return -cross_y; } else {