Skip to main content

Class: AABBTree

physics/aabb/aabbTree.AABBTree

Represents a tree data structure which contains nodes that store AABBs.

This tree is used to speed up the physics engine's broadphase.

see Intro to AABB Trees

see Physics Broadphase - AABB Tree

Constructors

constructor

โ€ข new AABBTree()

Properties

insertionsLastUpdate

โ€ข insertionsLastUpdate: number = 0

The number of nodes which had to be reinserted in the last tree update.

Defined in

src/physics/aabb/aabbTree.ts:31


leafMarginMax

โ€ข leafMarginMax: number = 10

Defined in

src/physics/aabb/aabbTree.ts:24


leafMarginMin

โ€ข leafMarginMin: number = 0.02

Defined in

src/physics/aabb/aabbTree.ts:23


leafMarginScale

โ€ข leafMarginScale: number = 0.2

Defined in

src/physics/aabb/aabbTree.ts:21


leafMarginSlop

โ€ข leafMarginSlop: number = 0.05

Defined in

src/physics/aabb/aabbTree.ts:22


margin

โ€ข margin: number = 0.1

Defined in

src/physics/aabb/aabbTree.ts:19


pairs

โ€ข pairs: CollisionPair[]

Defined in

src/physics/aabb/aabbTree.ts:26


root

โ€ข root: AABBNode

Defined in

src/physics/aabb/aabbTree.ts:18

Methods

add

โ–ธ add(aabb): void

Inserts an aabb into the tree.

Parameters

NameTypeDescription
aabbAABBThe AABB to insert

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:245


addNode

โ–ธ Private addNode(node, parent): void

Inserts a node into the tree.

Parameters

NameTypeDescription
nodeAABBNodeThe AABBNode to insert
parentAABBNode-

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:285


clearChildrenCrossedFlag

โ–ธ Private clearChildrenCrossedFlag(): void

Sets the childrenCrossed flag to false on all nodes in the tree.

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:126


collectPairs

โ–ธ collectPairs(): CollisionPair[]

Obtains all the pairs of CollisionObjects which could possibly be colliding.

Returns

CollisionPair[]

An array containing the CollisionPairs

Defined in

src/physics/aabb/aabbTree.ts:113


collectPairsHelper

โ–ธ Private collectPairsHelper(a, b): void

Collects CollisionPairs.

Parameters

NameTypeDescription
aAABBNodeAn AABBNode to check for pairs
bAABBNodeAn AABBNode to check for pairs

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:155


crossChildren

โ–ธ Private crossChildren(n): void

Parameters

NameType
nAABBNode

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:142


getHeight

โ–ธ getHeight(): number

Calculates and returns the height of the root node. (the height of the tree)

Returns

number

Defined in

src/physics/aabb/aabbTree.ts:344

โ–ธ getHeight(node): number

Calculates the height of the given node.

Parameters

NameTypeDescription
nodeAABBNodeThe node to start at

Returns

number

Defined in

src/physics/aabb/aabbTree.ts:351


pick

โ–ธ pick(point): AABB[]

Picks aabbs in the tree.

Parameters

NameTypeDescription
pointvec2The point to pick AABBs at.

Returns

AABB[]

The picked aabbs

Defined in

src/physics/aabb/aabbTree.ts:195


raycast

โ–ธ raycast(ray): AABB[]

Raycasts against aabbs in the tree.

Parameters

NameTypeDescription
rayRayThe ray to cast.

Returns

AABB[]

Defined in

src/physics/aabb/aabbTree.ts:219


remove

โ–ธ remove(obj): void

Removes the leaf node containing the AABB bounding the given CollisionObject.

Parameters

NameTypeDescription
objCollisionObjectThe CollisionObject to remove

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:260


removeNode

โ–ธ Private removeNode(node): void

Remove the given node and replace the parent with the node's sibling

Parameters

NameTypeDescription
nodeAABBNodeThe node to remove

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:323


update

โ–ธ update(): void

Updates the tree.

Returns

void

Defined in

src/physics/aabb/aabbTree.ts:36


updateAABBMargin

โ–ธ Private updateAABBMargin(leaf, force?): number | false

Updates a leaf node's aabb's margin based on the aabb's bound CollisionObject.

Parameters

NameTypeDefault valueDescription
leafAABBNodeundefinedThe leaf node to update
forcebooleanfalseForce the margin to be updated even when there is an insufficient margin difference

Returns

number | false

The new margin or false if the margin wasn't updated.

Defined in

src/physics/aabb/aabbTree.ts:90