protected virtual void OnFrameStarted(Object source, FrameEventArgs e) { onFrameStartedMeter.Enter(); float scaleMove = 200 * e.TimeSinceLastFrame; // reset acceleration zero camAccel = Vector3.Zero; // set the scaling of camera motion cameraScale = 100 * e.TimeSinceLastFrame; // TODO: Move this into an event queueing mechanism that is processed every frame input.Capture(); if (input.IsKeyPressed(KeyCodes.Escape)) { Root.Instance.QueueEndRendering(); onFrameStartedMeter.Exit(); return; } if (input.IsKeyPressed(KeyCodes.A)) { camAccel.x = -0.5f; } if (input.IsKeyPressed(KeyCodes.D)) { camAccel.x = 0.5f; } if (input.IsKeyPressed(KeyCodes.W)) { camAccel.z = -1.0f; } if (input.IsKeyPressed(KeyCodes.S)) { camAccel.z = 1.0f; } camAccel.y += (float)(input.RelativeMouseZ * 0.1f); if (input.IsKeyPressed(KeyCodes.Left)) { camera.Yaw(cameraScale); } if (input.IsKeyPressed(KeyCodes.Right)) { camera.Yaw(-cameraScale); } if (input.IsKeyPressed(KeyCodes.Up)) { camera.Pitch(cameraScale); } if (input.IsKeyPressed(KeyCodes.Down)) { camera.Pitch(-cameraScale); } // subtract the time since last frame to delay specific key presses toggleDelay -= e.TimeSinceLastFrame; // toggle rendering mode if (input.IsKeyPressed(KeyCodes.R) && toggleDelay < 0) { if (camera.SceneDetail == SceneDetailLevel.Points) { camera.SceneDetail = SceneDetailLevel.Solid; } else if (camera.SceneDetail == SceneDetailLevel.Solid) { camera.SceneDetail = SceneDetailLevel.Wireframe; } else { camera.SceneDetail = SceneDetailLevel.Points; } log.InfoFormat("Rendering mode changed to '{0}'.", camera.SceneDetail); toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.T) && toggleDelay < 0) { // toggle the texture settings switch (filtering) { case TextureFiltering.Bilinear: filtering = TextureFiltering.Trilinear; aniso = 1; break; case TextureFiltering.Trilinear: filtering = TextureFiltering.Anisotropic; aniso = 8; break; case TextureFiltering.Anisotropic: filtering = TextureFiltering.Bilinear; aniso = 1; break; } log.InfoFormat("Texture Filtering changed to '{0}'.", filtering); // set the new default MaterialManager.Instance.SetDefaultTextureFiltering(filtering); MaterialManager.Instance.DefaultAnisotropy = aniso; toggleDelay = 1; } if (input.IsKeyPressed(KeyCodes.P)) { string[] temp = Directory.GetFiles(Environment.CurrentDirectory, "screenshot*.jpg"); string fileName = string.Format("screenshot{0}.jpg", temp.Length + 1); TakeScreenshot(fileName); // show briefly on the screen window.DebugText = string.Format("Wrote screenshot '{0}'.", fileName); // show for 2 seconds debugTextDelay = 2.0f; } if (input.IsKeyPressed(KeyCodes.B)) { scene.ShowBoundingBoxes = !scene.ShowBoundingBoxes; } if (input.IsKeyPressed(KeyCodes.F)) { // hide all overlays, includes ones besides the debug overlay viewport.OverlaysEnabled = !viewport.OverlaysEnabled; } if (!input.IsMousePressed(MouseButtons.Left)) { float cameraYaw = -input.RelativeMouseX * .13f; float cameraPitch = -input.RelativeMouseY * .13f; camera.Yaw(cameraYaw); camera.Pitch(cameraPitch); } else { cameraVector.x += input.RelativeMouseX * 0.13f; } camVelocity += (camAccel * scaleMove * camSpeed); // move the camera based on the accumulated movement vector camera.MoveRelative(camVelocity * e.TimeSinceLastFrame); // Now dampen the Velocity - only if user is not accelerating if (camAccel == Vector3.Zero) { camVelocity *= (1 - (6 * e.TimeSinceLastFrame)); } // update performance stats once per second if (statDelay < 0.0f && showDebugOverlay) { UpdateStats(); statDelay = 1.0f; } else { statDelay -= e.TimeSinceLastFrame; } // turn off debug text when delay ends if (debugTextDelay < 0.0f) { debugTextDelay = 0.0f; window.DebugText = ""; } else if (debugTextDelay > 0.0f) { debugTextDelay -= e.TimeSinceLastFrame; } OverlayElement element = OverlayElementManager.Instance.GetElement("Core/DebugText"); element.Text = window.DebugText; onFrameStartedMeter.Exit(); }
public AutoTimer(TimingMeter meter) { this.meter = meter; meter.Enter(); }