Skip to content

Class: BroadPhase ​

The broad-phase wraps and extends a dynamic-tree to keep track of moved objects and query them on update.

Constructors ​

Constructor ​

new BroadPhase(): BroadPhase

Returns ​

BroadPhase

Properties ​

m_callback() ​

m_callback: (userDataA, userDataB) => void

Parameters ​

userDataA ​

any

userDataB ​

any

Returns ​

void


m_moveBuffer ​

m_moveBuffer: number[] = []


m_queryProxyId ​

m_queryProxyId: number


m_tree ​

m_tree: DynamicTree<FixtureProxy>

Methods ​

bufferMove() ​

bufferMove(proxyId): void

Parameters ​

proxyId ​

number

Returns ​

void


createProxy() ​

createProxy(aabb, userData): number

Create a proxy with an initial AABB. Pairs are not reported until UpdatePairs is called.

Parameters ​

aabb ​

AABBValue

userData ​

FixtureProxy

Returns ​

number


destroyProxy() ​

destroyProxy(proxyId): void

Destroy a proxy. It is up to the client to remove any pairs.

Parameters ​

proxyId ​

number

Returns ​

void


getFatAABB() ​

getFatAABB(proxyId): AABB

Get the fat AABB for a proxy.

Parameters ​

proxyId ​

number

Returns ​

AABB


getProxyCount() ​

getProxyCount(): number

Get the number of proxies.

Returns ​

number


getTreeBalance() ​

getTreeBalance(): number

Get the balance (integer) of the embedded tree.

Returns ​

number


getTreeHeight() ​

getTreeHeight(): number

Get the height of the embedded tree.

Returns ​

number


getTreeQuality() ​

getTreeQuality(): number

Get the quality metric of the embedded tree.

Returns ​

number


getUserData() ​

getUserData(proxyId): FixtureProxy

Get user data from a proxy. Returns null if the id is invalid.

Parameters ​

proxyId ​

number

Returns ​

FixtureProxy


moveProxy() ​

moveProxy(proxyId, aabb, displacement): void

Call moveProxy as many times as you like, then when you are done call UpdatePairs to finalized the proxy pairs (for your time step).

Parameters ​

proxyId ​

number

aabb ​

AABB

displacement ​

Vec2Value

Returns ​

void


query() ​

query(aabb, queryCallback): void

Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.

Parameters ​

aabb ​

AABBValue

queryCallback ​

DynamicTreeQueryCallback

Returns ​

void


queryCallback() ​

queryCallback(proxyId): boolean

Parameters ​

proxyId ​

number

Returns ​

boolean


rayCast() ​

rayCast(input, rayCastCallback): void

Ray-cast against the proxies in the tree. This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree.

Parameters ​

input ​

RayCastInput

The ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).

rayCastCallback ​

RayCastCallback

A function that is called for each proxy that is hit by the ray. If the return value is a positive number it will update the maxFraction of the ray cast input, and if it is zero it will terminate they ray cast.

Returns ​

void


shiftOrigin() ​

shiftOrigin(newOrigin): void

Shift the world origin. Useful for large worlds. The shift formula is: position -= newOrigin

Parameters ​

newOrigin ​

Vec2Value

The new origin with respect to the old origin

Returns ​

void


testOverlap() ​

testOverlap(proxyIdA, proxyIdB): boolean

Test overlap of fat AABBs.

Parameters ​

proxyIdA ​

number

proxyIdB ​

number

Returns ​

boolean


touchProxy() ​

touchProxy(proxyId): void

Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.

Parameters ​

proxyId ​

number

Returns ​

void


unbufferMove() ​

unbufferMove(proxyId): void

Parameters ​

proxyId ​

number

Returns ​

void


updatePairs() ​

updatePairs(addPairCallback): void

Update the pairs. This results in pair callbacks. This can only add pairs.

Parameters ​

addPairCallback ​

(userDataA, userDataB) => void

Returns ​

void