DebugDraw

class DebugDraw(pixel: TextureRegion, font: Font? = null)(source)

Draws what the physics sees, in world space, on a klyph Canvas: soft bodies filled from their outlines, and the solids they collide with. Its view adds more, a level at a time: every particle and tile edge, then every constraint coloured by its stress, then every contact and its normal (see DebugView). showBroadphase adds the broadphase's cells on top. What isn't shown costs nothing.

klyph has no polygons, so shapes are filled one row of ROW world units at a time, and lines are stretched, turned quads of pixel (App.assets.whitePixel). Labels need a font, such as App.assets.defaultFont; without one they are not drawn.

toString gives what it shows, for example DebugDraw(view=CONSTRAINTS, broadphase=false).

Constructors

Link copied to clipboard
constructor(pixel: TextureRegion, font: Font? = null)

Types

Link copied to clipboard
object Companion

The sizes and colours the drawing uses.

Properties

Link copied to clipboard
var layer: Int

Canvas layer the plain view is drawn in; details go in the layers just above it.

Link copied to clipboard

Whether overlay also shades the broadphase's cells and outlines its boxes.

Link copied to clipboard

Whether particles and tile edges are drawn: any view but DebugView.OFF.

Link copied to clipboard

How much to draw on top of the plain view.

Functions

Link copied to clipboard
fun broadphase(canvas: Canvas, world: PhysicsWorld)

Shades every cell of world's broadphase once per box filed there, so busy cells glow brighter, and outlines each box: one per soft body and one per colliding particle, from the world's own broadphase, and one per rigid body, from its contacts' broadphase.

Link copied to clipboard
fun constraints(canvas: Canvas, world: PhysicsWorld)

Draws every constraint of world from DebugView.CONSTRAINTS up, coloured by its stress, from blue squeezed through grey at rest to red stretched: a link along its length, a pin as a line to the point it holds, an attachment as a line to its point on its rigid body, a joint as a dot on its anchor (a line to its other end for a distance joint), a bend as a dot on its middle particle, an area as a dot in its middle.

Link copied to clipboard
fun contacts(canvas: Canvas, world: PhysicsWorld)

Marks, from DebugView.EVERYTHING up, every particle of world that touched something during the last step: a dot where it touched, and a short line along the normal it was pushed out by, in yellow on a floor and cyan on anything else. Every rigid body's velocity, as a line to where it will be in a tenth of a second. And every rigid contact the same way, a line the way it pushes the first body: green where friction holds it, orange where it slides, dim where it was found near but didn't push.

Link copied to clipboard
fun joints(canvas: Canvas, world: PhysicsWorld)

Draws every joint of world from DebugView.CONSTRAINTS up: a dot on its first anchor, yellow, or orange when its motor is on, a line to its second coloured by how far it's been pulled from where it should be (a slider's off its axis; a distance joint's line is its stick), and a weld's dot bigger. A hinge with limits shows them as a wedge fixed to its second end, and its first end's direction as a needle inside it; a slider shows the stretch of its axis it may slide along.

Link copied to clipboard
fun label(canvas: Canvas, text: CharSequence, x: Float, y: Float, color: Color = LABEL)

Writes text centred on x with its top at y, in world units, above everything else drawn here.

Link copied to clipboard
fun line(canvas: Canvas, x0: Float, y0: Float, x1: Float, y1: Float, thickness: Float, color: Color, layer: Int)

Draws a line of thickness world units from (x0, y0) to (x1, y1).

Link copied to clipboard
fun links(canvas: Canvas, constraints: Constraints, particles: Particles, color: Color = LINK, ropeColor: Color = ROPE)

Draws every live distance and rope in constraints as a line between its particles: ropes in ropeColor.

Link copied to clipboard
fun overlap(canvas: Canvas, world: PhysicsWorld, a: RigidBody, b: RigidBody, color: Color = CONTACT)

Draws where a and b of world overlap, shape by shape, as the narrowphase finds it, in color: each point as a dot on each surface, joined, and a line along the normal. Unlike contacts, it shows bodies that pass through each other, such as a kinematic body and a static one, which never push and so have no contacts.

Link copied to clipboard
fun overlay(canvas: Canvas, world: PhysicsWorld)

Draws everything view and showBroadphase ask for that a scene doesn't draw itself: constraints, contacts and broadphase. Call it after the scene, every frame.

Link copied to clipboard
fun particleBroadphase(canvas: Canvas, world: PhysicsWorld, ahead: Duration, cellSize: Float = 16.0f, cellColor: Color = CELL, pairColor: Color = PAIR)

Shows how a broadphase of cellSize sees every particle of world, each as the box it sweeps through in the next ahead: every cell a box is filed under, tinted once per box so busy cells glow brighter, and a line between the two particles of every pair that might touch. It finds them itself, so it shows particles that collide with nothing too.

Link copied to clipboard
inline fun particles(canvas: Canvas, particles: Particles, colorOf: (Particle) -> Color)

Draws every particle in particles as a square as wide as the particle, and at least two units, in the colour colorOf picks for it.

Link copied to clipboard
fun rigidBody(canvas: Canvas, world: PhysicsWorld, body: RigidBody, color: Color)

Fills every shape of body of world in color and outlines it, with a spoke on each round shape so its turning shows; with details, also marks its centre of mass. A sleeping body is drawn faded, half way to the background.

Link copied to clipboard
fun softBody(canvas: Canvas, world: PhysicsWorld, body: SoftBody, color: Color)

Fills body of world in color and outlines it; with details, also marks every particle.

Link copied to clipboard
fun solid(canvas: Canvas, solid: Solid, color: Color)

Fills one solid in color: a box whole, a slope one row at a time under its surface.

Link copied to clipboard
fun solids(canvas: Canvas, grid: SolidGrid, view: Rect, color: Color = SOLID)

Draws the solids of grid that lie in view, tiles and moving ones alike, in color. Tiles outside view cost nothing; with details, each tile's edge is drawn too.

Link copied to clipboard
fun square(canvas: Canvas, x: Float, y: Float, size: Float, color: Color)

Draws a square size wide centred on (x, y) in color, in the plain view's layer.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun turnedRect(canvas: Canvas, x: Float, y: Float, width: Float, height: Float, angle: Float, color: Color)

Fills a rectangle width by height centred on (x, y) and turned by angle radians, in color, with a darker edge: how a rigid box looks.