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
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.
Parameters
- Libraries.Language.Object: The object to compare to.
Return
integer: The Compare result, Smaller, Equal, or Larger.
Example
Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)
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.
Parameters
- Libraries.Game.Collision.BoundingBox2D: The BoundingBox2D of the item to be inserted into the tree.
- Libraries.Game.Collision.Item2DNode: The ItemNode2D of the item being inserted into the tree.
Return
integer: The integer id of the new tree node
Example
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)
DestroyNode(integer id)
This action removes from the Dynamic Bounding Volume Tree the node with the given node ID. This action is used internally.
Parameters
- integer id: The integer id number for the node which is to be removed
Example
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."
Equals(Libraries.Language.Object object)
This action determines if two objects are equal based on their hash code values.
Parameters
- Libraries.Language.Object: The to be compared.
Return
boolean: True if the hash codes are equal and false if they are not equal.
Example
use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)
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.
Parameters
- integer id: The integer id of the tree node containing the BoundingBox2D to be returned
Return
Libraries.Game.Collision.BoundingBox2D: the specified BoundingBox2D
Example
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)
GetHashCode()
This action gets the hash code for an object.
Return
integer: The integer hash code of the object.
Example
Object o
integer hash = o:GetHashCode()
GetItemNode(integer id)
This action returns the Item2DNode contained in the tree node with the given ID This is an internal action.
Parameters
- integer id: The integer id of the tree node containing the Item2DNode to be returned
Return
Libraries.Game.Collision.Item2DNode: The specified Item2DNode
Example
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)
GetNodeCount()
This action returns the number of nodes in the dynamic bounding volume tree. This action is used internally.
Return
integer: the number of nodes in the tree
Example
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."
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
Return
integer: the height of the tree
Example
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()
GetTreeQuality()
This action computes the quality of the tree (the ratio of the sum of the node perimeters to the root perimeter).
Return
number: the perimeter ratio of the tree
Example
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()
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.
Parameters
- integer id: The id of the node that is to be moved.
- Libraries.Game.Collision.BoundingBox2D: The boundingBox of the node to be moved.
- Libraries.Compute.Vector2: The displacement of the 2D object.
Example
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)
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.
Parameters
- Libraries.Game.Collision.BroadphaseCollision2D: The BroadphaseCollision2D which contains the tree to check the BoundingBox2D against
- Libraries.Game.Collision.BoundingBox2D: The BoundingBox2D we are checking for overlap with
Example
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)
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.
Parameters
- integer id: The integer id of the node to be paired
Return
boolean: whether the should proceed (always true)
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)
boolean result = broadphase:ShouldProceed(id2)
TestOverlap(integer idA, integer idB)
This action checks to see if the bounding boxes of two nodes overlap. This action is used internally.
Parameters
- integer idA: The integer id of one of the nodes to be checked.
- integer idB: The integer id of the other node to be checked.
Return
boolean: a boolean value that indicates whether the two nodes overlap.
Example
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
TouchNode(integer nodeID)
This action adds the node with the given id to the move list. This action is used internally.
Parameters
- integer nodeID: The id of the node to be touched.
Example
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)
UpdatePairs(Libraries.Game.Collision.CollisionManager2D collision)
This action updates the list of collideable pairs from the tree. This action is used internally
Parameters
- Libraries.Game.Collision.CollisionManager2D: The CollisionManager2D containing the relevant collision information.
Example
use Libraries.Game.Collision.BroadphaseCollision2D
use Libraries.Game.Collision.CollisionManager2D
BroadphaseCollision2D broadphase
CollisionManager2D collision
broadphase:UpdatePairs(collision)
On this page
Variables TableAction Documentation- Compare(Libraries.Language.Object object)
- CreateNode(Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Game.Collision.Item2DNode item)
- DestroyNode(integer id)
- Equals(Libraries.Language.Object object)
- GetBoundingBox(integer id)
- GetHashCode()
- GetItemNode(integer id)
- GetNodeCount()
- GetTreeBalance()
- GetTreeHeight()
- GetTreeQuality()
- MoveNode(integer id, Libraries.Game.Collision.BoundingBox2D boundingBox, Libraries.Compute.Vector2 displacement)
- Query(Libraries.Game.Collision.BroadphaseCollision2D broadphase, Libraries.Game.Collision.BoundingBox2D boundingBox)
- ShouldProceed(integer id)
- TestOverlap(integer idA, integer idB)
- TouchNode(integer nodeID)
- UpdatePairs(Libraries.Game.Collision.CollisionManager2D collision)