// // 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 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) NS_RRP_END