Ejemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            GamePadState  padState = GamePad.GetState(PlayerIndex.One);
            KeyboardState keyState = Keyboard.GetState();

            //if (padState.Buttons.Back == ButtonState.Pressed || keyState.IsKeyDown(Keys.Escape))
            //	Exit();

            if (IsKeyDown(keyState, Keys.R))
            {
                ResetSelectedPlugIn();
            }
            if (IsKeyDown(keyState, Keys.S))
            {
                SelectNextVehicle();
            }
            if (IsKeyDown(keyState, Keys.A))
            {
                _annotations.IsEnabled = !_annotations.IsEnabled;
            }
            if (IsKeyDown(keyState, Keys.Space))
            {
                Clock.TogglePausedState();
            }
            if (IsKeyDown(keyState, Keys.C))
            {
                Camera.SelectNextMode();
            }
            if (IsKeyDown(keyState, Keys.F))
            {
                SelectNextPresetFrameRate();
            }
            if (IsKeyDown(keyState, Keys.Tab))
            {
                SelectNextPlugin();
            }

            for (Keys key = Keys.F1; key <= Keys.F10; key++)
            {
                if (IsKeyDown(keyState, key))
                {
                    _selectedPlugIn.HandleFunctionKeys(key);
                }
            }

            _prevKeyState = keyState;

            // update global simulation clock
            Clock.Update();

            //  start the phase timer (XXX to accurately measure "overhead" time this
            //  should be in displayFunc, or somehow account for time outside this
            //  routine)
            InitPhaseTimers();

            // run selected PlugIn (with simulation's current time and step size)
            UpdateSelectedPlugIn(Clock.TotalSimulationTime, Clock.ElapsedSimulationTime);

            WorldMatrix = Matrix.Identity;

            Vector3 pos    = Camera.Position.ToXna();
            Vector3 lookAt = Camera.Target.ToXna();
            Vector3 up     = Camera.Up.ToXna();

            ViewMatrix = Matrix.CreateLookAt(new Vector3(pos.X, pos.Y, pos.Z), new Vector3(lookAt.X, lookAt.Y, lookAt.Z), new Vector3(up.X, up.Y, up.Z));

            ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(
                MathHelper.ToRadians(45),                  // 45 degree angle
                Graphics.GraphicsDevice.Viewport.Width / (float)Graphics.GraphicsDevice.Viewport.Height,
                1.0f, 400.0f);

            base.Update(gameTime);
        }