From bda30a003b07bfc179f906e9cbd0fd0e9946bbbb Mon Sep 17 00:00:00 2001 From: Henrique Gemignani Passos Lima Date: Mon, 17 Oct 2022 01:32:15 +0300 Subject: [PATCH] Add CRipple::CRipple --- include/MetroidPrime/CFluidPlane.hpp | 2 ++ include/MetroidPrime/CRipple.hpp | 28 ++++++++++++++++++ src/MetroidPrime/CRipple.cpp | 44 ++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 include/MetroidPrime/CRipple.hpp create mode 100644 src/MetroidPrime/CRipple.cpp diff --git a/include/MetroidPrime/CFluidPlane.hpp b/include/MetroidPrime/CFluidPlane.hpp index 93d39757..734ac44a 100644 --- a/include/MetroidPrime/CFluidPlane.hpp +++ b/include/MetroidPrime/CFluidPlane.hpp @@ -8,6 +8,8 @@ class CScriptWater; class CStateManager; +extern "C" uint sub_8012f098(); + class CFluidPlaneCPURender { public: struct SPatchInfo {}; diff --git a/include/MetroidPrime/CRipple.hpp b/include/MetroidPrime/CRipple.hpp new file mode 100644 index 00000000..82cba493 --- /dev/null +++ b/include/MetroidPrime/CRipple.hpp @@ -0,0 +1,28 @@ +#ifndef _CRIPPLE +#define _CRIPPLE + +#include "MetroidPrime/TGameTypes.hpp" + +#include "Kyoto/Math/CVector3f.hpp" + +class CRipple { + TUniqueId x0_id; + float x4_time; + CVector3f x8_center; + float x14_timeFalloff; + float x18_distFalloff; + float x1c_frequency; + float x20_amplitude; + float x24_lookupAmplitude; + float x28_ooTimeFalloff; + float x2c_ooDistFalloff; + float x30_ooPhase; + float x34_phase; + float x38_lookupPhase; + uint x3c_; + +public: + CRipple(TUniqueId id, const CVector3f& center, float intensity); +}; + +#endif // _CRIPPLE diff --git a/src/MetroidPrime/CRipple.cpp b/src/MetroidPrime/CRipple.cpp new file mode 100644 index 00000000..70ce7f10 --- /dev/null +++ b/src/MetroidPrime/CRipple.cpp @@ -0,0 +1,44 @@ +#include "MetroidPrime/CRipple.hpp" + +#include "MetroidPrime/CFluidPlane.hpp" + +#include "Kyoto/CRandom16.hpp" +#include "Kyoto/Math/CMath.hpp" + +#include "rstl/math.hpp" + +CRipple::CRipple(TUniqueId id, const CVector3f& center, float intensity) + : x0_id(id) + , x4_time(0.f) + , x8_center(center) + , x14_timeFalloff(2.f) + , x18_distFalloff(12.f) + , x1c_frequency(3.f) + , x20_amplitude(0.25f) + , x24_lookupAmplitude(0.00098039221f) + , x28_ooTimeFalloff(0.f) + , x2c_ooDistFalloff(0.f) + , x30_ooPhase(0.f) + , x34_phase(0.f) + , x38_lookupPhase(0.f) + , x3c_(sub_8012f098()) +{ + if (0.f < intensity && intensity < 1.f) { + static CRandom16 sRippleRandom(0xABBA); + + float value1 = (intensity * (sRippleRandom.Float() - 0.5f)) * 2.f * 0.1f + intensity; + float tmp = 2.f * (0.0f < value1 ? (1.0f < value1 ? 1.0f : value1) : 0.0f); + + x14_timeFalloff = 0.5f * tmp + 1.5f; + x18_distFalloff = 4.f * tmp + 8.f; + x1c_frequency = 2.f + tmp; + x20_amplitude = 0.15f * tmp + 0.1f; + x24_lookupAmplitude = x20_amplitude / 255.f; + } + + x28_ooTimeFalloff = 1.f / x14_timeFalloff; + x2c_ooDistFalloff = 1.f / x18_distFalloff; + x30_ooPhase = x18_distFalloff / 2.5f; + x34_phase = 1.f / x30_ooPhase; + x38_lookupPhase = 256.f * x34_phase; +}