@@ -117,10 +117,18 @@ public T Update(double elapsed, T target, T? targetVelocity = null)
117117
118118 protected void ComputeSingleValue ( float dt , ref float current , ref float velocity , float target , float targetVelocity )
119119 {
120- float k2Stable = MathF . Max ( MathF . Max ( k2 , dt * dt / 2 + dt * k1 / 2 ) , dt * k1 ) ;
120+ float k2Stable = MathF . Max ( MathF . Max ( k2 , ( dt * dt ) / 2 + ( dt * k1 ) / 2 ) , dt * k1 ) ;
121121
122122 current += dt * velocity ;
123- velocity += ( dt * ( target + k3 * targetVelocity - current - k1 * velocity ) ) / k2Stable ;
123+ velocity += ( dt * ( target + ( k3 * targetVelocity ) - current - ( k1 * velocity ) ) ) / k2Stable ;
124+ }
125+
126+ protected void ComputeSingleValue ( float dt , ref double current , ref double velocity , double target , double targetVelocity )
127+ {
128+ float k2Stable = MathF . Max ( MathF . Max ( k2 , ( dt * dt ) / 2 + ( dt * k1 ) / 2 ) , dt * k1 ) ;
129+
130+ current += dt * velocity ;
131+ velocity += ( dt * ( target + ( k3 * targetVelocity ) - current - ( k1 * velocity ) ) ) / k2Stable ;
124132 }
125133 }
126134
@@ -136,6 +144,18 @@ protected override float ComputeNextValue(float dt, float target, float targetVe
136144 }
137145 }
138146
147+ public class DoubleSpring : Spring < double >
148+ {
149+ protected override double GetTargetVelocity ( double target , double previousTarget , float dt ) => ( target - previousTarget ) / dt ;
150+
151+ protected override double ComputeNextValue ( float dt , double target , double targetVelocity )
152+ {
153+ ComputeSingleValue ( dt , ref Current , ref Velocity , target , targetVelocity ) ;
154+
155+ return Current ;
156+ }
157+ }
158+
139159 public class Vector2Spring : Spring < Vector2 >
140160 {
141161 protected override Vector2 GetTargetVelocity ( Vector2 target , Vector2 previousTarget , float dt ) => ( target - previousTarget ) / dt ;
0 commit comments