// Copyright (c) Craftwork Games. All rights reserved. // Licensed under the MIT license. // See LICENSE file in the project root for full license information. using Microsoft.Xna.Framework; namespace MonoGame.Extended.Particles.Profiles; /// /// A profile that distributes particles along the edges of a rectangular boundary. /// /// /// The randomly positions new particles on one of the four sides of a rectangular area /// centered at the emitter's position. Each side has an equal probability of being selected. Particles are given random /// unit vector headings, allowing them to move in any direction regardless of their starting edge. /// public sealed class BoxProfile : Profile { /// /// Gets or sets the width of the rectangular perimeter. /// public float Width { get; set; } /// /// Gets or sets the height of the rectangular perimeter. /// public float Height { get; set; } /// /// Computes the offset and heading for a new particle. /// /// A pointer to the Vector2 where the offset from the emitter position will be stored. /// A pointer to the Vector2 where the unit direction vector will be stored. public override unsafe void GetOffsetAndHeading(Vector2* offset, Vector2* heading) { switch (FastRandom.Shared.Next(4)) { case 0: // Left offset->X = Width * -0.5f; offset->Y = FastRandom.Shared.NextSingle(Height * -0.5f, Height * 0.5f); break; case 1: // Top offset->X = FastRandom.Shared.NextSingle(Width * -0.5f, Width * 0.5f); offset->Y = Height * -0.5f; break; case 2: // Right offset->X = Width * 0.5f; offset->Y = FastRandom.Shared.NextSingle(Height * -0.5f, Height * 0.5f); break; default: // Bottom offset->X = FastRandom.Shared.NextSingle(Width * -0.5f, Width * 0.5f); offset->Y = Height * 0.5f; break; } FastRandom.Shared.NextUnitVector(heading); } }