Пример #1
0
        public void UpdateFrame(long frame)
        {
            var currMillis = _lastMillis;

            _lastMillis = frame;

            if (currMillis == 0)
            {
                return;
            }
            if (!Focus || !Viewport.IsUnlocked(this) || !Viewport.Viewport.IsFocused)
            {
                if (FreeLook || FreeLookToggle)
                {
                    FreeLook = FreeLookToggle = false;
                    SetFreeLook();
                }
                return;
            }

            var seconds = (frame - currMillis) / 1000f;
            var units   = CameraNavigationViewportSettings.ForwardSpeed * seconds;

            var down = KeyboardState.IsAnyKeyDown(Keys.W, Keys.A, Keys.S, Keys.D);

            if (!down)
            {
                _downMillis = 0;
            }
            else if (_downMillis == 0)
            {
                _downMillis = currMillis;
            }

            if (CameraNavigationViewportSettings.TimeToTopSpeed > 0)
            {
                var downFor = (frame - _downMillis) / (CameraNavigationViewportSettings.TimeToTopSpeed * 1000);
                if (downFor >= 0 && downFor < 1)
                {
                    units *= (float)_easing.Evaluate((double)downFor);
                }
            }

            if (FreeLook)
            {
                if (KeyboardState.Shift)
                {
                    units *= 2;
                }
                if (KeyboardState.Ctrl)
                {
                    units /= 2;
                }
            }

            if (float.IsNaN(units) || float.IsInfinity(units) || units < 0.001f)
            {
                units = 0;
            }

            var move = units;
            var tilt = 2f;

            // These keys are used for hotkeys, don't want the 3D view to move about when trying to use hotkeys.
            var ignore = !FreeLook && KeyboardState.IsAnyKeyDown(Keys.ShiftKey, Keys.ControlKey, Keys.Alt);

            IfKey(Keys.W, () => Camera.Advance(move), ignore);
            IfKey(Keys.S, () => Camera.Advance(-move), ignore);
            IfKey(Keys.A, () => Camera.Strafe(-move), ignore);
            IfKey(Keys.D, () => Camera.Strafe(move), ignore);
            IfKey(Keys.Q, () => Camera.AscendAbsolute(move), ignore);
            IfKey(Keys.E, () => Camera.AscendAbsolute(-move), ignore);

            // Arrow keys are not really used for hotkeys all that much, so we allow shift+arrows to match Hammer's keys
            var shiftDown = KeyboardState.IsKeyDown(Keys.ShiftKey);
            var otherDown = KeyboardState.IsAnyKeyDown(Keys.ControlKey, Keys.Alt);

            IfKey(Keys.Right, () => { if (shiftDown)
                                      {
                                          Camera.Strafe(move);
                                      }
                                      else
                                      {
                                          Camera.Pan(-tilt);
                                      } }, otherDown);
            IfKey(Keys.Left, () => { if (shiftDown)
                                     {
                                         Camera.Strafe(-move);
                                     }
                                     else
                                     {
                                         Camera.Pan(tilt);
                                     } }, otherDown);
            IfKey(Keys.Up, () => { if (shiftDown)
                                   {
                                       Camera.Ascend(move);
                                   }
                                   else
                                   {
                                       Camera.Tilt(-tilt);
                                   } }, otherDown);
            IfKey(Keys.Down, () => { if (shiftDown)
                                     {
                                         Camera.Ascend(-move);
                                     }
                                     else
                                     {
                                         Camera.Tilt(tilt);
                                     } }, otherDown);
        }