Interface IDebugDrawer
- Namespace
- Box3D
- Assembly
- Box3D.NET.dll
Receives the primitives Box3D emits while drawing a world.
public interface IDebugDrawerExamples
A drawer that collects line segments for a renderer to upload:
struct SegmentCollector : IDebugDrawer
{
public List<(Vector3, Vector3, DebugColor)> Lines;
public void DrawSegment(Vector3 p1, Vector3 p2, DebugColor color)
=> Lines.Add((p1, p2, color));
// ... the rest may be left empty; Box3D skips nothing, but a drawer may.
}
var collector = new SegmentCollector { Lines = lines };
world.Draw(ref collector, DebugDrawOptions.Default with { DrawJoints = true });
Remarks
Implement this over whatever renderer the application already has. Box3D.NET deliberately knows nothing about OpenGL, Vulkan, Unity or anything else: it hands over points, segments and boxes in world space and the application decides what a line looks like.
Every method is called synchronously from inside Box3D.PhysicsWorld.Draw``1(``0@,Box3D.DebugDrawOptions@), on the thread that called it, and none of them may touch the world being drawn. Reading or writing the simulation from here is the same race as doing it mid-step.
A frame's worth of drawing allocates nothing, provided the implementation
does not allocate: the calls arrive through function pointers with no
delegate, no closure and no boxing. Implementing this on a struct
passed by ref keeps it that way and lets the JIT inline the calls.
Methods
- DrawBounds(BoundingBox, DebugColor)
-
Draws an axis-aligned bounding box.
- DrawBox(Vector3, Vector3, Quaternion, DebugColor)
-
Draws an oriented box.
- DrawCapsule(Vector3, Vector3, float, DebugColor, float)
-
Draws a capsule between two points.
- DrawPoint(Vector3, float, DebugColor)
-
Draws a point.
- DrawSegment(Vector3, Vector3, DebugColor)
-
Draws a line segment.
- DrawShape(nint, Vector3, Quaternion, DebugColor)
-
Draws a drawable built earlier by the shape factory.
- DrawSphere(Vector3, float, DebugColor, float)
-
Draws a sphere.
- DrawString(Vector3, ReadOnlySpan<byte>, DebugColor)
-
Draws text anchored to a world position.
- DrawTransform(Vector3, Quaternion)
-
Draws a coordinate frame, the application choosing the axis length.