示例#1
0
        /// <summary>
        /// Create a new SpriteBatch, which can be used to draw textures.
        /// Loads images of background, player and _allCars
        /// Creats an instance of state and collision class.
        /// Loads font and fontPos for drawing Score
        /// </summary>
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // Debug
            _debugTexture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            _debugTexture.SetData <Color>(new Color[] { Color.White });

            _background.LoadContent(Content);
            _player.LoadContent(Content);
            _player.LoadDebugTexture(_debugTexture);   // Debug load texture for player

            foreach (var car in _allCars)
            {
                car.LoadContent(Content);
            }

            _state     = new KeyboardState();
            _collision = new Collision();

            _font    = Content.Load <SpriteFont>("SpriteFont1");
            _fontPos = new Vector2(
                graphics.GraphicsDevice.Viewport.Width * 0.1f,
                graphics.GraphicsDevice.Viewport.Height * 0.1f
                );

            base.LoadContent();
        }
示例#2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Update scene
            core.Scene.Update(gameTime.ElapsedGameTime);

            // Update pointer ray with mouse position
            Point mousePos = core.Input.MousePos;

            core.Renderer.UpdatePointerRay(mousePos.X, mousePos.Y);

            // Update input
            core.Input.Update(gameTime.ElapsedGameTime);
            core.Input.Apply(core.Camera, true);

            // Space pressed
            if (
                core.Input.KeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space) &&
                !oldKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
            {
                // Test pointer over node
                if (core.Renderer.PointerOverNode != null)
                {
                    // Test node has action
                    if (core.Renderer.PointerOverNode.Action.Enabled)
                    {
                        ToggleAction((ModelNode)core.Renderer.PointerOverNode);
                    }
                }
            }

            oldKeyboardState = core.Input.KeyboardState;

            // Update camera
            core.Camera.Update();
        }
        /// <inheritdoc />
        /// <summary>
        /// Changes the position at the scene by arrows keys.
        /// </summary>
        public override void KeyboardState(GameTime gameTime, ref Microsoft.Xna.Framework.Input.KeyboardState keyboardState)
        {
            Vector2 moveVector = new Vector2();
            bool    moved      = false;

            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
            {
                moveVector += new Vector2(0, -MoveVectorSizeByKeyboard);
                moved       = true;
            }
            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
            {
                moveVector += new Vector2(0, MoveVectorSizeByKeyboard);
                moved       = true;
            }
            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
            {
                moveVector += new Vector2(-MoveVectorSizeByKeyboard, 0);
                moved       = true;
            }
            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
            {
                moveVector += new Vector2(MoveVectorSizeByKeyboard, 0);
                moved       = true;
            }

            // If any key for changing the position of the scene (moving scene) is down
            // we change the position based on elapsed time.
            if (moved)
            {
                Screen.Position += moveVector * (float)(gameTime.ElapsedGameTime.TotalMilliseconds * Screen.ScaleInversFactor);
            }
        }
示例#4
0
 internal static void Draw(Microsoft.Xna.Framework.Input.KeyboardState currentKeyState)
 {
     if (currentKeyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F1))
     {
         game.spriteBatch.Draw(adjustmentsHud, adjustmentsHudLocation, Color.White);
     }
 }
        protected override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

#if DEBUG
            pks = ks;
            ks  = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3) && pks.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                AssetManager.FrameCapture = true;
            }

            EngineGlobals.GameTime = gameTime;

            if (_errorOccured)
            {
                _debugConsole.Update(gameTime);
            }
            else
#endif
            time += dt;
            if (time > 0.1f)
            {
                System.Windows.Forms.Application.DoEvents();
                time = 0;
            }
            base.Update(gameTime);
        }
示例#6
0
 protected override void KeyDown(ref Microsoft.Xna.Framework.Input.KeyboardState currentKeyboardState, ref Microsoft.Xna.Framework.Input.KeyboardState oldKeyboardState)
 {
     if (!_justOpened && currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
     {
         CMasterControl.audioPlayer.addSfx(CMasterControl.audioPlayer.soundBank["menu:closeMenu"]);
         Master.Pop();
     }
 }
示例#7
0
        /// <summary>
        /// Called when the <see cref="SceneScreen"/> needs to be updated.
        /// Hands keyboard state over to the <see cref="State"/> (<see cref="SceneState.KeyboardState"/> method) of the SceneScreen control.
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to Update.</param>
        protected override void Update(GameTime gameTime)
        {
            if (Focused)
            {
                Microsoft.Xna.Framework.Input.KeyboardState keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

                State.KeyboardState(gameTime, ref keyboardState);
            }
        }
示例#8
0
 public static void update_input(Game game, GameTime gameTime, bool gameActive,
                                 Microsoft.Xna.Framework.Input.KeyboardState key_state,
                                 Microsoft.Xna.Framework.Input.GamePadState controller_state)
 {
     Tactile.Input.update(gameActive, gameTime, key_state, controller_state);
     Input.UpdateKeyboardStart(key_state);
     Input.UpdateGamepadState(controller_state);
     Tactile.Input.update_input_state(Input);
 }
示例#9
0
 public static void update_scene(Microsoft.Xna.Framework.Input.KeyboardState key_state)
 {
     if (Scene.scene_type == "Scene_Title")
     {
         ((Scene_Title)Scene).update(key_state);
     }
     else
     {
         Scene.update();
     }
 }
示例#10
0
        public static LProcess.AccelerometerState GetState()
        {
            if (!isInitialized)
            {
                throw new InvalidOperationException("You must Initialize before you can call GetState");
            }

            Vector3 stateValue = new Vector3();

#if WINDOWS_PHONE
            if (isActive)
            {
                if (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Device)
                {
                    lock (threadLock)
                    {
                        stateValue = nextValue;
                    }
                }
                else
                {
                    //°´¼üÄ£Äâ
                    Microsoft.Xna.Framework.Input.KeyboardState keyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

                    stateValue.Z = -1;

                    if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
                    {
                        stateValue.X--;
                    }
                    if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
                    {
                        stateValue.X++;
                    }
                    if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                    {
                        stateValue.Y++;
                    }
                    if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                    {
                        stateValue.Y--;
                    }
                    stateValue.Normalize();
                }
            }
#endif
            LProcess.AccelerometerState state = new LProcess.AccelerometerState(stateValue, isActive);
            if (LSystem.screenProcess != null)
            {
                LSystem.screenProcess.OnSensorChanged(state);
            }
            return(state);
        }
示例#11
0
        private void Application_Idle(object sender, EventArgs e)
        {
            Microsoft.Xna.Framework.Input.KeyboardState newState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (Form1.IsDown(newState, prevState, Microsoft.Xna.Framework.Input.Keys.Delete))
            {
                DeleteJointAnnotation(selectJoint);
                SelectJointAnnotation(null);
                pictureBox1.Invalidate();
            }
            prevState = newState;
        }
示例#12
0
        internal void ProcessKey(Microsoft.Xna.Framework.Input.KeyboardState currentState)
        {
            foreach (KeyBindingControl kbc in flpBindings.Controls)
            {
                // if this keybindingcontrol is in edit mode
                if (kbc.Editing)
                {
                    // apply the pressed key to it
                    kbc.SetKey(currentState);

                    // get focus off of the textbox
                    flpBindings.Focus();
                }
            }
        }
        /// <inheritdoc />
        /// <summary>
        /// Changes the <see cref="UniformScaling"/> value by holding left Shift.
        /// </summary>
        public override void KeyboardState(GameTime gameTime, ref Microsoft.Xna.Framework.Input.KeyboardState keyboardState)
        {
            base.KeyboardState(gameTime, ref keyboardState);

            // If left shift key is down the uniform scale is on.
            if (keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift))
            {
                UniformScaling = true;
            }
            // If left shift key is up the non-uniform scale is on.
            else if (keyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.LeftShift))
            {
                UniformScaling = false;
            }
        }
示例#14
0
        protected override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

#if DEBUG
            pks = ks;
            ks  = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3) && pks.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                AssetManager.FrameCapture = true;
            }

            if (_errorOccured)
            {
                _debugConsole.Update(gameTime);
            }
            else
#endif
            base.Update(gameTime);
        }
示例#15
0
        public void Update(DwarfTime time)
        {
#if DEBUG
            Microsoft.Xna.Framework.Input.KeyboardState k = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            if (k.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Home))
            {
                try
                {
                    GameState.Game.GraphicsDevice.Reset();
                }
                catch (Exception exception)
                {
                }
            }
#endif

            if (ScreenSaver == null)
            {
                ScreenSaver = new Terrain2D(Game);
            }

            if (NextState != null && NextState.IsInitialized)
            {
                if (CurrentState != null)
                {
                    CurrentState.OnExit();
                    CurrentState.OnPopped();
                }

                CurrentState = NextState;
                NextState    = null;
            }

            if (CurrentState != null && CurrentState.IsInitialized)
            {
                CurrentState.Update(time);
            }
        }
示例#16
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState keyboard, Microsoft.Xna.Framework.Input.MouseState mouse)
        {
            Viewport viewport       = MobileFortressClient.Game.GraphicsDevice.Viewport;
            ShipObj  Ship           = (ShipObj)Camera.Target;
            Vector3  Crosshair      = Ship.Entity.WorldTransform.Forward * 70;
            Vector3  ScreenLocation = viewport.Project(Crosshair, Camera.Projection, Camera.View, Matrix.CreateTranslation(Ship.Entity.WorldTransform.Translation));

            RCrosshairs.Location = new Point((int)ScreenLocation.X - Crosshairs.Width / 2, (int)ScreenLocation.Y - Crosshairs.Height / 2);

            Crosshair             = Ship.Entity.WorldTransform.Forward * 35;
            ScreenLocation        = viewport.Project(Crosshair, Camera.Projection, Camera.View, Matrix.CreateTranslation(Ship.Entity.WorldTransform.Translation));
            RCrosshairs2.Location = new Point((int)ScreenLocation.X - Crosshairs.Width / 4, (int)ScreenLocation.Y - Crosshairs.Height / 4);

            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (LockStatus == LockonStatus.Locking)
            {
                lockTime += dt;
                if (lockTime >= 0.2f)
                {
                    lockTime = 0f;
                    Resources.Sounds.LockingOn.Play();
                }
            }
            if (enemyLock)
            {
                enemyLockTime += dt;
                if (enemyLockTime >= Resources.Sounds.EnemyLockon.Duration.TotalSeconds * 1.2f)
                {
                    enemyLockTime = 0f;
                    Resources.Sounds.EnemyLockon.Play();
                }
            }

            FrameCounter.Update(gameTime);
            Manager.Update(gameTime, mouse);
        }
示例#17
0
        /// <summary>
        /// Update particles
        /// </summary>
        public override void Update(GameTime gameTime, Microsoft.Xna.Framework.Input.KeyboardState currentKeyState, Microsoft.Xna.Framework.Input.KeyboardState lastKeyState)
        {
            //Add velocity
            Velocity = Velocity - Gravity + Wind;

            if (TTL > 0)
            {
                TTL--;  //Decrease time to live as game goes on
            }
            if (Shrink) //Shrink
            {
                Size = SizeOriginal * (TTL > 0 ? (float)TTL / TTLoriginal : TTLoriginal / (float)TTLoriginal);
            }
            if (AlphaFade) //Fade out
            {
                Alpha = (float)TTL / (float)TTLoriginal;
                Color = new Color((byte)(BaseColor.R * Alpha), (byte)(BaseColor.G * Alpha), (byte)(BaseColor.R * Alpha), (byte)(BaseColor.A * Alpha));
            }


            if (!Collision)
            {
                Position += (Velocity * Speed) * ((float)gameTime.ElapsedGameTime.TotalSeconds * 60); //Set Position based on Velocity
            }
            Angle += AngularVelocity;                                                                 //Set Angle based on AngularVelocity

            if (Collision)
            {
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                LastPosition = Position;

                Rectangle bounds     = BoundingRectangle;
                int       leftTile   = (int)Math.Floor((float)bounds.Left / Tile.Width);
                int       rightTile  = (int)Math.Ceiling(((float)bounds.Right / Tile.Width)) - 1;
                int       topTile    = (int)Math.Floor((float)bounds.Top / Tile.Height);
                int       bottomTile = (int)Math.Ceiling(((float)bounds.Bottom / Tile.Height)) - 1;

                velocity.Y += GravityAcceleration * elapsed;
                velocity.Y  = MathHelper.Clamp(
                    Velocity.Y,
                    -MaxFallSpeed,
                    MaxFallSpeed);

                Velocity *= Speed;

                if (Velocity.X != 0f)
                {
                    Vector2 change = Velocity.X * Vector2.UnitX * elapsed;
                    change.X  = MathHelper.Clamp(change.X, -(Tile.Height - 12), Tile.Height - 12);
                    Position += change;
                    HandleCollisions(CollisionDirection.Horizontal);
                }
                if (Velocity.Y != 0f)
                {
                    Vector2 change = Velocity.Y * Vector2.UnitY * elapsed;
                    change.Y  = MathHelper.Clamp(change.Y, -(Tile.Height - 12), Tile.Height - 12);
                    Position += change;
                    if (Type == ParticleType.Snow && AlphaFade)
                    {
                        position = new Vector2(position.X, (float)Math.Round(position.Y));
                    }
                    HandleCollisions(CollisionDirection.Vertical);
                }

                // If the collision stopped us from moving, reset the Velocity to zero.
                if (Position.X == LastPosition.X)
                {
                    velocity.X = 0;
                }

                if (Position.Y == LastPosition.Y)
                {
                    velocity.Y = 0;
                }
            }
        }
示例#18
0
 public static bool IsCtrlDown(this Microsoft.Xna.Framework.Input.KeyboardState KeyState)
 {
     return(KeyState.IsKeyDown(XnaKeys.LeftControl) || KeyState.IsKeyDown(XnaKeys.RightControl));
 }
示例#19
0
        /// <summary>
        /// Handles the input and movement of the character.
        /// </summary>
        /// <param name="dt">Time since last frame in simulation seconds.</param>
        /// <param name="keyboardInput">Keyboard state.</param>
        /// <param name="gamePadInput">Gamepad state.</param>
        public void Update(float dt, Microsoft.Xna.Framework.Input.KeyboardState keyboardInput, Microsoft.Xna.Framework.Input.GamePadState gamePadInput)
        {
            //Update the wheel's graphics.
            for (int k = 0; k < 4; k++)
            {
                WheelModels[k].WorldTransform = Vehicle.Wheels[k].Shape.WorldTransform;
            }

            if (IsActive)
            {
                CameraControlScheme.Update(dt);
#if XBOX360
                float speed = gamePadInput.Triggers.Right * ForwardSpeed + gamePadInput.Triggers.Left * BackwardSpeed;
                Vehicle.Wheels[1].DrivingMotor.TargetSpeed = speed;
                Vehicle.Wheels[3].DrivingMotor.TargetSpeed = speed;

                if (gamePadInput.IsButtonDown(Buttons.LeftStick))
                {
                    foreach (Wheel wheel in Vehicle.Wheels)
                    {
                        wheel.Brake.IsBraking = true;
                    }
                }
                else
                {
                    foreach (Wheel wheel in Vehicle.Wheels)
                    {
                        wheel.Brake.IsBraking = false;
                    }
                }
                Vehicle.Wheels[1].Shape.SteeringAngle = (gamePadInput.ThumbSticks.Left.X * MaximumTurnAngle);
                Vehicle.Wheels[3].Shape.SteeringAngle = (gamePadInput.ThumbSticks.Left.X * MaximumTurnAngle);
#else
                if (keyboardInput.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.E))
                {
                    //Drive
                    Vehicle.Wheels[1].DrivingMotor.TargetSpeed = ForwardSpeed;
                    Vehicle.Wheels[3].DrivingMotor.TargetSpeed = ForwardSpeed;
                }
                else if (keyboardInput.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    //Reverse
                    Vehicle.Wheels[1].DrivingMotor.TargetSpeed = BackwardSpeed;
                    Vehicle.Wheels[3].DrivingMotor.TargetSpeed = BackwardSpeed;
                }
                else
                {
                    //Idle
                    Vehicle.Wheels[1].DrivingMotor.TargetSpeed = 0;
                    Vehicle.Wheels[3].DrivingMotor.TargetSpeed = 0;
                }
                if (keyboardInput.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space))
                {
                    //Brake
                    foreach (Wheel wheel in Vehicle.Wheels)
                    {
                        wheel.Brake.IsBraking = true;
                    }
                }
                else
                {
                    //Release brake
                    foreach (Wheel wheel in Vehicle.Wheels)
                    {
                        wheel.Brake.IsBraking = false;
                    }
                }
                //Use smooth steering; while held down, move towards maximum.
                //When not pressing any buttons, smoothly return to facing forward.
                float angle;
                bool  steered = false;
                if (keyboardInput.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
                {
                    steered = true;
                    angle   = Math.Max(Vehicle.Wheels[1].Shape.SteeringAngle - TurnSpeed * dt, -MaximumTurnAngle);
                    Vehicle.Wheels[1].Shape.SteeringAngle = angle;
                    Vehicle.Wheels[3].Shape.SteeringAngle = angle;
                }
                if (keyboardInput.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    steered = true;
                    angle   = Math.Min(Vehicle.Wheels[1].Shape.SteeringAngle + TurnSpeed * dt, MaximumTurnAngle);
                    Vehicle.Wheels[1].Shape.SteeringAngle = angle;
                    Vehicle.Wheels[3].Shape.SteeringAngle = angle;
                }
                if (!steered)
                {
                    //Neither key was pressed, so de-steer.
                    if (Vehicle.Wheels[1].Shape.SteeringAngle > 0)
                    {
                        angle = Math.Max(Vehicle.Wheels[1].Shape.SteeringAngle - TurnSpeed * dt, 0);
                        Vehicle.Wheels[1].Shape.SteeringAngle = angle;
                        Vehicle.Wheels[3].Shape.SteeringAngle = angle;
                    }
                    else
                    {
                        angle = Math.Min(Vehicle.Wheels[1].Shape.SteeringAngle + TurnSpeed * dt, 0);
                        Vehicle.Wheels[1].Shape.SteeringAngle = angle;
                        Vehicle.Wheels[3].Shape.SteeringAngle = angle;
                    }
                }
#endif
            }
            else
            {
                //Parking brake
                foreach (Wheel wheel in Vehicle.Wheels)
                {
                    wheel.Brake.IsBraking = true;
                }
                //Don't want the car to keep trying to drive.
                Vehicle.Wheels[1].DrivingMotor.TargetSpeed = 0;
                Vehicle.Wheels[3].DrivingMotor.TargetSpeed = 0;
            }
        }
示例#20
0
        /// <summary>
        ///  见接口
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="screenTarget"></param>
        public void RenderFullScene(ISceneRenderer renderer, RenderTarget screenTarget, RenderMode mode)
        {
            Microsoft.Xna.Framework.Input.KeyboardState ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C) &&
                lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.C))
            {
                testMode++;
                if (testMode > TestMode.Blurred)
                    testMode = TestMode.Final;
            }
            lastState = ks;

            if (testMode == TestMode.Original)
            {
                renderer.RenderScene(screenTarget, RenderMode.Final);
                return;
            }
            if (testMode == TestMode.Normal)
            {
                renderer.RenderScene(screenTarget, RenderMode.DeferredNormal);
                return;
            }

            renderer.RenderScene(nrmDepthBuffer, RenderMode.DeferredNormal);

            renderer.RenderScene(colorBuffer, RenderMode.Final);


            Viewport vp = renderSys.Viewport;

            ShaderSamplerState sampler1;
            sampler1.AddressU = TextureAddressMode.Clamp;
            sampler1.AddressV = TextureAddressMode.Clamp;
            sampler1.AddressW = TextureAddressMode.Clamp;
            sampler1.BorderColor = ColorValue.Transparent;
            sampler1.MagFilter = TextureFilter.Point;
            sampler1.MaxAnisotropy = 0;
            sampler1.MaxMipLevel = 0;
            sampler1.MinFilter = TextureFilter.Point;
            sampler1.MipFilter = TextureFilter.None;
            sampler1.MipMapLODBias = 0;


            ShaderSamplerState sampler2 = sampler1;
            sampler2.MagFilter = TextureFilter.Linear;
            sampler2.MinFilter = TextureFilter.Linear;

            #region 边缘合成
            renderSys.SetRenderTarget(0, testMode == TestMode.Edge ? screenTarget : edgeResultBuffer);
            edgeEff.Begin();

            edgeEff.SetSamplerStateDirect(0, ref sampler1);
            edgeEff.SetSamplerStateDirect(1, ref sampler1);

            edgeEff.SetTextureDirect(0, nrmDepthBuffer.GetColorBufferTexture());
            edgeEff.SetTextureDirect(1, testMode == TestMode.Edge ? whitePixel : colorBuffer.GetColorBufferTexture());

            Vector2 nrmBufSize = new Vector2(vp.Width, vp.Height);
            edgeEff.SetValue("normalBufferSize", ref nrmBufSize);
            DrawBigQuad();
            edgeEff.End();
            #endregion

            if (testMode == TestMode.Edge)
                return;
            if (testMode == TestMode.Depth)
            {
                renderSys.SetRenderTarget(0, screenTarget);
                depthViewEff.Begin();
                depthViewEff.SetSamplerStateDirect(0, ref sampler1);
                depthViewEff.SetTextureDirect(0, nrmDepthBuffer.GetColorBufferTexture());
                DrawBigQuad();
                depthViewEff.End();
                return;
            }
            #region 高斯X
            renderSys.SetRenderTarget(0, blurredRt1);

            gaussBlur.Begin();

            gaussBlur.SetSamplerStateDirect(0, ref sampler1);
            gaussBlur.SetTextureDirect(0, edgeResultBuffer.GetColorBufferTexture());

            for (int i = 0; i < SampleCount; i++)
            {
                gaussBlur.SetValueDirect(i, ref guassFilter.SampleOffsetsX[i]);
                gaussBlur.SetValueDirect(i + 15, guassFilter.SampleWeights[i]);
            }

            DrawSmallQuad();

            gaussBlur.End();
            #endregion

            #region 高斯Y

            renderSys.SetRenderTarget(0, testMode == TestMode.Blurred ? screenTarget : blurredRt2);
            gaussBlur.Begin();

            gaussBlur.SetSamplerStateDirect(0, ref sampler1);
            gaussBlur.SetTextureDirect(0, blurredRt1.GetColorBufferTexture());

            for (int i = 0; i < SampleCount; i++)
            {
                gaussBlur.SetValueDirect(i, ref guassFilter.SampleOffsetsY[i]);
                gaussBlur.SetValueDirect(i + 15, guassFilter.SampleWeights[i]);
            }
            if (testMode == TestMode.Blurred)
            {
                DrawBigQuad();
            }
            else
            {
                DrawSmallQuad();
            }

            gaussBlur.End();


            #endregion

            if (testMode == TestMode.Blurred)
                return;

            #region DOF合成

            renderSys.SetRenderTarget(0, screenTarget);

            compEff.Begin();

            compEff.SetSamplerStateDirect(0, ref sampler1);
            compEff.SetSamplerStateDirect(1, ref sampler2);
            compEff.SetSamplerStateDirect(2, ref sampler2);

            compEff.SetTextureDirect(0, edgeResultBuffer.GetColorBufferTexture());
            compEff.SetTextureDirect(1, blurredRt2.GetColorBufferTexture());
            compEff.SetTextureDirect(2, nrmDepthBuffer.GetColorBufferTexture());

            //if (camera != null)
            //{
            //    float focNear = (camera.Position.Length() - PlanetEarth.PlanetRadius) / camera.FarPlane;
            //    compEff.SetValue("FocusNear", focNear);
            //}
            //else 
            //{
            //    compEff.SetValue("FocusNear", 0.3f);
            //}

            renderSys.RenderStates.AlphaBlendEnable = true;
            renderSys.RenderStates.SourceBlend = Blend.SourceAlpha;
            renderSys.RenderStates.DestinationBlend = Blend.InverseSourceAlpha;
            renderSys.RenderStates.BlendOperation = BlendFunction.Add;

            DrawBigQuad();

            compEff.End();
            #endregion
        }
示例#21
0
        /// <summary>
        /// check for new updates
        /// </summary>
        public void Update()
        {
            // get the mousestate
            Microsoft.Xna.Framework.Input.MouseState ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            this.lastKeyboardState = this.currentKeyboardState;
            this.currentKeyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            // get the movement and position

            this.mouseMovement = new Microsoft.Xna.Framework.Vector2((FenrirGame.Instance.Properties.ScreenWidth / 2 - ms.X), (FenrirGame.Instance.Properties.ScreenHeight / 2 - ms.Y));
            this.currentMousePosition -= mouseMovement * 1.05f;
            Microsoft.Xna.Framework.Input.Mouse.SetPosition(FenrirGame.Instance.Properties.ScreenWidth / 2, FenrirGame.Instance.Properties.ScreenHeight / 2);

            if (this.currentMousePosition.X < 0)
                this.currentMousePosition.X = 0;
            else if (this.currentMousePosition.X > FenrirGame.Instance.Properties.ScreenWidth)
                this.currentMousePosition.X = FenrirGame.Instance.Properties.ScreenWidth;

            if (this.currentMousePosition.Y < 0)
                this.currentMousePosition.Y = 0;
            else if (this.currentMousePosition.Y > FenrirGame.Instance.Properties.ScreenHeight)
                this.currentMousePosition.Y = FenrirGame.Instance.Properties.ScreenHeight;

            // get the scrollwheel
            this.scrollValue = scrollValueOld - ms.ScrollWheelValue;
            this.scrollValueOld = ms.ScrollWheelValue;

            // calculate boundingbox
            this.boundingBox.X = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.X;
            this.boundingBox.Y = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.Y;

            // buttonstates
            Boolean leftPressed = ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            Boolean rightPressed = ms.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;

            // reset click events
            this.releaseLeft = false;
            this.releaseRight = false;
            this.leftClick = false;
            this.rightClick = false;

            // check if dragging or clicked
            if (leftPressed)
            {
                if (!this.dragLeftStart.HasValue)
                    this.dragLeftStart = this.currentMousePosition;
                else if (!this.leftDrag && (Math.Abs(this.currentMousePosition.X - this.dragLeftStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragLeftStart.Value.Y) > 5))
                    this.leftDrag = true;
            }
            else
            {
                if (this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = null;
                    this.leftDrag = false;
                    this.releaseLeft = true;

                    if (!this.leftDrag)
                        this.leftClick = true;
                }
            }

            if (rightPressed)
            {
                if (!this.dragRightStart.HasValue)
                    this.dragRightStart = this.currentMousePosition;
                else if (!this.rightDrag && (Math.Abs(this.currentMousePosition.X - this.dragRightStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragRightStart.Value.Y) > 5))
                    this.rightDrag = true;
            }
            else
            {
                if (this.dragRightStart.HasValue)
                {
                    this.dragRightStart = null;
                    this.rightDrag = false;
                    this.releaseRight = true;

                    if (!this.rightDrag)
                        this.rightClick = true;
                }
            }

            // keaboard stuff
            this.moveCamLeft = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A);
            this.moveCamRight = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D);
            this.moveCamUp = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W);
            this.moveCamDown = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S);
            this.resetCamRot = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0);

            if (currentKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape) && !lastKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape))
                this.endCurrentAction = true;
            else
                this.endCurrentAction = false;

            if (FenrirGame.Instance.Properties.CurrentGameState == GameState.InGame)
            {
                Microsoft.Xna.Framework.Vector3 nearsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 0f);
                Microsoft.Xna.Framework.Vector3 farsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 1f);

                Microsoft.Xna.Framework.Vector3 nearPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);
                Microsoft.Xna.Framework.Vector3 farPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    farsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);

                Microsoft.Xna.Framework.Vector3 direction = farPoint - nearPoint;
                direction.Normalize();
                this.mouseRay = new Microsoft.Xna.Framework.Ray(nearPoint, direction);

                this.currentMousePositionInWorld = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    Microsoft.Xna.Framework.Matrix.Identity
                    );
            }
        }
示例#22
0
        /// <summary>
        ///  见接口
        /// </summary>
        /// <param name="renderer"></param>
        /// <param name="screenTarget"></param>
        public void RenderFullScene(ISceneRenderer renderer, RenderTarget screenTarget, RenderMode mode)
        {
            Microsoft.Xna.Framework.Input.KeyboardState ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.C) &&
                lastState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.C))
            {
                testMode++;
                if (testMode > TestMode.Blurred)
                {
                    testMode = TestMode.Final;
                }
            }
            lastState = ks;

            if (testMode == TestMode.Original)
            {
                renderer.RenderScene(screenTarget, RenderMode.Final);
                return;
            }
            if (testMode == TestMode.Normal)
            {
                renderer.RenderScene(screenTarget, RenderMode.DeferredNormal);
                return;
            }

            renderer.RenderScene(nrmDepthBuffer, RenderMode.DeferredNormal);

            renderer.RenderScene(colorBuffer, RenderMode.Final);


            Viewport vp = renderSys.Viewport;

            ShaderSamplerState sampler1;

            sampler1.AddressU      = TextureAddressMode.Clamp;
            sampler1.AddressV      = TextureAddressMode.Clamp;
            sampler1.AddressW      = TextureAddressMode.Clamp;
            sampler1.BorderColor   = ColorValue.Transparent;
            sampler1.MagFilter     = TextureFilter.Point;
            sampler1.MaxAnisotropy = 0;
            sampler1.MaxMipLevel   = 0;
            sampler1.MinFilter     = TextureFilter.Point;
            sampler1.MipFilter     = TextureFilter.None;
            sampler1.MipMapLODBias = 0;


            ShaderSamplerState sampler2 = sampler1;

            sampler2.MagFilter = TextureFilter.Linear;
            sampler2.MinFilter = TextureFilter.Linear;

            #region 边缘合成
            renderSys.SetRenderTarget(0, testMode == TestMode.Edge ? screenTarget : edgeResultBuffer);
            edgeEff.Begin();

            edgeEff.SetSamplerStateDirect(0, ref sampler1);
            edgeEff.SetSamplerStateDirect(1, ref sampler1);

            edgeEff.SetTextureDirect(0, nrmDepthBuffer.GetColorBufferTexture());
            edgeEff.SetTextureDirect(1, testMode == TestMode.Edge ? whitePixel : colorBuffer.GetColorBufferTexture());

            Vector2 nrmBufSize = new Vector2(vp.Width, vp.Height);
            edgeEff.SetValue("normalBufferSize", ref nrmBufSize);
            DrawBigQuad();
            edgeEff.End();
            #endregion

            if (testMode == TestMode.Edge)
            {
                return;
            }
            if (testMode == TestMode.Depth)
            {
                renderSys.SetRenderTarget(0, screenTarget);
                depthViewEff.Begin();
                depthViewEff.SetSamplerStateDirect(0, ref sampler1);
                depthViewEff.SetTextureDirect(0, nrmDepthBuffer.GetColorBufferTexture());
                DrawBigQuad();
                depthViewEff.End();
                return;
            }
            #region 高斯X
            renderSys.SetRenderTarget(0, blurredRt1);

            gaussBlur.Begin();

            gaussBlur.SetSamplerStateDirect(0, ref sampler1);
            gaussBlur.SetTextureDirect(0, edgeResultBuffer.GetColorBufferTexture());

            for (int i = 0; i < SampleCount; i++)
            {
                gaussBlur.SetValueDirect(i, ref guassFilter.SampleOffsetsX[i]);
                gaussBlur.SetValueDirect(i + 15, guassFilter.SampleWeights[i]);
            }

            DrawSmallQuad();

            gaussBlur.End();
            #endregion

            #region 高斯Y

            renderSys.SetRenderTarget(0, testMode == TestMode.Blurred ? screenTarget : blurredRt2);
            gaussBlur.Begin();

            gaussBlur.SetSamplerStateDirect(0, ref sampler1);
            gaussBlur.SetTextureDirect(0, blurredRt1.GetColorBufferTexture());

            for (int i = 0; i < SampleCount; i++)
            {
                gaussBlur.SetValueDirect(i, ref guassFilter.SampleOffsetsY[i]);
                gaussBlur.SetValueDirect(i + 15, guassFilter.SampleWeights[i]);
            }
            if (testMode == TestMode.Blurred)
            {
                DrawBigQuad();
            }
            else
            {
                DrawSmallQuad();
            }

            gaussBlur.End();


            #endregion

            if (testMode == TestMode.Blurred)
            {
                return;
            }

            #region DOF合成

            renderSys.SetRenderTarget(0, screenTarget);

            compEff.Begin();

            compEff.SetSamplerStateDirect(0, ref sampler1);
            compEff.SetSamplerStateDirect(1, ref sampler2);
            compEff.SetSamplerStateDirect(2, ref sampler2);

            compEff.SetTextureDirect(0, edgeResultBuffer.GetColorBufferTexture());
            compEff.SetTextureDirect(1, blurredRt2.GetColorBufferTexture());
            compEff.SetTextureDirect(2, nrmDepthBuffer.GetColorBufferTexture());

            //if (camera != null)
            //{
            //    float focNear = (camera.Position.Length() - PlanetEarth.PlanetRadius) / camera.FarPlane;
            //    compEff.SetValue("FocusNear", focNear);
            //}
            //else
            //{
            //    compEff.SetValue("FocusNear", 0.3f);
            //}

            renderSys.RenderStates.AlphaBlendEnable = true;
            renderSys.RenderStates.SourceBlend      = Blend.SourceAlpha;
            renderSys.RenderStates.DestinationBlend = Blend.InverseSourceAlpha;
            renderSys.RenderStates.BlendOperation   = BlendFunction.Add;

            DrawBigQuad();

            compEff.End();
            #endregion
        }
示例#23
0
        /// <summary>
        /// check for new updates
        /// </summary>
        public void Update()
        {
            // get the mousestate
            Microsoft.Xna.Framework.Input.MouseState ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
            this.lastKeyboardState    = this.currentKeyboardState;
            this.currentKeyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            // get the movement and position

            this.mouseMovement         = new Microsoft.Xna.Framework.Vector2((FenrirGame.Instance.Properties.ScreenWidth / 2 - ms.X), (FenrirGame.Instance.Properties.ScreenHeight / 2 - ms.Y));
            this.currentMousePosition -= mouseMovement * 1.05f;
            Microsoft.Xna.Framework.Input.Mouse.SetPosition(FenrirGame.Instance.Properties.ScreenWidth / 2, FenrirGame.Instance.Properties.ScreenHeight / 2);

            if (this.currentMousePosition.X < 0)
            {
                this.currentMousePosition.X = 0;
            }
            else if (this.currentMousePosition.X > FenrirGame.Instance.Properties.ScreenWidth)
            {
                this.currentMousePosition.X = FenrirGame.Instance.Properties.ScreenWidth;
            }

            if (this.currentMousePosition.Y < 0)
            {
                this.currentMousePosition.Y = 0;
            }
            else if (this.currentMousePosition.Y > FenrirGame.Instance.Properties.ScreenHeight)
            {
                this.currentMousePosition.Y = FenrirGame.Instance.Properties.ScreenHeight;
            }

            // get the scrollwheel
            this.scrollValue    = scrollValueOld - ms.ScrollWheelValue;
            this.scrollValueOld = ms.ScrollWheelValue;

            // calculate boundingbox
            this.boundingBox.X = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.X;
            this.boundingBox.Y = (int)FenrirGame.Instance.Properties.Input.CurrentMousePosition.Y;

            // buttonstates
            Boolean leftPressed  = ms.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;
            Boolean rightPressed = ms.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed;

            // reset click events
            this.releaseLeft  = false;
            this.releaseRight = false;
            this.leftClick    = false;
            this.rightClick   = false;

            // check if dragging or clicked
            if (leftPressed)
            {
                if (!this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = this.currentMousePosition;
                }
                else if (!this.leftDrag && (Math.Abs(this.currentMousePosition.X - this.dragLeftStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragLeftStart.Value.Y) > 5))
                {
                    this.leftDrag = true;
                }
            }
            else
            {
                if (this.dragLeftStart.HasValue)
                {
                    this.dragLeftStart = null;
                    this.leftDrag      = false;
                    this.releaseLeft   = true;

                    if (!this.leftDrag)
                    {
                        this.leftClick = true;
                    }
                }
            }

            if (rightPressed)
            {
                if (!this.dragRightStart.HasValue)
                {
                    this.dragRightStart = this.currentMousePosition;
                }
                else if (!this.rightDrag && (Math.Abs(this.currentMousePosition.X - this.dragRightStart.Value.X) > 5) || (Math.Abs(this.currentMousePosition.Y - this.dragRightStart.Value.Y) > 5))
                {
                    this.rightDrag = true;
                }
            }
            else
            {
                if (this.dragRightStart.HasValue)
                {
                    this.dragRightStart = null;
                    this.rightDrag      = false;
                    this.releaseRight   = true;

                    if (!this.rightDrag)
                    {
                        this.rightClick = true;
                    }
                }
            }

            // keaboard stuff
            this.moveCamLeft  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A);
            this.moveCamRight = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D);
            this.moveCamUp    = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W);
            this.moveCamDown  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S);
            this.resetCamRot  = currentKeyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D0);

            if (currentKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape) && !lastKeyboardState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Escape))
            {
                this.endCurrentAction = true;
            }
            else
            {
                this.endCurrentAction = false;
            }

            if (FenrirGame.Instance.Properties.CurrentGameState == GameState.InGame)
            {
                Microsoft.Xna.Framework.Vector3 nearsource = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 0f);
                Microsoft.Xna.Framework.Vector3 farsource  = new Microsoft.Xna.Framework.Vector3(this.currentMousePosition.X, this.currentMousePosition.Y, 1f);

                Microsoft.Xna.Framework.Vector3 nearPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);
                Microsoft.Xna.Framework.Vector3 farPoint = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    farsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    FenrirGame.Instance.InGame.Camera.World);

                Microsoft.Xna.Framework.Vector3 direction = farPoint - nearPoint;
                direction.Normalize();
                this.mouseRay = new Microsoft.Xna.Framework.Ray(nearPoint, direction);

                this.currentMousePositionInWorld = FenrirGame.Instance.Properties.GraphicDeviceManager.GraphicsDevice.Viewport.Unproject(
                    nearsource,
                    FenrirGame.Instance.InGame.Camera.Projection,
                    FenrirGame.Instance.InGame.Camera.View,
                    Microsoft.Xna.Framework.Matrix.Identity
                    );
            }
        }
 public KeyboardHandler(Microsoft.Xna.Framework.Input.KeyboardState keyboardState)
 {
     // TODO: Complete member initialization
     this.keyboardState = keyboardState;
 }
示例#25
0
 public static bool IsDown(Microsoft.Xna.Framework.Input.KeyboardState newState, Microsoft.Xna.Framework.Input.KeyboardState prevState, Microsoft.Xna.Framework.Input.Keys key)
 {
     return(newState.IsKeyDown(key) && prevState.IsKeyUp(key));
 }
示例#26
0
 public Keyboard()
 {
     _keyboard = Microsoft.Xna.Framework.Input.Keyboard.GetState();
 }
        protected override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
            #if DEBUG
            pks = ks;
            ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3) && pks.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                AssetManager.FrameCapture = true;
            }

            EngineGlobals.GameTime = gameTime;

            if (_errorOccured)
            {
                _debugConsole.Update(gameTime);
            }
            else
            #endif
            time += dt;
            if (time > 0.1f)
            {
                System.Windows.Forms.Application.DoEvents();
                time = 0;
            }
            base.Update(gameTime);
        }
示例#28
0
 public static bool IsShiftDown(this Microsoft.Xna.Framework.Input.KeyboardState KeyState)
 {
     return(KeyState.IsKeyDown(XnaKeys.LeftShift) || KeyState.IsKeyDown(XnaKeys.RightShift));
 }
示例#29
0
 public override void HandleInput(Microsoft.Xna.Framework.Input.GamePadState gamePadState, Microsoft.Xna.Framework.Input.KeyboardState keyState, Microsoft.Xna.Framework.Input.MouseState mouseState)
 {
     //none?
 }
示例#30
0
 public static bool IsShiftUp(this Microsoft.Xna.Framework.Input.KeyboardState KeyState)
 {
     return(KeyState.IsShiftDown() == false);
 }
        protected override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            float dt = (float)gameTime.ElapsedGameTime.TotalSeconds;
            #if DEBUG
            pks = ks;
            ks = Microsoft.Xna.Framework.Input.Keyboard.GetState();

            if (ks.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3) && pks.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                AssetManager.FrameCapture = true;
            }

            if (_errorOccured)
            {
                _debugConsole.Update(gameTime);
            }
            else
            #endif
                base.Update(gameTime);
        }
示例#32
0
        private void Application_Idle(object sender, EventArgs e)
        {
            Microsoft.Xna.Framework.Input.KeyboardState newState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            onCtrl = newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) ||
                     newState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.RightControl);

            if (formRefSkeleton != null)
            {
                prevState = newState;
                return;
            }

            // Undo
            if (onCtrl && IsDown(newState, prevState, Microsoft.Xna.Framework.Input.Keys.Z))
            {
                Undo();
                if (tabControl.SelectedTab.Name == "tabSourceImages")
                {
                    RefleshAllImageView();
                }
                if (tabControl.SelectedTab.Name == "tabSkeletonFitting")
                {
                    skeletonFittingCanvas.Invalidate();
                    refSkeletonCanvas.Invalidate();
                }
                if (tabControl.SelectedTab.Name == "tabAnimation")
                {
                    seekbar.Maximum = animeCells.Sum(c => c.durationMilliseconds) / 10;
                    cellListView.Invalidate();
                }
                if (tabControl.SelectedTab.Name == "tabSegmentation")
                {
                    segmentCanvas.Invalidate();
                }
            }
            // Redo
            if (onCtrl && IsDown(newState, prevState, Microsoft.Xna.Framework.Input.Keys.Y))
            {
                Redo();
                if (tabControl.SelectedTab.Name == "tabSourceImages")
                {
                    RefleshAllImageView();
                }
                if (tabControl.SelectedTab.Name == "tabSkeletonFitting")
                {
                    skeletonFittingCanvas.Invalidate();
                    refSkeletonCanvas.Invalidate();
                }
                if (tabControl.SelectedTab.Name == "tabAnimation")
                {
                    seekbar.Maximum = animeCells.Sum(c => c.durationMilliseconds) / 10;
                    cellListView.Invalidate();
                }
                if (tabControl.SelectedTab.Name == "tabSegmentation")
                {
                    segmentCanvas.Invalidate();
                }
            }

            // Tab:SkeletonFitting
            if (IsDown(newState, prevState, Microsoft.Xna.Framework.Input.Keys.Delete) && tabControl.SelectedTab.Name == "tabSkeletonFitting")
            {
                if (!jointNameTextBox.Focused)
                {
                    var an = GetEditingAnnotation();
                    DeleteJointAnnotation(an, selectJoint);
                    DeleteBoneAnnotation(an, selectBone);
                    SelectJointAnnotation(an, null);
                    SelectBoneAnnotation(an, null);
                    skeletonFittingCanvas.Invalidate();
                }
            }


            // Tab:Composition
            if (IsDown(newState, prevState, Microsoft.Xna.Framework.Input.Keys.Delete) && tabControl.SelectedTab.Name == "tabComposition")
            {
                if (composition != null)
                {
                    composition.RemoveSegment(composition.editingSegment);
                    composition.SetEditingSegment(null);
                    compositionCanvas.Invalidate();
                }
            }

            // Tab:Animation
            if (tabControl.SelectedTab.Name == "tabAnimation")
            {
                if (IsDown(newState, prevState, Microsoft.Xna.Framework.Input.Keys.Delete))
                {
                    DeleteAnimeCells(selectCells);
                    selectCells.Clear();

                    seekbar.Maximum = animeCells.Sum(c => c.durationMilliseconds) / 10;
                    cellListView.Invalidate();
                }
            }

            prevState = newState;
        }