51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using Godot;
|
||
|
|
||
|
namespace Rokojori
|
||
|
{
|
||
|
public class Smoother
|
||
|
{
|
||
|
float overflowDelta = 0;
|
||
|
|
||
|
public float SmoothForDuration( float value, float nextValue, float duration, float delta, float processDelta = MathX.fps120Delta )
|
||
|
{
|
||
|
var coefficient = MathX.SmoothingCoefficient( duration * 1000f );
|
||
|
return SmoothWithCoefficient( value, nextValue, coefficient, delta );
|
||
|
}
|
||
|
|
||
|
|
||
|
public float SmoothWithCoefficient( float value, float nextValue, float coefficient, float delta, float processDelta = MathX.fps120Delta )
|
||
|
{
|
||
|
overflowDelta += delta;
|
||
|
|
||
|
while ( overflowDelta > processDelta )
|
||
|
{
|
||
|
value += coefficient * ( nextValue - value );
|
||
|
overflowDelta -= processDelta;
|
||
|
}
|
||
|
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
|
||
|
public Quaternion SmoothForDuration( Quaternion value, Quaternion nextValue, float duration, float delta, float processDelta = MathX.fps120Delta )
|
||
|
{
|
||
|
var coefficient = MathX.SmoothingCoefficient( duration * 1000f );
|
||
|
return SmoothWithCoefficient( value, nextValue, coefficient, delta );
|
||
|
}
|
||
|
|
||
|
public Quaternion SmoothWithCoefficient( Quaternion value, Quaternion nextValue, float coefficient, float delta, float processDelta = MathX.fps120Delta )
|
||
|
{
|
||
|
overflowDelta += delta;
|
||
|
|
||
|
while ( overflowDelta > processDelta )
|
||
|
{
|
||
|
value = value.Slerp( nextValue, coefficient );
|
||
|
overflowDelta -= processDelta;
|
||
|
}
|
||
|
|
||
|
return value;
|
||
|
}
|
||
|
}
|
||
|
}
|