From b4a75ff58eae83605751f896cd97fc9694092bed Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 15 Jun 2020 16:49:13 +0200 Subject: [PATCH] better touch controls! --- TouchyTickets/ParkMap.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/TouchyTickets/ParkMap.cs b/TouchyTickets/ParkMap.cs index 80cf52a..d18ef4c 100644 --- a/TouchyTickets/ParkMap.cs +++ b/TouchyTickets/ParkMap.cs @@ -79,15 +79,12 @@ namespace TouchyTickets { if (GameImpl.Instance.DrawMap && GameImpl.Instance.UiSystem.Controls.HandleTouch) { var camera = GameImpl.Instance.Camera; if (MlemGame.Input.GetGesture(GestureType.Pinch, out var pinch)) { - var startDiff = pinch.Position2 - pinch.Position; - var endDiff = pinch.Position2 + pinch.Delta2 - (pinch.Position + pinch.Delta); - if (startDiff.LengthSquared() < endDiff.LengthSquared()) { - // zooming in - camera.Zoom(pinch.Delta.Length() / camera.Scale); - } else { - // zooming out - camera.Zoom(-pinch.Delta.Length() / camera.Scale); - } + // pinch zoom + var center = (pinch.Position + pinch.Position2) / 2; + var newDist = Vector2.Distance(pinch.Position + pinch.Delta, pinch.Position2 + pinch.Delta2); + var oldDist = Vector2.Distance(pinch.Position, pinch.Position2); + var newScale = newDist / oldDist * camera.Scale; + camera.Zoom(newScale - camera.Scale, center); } else if (MlemGame.Input.GetGesture(GestureType.FreeDrag, out var drag)) { if (this.draggingAttraction) { // move the current placing position @@ -98,7 +95,7 @@ namespace TouchyTickets { this.PlacingPosition = nextPos; } else { // move the camera - camera.Position -= drag.Delta / camera.Scale; + camera.Position -= drag.Delta / camera.ActualScale; } } else if (this.PlacingAttraction != null) { foreach (var touch in MlemGame.Input.TouchState) {