// // RotationByVelocityModule.cpp // libcocos2d Mac // // Created by 徐俊杰 on 2020/4/24. // #include "rparticle/Modules/RotationByVelocityModule.h" //#include "UnityPrefix.h" //#include "rparticle/Modules/RotationByVelocityModule.h" //#include "Runtime/BaseClasses/ObjectDefines.h" #include "rparticle/Serialize/TransferFunctions/SerializeTransfer.h" #include "rparticle/ParticleSystemUtils.h" NS_RRP_BEGIN RotationBySpeedModule::RotationBySpeedModule () : ParticleSystemModule(false) , m_Range (0.0f, 1.0f) {} template void UpdateTpl(const MinMaxCurve& curve, ParticleSystemParticles& ps, size_t fromIndex, size_t toIndex, const Vector2f offsetScale) { if (!ps.usesRotationalSpeed) return; for (size_t q = fromIndex; q < toIndex; ++q) { const Vector3f vel = ps.velocity[q] + ps.animatedVelocity[q]; const float t = InverseLerpFast01 (offsetScale, Magnitude(vel)); const float random = GenerateRandom(ps.randomSeed[q] + kParticleSystemRotationBySpeedCurveId); ps.rotationalSpeed[q] += Evaluate (curve, t, random); } } void RotationBySpeedModule::Update (const ParticleSystemReadOnlyState& roState, const ParticleSystemState& state, ParticleSystemParticles& ps, const size_t fromIndex, const size_t toIndex) { Vector2f offsetScale = CalculateInverseLerpOffsetScale (m_Range * roState.GetRenderScale()); if (m_Curve.minMaxState == kMMCScalar) UpdateTpl(m_Curve, ps, fromIndex, toIndex, offsetScale); else if(m_Curve.IsOptimized() && m_Curve.UsesMinMax()) UpdateTpl(m_Curve, ps, fromIndex, toIndex, offsetScale); else if(m_Curve.IsOptimized()) UpdateTpl(m_Curve, ps, fromIndex, toIndex, offsetScale); else UpdateTpl(m_Curve, ps, fromIndex, toIndex, offsetScale); } void RotationBySpeedModule::CheckConsistency () { const float MyEpsilon = 0.001f; m_Range.y = std::max (m_Range.x + MyEpsilon, m_Range.y); } template void RotationBySpeedModule::Transfer (TransferFunction& transfer) { ParticleSystemModule::Transfer (transfer); transfer.Transfer (m_Curve, "curve"); transfer.Transfer (m_Range, "range"); } INSTANTIATE_TEMPLATE_TRANSFER(RotationBySpeedModule) NS_RRP_END