Click or drag to resize
DigitalRuneStep 10: More debug rendering
Render more debug information

It is a good idea to use the debug renderer a lot during development. With a few simply changes in MyGameComponent.cs, we can see a lot more information which helps to identify problems:

MyGameComponent.cs
using System.Linq;                                                                  // NEW
using DigitalRune.Physics;                                                          // NEWnamespace MyGame
{
    public class MyGameComponent : Microsoft.Xna.Framework.GameComponent
    {
        …

        public MyGameComponent(Game game)
            : base(game)
        {
            …

            //_myGraphicsScreen.DebugRenderer.DrawText("MyGame");                   // REMOVE
            //_myGraphicsScreen.DebugRenderer.DrawAxes(Pose.Identity, 1, false);    // REMOVE
        }

        public override void Update(GameTime gameTime)
        {
            if (_inputService.IsDown(Keys.Escape))
                Game.Exit();

            var debugRenderer = _myGraphicsScreen.DebugRenderer;                    // NEW
            debugRenderer.Clear();                                                  // NEW
            debugRenderer.DrawText("MyGame");                                       // NEW
            debugRenderer.DrawAxes(Pose.Identity, 1, false);                        // NEW

            foreach (var sceneNode in _myGraphicsScreen.Scene.GetDescendants())     // NEW
            {                                                                       // NEW
                debugRenderer.DrawObjects(                                          // NEW
                    _myGraphicsScreen.Scene.GetDescendants(),                       // NEW
                    Color.Yellow, true, false);                                     // NEW
                if (sceneNode is MeshNode)                                          // NEW
                    debugRenderer.DrawSkeleton(                                     // NEW
                        ((MeshNode)sceneNode).SkeletonPose, sceneNode.PoseWorld,    // NEW
                        sceneNode.ScaleWorld, 0.1f, Color.Orange, true);            // NEW
            }                                                                       // NEW

            var simulation = ServiceLocator.Current.GetInstance<Simulation>();      // NEW
            debugRenderer.DrawContacts(                                             // NEW
                simulation.CollisionDomain.ContactSets, 0.1f, Color.Green, true);   // NEW

            base.Update(gameTime);
        }
    }
}

In Update the debug renderer is cleared each frame and filled with new draw jobs. The foreach-loop enumerates all nodes of the scene graph. For each scene node the bounding shape is drawn using DrawObjects. If the scene node is a MeshNode, the animated skeleton of the mesh is drawn using DrawSkeleton. This is very helpful to check bone names and animation problems. DrawContacts draws all contact points of the physics simulaton.

Tutorial-01-18

The DebugRenderer has a lot of useful methods. Use them a lot!

For now, comment out the debug code to hide the debug graphics.

MyGameComponent.cs
public override void Update(GameTime gameTime)
    {
        if (_inputService.IsDown(Keys.Escape))
            Game.Exit();

        var debugRenderer = _myGraphicsScreen.DebugRenderer;
        debugRenderer.Clear();
        //debugRenderer.DrawText("MyGame");                                         // Comment out
        //debugRenderer.DrawAxes(Pose.Identity, 1, false);                          // Comment out

        //foreach (var sceneNode in _myGraphicsScreen.Scene.GetDescendants())       // Comment out
        //{                                                                         // Comment out
        //    debugRenderer.DrawObjects(                                            // Comment out
        //        _myGraphicsScreen.Scene.GetDescendants(),                         // Comment out
        //        Color.Yellow, true, false);                                       // Comment out
        //    if (sceneNode is MeshNode)                                            // Comment out
        //        debugRenderer.DrawSkeleton(
        //            ((MeshNode)sceneNode).SkeletonPose, sceneNode.PoseWorld,      // Comment out
        //            sceneNode.ScaleWorld, 0.1f, Color.Orange, true);              // Comment out
        //}                                                                         // Comment out

        //var simulation = ServiceLocator.Current.GetInstance<Simulation>();        // Comment out
        //debugRenderer.DrawContacts(                                               // Comment out
        //    simulation.CollisionDomain.ContactSets, 0.1f, Color.Green, true);     // Comment out

        base.Update(gameTime);
    }
    …