PackageBox2D.Collision
Classpublic class b2DynamicTree
Sourceb2DynamicTree.as

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.



Public Methods
 MethodDefined by
  
Constructing the tree initializes the node pool.
b2DynamicTree
  
CreateProxy(aabb:b2AABB, userData:*):b2DynamicTreeNode
Create a proxy.
b2DynamicTree
  
DestroyProxy(proxy:b2DynamicTreeNode):void
Destroy a proxy.
b2DynamicTree
  
GetFatAABB(proxy:b2DynamicTreeNode):b2AABB
b2DynamicTree
  
GetUserData(proxy:b2DynamicTreeNode):*
Get user data from a proxy.
b2DynamicTree
  
MoveProxy(proxy:b2DynamicTreeNode, aabb:b2AABB, displacement:b2Vec2):Boolean
Move a proxy with a swept AABB.
b2DynamicTree
  
Query(callback:Function, aabb:b2AABB):void
Query an AABB for overlapping proxies.
b2DynamicTree
  
RayCast(callback:Function, input:b2RayCastInput):void
Ray-cast against the proxies in the tree.
b2DynamicTree
  
Rebalance(iterations:int):void
Perform some iterations to re-balance the tree.
b2DynamicTree
Constructor detail
b2DynamicTree()constructor
public function b2DynamicTree()

Constructing the tree initializes the node pool.

Method detail
CreateProxy()method
public function CreateProxy(aabb:b2AABB, userData:*):b2DynamicTreeNode

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

Parameters
aabb:b2AABB
 
userData:*

Returns
b2DynamicTreeNode
DestroyProxy()method 
public function DestroyProxy(proxy:b2DynamicTreeNode):void

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

Parameters
proxy:b2DynamicTreeNode
GetFatAABB()method 
public function GetFatAABB(proxy:b2DynamicTreeNode):b2AABBParameters
proxy:b2DynamicTreeNode

Returns
b2AABB
GetUserData()method 
public function GetUserData(proxy:b2DynamicTreeNode):*

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

Parameters
proxy:b2DynamicTreeNode

Returns
*
MoveProxy()method 
public function 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
proxy:b2DynamicTreeNode
 
aabb:b2AABB
 
displacement:b2Vec2

Returns
Boolean
Query()method 
public function Query(callback:Function, aabb:b2AABB):void

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.

Parameters
callback:Function
 
aabb:b2AABB
RayCast()method 
public function RayCast(callback:Function, input:b2RayCastInput):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
callback:Function — the ray-cast input data. The ray extends from p1 to p1 + maxFraction (p2 - p1).
 
input:b2RayCastInput — a callback class that is called for each proxy that is hit by the ray. It should be of signature: function callback(input:b2RayCastInput, proxy::void
Rebalance()method 
public function Rebalance(iterations:int):void

Perform some iterations to re-balance the tree.

Parameters
iterations:int