/// <summary> /// Handle own and engine input /// </summary> /// <param name="gameTime"></param> private void HandleInput(GameTime gameTime) { if (!this.IsActive) { return; } if (fInputManager.KeyPressed(Keys.Escape)) { Exit(); } else if (fInputManager.KeyPressed(Keys.F1)) { fContainer.ShowInfo = !fContainer.ShowInfo; } else if (fInputManager.IsKeyDown(Keys.LeftAlt) && fInputManager.KeyPressed(Keys.Enter)) { fEngine.ToggleFullscreen(); } else if (fInputManager.KeyPressed(Keys.F3)) { fCurrentEngineIndex--; if (fCurrentEngineIndex < 0) { fCurrentEngineIndex = fEngines.Count - 1; } SetEngine(); } else if (fInputManager.KeyPressed(Keys.F4)) { fCurrentEngineIndex++; if (fCurrentEngineIndex >= fEngines.Count) { fCurrentEngineIndex = 0; } SetEngine(); } else if (fInputManager.KeyPressed(Keys.F5)) { fContainer.ClearScreen = !fContainer.ClearScreen; } else if (fInputManager.KeyPressed(Keys.F6)) { fInputManager.CaptureMouse = !fInputManager.CaptureMouse; } }
/// <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) { fCamera.Update(gameTime); if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (fEngine.InputManager.KeyPressed(Keys.P)) { fEngine.UpdatePaused = !fEngine.UpdatePaused; } if (fEngine.InputManager.KeyPressed(Keys.M)) { fEngine.ToggleFullscreen(); } fLabelDisplayMode.Text = $"Mode={fEngine.DisplayMode}"; fAdapterSize.Text = $"Adapter={fEngine.AdapterSize.Width}x{fEngine.AdapterSize.Height}"; fWindowSize.Text = $"Window={fEngine.WindowSize.Width}x{fEngine.WindowSize.Height}"; fAspectRatio.Text = $"AspectRatio={fEngine.AspectRatio}"; fFPS.Text = $"FPS={fEngine.FPS.FrameRate}"; int count = fPlane.NumberOfTriangles; foreach (var plane in fPlanes) { count += plane.NumberOfTriangles; } count += fObject1.NumberOfTriangles; fInfo.Text = $"#Triangles={count}"; lblDrawMode.Text = $"Draw Mode = {fDrawMode}"; lblShaderMode.Text = $"Shader Mode = {fShaderMode}"; lblRenderObjects.Text = $"Render Objects = {fRenderObjects}"; if (fEngine.MouseOverElement == null) { fCurrentElement.Text = "..."; } else { GuiElement element = fEngine.MouseOverElement; string name = String.Empty; bool isFirst = true; while (element != null) { if (!isFirst) { name = name + "/"; } isFirst = false; string n = element.GetType().Name; if (n.StartsWith("Gui")) { name = name + n.Substring(3); } else { name = name + n; } element = element.Parent; } fCurrentElement.Text = name; } if (fUpdatePlane) { SetPlane(); } int max = fPlane.Segments; double seconds = gameTime.TotalGameTime.TotalSeconds; for (int x = 0; x <= max; x++) { float nX = 2.0f * (float)x / max - 1.0f;// -1 to +1 for (int z = 0; z <= max; z++) { float nZ = 2.0f * (float)z / max - 1.0f; double r = Math.Sqrt(nX * nX + nZ * nZ); //double y = nX * Math.Cos(r * 12.0f - seconds * 4.2f) + nZ * Math.Sin((r - 0.5) * 3.1f - seconds * 1.9f); double y = Math.Cos(r * 10.0f - seconds * 2.0f) + Math.Sin(r * 10.0f - seconds * 2.1f); float height = 200.0f * (float)y; fPlane.SetHeight(x, z, height); } } fPlane.GenerateNormals(); base.Update(gameTime); }