Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DynamicTree

The DynamicTrees provides a spatial partiioning data structure for quickly querying for overlapping bounding boxes for all tracked bodies. The worst case performance of this is O(n*log(n)) where n is the number of bodies in the tree.

Internally the bounding boxes are organized as a balanced binary tree of bounding boxes, where the leaf nodes are tracked bodies. Every non-leaf node is a bounding box that contains child bounding boxes.

Hierarchy

  • DynamicTree

Index

Constructors

constructor

  • Parameters

    • Default value worldBounds: BoundingBox = new ex.BoundingBox(-Number.MAX_VALUE,-Number.MAX_VALUE,Number.MAX_VALUE,Number.MAX_VALUE)

    Returns DynamicTree

Properties

nodes

nodes: object

Type declaration

root

root: TreeNode

worldBounds

worldBounds: BoundingBox

Methods

Private _balance

  • Balances the tree about a node

    Parameters

    Returns TreeNode

Private _insert

  • Inserts a node into the dynamic tree

    Parameters

    Returns void

Private _remove

  • Removes a node from the dynamic tree

    Parameters

    Returns void

debugDraw

  • debugDraw(ctx: CanvasRenderingContext2D, delta: number): void
  • Parameters

    • ctx: CanvasRenderingContext2D
    • delta: number

    Returns void

getHeight

  • getHeight(): number
  • Returns the internal height of the tree, shorter trees are better. Performance drops as the tree grows

    Returns number

getNodes

  • Returns TreeNode[]

query

  • query(body: Body, callback: function): void
  • Queries the Dynamic Axis Aligned Tree for bodies that could be colliding with the provided body.

    In the query callback, it will be passed a potential collider. Returning true from this callback indicates that you are complete with your query and you do not want to continue. Returning false will continue searching the tree until all possible colliders have been returned.

    Parameters

    • body: Body
    • callback: function
        • (other: Body): boolean
        • Parameters

          Returns boolean

    Returns void

rayCastQuery

  • rayCastQuery(ray: Ray, max?: number, callback: function): void
  • Queries the Dynamic Axis Aligned Tree for bodies that could be intersecting. By default the raycast query uses an infinitely long ray to test the tree specified by max.

    In the query callback, it will be passed a potential body that intersects with the racast. Returning true from this callback indicates that your are complete with your query and do not want to continue. Return false will continue searching the tree until all possible bodies that would intersect with the ray have been returned.

    Parameters

    • ray: Ray
    • Default value max: number = Infinity
    • callback: function
        • (other: Body): boolean
        • Parameters

          Returns boolean

    Returns void

trackBody

  • trackBody(body: Body): void
  • Tracks a body in the dynamic tree

    Parameters

    Returns void

untrackBody

  • untrackBody(body: Body): void
  • Untracks a body from the dynamic tree

    Parameters

    Returns void

updateBody

  • updateBody(body: Body): boolean
  • Updates the dynamic tree given the current bounds of each body being tracked

    Parameters

    Returns boolean