Documentation
¶
Overview ¶
Package collide is the contract of a Space's collision engine: what it is told (Config), whom it reports to (Handler), and what a caller drives (Engine). Space.CollideEngine of package aabbworld builds one over a Space's CanCollide boxes.
Handler ¶
One Engine.Tick talks to the Handler in a fixed order. Touch is asked once for every pair of boxes that overlap, with the penetration between them; the handler may confirm the pair as it is, refine the penetration (a round shape inside a square box touches later than the box does) or veto the pair for this tick. Contact is told each confirmed pair once, with the penetration it is being separated by. Moved is told every box the engine pushed, once, where it came to rest — the caller writes that box back to whatever owns it. A box pushed out through an open edge is not Moved; it is listed by Engine.Left until the next Tick.
Config ¶
Reach is how far a box may travel in one tick, as a fraction of its shorter side; boxes whose reaches do not touch are never paired, so it bounds the work of a tick. Iterations caps the passes one Tick spends on chained overlaps: separating one pair may push a box into a third, which the next pass resolves.
Engine ¶
An Engine serves one goroutine. Tick reads the boxes of its Space as they are now — the Space need only have been Rebuilt since the items changed — and leaves them pushed apart; the Space answers its next Query with the pushed boxes on its own.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v1.5.0
type Config struct {
// Reach is how far a box may travel in a tick, as a fraction of its shorter side.
Reach float64
// Iterations caps the passes one Tick spends on chained overlaps.
Iterations int
}
Config is how far an Engine looks for pairs and how long it spends separating them.
type Engine ¶ added in v1.5.0
type Engine interface {
// Tick separates every overlapping pair the Space holds now and reports as it goes; the
// Space answers its next Query with the pushed boxes without another Rebuild.
Tick()
// Left is who the last Tick pushed out through an open edge; good until the next Tick.
Left() []uid.UID64
}
Engine finds and separates the overlapping CanCollide boxes of its Space, on one goroutine.
type Handler ¶ added in v1.5.0
type Handler interface {
// Touch says whether the shapes in two overlapping boxes really touch, and by how much.
Touch(a, b uid.UID64, pen geom.Vec) (geom.Vec, bool)
// Contact is a pair Touch confirmed, with the penetration it is being separated by.
Contact(a, b uid.UID64, pen geom.Vec)
// Moved is a box the Engine pushed, where it came to rest.
Moved(id uid.UID64, box plane.AABB)
}
Handler is told what an Engine finds: each overlapping pair once, and every box it pushed.