From accc5931026ddc20bc8441cb348d100a4182f358 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 27 Feb 2016 20:55:05 -1000 Subject: [PATCH] BNCE variable names and some doc-links --- Runtime/Particle/CColorElement.cpp | 2 + Runtime/Particle/CColorElement.hpp | 2 + Runtime/Particle/CEmitterElement.cpp | 2 + Runtime/Particle/CEmitterElement.hpp | 2 + Runtime/Particle/CIntElement.cpp | 2 + Runtime/Particle/CIntElement.hpp | 2 + Runtime/Particle/CModVectorElement.cpp | 55 +++++++++++++++----------- Runtime/Particle/CModVectorElement.hpp | 18 +++++---- Runtime/Particle/CRealElement.cpp | 7 +++- Runtime/Particle/CRealElement.hpp | 2 + Runtime/Particle/CUVElement.cpp | 2 + Runtime/Particle/CUVElement.hpp | 2 + Runtime/Particle/CVectorElement.cpp | 6 ++- Runtime/Particle/CVectorElement.hpp | 4 +- 14 files changed, 71 insertions(+), 37 deletions(-) diff --git a/Runtime/Particle/CColorElement.cpp b/Runtime/Particle/CColorElement.cpp index 433fb14a9..92fa57f3d 100644 --- a/Runtime/Particle/CColorElement.cpp +++ b/Runtime/Particle/CColorElement.cpp @@ -4,6 +4,8 @@ #include "CRandom16.hpp" #include +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Color_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CColorElement.hpp b/Runtime/Particle/CColorElement.hpp index dab30050e..024d54ce8 100644 --- a/Runtime/Particle/CColorElement.hpp +++ b/Runtime/Particle/CColorElement.hpp @@ -3,6 +3,8 @@ #include "IElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Color_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CEmitterElement.cpp b/Runtime/Particle/CEmitterElement.cpp index 9d0d46837..1c3dea82b 100644 --- a/Runtime/Particle/CEmitterElement.cpp +++ b/Runtime/Particle/CEmitterElement.cpp @@ -1,6 +1,8 @@ #include "CEmitterElement.hpp" #include "CRandom16.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Emitter_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CEmitterElement.hpp b/Runtime/Particle/CEmitterElement.hpp index 3651ecccc..97a6165d3 100644 --- a/Runtime/Particle/CEmitterElement.hpp +++ b/Runtime/Particle/CEmitterElement.hpp @@ -3,6 +3,8 @@ #include "IElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Emitter_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CIntElement.cpp b/Runtime/Particle/CIntElement.cpp index d4fc84141..8bd3d3060 100644 --- a/Runtime/Particle/CIntElement.cpp +++ b/Runtime/Particle/CIntElement.cpp @@ -2,6 +2,8 @@ #include "CParticleGlobals.hpp" #include "CRandom16.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Int_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CIntElement.hpp b/Runtime/Particle/CIntElement.hpp index 487de50ef..7b48804a8 100644 --- a/Runtime/Particle/CIntElement.hpp +++ b/Runtime/Particle/CIntElement.hpp @@ -3,6 +3,8 @@ #include "IElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Int_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CModVectorElement.cpp b/Runtime/Particle/CModVectorElement.cpp index 453f54f8a..460933d80 100644 --- a/Runtime/Particle/CModVectorElement.cpp +++ b/Runtime/Particle/CModVectorElement.cpp @@ -3,6 +3,8 @@ #include "CRandom16.hpp" #include +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Mod_Vector_Elements */ + namespace pshag { @@ -97,60 +99,65 @@ bool CMVETimeChain::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& return x4_a->GetValue(frame, pVel, pPos); } -CMVEBounce::CMVEBounce(CVectorElement *a, CVectorElement *b, CRealElement *c, CRealElement *d, bool f) - : x4_a(a), x8_b(b), xc_c(c), x10_d(d), x14_e(false), x15_f(f), x24_j(0.0) +CMVEBounce::CMVEBounce(CVectorElement* a, CVectorElement* b, CRealElement* c, CRealElement* d, bool f) +: x4_planePoint(a), x8_planeNormal(b), xc_friction(c), x10_restitution(d), x14_planePrecomputed(false), x15_dieOnPenetrate(f), x24_planeD(0.0) { - if (x4_a && x8_b && x4_a->IsFastConstant() && x8_b->IsFastConstant()) + if (x4_planePoint && x8_planeNormal && x4_planePoint->IsFastConstant() && x8_planeNormal->IsFastConstant()) { - x14_e = true; - x8_b->GetValue(0, x18_g); + /* Precompute Hesse normal form of plane (for penetration testing) + * https://en.wikipedia.org/wiki/Hesse_normal_form */ + x14_planePrecomputed = true; + x8_planeNormal->GetValue(0, x18_planeValidatedNormal); - if (x18_g.magSquared() > 0.0) - x18_g.normalize(); + if (x18_planeValidatedNormal.magSquared() > 0.0) + x18_planeValidatedNormal.normalize(); Zeus::CVector3f a; - x4_a->GetValue(0, a); - x24_j = x18_g.dot(a); + x4_planePoint->GetValue(0, a); + x24_planeD = x18_planeValidatedNormal.dot(a); } } bool CMVEBounce::GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const { - if (!x14_e) + if (!x14_planePrecomputed) { - x8_b->GetValue(frame, ((Zeus::CVector3f&)x18_g)); - ((Zeus::CVector3f&)x18_g).normalize(); + /* Compute Hesse normal form of plane (for penetration testing) */ + x8_planeNormal->GetValue(frame, ((Zeus::CVector3f&)x18_planeValidatedNormal)); + ((Zeus::CVector3f&)x18_planeValidatedNormal).normalize(); Zeus::CVector3f a; - x4_a->GetValue(frame, a); + x4_planePoint->GetValue(frame, a); - (float&)(x24_j) = x18_g.dot(a); + (float&)(x24_planeD) = x18_planeValidatedNormal.dot(a); } - float dot = x18_g.dot(pPos); - if ((dot - x24_j) <= 0.0f) + float dot = x18_planeValidatedNormal.dot(pPos); + if ((dot - x24_planeD) <= 0.0f) { - if (x15_f) + if (x15_dieOnPenetrate) return true; } else return false; + /* Deflection event */ + if (pVel.magSquared() > 0.0f) return false; Zeus::CVector3f delta = pPos - pVel; - pPos += Zeus::CVector3f{(-((((delta.z * ((delta.x * (delta.y * x18_g.y)) - + ((pVel.x * (x18_g.y * pVel.y)) + x18_g.x))) + x18_g.z) - x24_j)) / - ((pVel.z * ((pVel.x * (x18_g.y * pVel.y)) + x18_g.x)) + x18_g.z)) - ( - (x18_g.z * ((x18_g.x * (x18_g.y * pVel.y)) + pVel.x)) + pVel.z)} * pVel; + pPos += Zeus::CVector3f{(-((((delta.z * ((delta.x * (delta.y * x18_planeValidatedNormal.y)) + + ((pVel.x * (x18_planeValidatedNormal.y * pVel.y)) + x18_planeValidatedNormal.x))) + x18_planeValidatedNormal.z) - x24_planeD)) / + ((pVel.z * ((pVel.x * (x18_planeValidatedNormal.y * pVel.y)) + x18_planeValidatedNormal.x)) + x18_planeValidatedNormal.z)) - ( + (x18_planeValidatedNormal.z * ((x18_planeValidatedNormal.x * (x18_planeValidatedNormal.y * pVel.y)) + pVel.x)) + pVel.z)} * pVel; float d = 0.0f; - x10_d->GetValue(frame, d); + x10_restitution->GetValue(frame, d); pVel -= d * pVel; float c = 0.0f; - xc_c->GetValue(frame, c); - pVel -= Zeus::CVector3f{(1.0f + c) * ((x18_g.z * (x18_g.x * (x18_g.y * pVel.y)) + pVel.x) + pVel.x)} * x18_g; + xc_friction->GetValue(frame, c); + pVel -= Zeus::CVector3f{(1.0f + c) * ((x18_planeValidatedNormal.z * (x18_planeValidatedNormal.x * (x18_planeValidatedNormal.y * pVel.y)) + pVel.x) + pVel.x)} * x18_planeValidatedNormal; return false; } diff --git a/Runtime/Particle/CModVectorElement.hpp b/Runtime/Particle/CModVectorElement.hpp index 99a45fa9f..e195b7618 100644 --- a/Runtime/Particle/CModVectorElement.hpp +++ b/Runtime/Particle/CModVectorElement.hpp @@ -3,6 +3,8 @@ #include "IElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Mod_Vector_Elements */ + namespace pshag { @@ -58,14 +60,14 @@ public: class CMVEBounce : public CModVectorElement { - std::unique_ptr x4_a; - std::unique_ptr x8_b; - std::unique_ptr xc_c; - std::unique_ptr x10_d; - bool x14_e; - bool x15_f; - Zeus::CVector3f x18_g; - float x24_j; + std::unique_ptr x4_planePoint; + std::unique_ptr x8_planeNormal; + std::unique_ptr xc_friction; + std::unique_ptr x10_restitution; + bool x14_planePrecomputed; + bool x15_dieOnPenetrate; + Zeus::CVector3f x18_planeValidatedNormal; + float x24_planeD; public: CMVEBounce(CVectorElement* a, CVectorElement* b, CRealElement* c, CRealElement* d, bool e); bool GetValue(int frame, Zeus::CVector3f& pVel, Zeus::CVector3f& pPos) const; diff --git a/Runtime/Particle/CRealElement.cpp b/Runtime/Particle/CRealElement.cpp index bb3936798..3712400b3 100644 --- a/Runtime/Particle/CRealElement.cpp +++ b/Runtime/Particle/CRealElement.cpp @@ -1,8 +1,11 @@ #include "CRealElement.hpp" #include "CParticleGlobals.hpp" #include "CRandom16.hpp" +#include "CElementGen.hpp" #include +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Real_Elements */ + namespace pshag { @@ -278,13 +281,13 @@ bool CREParticleAccessParam8::GetValue(int frame, float& valOut) const bool CREPSLL::GetValue(int frame, float& valOut) const { - //valOut = CParticleGlobals::g_particleMetrics->x2c_psll; + valOut = CElementGen::g_currentParticle->x2c_lineLengthOrSize; return false; } bool CREPRLW::GetValue(int frame, float& valOut) const { - //valOut = CParticleGlobals::g_particleMetrics->x30_prlw; + valOut = CElementGen::g_currentParticle->x30_lineWidthOrRota; return false; } diff --git a/Runtime/Particle/CRealElement.hpp b/Runtime/Particle/CRealElement.hpp index 1d88be972..b53d08a43 100644 --- a/Runtime/Particle/CRealElement.hpp +++ b/Runtime/Particle/CRealElement.hpp @@ -3,6 +3,8 @@ #include "IElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Real_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CUVElement.cpp b/Runtime/Particle/CUVElement.cpp index fa31b4811..c9f236306 100644 --- a/Runtime/Particle/CUVElement.cpp +++ b/Runtime/Particle/CUVElement.cpp @@ -1,5 +1,7 @@ #include "CUVElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#UV_Elements */ + namespace pshag { diff --git a/Runtime/Particle/CUVElement.hpp b/Runtime/Particle/CUVElement.hpp index 8c0214ce8..85b74c5f4 100644 --- a/Runtime/Particle/CUVElement.hpp +++ b/Runtime/Particle/CUVElement.hpp @@ -5,6 +5,8 @@ #include "CToken.hpp" #include "CTexture.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#UV_Elements */ + namespace pshag { class CToken; diff --git a/Runtime/Particle/CVectorElement.cpp b/Runtime/Particle/CVectorElement.cpp index f369a20ff..0441bb5df 100644 --- a/Runtime/Particle/CVectorElement.cpp +++ b/Runtime/Particle/CVectorElement.cpp @@ -4,6 +4,8 @@ #include "CElementGen.hpp" #include +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Vector_Elements */ + namespace pshag { @@ -192,7 +194,7 @@ bool CVEFastConstant::GetValue(int frame, Zeus::CVector3f& valOut) const } CVECircle::CVECircle(CVectorElement* a, CVectorElement* b, CRealElement* c, CRealElement* d, CRealElement* e) -: x4_direction(a), x20_angleConstant(c), x24_angleLinear(d), x28_magnitude(e) +: x4_direction(a), x20_angleConstant(c), x24_angleLinear(d), x28_radius(e) { Zeus::CVector3f bv; b->GetValue(0, bv); @@ -210,7 +212,7 @@ bool CVECircle::GetValue(int frame, Zeus::CVector3f& valOut) const float c, d, e; x20_angleConstant->GetValue(frame, c); x24_angleLinear->GetValue(frame, d); - x28_magnitude->GetValue(frame, e); + x28_radius->GetValue(frame, e); float curAngle = (d * frame + c) * M_PI / 180.f; diff --git a/Runtime/Particle/CVectorElement.hpp b/Runtime/Particle/CVectorElement.hpp index 0acbc00c9..ddd662312 100644 --- a/Runtime/Particle/CVectorElement.hpp +++ b/Runtime/Particle/CVectorElement.hpp @@ -3,6 +3,8 @@ #include "IElement.hpp" +/* Documentation at: http://www.metroid2002.com/retromodding/wiki/Particle_Script#Vector_Elements */ + namespace pshag { @@ -104,7 +106,7 @@ class CVECircle : public CVectorElement Zeus::CVector3f x14_yVec; std::unique_ptr x20_angleConstant; std::unique_ptr x24_angleLinear; - std::unique_ptr x28_magnitude; + std::unique_ptr x28_radius; public: CVECircle(CVectorElement* a, CVectorElement* b, CRealElement* c, CRealElement* d, CRealElement* e); bool GetValue(int frame, Zeus::CVector3f& valOut) const;