public static Keys[] GetDownKeys() { List <Keys> keys = new List <Keys>(); state.GetDownKeys(keys); return(keys.ToArray()); }
public bool IsAnyKeyPress() { List <Keys> keys = new List <Keys>(); CurrentKeyboardState.GetDownKeys(keys); return(keys.Count > 0); }
protected override void Draw(GameTime gameTime) { // Clears the screen with the Color.CornflowerBlue GraphicsDevice.Clear(Color.CornflowerBlue); // print the current mouse state var sb = new StringBuilder(); sb.AppendLine("Down keys:"); keyboardState.GetDownKeys(keys); foreach (var key in keys) { sb.AppendFormat("Key: {0}, Code: {1}\n", key, (int)key); } // Render the text spriteBatch.Begin(); spriteBatch.DrawString(arial16BMFont, sb.ToString(), new Vector2(8, 32), Color.White); spriteBatch.End(); // Handle base.Draw base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { // Use time in seconds directly var time = (float)gameTime.TotalGameTime.TotalSeconds; // Make offline rendering GraphicsDevice.SetRenderTargets(GraphicsDevice.DepthStencilBuffer, renderTargetOffScreen); // Clears the screen with the Color.CornflowerBlue GraphicsDevice.Clear(Color.CornflowerBlue); // Constant used to translate 3d models float translateX = 0.0f; // ------------------------------------------------------------------------ // Draw the 3d model // ------------------------------------------------------------------------ var world = Matrix.Scaling(0.003f) * Matrix.RotationY(time) * Matrix.Translation(0, -1.5f, 2.0f); model.Draw(GraphicsDevice, world, view, projection); translateX += 3.5f; // ------------------------------------------------------------------------ // Draw the 3d primitive using BasicEffect // ------------------------------------------------------------------------ basicEffect.World = Matrix.Scaling(2.0f, 2.0f, 2.0f) * Matrix.RotationX(0.8f * (float)Math.Sin(time * 1.45)) * Matrix.RotationY(time * 2.0f) * Matrix.RotationZ(0) * Matrix.Translation(translateX, -1.0f, 0); primitive.Draw(basicEffect); // ------------------------------------------------------------------------ // Draw the some 2d text // ------------------------------------------------------------------------ spriteBatch.Begin(); var text = new StringBuilder("This text is displayed with SpriteBatch").AppendLine(); List <Keys> keys = new List <Keys>(); // Display pressed keys keyboardState.GetDownKeys(keys); text.Append("Key Pressed: ["); foreach (var key in keys) { text.Append(key.ToString()); text.Append(" "); } text.Append("]").AppendLine(); // Display mouse coordinates and mouse button status text.AppendFormat("Mouse ({0},{1}) Left: {2}, Right {3}", mouseState.X, mouseState.Y, mouseState.LeftButton, mouseState.RightButton).AppendLine(); spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White); spriteBatch.End(); // ------------------------------------------------------------------------ // Use SpriteBatch to draw some balls on the screen using NonPremultiplied mode // as the sprite texture used is not premultiplied // ------------------------------------------------------------------------ spriteBatch.Begin(SpriteSortMode.Deferred, GraphicsDevice.BlendStates.NonPremultiplied); for (int i = 0; i < 40; i++) { var posX = (float)Math.Cos(time * 4.5f + i * 0.1f) * 60.0f + 136.0f; var posY = GraphicsDevice.BackBuffer.Height * 2.0f / 3.0f + 100.0f * (float)Math.Sin(time * 10.0f + i * 0.4f); spriteBatch.Draw( ballsTexture, new Vector2(posX, posY), new Rectangle(0, 0, 32, 32), Color.White, 0.0f, new Vector2(16, 16), Vector2.One, SpriteEffects.None, 0f); } spriteBatch.End(); // ------------------------------------------------------------------------ // Cheap bloom post effect // Blur applied only on latest downscale render target // ------------------------------------------------------------------------ // Setup states for posteffect GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.Default); GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default); GraphicsDevice.SetDepthStencilState(GraphicsDevice.DepthStencilStates.None); // Apply BrightPass const float brightPassThreshold = 0.5f; GraphicsDevice.SetRenderTargets(renderTargetDownScales[0]); bloomEffect.CurrentTechnique = bloomEffect.Techniques["BrightPassTechnique"]; bloomEffect.Parameters["Texture"].SetResource(renderTargetOffScreen); bloomEffect.Parameters["PointSampler"].SetResource(GraphicsDevice.SamplerStates.PointClamp); bloomEffect.Parameters["BrightPassThreshold"].SetValue(brightPassThreshold); GraphicsDevice.Quad.Draw(bloomEffect.CurrentTechnique.Passes[0]); // Down scale passes for (int i = 1; i < renderTargetDownScales.Length; i++) { GraphicsDevice.SetRenderTargets(renderTargetDownScales[i]); GraphicsDevice.Quad.Draw(renderTargetDownScales[0]); } // Horizontal blur pass var renderTargetBlur = renderTargetDownScales[renderTargetDownScales.Length - 1]; GraphicsDevice.SetRenderTargets(renderTargetBlurTemp); bloomEffect.CurrentTechnique = bloomEffect.Techniques["BlurPassTechnique"]; bloomEffect.Parameters["Texture"].SetResource(renderTargetBlur); bloomEffect.Parameters["LinearSampler"].SetResource(GraphicsDevice.SamplerStates.LinearClamp); bloomEffect.Parameters["TextureTexelSize"].SetValue(new Vector2(1.0f / renderTargetBlurTemp.Width, 1.0f / renderTargetBlurTemp.Height)); GraphicsDevice.Quad.Draw(bloomEffect.CurrentTechnique.Passes[0]); // Vertical blur pass GraphicsDevice.SetRenderTargets(renderTargetBlur); bloomEffect.Parameters["Texture"].SetResource(renderTargetBlurTemp); GraphicsDevice.Quad.Draw(bloomEffect.CurrentTechnique.Passes[1]); // Render to screen GraphicsDevice.SetRenderTargets(GraphicsDevice.BackBuffer); GraphicsDevice.Quad.Draw(renderTargetOffScreen); // Add bloom on top of it GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Additive); GraphicsDevice.Quad.Draw(renderTargetBlur); GraphicsDevice.SetBlendState(GraphicsDevice.BlendStates.Default); base.Draw(gameTime); }
void Update_Input() { keyboardState = keyboardManager.GetState(); mouseState = mouseManager.GetState(); // if Esc is pressed - quit program if (keyboardState.IsKeyPressed(Keys.Escape)) { Exit(); return; } if (keyboardState.IsKeyPressed(Keys.K)) { tiles[3].PlayDelegate(); } if (keyboardState.IsKeyPressed(Keys.J)) { tiles[3].StopDelegate(); } if (keyboardState.IsKeyPressed(Keys.O)) { tiles[4].PlayDelegate(); } if (keyboardState.IsKeyPressed(Keys.P)) { tiles[4].StopDelegate(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int mouseWheelOffset = mouseState.WheelDelta - lastWheelDelta; if (mouseWheelOffset != 0) { int multiply = 10; if (keyboardState.IsKeyDown(Keys.Control)) { multiply = 1; } if (keyboardState.IsKeyDown(Keys.Shift)) { multiply = 100; } config.cameraControl.ExposureTime += multiply * mouseWheelOffset; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // info tiles if (keyboardState.IsKeyPressed(Keys.F1)) { config.hud.helpMenu ^= true; hmd.EnableHSWDisplaySDKRender(true); hmd.DismissHSWDisplay(); // not functional } if (keyboardState.IsKeyPressed(Keys.F2)) { config.hud.toolStrip ^= true; } if (keyboardState.IsKeyPressed(Keys.F3)) { config.hud.timeStrip ^= true; } if (keyboardState.IsKeyPressed(Keys.F5)) { ra.angleType = e_valueType.wantedValue; } if (keyboardState.IsKeyPressed(Keys.F6)) { ra.angleType = e_valueType.sentValue; } if (keyboardState.IsKeyPressed(Keys.F7)) { ra.angleType = e_valueType.seenValue; } if (keyboardState.IsKeyPressed(Keys.F8)) { config.roboticArmPostureOnCameraCapture ^= true; } if (keyboardState.IsKeyPressed(Keys.M) && keyboardState.IsKeyDown(Keys.Control)) { //config.READ_dataFromMotors ^= true; // toggle config.player.ResetPositionAndBodyYaw(); config.WRITE_dataToMotors ^= true; } else if (keyboardState.IsKeyPressed(Keys.M) && keyboardState.IsKeyDown(Keys.Shift)) { //config.READ_dataFromMotors ^= true; // toggle config.READ_dataFromMotors ^= true; } else if (keyboardState.IsKeyPressed(Keys.M)) { config.motorSpeedControl ^= true; } if (keyboardState.IsKeyPressed(Keys.R) && keyboardState.IsKeyDown(Keys.Control)) { config.player.ResetPosition(); } else if (keyboardState.IsKeyPressed(Keys.R) && keyboardState.IsKeyDown(Keys.Shift)) { config.player.ResetBodyYaw(); } else if (keyboardState.IsKeyPressed(Keys.R)) { config.player.ResetPositionAndBodyYaw(); } if (keyboardState.IsKeyPressed(Keys.F)) { config.draw.RoboticArm ^= true; ra.draw = config.draw.RoboticArm; } if (keyboardState.IsKeyPressed(Keys.C) && keyboardState.IsKeyDown(Keys.Shift)) { config.ReadCameraStream ^= true; if (config.ReadCameraStream) { START_streaming(); } else { STOP_streaming(); } } if (keyboardState.IsKeyPressed(Keys.U)) { if (textureConversionAlgorithm == e_textureConversionAlgorithm.unsafeConversion_pointerForLoop) { // last textureConversionAlgorithm = 0; } else { textureConversionAlgorithm++; } } if (keyboardState.IsKeyPressed(Keys.D1) && keyboardState.IsKeyDown(Keys.Shift)) { config.player.PositionLock = e_positionLock.cameraSensor; } if (keyboardState.IsKeyPressed(Keys.D2) && keyboardState.IsKeyDown(Keys.Shift)) { config.player.PositionLock = e_positionLock.desk; } if (keyboardState.IsKeyPressed(Keys.D3) && keyboardState.IsKeyDown(Keys.Shift)) { config.player.PositionLock = e_positionLock.overDesk; } if (keyboardState.IsKeyPressed(Keys.Tab)) { config.player.PositionLockActive ^= true; } if (keyboardState.IsKeyPressed(Keys.D1)) { config.cameraArtificialDelay = false; lock (queuePixelData_locker) { que.Clear(); } } if (keyboardState.IsKeyPressed(Keys.D2)) { config.cameraArtificialDelay = true; lock (queuePixelData_locker) { que.Clear(); } config.cameraFrameQueueLength = config.cameraFrameQueueLengthList[0]; } if (keyboardState.IsKeyPressed(Keys.D3)) { config.cameraArtificialDelay = true; lock (queuePixelData_locker) { que.Clear(); } config.cameraFrameQueueLength = config.cameraFrameQueueLengthList[1]; } if (keyboardState.IsKeyPressed(Keys.D4)) { config.cameraArtificialDelay = true; lock (queuePixelData_locker) { que.Clear(); } config.cameraFrameQueueLength = config.cameraFrameQueueLengthList[2]; } if (keyboardState.IsKeyPressed(Keys.D5)) { config.cameraArtificialDelay = true; lock (queuePixelData_locker) { que.Clear(); } config.cameraFrameQueueLength = config.cameraFrameQueueLengthList[3]; } if (keyboardState.IsKeyPressed(Keys.D6)) { config.cameraArtificialDelay = true; lock (queuePixelData_locker) { que.Clear(); } config.cameraFrameQueueLength = config.cameraFrameQueueLengthList[4]; } if (keyboardState.IsKeyPressed(Keys.X)) { measurementStart = DateTime.Now; } HUD.AppendLine(string.Format( "W{0}|A{1}|S{2}", keyboardState.IsKeyDown(Keys.W), keyboardState.IsKeyDown(Keys.A), keyboardState.IsKeyDown(Keys.S) )); config.player.FrameTime = gameTime.ElapsedGameTime.Milliseconds; config.player.MoveForward(keyboardState.IsKeyDown(Keys.W)); config.player.MoveSideStep(keyboardState.IsKeyDown(Keys.A), false); config.player.MoveBackward(keyboardState.IsKeyDown(Keys.S)); config.player.MoveSideStep(keyboardState.IsKeyDown(Keys.D), true); config.player.MoveUpward(keyboardState.IsKeyDown(Keys.E)); config.player.MoveDownward(keyboardState.IsKeyDown(Keys.Q)); config.player.SetupSpeed(keyboardState.IsKeyDown(Keys.Shift), keyboardState.IsKeyDown(Keys.Control)); if (keyboardState.IsKeyPressed(Keys.J) && keyboardState.IsKeyDown(Keys.Control)) { config.draw.SkySurface ^= true; } List <Keys> keys = new List <Keys>(); keyboardState.GetDownKeys(keys); //foreach (var key in keys) // sb.AppendFormat("Key: {0}, Code: {1}\n", key, (int)key); // numer keys (NOT numpad ones) have name like D0, D1, etc... // associate available modes each with its key //for (int i = 0; i < availableModes.Count; i++) //{ // var key = (Keys)Enum.Parse(typeof(Keys), "D" + i); // if (keyboardState.IsKeyPressed(key)) // { // ApplyMode(availableModes[i]); // return; // } //} lastWheelDelta = mouseState.WheelDelta; }
protected override void Draw(GameTime gameTime) { // Use time in seconds directly var time = (float)gameTime.TotalGameTime.TotalSeconds; // Clears the screen with the Color.CornflowerBlue GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullFront); //draw a skybox skyEffect.Parameters["World"].SetValue(Matrix.Scaling(500)); skyEffect.Parameters["Projection"].SetValue(projection); skyEffect.Parameters["View"].SetValue(view); skyEffect.Parameters["CameraPosition"].SetValue(eyePosition); skyCube.Draw(skyEffect); GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullBack); //draw the cubes foreach (EffectTechnique effectTechnique in cubeEffect.Techniques) { foreach (EffectPass pass in effectTechnique.Passes) { cubeEffect.Parameters["LightPosition"].SetValue(0, lights[0].position); cubeEffect.Parameters["LightPosition"].SetValue(1, lights[1].position); cubeEffect.Parameters["LightPosition"].SetValue(2, lights[2].position); cubeEffect.Parameters["LightColor"].SetValue(0, lights[0].color.ToVector4()); cubeEffect.Parameters["LightColor"].SetValue(1, lights[1].color.ToVector4()); cubeEffect.Parameters["LightColor"].SetValue(2, lights[2].color.ToVector4()); Matrix world; for (int i = 0; i < cubes.Length; ++i) { pass.Apply(); world = Matrix.Scaling(cubes[i].scale) * Matrix.Translation(cubes[i].position); cubeEffect.Parameters["World"].SetValue(world); Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(world)); cubeEffect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix); cubeEffect.Parameters["Projection"].SetValue(projection); cubeEffect.Parameters["View"].SetValue(view); cubeEffect.Parameters["Camera"].SetValue(eyePosition); cubeEffect.Parameters["DiffuseColor"].SetValue(cubes[i].color.ToVector4()); cubes[i].Draw(cubeEffect); } } } //draw the lights basicEffect.Projection = projection; basicEffect.View = view; basicEffect.LightingEnabled = true; basicEffect.EnableDefaultLighting(); for (int i = 0; i < 3; ++i) { basicEffect.World = Matrix.Scaling(5) * Matrix.Translation(lights[i].position); basicEffect.DiffuseColor = lights[i].color.ToVector4(); basicEffect.EmissiveColor = lights[i].color.ToVector3(); basicEffect.SpecularColor = Vector3.Zero; ballPrimitive.Draw(basicEffect); } spriteBatch.Begin(); var text = new StringBuilder("Text is working~").AppendLine(); List <Keys> keys = new List <Keys>(); //Display pressed keys keyBoardState.GetDownKeys(keys); text.Append("Key Pressed: ["); foreach (var key in keys) { text.Append(key.ToString()); text.Append(" "); } text.Append("]").AppendLine(); spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White); spriteBatch.End(); base.Draw(gameTime); }
protected override void Draw(GameTime gameTime) { // Use time in seconds directly var time = (float)gameTime.TotalGameTime.TotalSeconds; if (loading) { GraphicsDevice.Clear(Color.Black); float loadingScale = 0.7f; loadingEffect.Parameters["World"].SetValue(Matrix.Scaling(loadingScreen.Width / (float)Window.ClientBounds.Width * loadingScale, loadingScreen.Height / (float)Window.ClientBounds.Height * loadingScale, 1.0f)); loadingEffect.Parameters["Texture"].SetResource(loadingScreen); loadingEffect.Parameters["TileIndex"].SetValue((float)Math.Min(loadingProgress, 10)); //GraphicsDevice.Quad.Draw(loadingEffect, false); plane.Draw(loadingEffect); } else { // Clears the screen with the Color.CornflowerBlue GraphicsDevice.Clear(Color.CornflowerBlue); // ------------------------------------------------------------------------ // Draw the some 2d text // ------------------------------------------------------------------------ spriteBatch.Begin(); var text = new StringBuilder("Zoom").Append(zoom / 0.18f).AppendLine(); // Display pressed keys var pressedKeys = new List <Keys>(); //keyboardState.GetDownKeys(); keyboardState.GetDownKeys(pressedKeys); text.Append("Key Pressed: ["); foreach (var key in pressedKeys) { text.Append(key.ToString()); text.Append(" "); } text.Append("]").AppendLine(); // Display mouse coordinates and mouse button status text.AppendFormat("Selected: {4},{5}", mouseState.X, mouseState.Y, mouseState.LeftButton, mouseState.RightButton, selectedTile.X, selectedTile.Y).AppendLine(); spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White); spriteBatch.End(); basicEffect.View = Matrix.LookAtLH(cameraPosition + cameraOffset, cameraPosition, Vector3.UnitZ); tristram.DrawFloors(GraphicsDevice, basicEffect.View, basicEffect.Projection, floorEffect, plane); // Selected Tile basicEffect.TextureEnabled = true; basicEffect.World = Matrix.Translation(selectedTile.X * 5, selectedTile.Y * 5, 0); plane.Draw(basicEffect); tristram.DrawWalls(GraphicsDevice, basicEffect.View, basicEffect.Projection, floorEffect, billboard); // Test Billboard //basicEffect.World = Matrix.RotationX(MathUtil.DegreesToRadians(90)) * Matrix.RotationZ(MathUtil.DegreesToRadians(-45)) * Matrix.Translation(50, 50, 0); //billboard.Draw(basicEffect); GraphicsDevice.SetRasterizerState(GraphicsDevice.RasterizerStates.CullBack); basicEffect.TextureEnabled = false; basicEffect.World = Matrix.Translation(0, 1, 0) * Matrix.RotationX(MathUtil.DegreesToRadians(90)); player.Draw(basicEffect); spriteBatch.Begin(); spriteBatch.DrawString(arial16Font, text.ToString(), new Vector2(16, 16), Color.White); spriteBatch.End(); // Draw the UI //quadEffect.Parameters["Texture"].SetResource(browser.Texture); //GraphicsDevice.Quad.Draw(quadEffect, true); } base.Draw(gameTime); }
private void UpdateKeyboardState() { KeyboardState keyState = keyboard.GetState(); keyState.GetDownKeys(pressedKeys); }