From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../ParticleSystem/Modules/RotationModule.cpp | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Runtime/Graphics/ParticleSystem/Modules/RotationModule.cpp (limited to 'Runtime/Graphics/ParticleSystem/Modules/RotationModule.cpp') diff --git a/Runtime/Graphics/ParticleSystem/Modules/RotationModule.cpp b/Runtime/Graphics/ParticleSystem/Modules/RotationModule.cpp new file mode 100644 index 0000000..7f331d6 --- /dev/null +++ b/Runtime/Graphics/ParticleSystem/Modules/RotationModule.cpp @@ -0,0 +1,83 @@ +#include "UnityPrefix.h" +#include "RotationModule.h" +#include "Runtime/BaseClasses/ObjectDefines.h" +#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h" +#include "Runtime/Graphics/ParticleSystem/ParticleSystemUtils.h" +#include "Runtime/Math/Random/Random.h" +#include "Runtime/Math/Vector2.h" + +struct DualMinMaxPolyCurves +{ + MinMaxOptimizedPolyCurves optRot; + MinMaxPolyCurves rot; +}; + +template +void UpdateTpl(const MinMaxCurve& curve, ParticleSystemParticles& ps, const size_t fromIndex, const size_t toIndex) +{ + if ( !ps.usesRotationalSpeed ) return; + for (size_t q = fromIndex; q < toIndex; ++q) + { + const float time = NormalizedTime(ps, q); + const float random = GenerateRandom(ps.randomSeed[q] + kParticleSystemRotationCurveId); + ps.rotationalSpeed[q] += Evaluate (curve, time, random); + } +} + +template +void UpdateProceduralTpl(const DualMinMaxPolyCurves& curves, ParticleSystemParticles& ps) +{ + const size_t count = ps.array_size (); + for (int q=0; q(m_Curve, ps, fromIndex, toIndex); + else if(m_Curve.IsOptimized() && m_Curve.UsesMinMax()) + UpdateTpl(m_Curve, ps, fromIndex, toIndex); + else if(m_Curve.IsOptimized()) + UpdateTpl(m_Curve, ps, fromIndex, toIndex); + else + UpdateTpl(m_Curve, ps, fromIndex, toIndex); + +} + +void RotationModule::UpdateProcedural (const ParticleSystemState& state, ParticleSystemParticles& ps) +{ + DualMinMaxPolyCurves curves; + if(m_Curve.IsOptimized()) + { + curves.optRot = m_Curve.polyCurves; curves.optRot.Integrate(); + UpdateProceduralTpl(curves, ps); + } + else + { + DebugAssert(CurvesSupportProcedural (m_Curve.editorCurves, m_Curve.minMaxState)); + BuildCurves(curves.rot, m_Curve.editorCurves, m_Curve.GetScalar(), m_Curve.minMaxState); curves.rot.Integrate(); + UpdateProceduralTpl(curves, ps); + } +} + +template +void RotationModule::Transfer (TransferFunction& transfer) +{ + ParticleSystemModule::Transfer (transfer); + transfer.Transfer (m_Curve, "curve"); +} +INSTANTIATE_TEMPLATE_TRANSFER(RotationModule) -- cgit v1.1-26-g67d0