move Lerp into AnimUtils.cs

This commit is contained in:
goat 2021-07-18 19:24:33 +02:00
parent 4031a702c1
commit d9b6a05fc5
No known key found for this signature in database
GPG key ID: F18F057873895461
2 changed files with 26 additions and 16 deletions

View file

@ -0,0 +1,19 @@
using System.Numerics;
/// <summary>
/// Class providing helper functions when facilitating animations.
/// </summary>
public static class AnimUtil
{
public static float Lerp(float firstFloat, float secondFloat, float by)
{
return (firstFloat * (1 - @by)) + (secondFloat * by);
}
public static Vector2 Lerp(Vector2 firstVector, Vector2 secondVector, float by)
{
var retX = Lerp(firstVector.X, secondVector.X, by);
var retY = Lerp(firstVector.Y, secondVector.Y, by);
return new Vector2(retX, retY);
}
}

View file

@ -4,6 +4,9 @@ using System.Numerics;
namespace Dalamud.Interface.Animation
{
/// <summary>
/// Base class facilitating the implementation of easing functions.
/// </summary>
public abstract class Easing
{
private readonly Stopwatch animationTimer = new();
@ -35,17 +38,17 @@ namespace Dalamud.Interface.Animation
public Vector2 EasedPoint { get; private set; }
/// <summary>
/// Gets the current value of the animation, from 0 to 1.
/// Gets or sets the current value of the animation, from 0 to 1.
/// </summary>
public double Value
{
get => this.valueInternal;
set
protected set
{
this.valueInternal = Math.Min(value, 1);
if (Point1.HasValue && Point2.HasValue)
EasedPoint = Lerp(Point1.Value, Point2.Value, (float)this.valueInternal);
if (this.Point1.HasValue && this.Point2.HasValue)
this.EasedPoint = AnimUtil.Lerp(this.Point1.Value, this.Point2.Value, (float)this.valueInternal);
}
}
@ -87,17 +90,5 @@ namespace Dalamud.Interface.Animation
/// Updates the animation.
/// </summary>
public abstract void Update();
private static float Lerp(float firstFloat, float secondFloat, float by)
{
return (firstFloat * (1 - @by)) + (secondFloat * by);
}
private static Vector2 Lerp(Vector2 firstVector, Vector2 secondVector, float by)
{
var retX = Lerp(firstVector.X, secondVector.X, by);
var retY = Lerp(firstVector.Y, secondVector.Y, by);
return new Vector2(retX, retY);
}
}
}