From 10656be954aa02a2e67fde0cb2f5d0d3e4b968eb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Jul 2018 16:54:52 +0200 Subject: [PATCH] Add interpolation to repeat point during sliding --- .../Objects/Drawables/DrawableRepeatPoint.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs index 26f3ee6bb4..77f813ae1e 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs @@ -74,6 +74,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables } } + private bool hasRotation; + public void UpdateSnakingPosition(Vector2 start, Vector2 end) { bool isRepeatAtEnd = repeatPoint.RepeatIndex % 2 == 0; @@ -87,15 +89,30 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables 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)); + + if (!hasRotation || Math.Abs(aimRotation - Rotation) > 180) + { + Rotation = aimRotation; + hasRotation = true; + } + else + { + Rotation = Interpolation.ValueAt(MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 100), Rotation, aimRotation, 0, 600, Easing.OutQuint); + } } } }