Ejemplo n.º 1
0
        private State GetStateAtPoint(int x, int y, Viewport2D viewport, out Camera activeCamera)
        {
            var d = 5 / viewport.Zoom;

            foreach (var cam in GetCameras())
            {
                var p    = viewport.ScreenToWorld(x, y);
                var pos  = viewport.Flatten(cam.EyePosition);
                var look = viewport.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);
        }
Ejemplo n.º 2
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport2D;

            if (vp == null)
            {
                return;
            }
            _state = GetStateAtPoint(e.X, vp.Height - e.Y, vp, out _stateCamera);
            if (_state == State.None && KeyboardState.Shift)
            {
                var p = SnapIfNeeded(vp.Expand(vp.ScreenToWorld(e.X, vp.Height - e.Y)));
                _stateCamera = new Camera {
                    EyePosition = p, LookPosition = p + Coordinate.UnitX * 1.5m * Document.Map.GridSpacing
                };
                Document.Map.Cameras.Add(_stateCamera);
                _state = State.MovingLook;
            }
            if (_stateCamera != null)
            {
                SetViewportCamera(_stateCamera.EyePosition, _stateCamera.LookPosition);
                Document.Map.ActiveCamera = _stateCamera;
            }
        }
Ejemplo n.º 3
0
 public override void MouseDown(ViewportBase viewport, ViewportEvent e)
 {
     var vp = viewport as Viewport2D;
     if (vp == null) return;
     _state = GetStateAtPoint(e.X, vp.Height - e.Y, vp, out _stateCamera);
     if (_state == State.None && KeyboardState.Shift)
     {
         var p = SnapIfNeeded(vp.Expand(vp.ScreenToWorld(e.X, vp.Height - e.Y)));
         _stateCamera = new Camera { EyePosition = p, LookPosition = p + Coordinate.UnitX * 1.5m * Document.Map.GridSpacing };
         Document.Map.Cameras.Add(_stateCamera);
         _state = State.MovingLook;
     }
     if (_stateCamera != null)
     {
         SetViewportCamera(_stateCamera.EyePosition, _stateCamera.LookPosition);
         Document.Map.ActiveCamera = _stateCamera;
     }
 }
Ejemplo n.º 4
0
        private State GetStateAtPoint(int x, int y, Viewport2D viewport, out Camera activeCamera)
        {
            var d = 5 / viewport.Zoom;

            foreach (var cam in GetCameras())
            {
                var p = viewport.ScreenToWorld(x, y);
                var pos = viewport.Flatten(cam.EyePosition);
                var look = viewport.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;
        }