mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-13 11:20:31 +00:00
Add double variant for Spring class (#6706)
* Add double variant for spring class * Fix precedence implicit brackets --------- Co-authored-by: marvin <m.schuerz@hautzy.com> Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
@@ -117,10 +117,18 @@ namespace osu.Framework.Graphics.Transforms
|
||||
|
||||
protected void ComputeSingleValue(float dt, ref float current, ref float velocity, float target, float targetVelocity)
|
||||
{
|
||||
float k2Stable = MathF.Max(MathF.Max(k2, dt * dt / 2 + dt * k1 / 2), dt * k1);
|
||||
float k2Stable = MathF.Max(MathF.Max(k2, (dt * dt) / 2 + (dt * k1) / 2), dt * k1);
|
||||
|
||||
current += dt * velocity;
|
||||
velocity += (dt * (target + k3 * targetVelocity - current - k1 * velocity)) / k2Stable;
|
||||
velocity += (dt * (target + (k3 * targetVelocity) - current - (k1 * velocity))) / k2Stable;
|
||||
}
|
||||
|
||||
protected void ComputeSingleValue(float dt, ref double current, ref double velocity, double target, double targetVelocity)
|
||||
{
|
||||
float k2Stable = MathF.Max(MathF.Max(k2, (dt * dt) / 2 + (dt * k1) / 2), dt * k1);
|
||||
|
||||
current += dt * velocity;
|
||||
velocity += (dt * (target + (k3 * targetVelocity) - current - (k1 * velocity))) / k2Stable;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +144,18 @@ namespace osu.Framework.Graphics.Transforms
|
||||
}
|
||||
}
|
||||
|
||||
public class DoubleSpring : Spring<double>
|
||||
{
|
||||
protected override double GetTargetVelocity(double target, double previousTarget, float dt) => (target - previousTarget) / dt;
|
||||
|
||||
protected override double ComputeNextValue(float dt, double target, double targetVelocity)
|
||||
{
|
||||
ComputeSingleValue(dt, ref Current, ref Velocity, target, targetVelocity);
|
||||
|
||||
return Current;
|
||||
}
|
||||
}
|
||||
|
||||
public class Vector2Spring : Spring<Vector2>
|
||||
{
|
||||
protected override Vector2 GetTargetVelocity(Vector2 target, Vector2 previousTarget, float dt) => (target - previousTarget) / dt;
|
||||
|
||||
Reference in New Issue
Block a user