From 80843df748627926078ced00e3f069c8d98c79a6 Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Mon, 3 Oct 2022 16:15:34 +0300 Subject: [PATCH] Improve match for CScriptSpecialFunction::Render --- .../ScriptObjects/CScriptSpecialFunction.s | 6 +-- include/Kyoto/Math/CAABox.hpp | 7 +++ include/Kyoto/Math/CTransform4f.hpp | 2 +- include/MetaRender/CCubeRenderer.hpp | 2 +- include/MetroidPrime/CStateManager.hpp | 1 + .../ScriptObjects/CScriptSpecialFunction.cpp | 46 ++++++++++++------- 6 files changed, 42 insertions(+), 22 deletions(-) diff --git a/asm/MetroidPrime/ScriptObjects/CScriptSpecialFunction.s b/asm/MetroidPrime/ScriptObjects/CScriptSpecialFunction.s index 6cbc8240..ecd13220 100644 --- a/asm/MetroidPrime/ScriptObjects/CScriptSpecialFunction.s +++ b/asm/MetroidPrime/ScriptObjects/CScriptSpecialFunction.s @@ -16,7 +16,7 @@ lbl_803E2B68: .4byte SetActive__6CActorFb .4byte PreRender__22CScriptSpecialFunctionFR13CStateManagerRC14CFrustumPlanes .4byte AddToRenderer__22CScriptSpecialFunctionFRC14CFrustumPlanesR13CStateManager - .4byte Render__22CScriptSpecialFunctionCFRC13CStateManager + .4byte Render__22CScriptSpecialFunctionFR13CStateManager .4byte CanRenderUnsorted__6CActorCFRC13CStateManager .4byte CalculateRenderBounds__6CActorFv .4byte HealthInfo__6CActorFR13CStateManager @@ -958,8 +958,8 @@ lbl_8014FC98: /* 8014FCB4 0014CC14 38 21 08 B0 */ addi r1, r1, 0x8b0 /* 8014FCB8 0014CC18 4E 80 00 20 */ blr -.global Render__22CScriptSpecialFunctionCFRC13CStateManager -Render__22CScriptSpecialFunctionCFRC13CStateManager: +.global Render__22CScriptSpecialFunctionFR13CStateManager +Render__22CScriptSpecialFunctionFR13CStateManager: /* 8014FCBC 0014CC1C 94 21 FE A0 */ stwu r1, -0x160(r1) /* 8014FCC0 0014CC20 7C 08 02 A6 */ mflr r0 /* 8014FCC4 0014CC24 90 01 01 64 */ stw r0, 0x164(r1) diff --git a/include/Kyoto/Math/CAABox.hpp b/include/Kyoto/Math/CAABox.hpp index 8e25ee2d..62fde5f8 100644 --- a/include/Kyoto/Math/CAABox.hpp +++ b/include/Kyoto/Math/CAABox.hpp @@ -67,6 +67,13 @@ public: CVector3f ClampToBox(const CVector3f& vec) const; CAABox GetTransformedAABox(const CTransform4f& xf) const; + inline CVector3f GetExtents() const { + // Name is a guess + CVector3f result = max - min; + result *= 0.5f; + return result; + } + const CVector3f& GetMinPoint() const { return min; } const CVector3f& GetMaxPoint() const { return max; } diff --git a/include/Kyoto/Math/CTransform4f.hpp b/include/Kyoto/Math/CTransform4f.hpp index 031755b2..f49d03b5 100644 --- a/include/Kyoto/Math/CTransform4f.hpp +++ b/include/Kyoto/Math/CTransform4f.hpp @@ -70,7 +70,7 @@ public: // RotateZ__12CTransform4fFRC9CRelAngle // Scale__12CTransform4fFf // Scale__12CTransform4fFfff - // Scale__12CTransform4fFRC9CVector3f + static CTransform4f Scale(const CVector3f&); // ScaleBy__12CTransform4fFf // SetRotation__12CTransform4fFRC12CTransform4f // SetRotation__12CTransform4fFRC9CMatrix3f diff --git a/include/MetaRender/CCubeRenderer.hpp b/include/MetaRender/CCubeRenderer.hpp index 2f12cd38..b60712a1 100644 --- a/include/MetaRender/CCubeRenderer.hpp +++ b/include/MetaRender/CCubeRenderer.hpp @@ -71,7 +71,7 @@ public: virtual void DrawModelFlat(); virtual void SetWireframeFlags(); virtual void SetWorldFog(); - virtual void RenderFogVolume(); + virtual void RenderFogVolume(const CColor&, const CAABox&, const TLockedToken*, const CSkinnedModel*); virtual void SetThermal(); virtual void SetThermalColdScale(); virtual void DoThermalBlendCold(); diff --git a/include/MetroidPrime/CStateManager.hpp b/include/MetroidPrime/CStateManager.hpp index 3a8d2cc7..e0e9b3cb 100644 --- a/include/MetroidPrime/CStateManager.hpp +++ b/include/MetroidPrime/CStateManager.hpp @@ -147,6 +147,7 @@ public: xef4_pendingScreenTex.xc_extent = extent; } const SOnScreenTex& GetPendingScreenTex() const { return xef4_pendingScreenTex; } + float IntegrateVisorFog(float f); void SetShouldQuitGame(bool should) { xf94_25_quitGame = should; } void SetSkipCinematicSpecialFunction(TUniqueId id) { xf38_skipCineSpecialFunc = id; } diff --git a/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp b/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp index 3af10bf8..7596d0d5 100644 --- a/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp +++ b/src/MetroidPrime/ScriptObjects/CScriptSpecialFunction.cpp @@ -13,10 +13,12 @@ #include "MetroidPrime/ScriptObjects/CScriptPlatform.hpp" #include "MetroidPrime/TCastTo.hpp" +#include "MetaRender/CCubeRenderer.hpp" #include "Collision/CMaterialFilter.hpp" #include "Kyoto/Audio/CSfxManager.hpp" +#include "Kyoto/Graphics/CGraphics.hpp" #include "Kyoto/Math/CFrustumPlanes.hpp" #include "Kyoto/Math/CMath.hpp" #include "Kyoto/Math/CRelAngle.hpp" @@ -27,14 +29,12 @@ #include "Runtime/w_fmod.h" #include "rstl/math.hpp" - namespace rstl { - static int string_find(const string& haystack, const string& needle, int) { - // TODO: proper implementation - return 0; - } +static int string_find(const string& haystack, const string& needle, int) { + // TODO: proper implementation + return 0; } - +} // namespace rstl CScriptSpecialFunction::CScriptSpecialFunction( TUniqueId uid, const rstl::string& name, const CEntityInfo& info, const CTransform4f& xf, @@ -847,7 +847,8 @@ void CScriptSpecialFunction::ThinkSpinnerController(float dt, CStateManager& mgr animData->SetPlaybackRate(1.f); // Redundant copy is needed SAdvancementDeltas deltas = plat->UpdateAnimation(dur, mgr, true); - plat->SetTransform(x13c_spinnerInitialXf * deltas.xc_rotDelta.BuildTransform4f(deltas.x0_posDelta)); + plat->SetTransform(x13c_spinnerInitialXf * + deltas.xc_rotDelta.BuildTransform4f(deltas.x0_posDelta)); } } } @@ -926,17 +927,28 @@ void CScriptSpecialFunction::ThinkObjectFollowObject(float, CStateManager& mgr) void CScriptSpecialFunction::Render(CStateManager& mgr) { if (xe8_function == kSF_FogVolume) { - /* TODO - const float z = mgr.IntegrateVisorFog(xfc_float1 * std::sin(CGraphics::GetSecondsMod900())); - if (z > 0.f) { - CVector3f max = GetTranslation() + x10c_vector3f; - max.SetZ(max.GetZ() + z); - const CAABox box(GetTranslation() - x10c_vector3f, max); - const CTransform4f modelMtx = CTransform4f::Translate(box.center()) * - CTransform4f::Scale(box.extents()); g_Renderer->SetModelMatrix(modelMtx); - g_Renderer->RenderFogVolume(x118_color, zeus::CAABox(-1.f, 1.f), nullptr, nullptr); + if (GetActive()) { + const float z = mgr.IntegrateVisorFog( + xfc_float1 * CMath::FastSinR(CGraphics::GetSecondsMod900() * x100_float2)); + if (z > 0.f) { + CVector3f translation = GetTranslation(); + CVector3f min(translation - x10c_vector3f); + CVector3f max(translation.GetX() + x10c_vector3f.GetX(), + translation.GetY() + x10c_vector3f.GetY(), 0.0); + max.SetZ(translation.GetZ() + x10c_vector3f.GetZ() + z); + CAABox box(min, max); + CVector3f extents(box.GetExtents()); + CTransform4f modelMtx = + CTransform4f::Translate(box.GetCenterPoint()) * CTransform4f::Scale(extents); + + CVector3f renderMin(-1.f, -1.f, -1.f); + CVector3f renderMax(1.f, 1.f, 1.f); + CAABox renderbox(renderMin, renderMax); + + gpRender->SetModelMatrix(modelMtx); + gpRender->RenderFogVolume(x118_color, renderbox, nullptr, nullptr); + } } - */ } else { CActor::Render(mgr); }