BoxFillProfile.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 randomly distributes particles throughout a rectangular area.
  8. /// </summary>
  9. /// <remarks>
  10. /// The <see cref="BoxFillProfile"/> generates random positions within a rectangle centered the emitter's position, with
  11. /// random unit vector headings. This creates a uniform distribution of particles across the defined area, with
  12. /// particles moving in all directions.
  13. /// </remarks>
  14. public sealed class BoxFillProfile : Profile
  15. {
  16. /// <summary>
  17. /// The width of the rectangular area.
  18. /// </summary>
  19. public float Width;
  20. /// <summary>
  21. /// The height of the rectangular area.
  22. /// </summary>
  23. public float Height;
  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. offset->X = FastRandom.Shared.NextSingle(Width * -0.5f, Width * 0.5f);
  32. offset->Y = FastRandom.Shared.NextSingle(Height * -0.5f, Height * 0.5f);
  33. FastRandom.Shared.NextUnitVector(heading);
  34. }
  35. }