Physics · class

DynamicTree

Explained in Your first game, Rigid bodies.

class DynamicTree
import { DynamicTree } from '@driftengine/physics';

Constructor

new

constructor(capacity?: number)
ParameterTypeDescription
capacity?number

Properties

NameTypeDescription
rootnumber
boundsFloat32ArrayminX, minY, minZ, maxX, maxY, maxZ per node.
parentInt32Array
child1Int32Array
child2Int32Array
proxyInt32ArrayThe caller's own id for a leaf; −1 on an internal node.
heightInt32Array

Accessors

NameTypeDescription
countgetnumberHow many nodes are in use. A tree of n leaves has 2n − 1 nodes.

Methods

insert

insert(proxyId: number, box: Aabb): number
ParameterTypeDescription
proxyIdnumber
boxAabb

remove

remove(leaf: number): void
ParameterTypeDescription
leafnumber

move

move(leaf: number, box: Aabb): boolean

Re-place a proxy whose tight box has moved. Returns whether the tree changed.

ParameterTypeDescription
leafnumber
boxAabb
More

A move entirely inside the fat box is free: the stored bounds still enclose the proxy, so no query can miss it. That is the whole point of the margin, and the reason it is a conservative enlargement rather than a tolerance.

query

query(box: Aabb, out: Int32Array): number

Fill out with every proxy id whose stored box overlaps box. Returns how many.

ParameterTypeDescription
boxAabb
outInt32Array