LineProfile.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 Microsoft.Xna.Framework;
  5. namespace MonoGame.Extended.Particles.Profiles;
  6. /// <summary>
  7. /// A profile that distributes particles uniformly along a line segment with random headings.
  8. /// </summary>
  9. /// <remarks>
  10. /// The <see cref="LineProfile"/> positions particles randomly along a line segment centered at the emitter position and
  11. /// defined by an axis direction and length. Unlike <see cref="LineUniformProfile"/>, this profile gives each particle a
  12. /// random heading in any direction.
  13. /// </remarks>
  14. public sealed class LineProfile : Profile
  15. {
  16. /// <summary>
  17. /// The direction vector of the line axis.
  18. /// </summary>
  19. public Vector2 Axis;
  20. /// <summary>
  21. /// The length of the line segment.
  22. /// </summary>
  23. public float Length;
  24. /// <summary>
  25. /// Computes the offset and heading for a new particle.
  26. /// </summary>
  27. /// <param name="offset">A pointer to the Vector2 where the offset from the emitter position will be stored.</param>
  28. /// <param name="heading">A pointer to the Vector2 where the unit direction vector will be stored.</param>
  29. public override unsafe void GetOffsetAndHeading(Vector2* offset, Vector2* heading)
  30. {
  31. float value = FastRandom.Shared.NextSingle(Length * -0.5f, Length * 0.5f);
  32. offset->X = Axis.X * value;
  33. offset->Y = Axis.Y * value;
  34. FastRandom.Shared.NextUnitVector(heading);
  35. }
  36. }