From acea7b2e728787a0d83bbf83c8c1f042d2c32e7e Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Mon, 3 Jun 2024 10:15:45 +0800 Subject: + plugins project --- .../Modifiers/VelocityModifier.cs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/VelocityModifier.cs (limited to 'Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/VelocityModifier.cs') diff --git a/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/VelocityModifier.cs b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/VelocityModifier.cs new file mode 100644 index 0000000..f089abc --- /dev/null +++ b/Plugins/MonoGame.Extended/source/MonoGame.Extended.Particles/Modifiers/VelocityModifier.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using MonoGame.Extended.Particles.Modifiers.Interpolators; + +namespace MonoGame.Extended.Particles.Modifiers +{ + public class VelocityModifier : Modifier + { + public List Interpolators { get; set; } = new List(); + + public float VelocityThreshold { get; set; } + + public override unsafe void Update(float elapsedSeconds, ParticleBuffer.ParticleIterator iterator) + { + var velocityThreshold2 = VelocityThreshold*VelocityThreshold; + var n = Interpolators.Count; + + while (iterator.HasNext) + { + var particle = iterator.Next(); + var velocity2 = particle->Velocity.LengthSquared(); + + if (velocity2 >= velocityThreshold2) + { + for (var i = 0; i < n; i++) + { + var interpolator = Interpolators[i]; + interpolator.Update(1, particle); + } + } + else + { + var t = (float) Math.Sqrt(velocity2)/VelocityThreshold; + for (var i = 0; i < n; i++) + { + var interpolator = Interpolators[i]; + interpolator.Update(t, particle); + } + } + } + } + } +} \ No newline at end of file -- cgit v1.1-26-g67d0