123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // RotationModule.cpp
- // cocos2d_libs
- //
- // Created by 徐俊杰 on 2020/4/24.
- //
- #include "rparticle/Modules/RotationModule.h"
- //#include "UnityPrefix.h"
- //#include "rparticle/Modules/RotationModule.h"
- //#include "Runtime/BaseClasses/ObjectDefines.h"
- #include "rparticle/Serialize/TransferFunctions/SerializeTransfer.h"
- #include "rparticle/ParticleSystemUtils.h"
- #include "rparticle/Math/Random/Random.h"
- //#include "Runtime/Math/Vector2.h"
- NS_RRP_BEGIN
- struct DualMinMaxPolyCurves
- {
- MinMaxOptimizedPolyCurves optRot;
- MinMaxPolyCurves rot;
- };
- template<ParticleSystemCurveEvalMode mode>
- 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<mode> (curve, time, random);
- }
- }
- template<bool isOptimized>
- void UpdateProceduralTpl(const DualMinMaxPolyCurves& curves, ParticleSystemParticles& ps)
- {
- const size_t count = ps.array_size ();
- for (int q=0; q<count; q++)
- {
- float time = NormalizedTime(ps, q);
- float random = GenerateRandom(ps.randomSeed[q] + kParticleSystemRotationCurveId);
- float range = ps.startLifetime[q];
- float value;
- if(isOptimized)
- value = EvaluateIntegrated (curves.optRot, time, random);
- else
- value = EvaluateIntegrated (curves.rot, time, random);
- ps.rotation[q] += value * range;
- }
- }
- RotationModule::RotationModule() : ParticleSystemModule(false)
- {}
- void RotationModule::Update (const ParticleSystemReadOnlyState& roState, const ParticleSystemState& state, ParticleSystemParticles& ps, const size_t fromIndex, const size_t toIndex)
- {
- if (m_Curve.minMaxState == kMMCScalar)
- UpdateTpl<kEMScalar>(m_Curve, ps, fromIndex, toIndex);
- else if(m_Curve.IsOptimized() && m_Curve.UsesMinMax())
- UpdateTpl<kEMOptimizedMinMax>(m_Curve, ps, fromIndex, toIndex);
- else if(m_Curve.IsOptimized())
- UpdateTpl<kEMOptimized>(m_Curve, ps, fromIndex, toIndex);
- else
- UpdateTpl<kEMSlow>(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<true>(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<false>(curves, ps);
- }
- }
- template<class TransferFunction>
- void RotationModule::Transfer (TransferFunction& transfer)
- {
- ParticleSystemModule::Transfer (transfer);
- transfer.Transfer (m_Curve, "curve");
- }
- INSTANTIATE_TEMPLATE_TRANSFER(RotationModule)
- NS_RRP_END
|