Provides fast line based, GPU powered drawing API for 2d debug drawing, and drawing of Physics2D physics data.
Coordinates of the DebugDraw object are that of Physics2D, with scaling to pixels defined solely by the viewports set on this object.
Required scripts
The Physics2DDevice object requires:
/*{{ javascript("jslib/physics2ddevice.js") }}*/
/*{{ javascript("jslib/physics2ddebugdraw.js") }}*/
Summary
Create a DebugDraw object.
DebugDraw object uses the GraphicsDevice object to render line based primitives on the GPU with methods for rendering a Physics2D World and other Physics2D objects.
Syntax
var debug = Physics2DDebugDraw.create({
graphicsDevice : gd
});
Summary
Define the region in Physics2D coordinates that is to be drawn to the screen.
This method will take effect upon the next call to debug.begin().
Syntax
debug.setPhysics2DViewport(rectangle);
The rectangle in Physics2D coordinates to be drawn.
If using Draw2D in conjunction with Physics2D, then as long as your graphics logic uses the same coordinates as Physics2D you would most likely find that using the value of draw2D.getViewport() is the best fit for the Physics2D viewport so that debug drawing is correctly aligned.
Summary
Define the region in screen pixels (with top-left corner at (0,0)) to which the Physics2D viewport will be mapped onto.
Anything outside of this region will be clipped.
Syntax
debug.setScreenViewport(rectangle);
The rectangle in screen pixels to be drawn to.
If using Draw2D in conjunction with Physics2D, then you would most likely find that using the value of draw2D.getScreenSpaceViewport() is the best fit for the Screen viewport so that debug drawing is correctly aligned.
Summary
Begin debug drawing state.
This call will update shader parameters for drawing based on viewports, as well as setting the scissor on the graphics device.
Syntax
debug.begin();
Summary
End debug drawing state.
This call will dispatch all drawing data to the GPU that has accumulated since the matching calling to begin().
Syntax
debug.end();
Summary
Destroy debug draw object, releasing memory allocated on GPU through the GraphicsDevice
You cannot use this object after it has been destroyed.
Syntax
debug.destroy();
Summary
Draw a RigidBody object.
The colors with which the shapes of the body are drawn is controlled by the various color properties of this object.
Syntax
debug.drawRigidBody(rigidBody);
Summary
Draw a Constraint object.
Drawing of the constraint is deferred to the constraint object itself. In built constraints make use of the common DebugDraw methods and colors listed in the properties of this object.
Syntax
debug.drawConstraint(constraint);
Summary
Draw a World object.
Control of what parts of the world is drawn is given by the various properties of this object like showRigidBodies and showContacts.
Syntax
debug.drawWorld(world);
Summary
Draw a single line with given color.
Syntax
debug.drawLine(x1, y1, x2, y2, color);
Summary
Draw a quadratic bezier curve with given color.
The accuracy with which the curve is drawn is controlled by the curveMaxError property.
Syntax
debug.drawCurve(x1, y1, cx, cy, x2, y2, color);
Summary
Draw an axis aligned rectangle with given color.
Syntax
debug.drawRectangle(x1, y1, x2, y2, color);
Summary
Draw a circle with given color.
The accuracy with which this circle is drawn is controlled by the circleMaxError property of this object.
Syntax
debug.drawCircle(x, y, radius, color);
Summary
Draw a circular spiral with given color.
Syntax
debug.drawSpiral(x, y, angle1, angle2, radius1, radius2, color);
Summary
Draw a linear spring (sine-wave) with given color.
Syntax
debug.drawLinearSpring(x1, y1, x2, y2, numCoils, radius, color);
Summary
Draw a spiral spring (sine-wave perturbed circular spiral) with given color.
The percentage of the gap between spiral arms into which the spring is drawn is controlled by the spiralSpringSize property of this object.
Syntax
debug.drawSpiralSpring(x, y, angle1, angle2, radius1, radius2, numCoils, color);
Provides a scaling factor from physics coordinates to screen pixels.
This value is computed when begin() is called.
Note
Read Only
Provides a scaling factor from screen pixels to physics coordinates.
This value is computed when begin() is called.
Note
Read Only
Flag determining whether constraints will be drawn in calls to drawWorld(..).
Default value is true.
Flag determining whether contact points will be drawn in calls to drawWorld(..).
Default value is false.
Flag determining whether contact impulses will be drawn in calls to drawWorld(..).
For impulses to be drawn, it must also be the case that showContacts is true.
Default value is false.
Flag determining whether rigid bodies will be drawn in calls to drawWorld(..).
Default value is true.
Flag determining whether collidable shapes will be drawn in calls to drawWorld(..) and drawRigidBody(..).
Default value is true.
Flag determining whether shapes with sensor true will be drawn in calls to drawWorld(..) and drawRigidBody(..).
Default value is true.
Flag determining whether rigid body details (origin, and change in position since last update) will be drawn in calls to drawWorld(..), and drawRigidBody(..).
Default value is false.
Flag determining whether shape details (world-space bounds) will be drawn in calls to drawWorld(..), and drawRigidBody(..).
Default value is false.
The maximum error, measured as the distance from the chord drawn to the circle in pixels.
Default value is 0.4px.
The maximum error, measured as the distance from the chord drawn to the curve in pixels.
Default value is 0.6px.
The fraction of the gap between spiral arms, in which the spring will be drawn.
Default value is 0.75.