/// <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; } }
/// <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 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)); }
/// <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 ); } }
/// <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 }
public bool IsKeyUp(SadConsole.Input.Keys key) => _keyboard.IsKeyUp((Microsoft.Xna.Framework.Input.Keys)key);