private void DrawBody(Body body, Func <Vector2, Vector2> toScreen)
        {
            // Draw the fixtures attached to this body.
            if (RenderFixtures)
            {
                // Get color to draw primitives in based on body state.
                Color color;
                if (!body.Enabled)
                {
                    color = DisabledShapeColor;
                }
                else if (body.Type == Body.BodyType.Static)
                {
                    color = StaticShapeColor;
                }
                else if (body.Type == Body.BodyType.Kinematic)
                {
                    color = KinematicShapeColor;
                }
                else if (!body.IsAwake)
                {
                    color = SleepingShapeColor;
                }
                else
                {
                    color = DefaultShapeColor;
                }

                // Get all fixtures attached to this body.
                foreach (Fixture fixture in body.Fixtures)
                {
                    switch (fixture.Type)
                    {
                    case Fixture.FixtureType.Circle:
                    {
                        var circle = fixture as CircleFixture;
                        System.Diagnostics.Debug.Assert(circle != null);
                        _primitiveBatch.DrawSolidCircle(
                            toScreen(circle.Center),
                            UnitConversion.ToScreenUnits(circle.Radius),
                            color);
                    }
                    break;

                    case Fixture.FixtureType.Edge:
                    {
                        var edge = fixture as EdgeFixture;
                        System.Diagnostics.Debug.Assert(edge != null);
                        _primitiveBatch.DrawLine(
                            toScreen(edge.Vertex1),
                            toScreen(edge.Vertex2),
                            color);
                    }
                    break;

                    case Fixture.FixtureType.Polygon:
                    {
                        var polygon = fixture as PolygonFixture;
                        System.Diagnostics.Debug.Assert(polygon != null);
                        _primitiveBatch.DrawFilledPolygon(
                            polygon.Vertices
                            .Take(polygon.Count)
                            .Select(toScreen).ToList(),
                            color);
                    }
                    break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }

            // Draw the transform at the center of mass.
            if (RenderCenterOfMass)
            {
                var p1 = toScreen(body.Sweep.LocalCenter);
                // We want to use the normal (untransformed in FarValue case) method
                // for mapping to screen space when computing our axis length.
                _primitiveBatch.DrawLine(p1, p1 + XnaUnitConversion.ToScreenUnits(Vector2.UnitX * AxisScale), Color.Red);
                _primitiveBatch.DrawLine(p1, p1 + XnaUnitConversion.ToScreenUnits(Vector2.UnitY * AxisScale), Color.Blue);
            }
        }