// Copyright (c) Craftwork Games. All rights reserved.
// Licensed under the MIT license.
// See LICENSE file in the project root for full license information.
using System;
using Microsoft.Xna.Framework;
namespace MonoGame.Extended.Particles.Profiles;
///
/// A profile that distributes particles along the perimeter of a circle with controllable radiation patterns.
///
///
///
/// The positions new particles exclusively on the circumference of a circle centered
/// at the emitter's position. Unlike which distributes particles throughout the
/// circular area, this profile places particles only on the edge.
///
///
/// The movement direction (heading) of each particle can be configured to radiate inward toward the center,
/// outward from the center, or in random directions unrelated to their position.
///
///
public sealed class RingProfile : Profile
{
///
/// Gets or sets the radius if the ring.
///
public float Radius { get; set; }
///
/// Gets or sets the radiation mode that determines how particle headings are calculated.
///
public CircleRadiation Radiate { 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.
///
/// Thrown when contains an unsupported value.
///
public override unsafe void GetOffsetAndHeading(Vector2* offset, Vector2* heading)
{
FastRandom.Shared.NextUnitVector(heading);
switch (Radiate)
{
case CircleRadiation.In:
offset->X = -heading->X * Radius;
offset->Y = -heading->Y * Radius;
break;
case CircleRadiation.Out:
offset->X = heading->X * Radius;
offset->Y = heading->Y * Radius;
break;
case CircleRadiation.None:
offset->X = heading->X * Radius;
offset->Y = heading->Y * Radius;
FastRandom.Shared.NextUnitVector(heading);
break;
default:
throw new ArgumentOutOfRangeException(nameof(Radiate), Radiate, "Unsupported radiation mode");
}
}
}