mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
move Lerp into AnimUtils.cs
This commit is contained in:
parent
4031a702c1
commit
d9b6a05fc5
2 changed files with 26 additions and 16 deletions
19
Dalamud/Interface/Animation/AnimUtil.cs
Normal file
19
Dalamud/Interface/Animation/AnimUtil.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue