Merge pull request #3106 from peppy/fix-repeat-arrow-interpolation

Add interpolation to repeat point during sliding
This commit is contained in:
Dean Herbert 2018-07-31 17:03:26 +09:00 committed by GitHub
commit bc92bed72f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 1 deletions

View File

@ -75,6 +75,8 @@ protected override void UpdateCurrentState(ArmedState state)
}
}
private bool hasRotation;
public void UpdateSnakingPosition(Vector2 start, Vector2 end)
{
bool isRepeatAtEnd = repeatPoint.RepeatIndex % 2 == 0;
@ -88,15 +90,33 @@ public void UpdateSnakingPosition(Vector2 start, Vector2 end)
int searchStart = isRepeatAtEnd ? curve.Count - 1 : 0;
int direction = isRepeatAtEnd ? -1 : 1;
Vector2 aimRotationVector = Vector2.Zero;
// find the next vector2 in the curve which is not equal to our current position to infer a rotation.
for (int i = searchStart; i >= 0 && i < curve.Count; i += direction)
{
if (Precision.AlmostEquals(curve[i], Position))
continue;
Rotation = MathHelper.RadiansToDegrees((float)Math.Atan2(curve[i].Y - Position.Y, curve[i].X - Position.X));
aimRotationVector = curve[i];
break;
}
float aimRotation = MathHelper.RadiansToDegrees((float)Math.Atan2(aimRotationVector.Y - Position.Y, aimRotationVector.X - Position.X));
while (Math.Abs(aimRotation - Rotation) > 180)
aimRotation += aimRotation < Rotation ? 360 : -360;
if (!hasRotation)
{
Rotation = aimRotation;
hasRotation = true;
}
else
{
// If we're already snaking, interpolate to smooth out sharp curves (linear sliders, mainly).
Rotation = Interpolation.ValueAt(MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 100), Rotation, aimRotation, 0, 50, Easing.OutQuint);
}
}
}
}