RotationModifier.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using MonoGame.Extended.Particles.Data;
  5. namespace MonoGame.Extended.Particles.Modifiers;
  6. /// <summary>
  7. /// A modifier that applies a constant rotational velocity to particles.
  8. /// </summary>
  9. /// <remarks>
  10. /// The <see cref="RotationModifier"/> changes the orientation of particles over time
  11. /// by applying a continuous rotation at a specified rate.
  12. ///
  13. /// The rotation is applied uniformly to all particles, but can be combined with other modifiers
  14. /// to create more complex behaviors. For non-uniform rotation, consider using multiple particle
  15. /// emitters with different rotation rates or implementing a custom modifier.
  16. /// </remarks>
  17. public class RotationModifier : Modifier
  18. {
  19. /// <summary>
  20. /// Gets or sets the rate at which particles rotate, in radians per second.
  21. /// </summary>
  22. /// <remarks>
  23. /// Positive values cause clockwise rotation, while negative values cause
  24. /// counter-clockwise rotation.
  25. /// </remarks>
  26. public float RotationRate;
  27. /// <summary>
  28. /// Updates all particles by applying rotation based on the elapsed time.
  29. /// </summary>
  30. /// <inheritdoc/>
  31. public override unsafe void Update(float elapsedSeconds, ParticleIterator iterator)
  32. {
  33. if (!Enabled) { return; }
  34. float rotationRateDelta = RotationRate * elapsedSeconds;
  35. while (iterator.HasNext)
  36. {
  37. Particle* particle = iterator.Next();
  38. particle->Rotation += rotationRateDelta;
  39. }
  40. }
  41. }