Class Box2DDebugDraw
Box2D's own debug drawing, rendered through a ShapeBatch: every shape, joint, contact point, force, bounding box, island and body name the testbed can show, from one call a frame, with the testbed's toggles as properties.
public sealed class Box2DDebugDraw
- Inheritance
-
Box2DDebugDraw
Examples
var debugDraw = new Box2DDebugDraw(shapeBatch) { DrawContactPoints = true };
// each frame, after the simulation update
debugDraw.Draw(simulation);
Remarks
b2World_Draw walks the world and calls back for each primitive - a solid polygon with a
transform and rounding radius, a circle, a capsule, a line, a point. Those map almost one to one
onto the batch, which draws polygons with rounding and pixel-constant borders. Shapes are on by
default, as in Box2D; joints are on here as well, since drawing them is the usual reason to use
this. The rest is off until asked for.
Sizes: lines are LinePixels wide on screen at any zoom; a point's size is in screen pixels in the testbed and has no equivalent in the batch, so it is scaled by PointScale into world units. Text has no renderer of its own; set DrawString to route body names and joint labels wherever you like.
Constructors
Box2DDebugDraw(ShapeBatch)
Creates the adapter over a batch. Add the batch with game.AddShapeBatch() first.
public Box2DDebugDraw(ShapeBatch batch)
Parameters
batchShapeBatch
Properties
DrawBodyNames
Body names, through DrawString.
public bool DrawBodyNames { get; set; }
Property Value
DrawBounds
Axis-aligned bounding boxes of every shape.
public bool DrawBounds { get; set; }
Property Value
DrawContactFeatures
Contact feature ids as text.
public bool DrawContactFeatures { get; set; }
Property Value
DrawContactForces
Contact normal impulses, as lines scaled by ForceScale.
public bool DrawContactForces { get; set; }
Property Value
DrawContactNormals
Contact normals.
public bool DrawContactNormals { get; set; }
Property Value
DrawContactPoints
Contact points.
public bool DrawContactPoints { get; set; }
Property Value
DrawFrictionForces
Contact friction impulses, as lines scaled by ForceScale.
public bool DrawFrictionForces { get; set; }
Property Value
DrawGraphColors
Colour each shape by its constraint-graph colour instead of its body state.
public bool DrawGraphColors { get; set; }
Property Value
DrawIslands
Sleep islands, as bounding boxes.
public bool DrawIslands { get; set; }
Property Value
DrawJointExtras
Joint limits, targets and the like, drawn on top of the joints.
public bool DrawJointExtras { get; set; }
Property Value
DrawJoints
Joints as lines between their anchors. On by default here, unlike in Box2D.
public bool DrawJoints { get; set; }
Property Value
DrawMass
A marker at each body's centre of mass, with its mass as text.
public bool DrawMass { get; set; }
Property Value
DrawShapes
Every shape, in Box2D's body-state colours. On by default.
public bool DrawShapes { get; set; }
Property Value
DrawString
Where text goes: world position, the text, its colour. Nothing is drawn when unset.
public Action<Vector2, string, Color>? DrawString { get; set; }
Property Value
ForceScale
Length per unit of force for the force lines.
public float ForceScale { get; set; }
Property Value
JointScale
Size of the joint drawings.
public float JointScale { get; set; }
Property Value
LinePixels
On-screen width of every line, in pixels.
public float LinePixels { get; set; }
Property Value
PointScale
World units per unit of a point's size; Box2D sizes points in screen pixels.
public float PointScale { get; set; }
Property Value
Methods
Draw(B2WorldId)
Submits the whole world to the batch. Call once per frame, after stepping.
public void Draw(B2WorldId world)
Parameters
worldB2WorldId
Draw(Box2DSimulation)
Submits the whole world to the batch. Call once per frame, after stepping.
public void Draw(Box2DSimulation simulation)
Parameters
simulationBox2DSimulation