Example #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;
            }
        }
Example #2
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;
                }
            }
        }