示例#1
0
        private void ApplyKeyBindings(float frameTime)
        {
            if (camera.playerMover == null)
            {
                return;
            }

            Vector3 direction  = Vector3.Zero;
            bool    translated = false;
            float   walkMovementSpeed;

            slowFlySpeed  = Keyboard[Key.AltLeft];
            fastFlySpeed  = Keyboard[Key.ShiftLeft];
            movementSpeed = fastFlySpeed ? 10.0f : 1.0f;
            movementSpeed = slowFlySpeed ? 0.01f : movementSpeed;

            fastWalkSpeed            = Keyboard[Key.ShiftLeft];
            walkMovementSpeed        = fastWalkSpeed ? Config.walkVelocityFast : Config.walkVelocityScale;
            camera.walkMovementSpeed = walkMovementSpeed;

            if (Keyboard[Key.Escape] || Keyboard[Key.Q])
            {
                // QUIT APPLICATION
                if (this.WindowState == WindowState.Fullscreen)
                {
                    this.WindowState = WindowState.Normal;
                }

                Quit();
            }

            Vector3 lookat  = QuaternionLib.Rotate(camera.Orientation, Vector3.UnitY);
            Vector3 forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
            Vector3 up      = Vector3.UnitZ;
            Vector3 left    = up.Cross(forward);
            Vector3 right   = up.Cross(camera.Direction);

            if (navigationType == NavigationType.Walk)
            {
                if (Keyboard[Key.W])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    direction     -= camera.Forward * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
                if (Keyboard[Key.S])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    direction     += camera.Forward * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
                if (Keyboard[Key.A])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    camera.Right   = right;

                    direction += camera.Right * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
                if (Keyboard[Key.D])
                {
                    camera.Forward = new Vector3(lookat.X, 0, lookat.Z).Normalized();
                    camera.Right   = right;

                    direction -= camera.Right * (Config.playerDirectionMagnitude * walkMovementSpeed);

                    translated = true;
                }
            }
            else if (navigationType == NavigationType.Fly)
            {
                if (Keyboard[Key.T])
                {
                    camera.Fly(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.G])
                {
                    camera.Fly(-playerDirectionMagnitude * movementSpeed);
                }

                if (Keyboard[Key.W])
                {
                    camera.Walk(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.S])
                {
                    camera.Walk(-playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.A])
                {
                    camera.Strafe(playerDirectionMagnitude * movementSpeed);
                }
                if (Keyboard[Key.D])
                {
                    camera.Strafe(-playerDirectionMagnitude * movementSpeed);
                }
            }



            if (Keyboard[Key.PageUp])
            {
                //drawMap = false;
            }
            if (Keyboard[Key.PageDown])
            {
                //drawMap = true;
            }

            bool rotated = false;

            if (Keyboard[Key.Left])
            {
                camera.ApplyYaw(-Config.turnMagnitude);
                rotated = true;
            }
            if (Keyboard[Key.Right])
            {
                camera.ApplyYaw(Config.turnMagnitude);
                rotated = true;
            }
            if (Keyboard[Key.Up])
            {
                camera.ApplyPitch(-Config.turnMagnitude);
                rotated = true;
            }
            if (Keyboard[Key.Down])
            {
                camera.ApplyPitch(Config.turnMagnitude);
                rotated = true;
            }

            // Calibrator (for translation debugging)
            if (Keyboard[Key.Number1])
            {
                camera.calibTrans.X += camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number2])
            {
                camera.calibTrans.X -= camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number3])
            {
                camera.calibTrans.Y += camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number4])
            {
                camera.calibTrans.Y -= camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number5])
            {
                camera.calibTrans.Z += camera.calibSpeed.Z;
            }
            if (Keyboard[Key.Number6])
            {
                camera.calibTrans.Z -= camera.calibSpeed.Z;
            }

            // Calibrator (for orientation debugging)
            if (Keyboard[Key.Number6])
            {
                camera.calibOrient.X += camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number7])
            {
                camera.calibOrient.X -= camera.calibSpeed.X;
            }
            if (Keyboard[Key.Number8])
            {
                camera.calibOrient.Y += camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Number9])
            {
                camera.calibOrient.Y -= camera.calibSpeed.Y;
            }
            if (Keyboard[Key.Minus])
            {
                camera.calibOrient.Z += camera.calibSpeed.Z;
            }
            if (Keyboard[Key.Plus])
            {
                camera.calibOrient.Z -= camera.calibSpeed.Z;
            }



            if (rotated)
            {
                camera.ApplyRotation();
            }

            if (navigationType == NavigationType.Walk)
            {
                camera.move(direction, frameTime);
            }


            //camera.update(frameTime);
        }