Code/Animations/SpinAnimation.cs
using System;
namespace BetterUI.Animations;
/// <summary>
/// Animates a component spinning around a given axis.
/// </summary>
public class SpinAnimation : AnimationBase
{
private Vector3 _rotation;
/// <summary>
/// Gets or sets whether to use a sine wave to interpolate the rotation.
/// </summary>
[Property]
public bool EnableSin { get; set; }
/// <summary>
/// Gets or sets the maximum angle of rotation.
/// </summary>
[Property]
public float MaxAngle { get; set; } = 180f;
protected override void OnAnimate( float t )
{
var easedTime = ApplyEasing( NormalizedTime, Easing );
if ( EnableSin )
{
var angle = MathF.Sin( easedTime * MathF.PI * 2 ) * MaxAngle;
WorldRotation = Rotation.FromPitch( angle );
}
else
{
_rotation += Axis * 1f;
WorldRotation = new Angles( _rotation );
}
}
}