protected override void MouseDown(MapViewport viewport, OrthographicCamera camera, ViewportEvent e) { var vp = viewport; if (vp == null) { return; } var gs = Document.Map.Data.GetOne <GridData>()?.Grid?.Spacing ?? 64; _state = GetStateAtPoint(e.X, e.Y, camera, out _stateCamera); if (_state == State.None && KeyboardState.Shift) { var p = SnapIfNeeded(camera.ScreenToWorld(e.X, e.Y)); _stateCamera = new Camera { EyePosition = p, LookPosition = p + Vector3.UnitX * 1.5f * gs }; Document.Map.Data.Add(_stateCamera); _state = State.MovingLook; } if (_stateCamera != null) { SetViewportCamera(_stateCamera.EyePosition, _stateCamera.LookPosition); GetDocumentCameras().ForEach(x => x.IsActive = false); _stateCamera.IsActive = true; } }
private State GetStateAtPoint(int x, int y, OrthographicCamera camera, out Camera activeCamera) { var d = 5 / camera.Zoom; foreach (var cam in GetCameraList()) { var p = camera.Flatten(camera.ScreenToWorld(new Vector3(x, y, 0))); var pos = camera.Flatten(cam.EyePosition); var look = camera.Flatten(cam.LookPosition); activeCamera = cam; if (p.X >= pos.X - d && p.X <= pos.X + d && p.Y >= pos.Y - d && p.Y <= pos.Y + d) { return(State.MovingPosition); } if (p.X >= look.X - d && p.X <= look.X + d && p.Y >= look.Y - d && p.Y <= look.Y + d) { return(State.MovingLook); } } activeCamera = null; return(State.None); }