Table of Contents

Class Box2DDebugDraw

Namespace
Stride.CommunityToolkit.Box2D
Assembly
Stride.CommunityToolkit.Box2D.dll

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

batch ShapeBatch

Properties

DrawBodyNames

Body names, through DrawString.

public bool DrawBodyNames { get; set; }

Property Value

bool

DrawBounds

Axis-aligned bounding boxes of every shape.

public bool DrawBounds { get; set; }

Property Value

bool

DrawContactFeatures

Contact feature ids as text.

public bool DrawContactFeatures { get; set; }

Property Value

bool

DrawContactForces

Contact normal impulses, as lines scaled by ForceScale.

public bool DrawContactForces { get; set; }

Property Value

bool

DrawContactNormals

Contact normals.

public bool DrawContactNormals { get; set; }

Property Value

bool

DrawContactPoints

Contact points.

public bool DrawContactPoints { get; set; }

Property Value

bool

DrawFrictionForces

Contact friction impulses, as lines scaled by ForceScale.

public bool DrawFrictionForces { get; set; }

Property Value

bool

DrawGraphColors

Colour each shape by its constraint-graph colour instead of its body state.

public bool DrawGraphColors { get; set; }

Property Value

bool

DrawIslands

Sleep islands, as bounding boxes.

public bool DrawIslands { get; set; }

Property Value

bool

DrawJointExtras

Joint limits, targets and the like, drawn on top of the joints.

public bool DrawJointExtras { get; set; }

Property Value

bool

DrawJoints

Joints as lines between their anchors. On by default here, unlike in Box2D.

public bool DrawJoints { get; set; }

Property Value

bool

DrawMass

A marker at each body's centre of mass, with its mass as text.

public bool DrawMass { get; set; }

Property Value

bool

DrawShapes

Every shape, in Box2D's body-state colours. On by default.

public bool DrawShapes { get; set; }

Property Value

bool

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

Action<Vector2, string, Color>

ForceScale

Length per unit of force for the force lines.

public float ForceScale { get; set; }

Property Value

float

JointScale

Size of the joint drawings.

public float JointScale { get; set; }

Property Value

float

LinePixels

On-screen width of every line, in pixels.

public float LinePixels { get; set; }

Property Value

float

PointScale

World units per unit of a point's size; Box2D sizes points in screen pixels.

public float PointScale { get; set; }

Property Value

float

Methods

Draw(B2WorldId)

Submits the whole world to the batch. Call once per frame, after stepping.

public void Draw(B2WorldId world)

Parameters

world B2WorldId

Draw(Box2DSimulation)

Submits the whole world to the batch. Call once per frame, after stepping.

public void Draw(Box2DSimulation simulation)

Parameters

simulation Box2DSimulation