From 941c4d793cb0993f466106cdbbe5971938c0508a Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 12 Jun 2018 16:32:02 -1000 Subject: [PATCH] Fix CScriptEffect translation set --- DataSpec/DNACommon/ParticleCommon.hpp | 2 +- Runtime/Particle/CModVectorElement.cpp | 19 +++++-------------- Runtime/Particle/CModVectorElement.hpp | 4 ++-- Runtime/World/CScriptEffect.cpp | 12 ++++++------ 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/DataSpec/DNACommon/ParticleCommon.hpp b/DataSpec/DNACommon/ParticleCommon.hpp index a1b42d500..069fa8dbb 100644 --- a/DataSpec/DNACommon/ParticleCommon.hpp +++ b/DataSpec/DNACommon/ParticleCommon.hpp @@ -774,7 +774,7 @@ struct MVESwirl : IModVectorElement AT_DECL_DNA_YAML VectorElementFactory helixPoint; VectorElementFactory curveBinormal; - RealElementFactory targetRadius; + RealElementFactory filterGain; RealElementFactory tangentialVelocity; const char* ClassID() const {return "SWRL";} }; diff --git a/Runtime/Particle/CModVectorElement.cpp b/Runtime/Particle/CModVectorElement.cpp index 400510b4a..5870dead9 100644 --- a/Runtime/Particle/CModVectorElement.cpp +++ b/Runtime/Particle/CModVectorElement.cpp @@ -249,22 +249,13 @@ bool CMVESwirl::GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos x4_helixPoint->GetValue(frame, a); x8_curveBinormal->GetValue(frame, b); - /* Compute Frenet–Serret normal - * https://en.wikipedia.org/wiki/Frenet–Serret_formulas */ - const zeus::CVector3f diff = a - pPos; - float x = (diff.x - (((diff.z * ((diff.x * (diff.y * b.y)) + b.x)) + b.z) * b.x)); - float y = (diff.y - (((diff.z * ((diff.x * (diff.y * b.y)) + b.x)) + b.z) * b.y)); - float z = (diff.z - (((diff.z * ((diff.x * (diff.y * b.y)) + b.x)) + b.z) * b.z)); + const zeus::CVector3f posToOrigin = a - pPos; + const zeus::CVector3f posToHelix = posToOrigin - posToOrigin.dot(b) * b; float c = 0.0f, d = 0.0f; - xc_targetRadius->GetValue(frame, c); + xc_filterGain->GetValue(frame, c); x10_tangentialVelocity->GetValue(frame, d); - - /* Integrate tangential velocity by crossing particle normal with binormal, - * also "homing" towards the target radius */ - const float f9 = (b.z * ((b.x * (b.y * pVel.y)) + pVel.x)) + pVel.x; - pVel.x = (c * ((f9 * b.x) + (d * ((b.y * (y * b.z)) - z)))) + ((1.0 - c) * pVel.x); - pVel.y = (c * ((f9 * b.y) + (d * ((b.z * x) - (z * b.x))))) + ((1.0 - c) * pVel.y); - pVel.z = (c * ((f9 * b.z) + (d * ((b.x * (x * b.y)) - y)))) + ((1.0 - c) * pVel.x); + const zeus::CVector3f wetVel = (posToHelix.cross(b) * d + b * b.dot(pVel)); + pVel = c * wetVel + (1.f - c) * pVel; return false; } diff --git a/Runtime/Particle/CModVectorElement.hpp b/Runtime/Particle/CModVectorElement.hpp index a24bd9c99..6c4a93fb0 100644 --- a/Runtime/Particle/CModVectorElement.hpp +++ b/Runtime/Particle/CModVectorElement.hpp @@ -157,13 +157,13 @@ class CMVESwirl : public CModVectorElement { std::unique_ptr x4_helixPoint; std::unique_ptr x8_curveBinormal; - std::unique_ptr xc_targetRadius; + std::unique_ptr xc_filterGain; std::unique_ptr x10_tangentialVelocity; public: CMVESwirl(std::unique_ptr&& a, std::unique_ptr&& b, std::unique_ptr&& c, std::unique_ptr&& d) : x4_helixPoint(std::move(a)), x8_curveBinormal(std::move(b)), - xc_targetRadius(std::move(c)), x10_tangentialVelocity(std::move(d)) {} + xc_filterGain(std::move(c)), x10_tangentialVelocity(std::move(d)) {} bool GetValue(int frame, zeus::CVector3f& pVel, zeus::CVector3f& pPos) const; }; diff --git a/Runtime/World/CScriptEffect.cpp b/Runtime/World/CScriptEffect.cpp index d03219890..df112c3f8 100644 --- a/Runtime/World/CScriptEffect.cpp +++ b/Runtime/World/CScriptEffect.cpp @@ -62,7 +62,7 @@ CScriptEffect::CScriptEffect(TUniqueId uid, std::string_view name, const CEntity zeus::CTransform newXf = xf; newXf.origin = zeus::CVector3f::skZero; x104_particleSystem->SetOrientation(newXf); - x104_particleSystem->SetTranslation(xf.origin); + x104_particleSystem->SetGlobalTranslation(xf.origin); x104_particleSystem->SetLocalScale(scale); x104_particleSystem->SetParticleEmission(active); x104_particleSystem->SetModulationColor(lParms.GetNoLightsAmbient()); @@ -77,7 +77,7 @@ CScriptEffect::CScriptEffect(TUniqueId uid, std::string_view name, const CEntity zeus::CTransform newXf = xf; newXf.origin = zeus::CVector3f::skZero; xf4_electric->SetOrientation(newXf); - xf4_electric->SetTranslation(xf.origin); + xf4_electric->SetGlobalTranslation(xf.origin); xf4_electric->SetLocalScale(scale); xf4_electric->SetParticleEmission(active); } @@ -106,7 +106,7 @@ void CScriptEffect::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSt zeus::CTransform newXf = GetTransform(); newXf.origin = zeus::CVector3f::skZero; x104_particleSystem->SetOrientation(newXf); - x104_particleSystem->SetTranslation(GetTranslation()); + x104_particleSystem->SetGlobalTranslation(GetTranslation()); x104_particleSystem->SetLocalScale(scale); x104_particleSystem->SetParticleEmission(oldActive); x104_particleSystem->SetModulationColor(color); @@ -121,7 +121,7 @@ void CScriptEffect::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSt zeus::CTransform newXf = GetTransform(); newXf.origin = zeus::CVector3f::skZero; xf4_electric->SetOrientation(newXf); - xf4_electric->SetTranslation(GetTranslation()); + xf4_electric->SetGlobalTranslation(GetTranslation()); xf4_electric->SetLocalScale(scale); xf4_electric->SetParticleEmission(oldActive); xf4_electric->SetModulationColor(color); @@ -291,14 +291,14 @@ void CScriptEffect::Think(float dt, CStateManager& mgr) zeus::CTransform newXf = x34_transform; newXf.origin = zeus::CVector3f::skZero; x104_particleSystem->SetOrientation(newXf); - x104_particleSystem->SetTranslation(x34_transform.origin); + x104_particleSystem->SetGlobalTranslation(x34_transform.origin); } if (xf4_electric) { zeus::CTransform newXf = x34_transform; newXf.origin = zeus::CVector3f::skZero; xf4_electric->SetOrientation(newXf); - xf4_electric->SetTranslation(x34_transform.origin); + xf4_electric->SetGlobalTranslation(x34_transform.origin); } if (TCastToPtr act = mgr.ObjectById(x108_lightId))