Class
Gizmo2D
View sourceProvides a labelled world resource for immediate-mode two-dimensional debug drawing.
The generic label is part of the resource’s type ID, so use the same
constructor when retrieving it; different labels produce separate gizmo
resources. The constructor is exposed as Gizmo2D#type for code
that needs to inspect the label.
The resource keeps its current drawing transform, collects transformed line
and polyline vertices in Gizmo2D#buffer, and uses
Gizmo2D#settings for line width, cap, join, and dash behavior. Use
Gizmo2D#reset, Gizmo2D#setTransform, and the transform
helpers to position subsequent shapes; use primitive helpers such as
Gizmo2D#line, Gizmo2D#arc, and Gizmo2D#grid to
append geometry. Drawing clears the buffer only after a successful draw;
missing window or canvas resources leave the buffer intact.
Examples
import { Color } from '@wimaengine/color'
import { Gizmo2D } from '@wimaengine/gizmo'
import { typeidGeneric } from '@wimaengine/type'
class PhysicsDebug {}
function drawPhysicsDebug(world) {
const gizmo = world.getResourceByTypeId(
typeidGeneric(Gizmo2D, [PhysicsDebug])
)
gizmo.reset().translate(10, 10).circle(2, Color.RED)
}Constructor
View source
Properties
readonlytype: Constructor<T>
View sourcebuffer: GizmoBuffer<Vector2>
View sourceDefault: ...
settings: GizmoSettings
View sourceMethods
reset(): Gizmo2D<T>
View sourcesetTransform(matrix: Affine2): Gizmo2D<T>
View sourcetransform(matrix: Affine2): Gizmo2D<T>
View sourcetranslate(x: number, y: number): Gizmo2D<T>
View sourcerotate(angle: number): Gizmo2D<T>
View sourcescale(x: number, y: number): Gizmo2D<T>
View sourcecompose(translation: Vector2, orientation: Rotary, scale: Vector2): Gizmo2D<T>
View sourcetext(value: string, color: Color, align: number, size: number): Gizmo2D<T>
View sourceDraws stroked text at the current transform’s origin.
line(start: Vector2, end: Vector2, color: Color): Gizmo2D<T>
View sourcelineGradient(start: Vector2, end: Vector2, colorStart: Color, colorEnd: Color): Gizmo2D<T>
View sourcefillText(value: string, color: Color, align: number, size: number): Gizmo2D<T>
View sourceDraws filled text at the current transform’s origin.
polyline(points: Vector2[], color: Color): Gizmo2D<T>
View sourcepolylineGradient(points: [Vector2, Color][]): Gizmo2D<T>
View sourcearc(arcStart: number, arcEnd: number, radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>
View sourcesector(arcStart: number, arcEnd: number, radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>
View sourceDraws a sector outline from the origin.
fillSector(arcStart: number, arcEnd: number, radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>
View sourceDraws a filled sector from the origin.
polygon(vertices: Vector2[], color: Color): Gizmo2D<T>
View sourceDraws a closed polygon outline.
fillPolygon(vertices: Vector2[], color: Color): Gizmo2D<T>
View sourceDraws a filled convex polygon.
capsule(radius: number, halfLength: number, color: Color, resolution: number): Gizmo2D<T>
View sourceDraws a capsule centered on the origin and aligned to the local Y axis.
fillCapsule(radius: number, halfLength: number, color: Color, resolution: number): Gizmo2D<T>
View sourceDraws a filled capsule centered on the origin and aligned to the local Y axis.
triangle(base: number, height: number, baseRatio?: number, color: Color): Gizmo2D<T>
View sourcefillTriangle(base: number, height: number, baseRatio?: number, color: Color): Gizmo2D<T>
View sourceDraws a filled triangle.
arrow(direction: Vector2, length: number, color: Color): Gizmo2D<T>
View sourcegrid(cellCount: Vector2, spacing: Vector2, color: Color, drawEdges: BVector2): Gizmo2D<T>
View sourceaxes(length: number): Gizmo2D<T>
View sourcecircle(radius: number, color: Color, resolution: number): Gizmo2D<T>
View sourcefillCircle(radius: number, color: Color, resolution: number): Gizmo2D<T>
View sourceDraws a filled circle.
rect(halfWidth: number, halfHeight: number, color: Color): Gizmo2D<T>
View sourcefillRect(halfWidth: number, halfHeight: number, color: Color): Gizmo2D<T>
View sourceDraws a filled rectangle centered on the origin.
ellipse(radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>
View sourcefillEllipse(radiusX: number, radiusY: number, color: Color, resolution: number): Gizmo2D<T>
View sourceDraws a filled ellipse.
