示例#1
0
        private void UpdateCameraInput()
        {
            if (MouseCondition.Scrolled())
            {
                int scrollDelta = MouseCondition.ScrollDelta;
                _targetExp = MathHelper.Clamp(_targetExp - scrollDelta * _expDistance, _maxExp, _minExp);
            }

            if (RotateLeft.Pressed())
            {
                _targetRotation += MathHelper.Pi / 8f;
            }
            if (RotateRight.Pressed())
            {
                _targetRotation -= MathHelper.Pi / 8f;
            }

            _mouseWorld = Vector2.Transform(InputHelper.NewMouse.Position.ToVector2(), Matrix.Invert(GetView()));

            if (CameraDrag.Pressed())
            {
                _dragAnchor = _mouseWorld;
                _isDragged  = true;
            }
            if (_isDragged && CameraDrag.HeldOnly())
            {
                _xy        += _dragAnchor - _mouseWorld;
                _mouseWorld = _dragAnchor;
            }
            if (_isDragged && CameraDrag.Released())
            {
                _isDragged = false;
            }
        }
示例#2
0
        private void SingleHover()
        {
            _hoveredEntity = null;
            if (_selection.Rect == null)
            {
                bool   addSelected = false;
                Entity?first       = null;
                // If there's a single element selected, it can have resize handles. Expand it's bounds to see if we're hovering that.
                if (_selectedEntities.Count() == 1)
                {
                    first = _selectedEntities.First();
                    var inset = first.Inset;
                    addSelected = !inset.Contains(Camera.MouseWorld) && Utility.ExpandRect(new RectangleF(inset.X, inset.Y, inset.Width, inset.Height), _edit.HandleDistanceWorld).Contains(Camera.MouseWorld);
                }

                List <Entity> hoversUnderMouse;
                List <Entity> selectedAndHovered;
                if (addSelected)
                {
                    hoversUnderMouse = new QueryFilter(_aabbTree.Query(Camera.MouseWorld), _activeLayers).Append(first !).OrderBy(e => e).ToList();
                    // This can only happen when there's only 1 selection so we can do a special case here.
                    selectedAndHovered = new List <Entity> {
                        first !
                    };
                }
                else
                {
                    hoversUnderMouse   = new QueryFilter(_aabbTree.Query(Camera.MouseWorld), _activeLayers).OrderBy(e => e).ToList();
                    selectedAndHovered = _selectedEntities.Query(Camera.MouseWorld).OrderBy(e => e).ToList();
                }

                var hoverCount = hoversUnderMouse.Count();
                // Skip if there are no hovers.
                if (hoverCount > 0)
                {
                    int cycleReset = 0;
                    // If there's a selection, always give it priority over everything else.
                    if (selectedAndHovered.Count() > 0)
                    {
                        cycleReset = hoverCount - 1 - hoversUnderMouse.IndexOf(selectedAndHovered.Last());
                    }

                    // If we aren't cycling, then select the selection at the top or element at the top.
                    if (_cycleMouse == null)
                    {
                        _cycleIndex = cycleReset;
                    }
                    // If we're current cycling over the hovers, we reset when the mouse moves enough.
                    else if (Vector2.DistanceSquared(_cycleMouse.Value, Camera.MouseWorld) > Utility.ScreenArea(10))
                    {
                        _cycleIndex = cycleReset;
                        _cycleMouse = null;
                    }
                    // If we want to cycle over the hovers, save current mouse position so that we can reset later.
                    if (MouseCondition.Scrolled() && Triggers.SelectionCycle.Held())
                    {
                        _cycleIndex += MathF.Sign(MouseCondition.ScrollDelta);
                        _cycleMouse  = Camera.MouseWorld;
                    }

                    // Now we can do the selection.
                    _hoveredEntity = hoversUnderMouse.ElementAt(Utility.Mod(hoverCount - 1 - _cycleIndex, hoverCount));
                }
                else
                {
                    _cycleIndex = 0;
                    _cycleMouse = null;
                }
            }
        }
示例#3
0
        private void UpdateCameraInput(Camera c, int index)
        {
            int x = InputHelper.NewMouse.X;
            int y = InputHelper.NewMouse.Y;

            if (!_isDragged && CameraContains(c, x, y) || _isDragged && _currentCamera == index)
            {
                _currentCamera = index;
                if (MouseCondition.Scrolled())
                {
                    int scrollDelta = MouseCondition.ScrollDelta;
                    SetZoom(c, MathF.Min(MathF.Max(GetZoom(c) - scrollDelta * 0.001f, 0.2f), 10f));
                }

                if (RotateLeft.Pressed())
                {
                    c.Rotation += MathHelper.PiOver4;
                }
                if (RotateRight.Pressed())
                {
                    c.Rotation -= MathHelper.PiOver4;
                }

                if (Forward.Held())
                {
                    c.Z -= 0.1f;
                }
                if (Backward.Held())
                {
                    c.Z += 0.1f;
                }

                if (IncreaseFocal.Held())
                {
                    var temp = c.Z / c.FocalLength;

                    c.FocalLength += 0.01f;

                    c.Z = c.FocalLength * temp;
                }
                if (DecreaseFocal.Held())
                {
                    var temp = c.Z / c.FocalLength;

                    c.FocalLength -= 0.01f;

                    c.Z = c.FocalLength * temp;
                }

                if (ResetCamera.Pressed())
                {
                    c.Scale       = new Vector2(1f, 1f);
                    c.XY          = new Vector2(0f, 0f);
                    c.Z           = 2f;
                    c.Rotation    = 0f;
                    c.FocalLength = 1f;
                }

                _mouseWorld = c.ScreenToWorld(x, y);

                if (CameraDrag.Pressed())
                {
                    _dragAnchor = _mouseWorld;
                    _isDragged  = true;
                }
                if (_isDragged && CameraDrag.HeldOnly())
                {
                    c.XY       += _dragAnchor - _mouseWorld;
                    _mouseWorld = _dragAnchor;
                }
                if (_isDragged && CameraDrag.Released())
                {
                    _isDragged = false;
                }
            }
        }