public void DrawPhysicsDebugView()
        {
            if (MainEditor.ShowPhysicsShapes)
            {
                // Matrix projection und Matrix view for PhysicsDebugView
                //
                // Calculate the projection and view adjustments for the debug view
                Projection = Matrix.CreateOrthographicOffCenter(0f, ViewportWidth / MeterInPixels,
                                                                ViewportHeight / MeterInPixels, 0f, 0f,
                                                                1f);

                // Draw the physics debug view
                PhysicsDebugView.RenderDebugData(ref Projection);
            }
        }
예제 #2
0
파일: Game.cs 프로젝트: lab132/owlicity
        /// <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)
        {
            float deltaSeconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            base.Draw(gameTime);

            GraphicsDevice.Clear(Color.CornflowerBlue);
            CameraData cam              = ActiveCamera.CameraComponent.CamData;
            Matrix     viewMatrix       = cam.Effect.View;
            Matrix     projectionMatrix = cam.Effect.Projection;

            if (MainDrawingEnabled)
            {
                WorldRenderer.Begin(sortMode: SpriteSortMode.BackToFront, effect: cam.Effect);

                foreach (GameObject go in GameObjects)
                {
                    go.Draw(WorldRenderer);
                }

                WorldRenderer.End();
            }

            if (HudEnabled)
            {
                UIRenderer.Begin(SpriteSortMode.Texture);
                Hud.Draw(UIRenderer, deltaSeconds);
                UIRenderer.End();
            }

            if (DebugDrawingEnabled)
            {
                PhysicsDebugView.BeginCustomDraw(ref projectionMatrix, ref viewMatrix);

                foreach (DebugDrawCommand drawCommand in DebugDrawCommands)
                {
                    drawCommand(PhysicsDebugView);
                }

                for (int slot = 0; slot < Perf.NumSlots; slot++)
                {
                    TimeSpan slotMin = TimeSpan.MaxValue;
                    TimeSpan slotMax = TimeSpan.MinValue;
                    TimeSpan slotAvg = TimeSpan.Zero;
                    for (int sampleIndex = 0; sampleIndex < Perf.NumSamplesPerFrame; sampleIndex++)
                    {
                        TimeSpan sampleValue = Perf.Samples[slot, sampleIndex].Elapsed;
                        if (sampleValue < slotMin)
                        {
                            slotMin = sampleValue;
                        }
                        if (sampleValue > slotMax)
                        {
                            slotMax = sampleValue;
                        }
                        slotAvg += sampleValue;
                    }
                    slotAvg = new TimeSpan(ticks: slotAvg.Ticks / Perf.NumSamplesPerFrame);

                    Vector2 pos = new Vector2(20, 30 * slot + 20);
                    Func <TimeSpan, string> f = ts => $"{ts.TotalMilliseconds.ToString("N04", System.Globalization.CultureInfo.InvariantCulture)}ms";
                    PhysicsDebugView.DrawString(pos, $"{(PerformanceSlots)slot}: min {f(slotMin)} | max {f(slotMax)} | avg {f(slotAvg)}");
                }

                PhysicsDebugView.EndCustomDraw();
            }

            PhysicsDebugView.RenderDebugData(ref projectionMatrix, ref viewMatrix);
        }