Game::Collisions::AABB
new({ x => 0, y => 0, length => 4, height => 6, user_data => ..., })
Constructor. user_data can be arbitrary data. Often, this will be the more complex object associated with this AABB.
user_data
If user_data inherits from Game::Collisions::UserData, then it will be called whenever the AABB is moved. This will happen after the AABB moves, but before the rest of the tree is updated.
Basic accessors for all the data.
Pass in the AABB object that will become the left node in the tree. Automatically sets the parent.
Pass in the AABB object that will become the right node in the tree. Automatically sets the parent.
Sets the user data.
Pass in the AABB object that will become the parent of this one. Does not set the left or right node on the parent.
Walks up the tree from this node to ensure all the parents are big enough to contain their children.
Pass in another AABB object. Returns true if it collides with this one.
Pass in another AABB object. Returns true if this object is big enough to completely enclose that object.
Pass in another AABB object that you plan to add to the tree. Searches the tree from this point down to find the best sibling for that object and returns it.
The definition of "best" is based on the surface area of each node. Less surface area is considered better as we're walking down the tree. In the future, this might take a subref that provides its own definition of "best".
Generally, this is only called on the root of the tree.
Returns true if this has either a left or right node.
Returns a string that textually represents the tree. Mainly for debugging.
Moves the AABB, making sure everything is still consistent in the tree after the move is done.
Passed a new AABB object that we want to add to the tree. Finds the best place for it (see find_best_sibling_node()) and puts it there.
find_best_sibling_node()
Walks the tree to see if we'd be more in balance if it were rotated. Returns -1 if we should be left-rotated, 1 if we should be right-rotated, and 0 if we're in balance and should stay how we are.
Removes this AABB from the tree. As long as you use this method to remove nodes, you shouldn't run into any memory leaks due to circular references.
To install Game::Collisions, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Game::Collisions
CPAN shell
perl -MCPAN -e shell install Game::Collisions
For more information on module installation, please visit the detailed CPAN module installation guide.