Class b2DynamicTree

A dynamic tree arranges data in a binary tree to accelerate queries such as volume queries and ray casts. Leafs are proxies with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor so that the proxy AABB is bigger than the client object. This allows the client object to move by small amounts without triggering a tree update. Nodes are pooled.

Index

Constructor methods

Methods

Constructor methods

constructor(): b2DynamicTree

Constructing the tree initializes the node pool.

Returns

b2DynamicTree

Methods

public CreateProxy(aabb: b2AABB, userData: any): b2DynamicTreeNode

Create a proxy. Provide a tight fitting AABB and a userData.

Parameters

  • aabb: b2AABB

    AABB.

  • userData: any

Returns

b2DynamicTreeNode

Dynamic tree node.

public DestroyProxy(proxy: b2DynamicTreeNode)

Destroy a proxy. This asserts if the id is invalid.

Parameters

public GetFatAABB(proxy: b2DynamicTreeNode): b2AABB

Gets the Fat AABB for the proxy.

Parameters

Returns

b2AABB

Fat AABB for proxy.

public GetUserData(proxy: b2DynamicTreeNode): any

Get user data from a proxy. Returns null if the proxy is invalid. Cast to your type on return.

Parameters

Returns

any

User data for proxy or null if proxy is invalid.

public MoveProxy(proxy: b2DynamicTreeNode, aabb: b2AABB, displacement: b2Vec2): boolean

Move a proxy with a swept AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately.

Parameters

Returns

boolean

public Query(callback: (proxy: Box2D.Collision.b2DynamicTreeNode) => boolean, aabb: b2AABB)

Query an AABB for overlapping proxies. The callback is called for each proxy that overlaps the supplied AABB. The callback should match function signature fuction callback(proxy:b2DynamicTreeNode):Boolean and should return false to trigger premature termination.

aabb

Proxies are query for overlap on this AABB.

Parameters

  • callback: (proxy: Box2D.Collision.b2DynamicTreeNode) => boolean

    Called for each proxy that overlaps the supplied AABB. param proxy Proxy overlapping the supplied AABB.

  • aabb: b2AABB

public RayCast(callback: (input: Box2D.Collision.b2RayCastInput, proxy: Box2D.Collision.b2DynamicTreeNode) => number, input: b2RayCastInput)

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

  • callback: (input: Box2D.Collision.b2RayCastInput, proxy: Box2D.Collision.b2DynamicTreeNode) => number

    Called for each proxy that is hit by the ray. param input Ray cast input data. param proxy The proxy hit by the ray cast. return Return value is the new value for maxFraction.

  • input: b2RayCastInput

    Ray cast input data. Query all proxies along this ray cast.

public Rebalance(iterations: number)

Perform some iterations to re-balance the tree.

Parameters

  • iterations: number

    Number of rebalance iterations to perform.