public void EndFrameRendering() { var bepuPhysicsManager = _sceneInterface.GetManager <BEPUPhysicsManager>(false); if (bepuPhysicsManager == null) { return; } if (!Visible || _sceneState == null) { return; } ModelDrawer.Draw(_sceneState.View, _sceneState.Projection); LineDrawer.LightingEnabled = false; LineDrawer.VertexColorEnabled = true; LineDrawer.World = Matrix.Identity; LineDrawer.View = _sceneState.View; LineDrawer.Projection = _sceneState.Projection; ContactDrawer.Draw(LineDrawer, bepuPhysicsManager.Space); BoundingBoxDrawer.Draw(LineDrawer, bepuPhysicsManager.Space); SimulationIslandDrawer.Draw(LineDrawer, bepuPhysicsManager.Space); Application.Graphics.GraphicsDevice.SamplerStates.Reset(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(new Color(.41f, .41f, .45f, 1)); var viewMatrix = Camera.ViewMatrix; var projectionMatrix = Camera.ProjectionMatrix; if (displayEntities) { ModelDrawer.Draw(viewMatrix, projectionMatrix); } if (displayConstraints) { ConstraintDrawer.Draw(viewMatrix, projectionMatrix); } LineDrawer.LightingEnabled = false; LineDrawer.VertexColorEnabled = true; LineDrawer.World = Matrix.Identity; LineDrawer.View = MathConverter.Convert(viewMatrix); LineDrawer.Projection = MathConverter.Convert(projectionMatrix); if (displayContacts) { ContactDrawer.Draw(LineDrawer, currentSimulation.Space); } if (displayBoundingBoxes) { BoundingBoxDrawer.Draw(LineDrawer, currentSimulation.Space); } if (displaySimulationIslands) { SimulationIslandDrawer.Draw(LineDrawer, currentSimulation.Space); } //This doesn't actually draw the elements in the demo (that's the modeldrawer's job), //but some demos can specify their own extra stuff to draw. currentSimulation.Draw(); base.Draw(gameTime); #region UI Drawing UIDrawer.Begin(); int bottom = GraphicsDevice.Viewport.Bounds.Height; int right = GraphicsDevice.Viewport.Bounds.Width; if (displayUI) { FPStotalSinceLast += gameTime.ElapsedGameTime.TotalSeconds; FPStotalFramesSinceLast++; if (gameTime.TotalGameTime.TotalSeconds - FPSlastTime > .25 && gameTime.ElapsedGameTime.TotalSeconds > 0) { double avg = FPStotalSinceLast / FPStotalFramesSinceLast; FPSlastTime = gameTime.TotalGameTime.TotalSeconds; FPStoDisplay = Math.Round(1 / avg, 1); averagePhysicsTime = Math.Round(1000 * currentSimulation.PhysicsTime, 1); FPStotalSinceLast = 0; FPStotalFramesSinceLast = 0; } DataTextDrawer.Draw("FPS: ", FPStoDisplay, new Vector2(50, bottom - 150)); DataTextDrawer.Draw("Physics Time (ms): ", averagePhysicsTime, new Vector2(50, bottom - 133)); DataTextDrawer.Draw("Collision Pairs: ", currentSimulation.Space.NarrowPhase.Pairs.Count, new Vector2(50, bottom - 116)); if (displayActiveEntityCount) { int countActive = 0; for (int i = 0; i < currentSimulation.Space.Entities.Count; i++) { if (currentSimulation.Space.Entities[i].ActivityInformation.IsActive) { countActive++; } } DataTextDrawer.Draw("Active Objects: ", countActive, new Vector2(50, bottom - 99)); } #if !WINDOWS DataTextDrawer.Draw("Press Start for Controls", new Vector2(50, bottom - 82)); #else DataTextDrawer.Draw("Press F1 for Controls", new Vector2(50, bottom - 82)); #endif TinyTextDrawer.Draw("Current Simulation: ", currentSimulationIndex, new Vector2(right - 200, bottom - 100)); TinyTextDrawer.Draw(currentSimulation.Name, new Vector2(right - 180, bottom - 86)); currentSimulation.DrawUI(); } if (displayMenu) { UIDrawer.Draw(controlsMenu, new Rectangle(right / 2 - 400, bottom / 2 - 300, 800, 600), Color.White); } UIDrawer.End(); #endregion }