Ctrl+K

DynamicTree

Declaration

public class tainicom.Aether.Physics2D.Collision.DynamicTree

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 Settings.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 and relocatable, so we use node indices rather than pointers.

Type Parameters

Name Description
TNode

Constructors

DynamicTree

Constructing the tree initializes the node pool.

void DynamicTree()

Properties

Height

Compute the height of the binary tree in O(N) time. Should not be called often.

int Height { get }

AreaRatio

Get the ratio of the sum of the node areas to the root area.

float AreaRatio { get }

MaxBalance

Get the maximum balance of an node in the tree. The balance is the difference in height of the two children of a node.

int MaxBalance { get }

Methods

AddProxy

Create a proxy in the tree as a leaf node. We return the index of the node instead of a pointer so that we can grow the node pool. ///

int AddProxy(ref AABB aabb)

Parameters:

Name Type Description
aabb ref tainicom.Aether.Physics2D.Collision.AABB The aabb.

Returns: Index of the created proxy

RemoveProxy

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

void RemoveProxy(int proxyId)

Parameters:

Name Type Description
proxyId System.Int32 The proxy id.

MoveProxy

Move a proxy with a swepted 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.

bool MoveProxy(int proxyId, ref AABB aabb, Vector2 displacement)

Parameters:

Name Type Description
proxyId System.Int32 The proxy id.
aabb ref tainicom.Aether.Physics2D.Collision.AABB The aabb.
displacement Strawberry.Math.Vector2 The displacement.

Returns: true if the proxy was re-inserted.

SetUserData

Set proxy user data.

void SetUserData(int proxyId, TNode userData)

Parameters:

Name Type Description
proxyId System.Int32 The proxy id.
userData TNode The proxy user data.

GetUserData

Get proxy user data.

TNode GetUserData(int proxyId)

Parameters:

Name Type Description
proxyId System.Int32 The proxy id.

Returns: the proxy user data or 0 if the id is invalid.

GetFatAABB

Get the fat AABB for a proxy.

void GetFatAABB(int proxyId, out AABB fatAABB)

Parameters:

Name Type Description
proxyId System.Int32 The proxy id.
fatAABB out tainicom.Aether.Physics2D.Collision.AABB The fat AABB.

GetFatAABB

Get the fat AABB for a proxy.

AABB GetFatAABB(int proxyId)

Parameters:

Name Type Description
proxyId System.Int32 The proxy id.

Returns: The fat AABB.

TestFatAABBOverlap

Test overlap of fat AABBs.

bool TestFatAABBOverlap(int proxyIdA, int proxyIdB)

Parameters:

Name Type Description
proxyIdA System.Int32 The proxy id A.
proxyIdB System.Int32 The proxy id B.

Query

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

void Query(BroadPhaseQueryCallback callback, ref AABB aabb)

Parameters:

Name Type Description
callback tainicom.Aether.Physics2D.Collision.BroadPhaseQueryCallback The callback.
aabb ref tainicom.Aether.Physics2D.Collision.AABB The aabb.

RayCast

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.

void RayCast(BroadPhaseRayCastCallback callback, ref RayCastInput input)

Parameters:

Name Type Description
callback tainicom.Aether.Physics2D.Collision.BroadPhaseRayCastCallback A callback class that is called for each proxy that is hit by the ray.
input ref tainicom.Aether.Physics2D.Collision.RayCastInput The ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).

ComputeHeight

Compute the height of a sub-tree.

int ComputeHeight(int nodeId)

Parameters:

Name Type Description
nodeId System.Int32 The node id to use as parent.

Returns: The height of the tree.

ComputeHeight

Compute the height of the entire tree.

int ComputeHeight()

Returns: The height of the tree.

ValidateStructure

void ValidateStructure(int index)

Parameters:

Name Type Description
index System.Int32

ValidateMetrics

void ValidateMetrics(int index)

Parameters:

Name Type Description
index System.Int32

Validate

Validate this tree. For testing.

void Validate()

RebuildBottomUp

Build an optimal tree. Very expensive. For testing.

void RebuildBottomUp()

ShiftOrigin

Shift the origin of the nodes

void ShiftOrigin(Vector2 newOrigin)

Parameters:

Name Type Description
newOrigin Strawberry.Math.Vector2 The displacement to use.