Esempio n. 1
0
        public static void CameraControlFps(Camera camera)
        {
            GuiManager.Cursor.StaticPosition = true;
            Vector3 up = new Vector3(0, 1, 0);

            camera.Velocity = new Vector3();

            Keys forwardKey = Keys.W;
            Keys backKey    = Keys.S;
            Keys leftKey    = Keys.A;
            Keys rightKey   = Keys.D;

            FlatRedBall.Input.Keyboard keyboard = InputManager.Keyboard;

            float movementSpeed = 7;

            if (keyboard.KeyDown(forwardKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M31, camera.RotationMatrix.M32, camera.RotationMatrix.M33) *
                    movementSpeed;
            }
            else if (keyboard.KeyDown(backKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M31, camera.RotationMatrix.M32, camera.RotationMatrix.M33) *
                    -movementSpeed;
            }

            if (keyboard.KeyDown(leftKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13) *
                    -movementSpeed;
            }
            if (keyboard.KeyDown(rightKey))
            {
                camera.Velocity +=
                    new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13) *
                    movementSpeed;
            }

#if FRB_XNA
            // These vaules may be way too fast/slow because I modified it to use pixels rather
            // than the somewhat arbitrary world coordinates
            camera.RotationMatrix *=
                Matrix.CreateFromAxisAngle(
                    camera.RotationMatrix.Right,
                    -.2f * GuiManager.Cursor.ScreenYChange * TimeManager.SecondDifference);

            camera.RotationMatrix *=
                Matrix.CreateFromAxisAngle(
                    up,
                    -.2f * GuiManager.Cursor.ScreenXChange * TimeManager.SecondDifference);
#elif FRB_MDX
            camera.RotationMatrix *=
                Matrix.RotationAxis(
                    new Vector3(camera.RotationMatrix.M11, camera.RotationMatrix.M12, camera.RotationMatrix.M13),
                    -.2f * GuiManager.Cursor.YVelocity * TimeManager.SecondDifference);

            camera.RotationMatrix *=
                Matrix.RotationAxis(
                    up,
                    -.2f * GuiManager.Cursor.XVelocity * TimeManager.SecondDifference);
#endif
        }