Exemplo n.º 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);
        }
        private void ApplyKeyBindings(FrameEventArgs e)
        {
            Vector3 direction  = Vector3.Zero;
            bool    rotated    = false;
            bool    translated = false;

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



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

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



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

                //X3DProgram.Quit();
                System.Diagnostics.Process.GetCurrentProcess().Kill(); // Fast !
            }

            if (Keyboard[Key.R])
            {
                // RESET CAMERA POSITION+ORIENTATION
                ActiveCamera.Reset();
            }

            if (NavigationInfo.NavigationType != NavigationType.Examine)
            {
                if (Keyboard[Key.T])
                {
                    ActiveCamera.Fly(playerDirectionMagnitude * movementSpeed);
                    translated = true;
                }
                if (Keyboard[Key.G])
                {
                    ActiveCamera.Fly(-playerDirectionMagnitude * movementSpeed);
                    translated = true;
                }

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

                #region G.3 Emulate pointing device Key Bindings

                if (Keyboard[Key.Left])
                {
                    ActiveCamera.ApplyYaw(-playerDirectionMagnitude * movementSpeed);

                    rotated = true;
                }
                if (Keyboard[Key.Right])
                {
                    ActiveCamera.ApplyYaw(playerDirectionMagnitude * movementSpeed);

                    rotated = true;
                }
                if (Keyboard[Key.Up])
                {
                    ActiveCamera.ApplyPitch(-playerDirectionMagnitude * movementSpeed);
                    rotated = true;
                }
                if (Keyboard[Key.Down])
                {
                    ActiveCamera.ApplyPitch(playerDirectionMagnitude * movementSpeed);

                    rotated = true;
                }

                if (Keyboard[Key.Number0])
                {
                    ActiveCamera.ApplyRoll(-0.1f);
                    rotated = true;
                }
                if (Keyboard[Key.Number9])
                {
                    ActiveCamera.ApplyRoll(0.1f);
                    rotated = true;
                }

                #endregion
            }

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