Libraries.Game.Collision.BroadphaseCollision2D Documentation

BroadphaseCollison2D computes collision pairs. Pairs are generated for collideable objects that may touch. This class contains a DynamicBoundingVolumeTree2D which it uses to compute the pairs. This class is used for interactions with that tree. This class is used internally by CollisonManager2D.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
use Libraries.Game.Collision.BoundingBox2D
use Libraries.Game.Collision.Item2DNode
use Libraries.Compute.Vector2

    BroadphaseCollision2D broadphase
    BoundingBox2D boundingBox1
    BoundingBox2D boundingBox2
    BoundingBox2D boundingBox3

    Item2DNode item1
    Item2DNode item2
    Item2DNode item3

    BoundingBox2D queryBox
    Vector2 minimum
    Vector2 maximum

    integer id1 = broadphase:CreateNode(boundingBox1, item1)
    integer id2 = broadphase:CreateNode(boundingBox2, item2)
    integer id3 = broadphase:CreateNode(boundingBox3, item3)

    minimum:Set(-1,-1)
    maximum:Set(1,1)
    queryBox:Set(minimum, maximum)

    broadphase:Query(broadphase, queryBox)

Inherits from: Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
CreateNode(Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Game.Collision.Item2DNode item)This action creates a new node for the Dynamic Bounding Volume Tree with the given BoundingBox and given Item and inserts the new node as a leaf in the tree.
DestroyNode(integer id)This action removes from the Dynamic Bounding Volume Tree the node with the given node ID.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetBoundingBox(integer id)This action returns the bounding box contained in the tree node with the given ID.
GetHashCode()This action gets the hash code for an object.
GetItemNode(integer id)This action returns the Item2DNode contained in the tree node with the given ID This is an internal action.
GetNodeCount()This action returns the number of nodes in the dynamic bounding volume tree.
GetTreeBalance()This action computes the maximum balance of the tree.
GetTreeHeight()This action returns the height of the tree
GetTreeQuality()This action computes the quality of the tree (the ratio of the sum of the node perimeters to the root perimeter).
MoveNode(integer id, Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Compute.Vector2 displacement)This action moves the Item2D contained in the tree node with the given node ID by the given displacement vector.
Query(Libraries.Game.Collision.BroadphaseCollision2D broadphase, Libraries.Game.Collision.BoundingBox2D boundingBox)This action queries the tree for bounding boxes that overlap with the given bounding box.
ShouldProceed(integer id)This action adds the given node to the pair list with the query node, if the given node is not the query node.
TestOverlap(integer idA, integer idB)This action checks to see if the bounding boxes of two nodes overlap.
TouchNode(integer nodeID)This action adds the node with the given id to the move list.
UpdatePairs(Libraries.Game.Collision.CollisionManager2D collision)This action updates the list of collideable pairs from the tree.

Actions Documentation

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

Object o
        Object t
        integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

CreateNode(Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Game.Collision.Item2DNode item)

This action creates a new node for the Dynamic Bounding Volume Tree with the given BoundingBox and given Item and inserts the new node as a leaf in the tree. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox

        Item2DNode item

        output "This item was added to node number " + broadphase:CreateNode(boundingBox, item)

Parameters

Return

integer: The integer id of the new tree node

DestroyNode(integer id)

This action removes from the Dynamic Bounding Volume Tree the node with the given node ID. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox

        Item2DNode item
        integer id = broadphase:CreateNode(boundingBox, item)
        output "This item was added to node number " + id

        broadphase:DestroyNode(id)
        output "Node number " + id + " was removed from the tree."

Parameters

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetBoundingBox(integer id)

This action returns the bounding box contained in the tree node with the given ID. Note that this bounding box is slightly larger than the bounding box of the item contained in this node. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2

        Item2DNode item1
        Item2DNode item2

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)

        BoundingBox2D result
        result = broadphase:GetBoundingBox(id2)

Parameters

Return

Libraries.Game.Collision.BoundingBox2D: the specified BoundingBox2D

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetItemNode(integer id)

This action returns the Item2DNode contained in the tree node with the given ID This is an internal action.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2

        Item2DNode item1
        Item2DNode item2

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)

        Item2DNode result
        result = broadphase:GetItemNode(id2)

Parameters

Return

Libraries.Game.Collision.Item2DNode: The specified Item2DNode

GetNodeCount()

This action returns the number of nodes in the dynamic bounding volume tree. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2

        Item2DNode item1
        Item2DNode item2

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)


        output "There are " + broadphase:GetNodeCount() + " nodes in the tree."

Return

integer: the number of nodes in the tree

GetTreeBalance()

This action computes the maximum balance of the tree. The maximum balance is the maximum difference of the heights of the two children of any node. Attributes: Returns the maximum balance of the tree Atributes: Example use Libraries.Game.Collision.BroadphaseCollision2D use Libraries.Game.Collision.BoundingBox2D use Libraries.Game.Collision.Item2DNode BroadphaseCollision2D broadphase BoundingBox2D boundingBox1 BoundingBox2D boundingBox2 BoundingBox2D boundingBox3 Item2DNode item1 Item2DNode item2 Item2DNode item3 integer id1 = broadphase:CreateNode(boundingBox1, item1) integer id2 = broadphase:CreateNode(boundingBox2, item2) integer id3 = broadphase:CreateNode(boundingBox3, item3) output "Tree has maximum balance " + broadphase:GetTreeBalance()

Return

integer:

GetTreeHeight()

This action returns the height of the tree

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2

        Item2DNode item1
        Item2DNode item2

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)
        output "Tree has height " + broadphase:GetTreeHeight()

        broadphase:DestroyNode(id2)
        output "After removing node 2 , tree has height " + broadphase:GetTreeHeight()

Return

integer: the height of the tree

GetTreeQuality()

This action computes the quality of the tree (the ratio of the sum of the node perimeters to the root perimeter).

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode
    use Libraries.Compute.Vector2

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2

        Vector2 minimum1
        Vector2 minimum2
        Vector2 maximum1
        Vector2 maximum2

        minimum1:Set(0, 0)
        minimum2:Set(0.5, 0.5)
        maximum1:Set(1, 1)
        maximum2:Set(1.5, 1.5)
        boundingBox1:Set(minimum1, maximum1)
        boundingBox2:Set(minimum2, maximum2)

        Item2DNode item1
        Item2DNode item2

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)
    
        output "The perimeter ratio is " + tree:GetPerimeterRatio()

Return

number: the perimeter ratio of the tree

MoveNode(integer id, Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Compute.Vector2 displacement)

This action moves the Item2D contained in the tree node with the given node ID by the given displacement vector. If the node moves outside of its existing bounding box, then the object is removed from the tree, a new bounding box is calculated, and it is reinserted into the tree. Otherwise, the node is left where it is in the tree. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode
    use Libraries.Compute.Vector2

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox
        Vector2 displacement

        Item2DNode item
        integer id = broadphase:CreateNode(boundingBox, item)
        output "This item was added to node number " + id

        displacement:Set(1, 5)
        broadphase:MoveNode(id, boundingBox, displacement)

Parameters

Query(Libraries.Game.Collision.BroadphaseCollision2D broadphase, Libraries.Game.Collision.BoundingBox2D boundingBox)

This action queries the tree for bounding boxes that overlap with the given bounding box.

Example Code

use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode
    use Libraries.Compute.Vector2
    use Libraries.Game.Collision.BroadphaseCollision2D

        BroadphaseCollision2D broadphase

        BoundingBox2D overlap
        Vector2 minimumOverlap
        Vector2 maximumOverlap
        minimumOverlap:Set(-1.5, -1.5)
        maximumOverlap:Set(-0.5, -0.5)
        overlap:Set(minimumOverlap, maximumOverlap)

        tree:Query(broadphase, overlap)

Parameters

ShouldProceed(integer id)

This action adds the given node to the pair list with the query node, if the given node is not the query node. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2
        BoundingBox2D boundingBox3

        Item2DNode item1
        Item2DNode item2
        Item2DNode item3

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)
        integer id3 = broadphase:CreateNode(boundingBox3, item3)

        boolean result = broadphase:ShouldProceed(id2)

Parameters

Return

boolean: whether the should proceed (always true)

TestOverlap(integer idA, integer idB)

This action checks to see if the bounding boxes of two nodes overlap. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox1
        BoundingBox2D boundingBox2

        Item2DNode item1
        Item2DNode item2

        integer id1 = broadphase:CreateNode(boundingBox1, item1)
        integer id2 = broadphase:CreateNode(boundingBox2, item2)

        boolean result = false
        result = broadphase:TestOverlap(id1, id2)
        if result
            output "Nodes " + id1 + " and " + id2 + " overlap."
        else
            output "No overlap."
        end

Parameters

Return

boolean: a boolean value that indicates whether the two nodes overlap.

TouchNode(integer nodeID)

This action adds the node with the given id to the move list. This action is used internally.

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.BoundingBox2D
    use Libraries.Game.Collision.Item2DNode

        BroadphaseCollision2D broadphase
        BoundingBox2D boundingBox

        Item2DNode item
        integer id = broadphase:CreateNode(boundingBox, item)

        broadphase:TouchNode(id)

Parameters

UpdatePairs(Libraries.Game.Collision.CollisionManager2D collision)

This action updates the list of collideable pairs from the tree. This action is used internally

Example Code

use Libraries.Game.Collision.BroadphaseCollision2D
    use Libraries.Game.Collision.CollisionManager2D

        BroadphaseCollision2D broadphase
        CollisionManager2D collision

        broadphase:UpdatePairs(collision)

Parameters