Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/azrafe7/hxaabbtree
Haxe dynamic AABB tree.
https://github.com/azrafe7/hxaabbtree
Last synced: 11 days ago
JSON representation
Haxe dynamic AABB tree.
- Host: GitHub
- URL: https://github.com/azrafe7/hxaabbtree
- Owner: azrafe7
- License: mit
- Created: 2014-06-07T19:15:09.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-18T23:27:53.000Z (over 10 years ago)
- Last Synced: 2024-11-05T13:22:38.938Z (about 2 months ago)
- Language: Haxe
- Size: 355 KB
- Stars: 19
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
AABBTree
========Haxe dynamic [AABB tree](http://en.wikipedia.org/wiki/Bounding_volume_hierarchy) for spatial partitioning and query.
- fast insertion/removal/update
- supports both AABB and raycast type of queries (with filtering callbacks)
- easy to use and highly customizable (fattening factor, pool properties, insert strategies, etc.)
- extendable debug renderer to visualize build steps
- no dependenciesCheck the [demo](https://dl.dropboxusercontent.com/u/32864004/dev/FPDemo/AABBTreeTest01.swf):
![](screenshot.png)
###AS3 PORT
A port to as3 can be found here: [https://github.com/azrafe7/as3AABBTree](https://github.com/azrafe7/as3AABBTree).###BASIC USAGE EXAMPLE
```haxe
// instances of this class will be stored in the tree
class Entity
{
public var id:Int = -1; // id to interact with the tree
public var mbr:AABB; // minimum bounding rect
public var type:String;
//...
public function new(type:String, x:Float, y:Float, width:Float, height:Float)
{
this.type = type;
mbr = new AABB(x, y, width, height);
//...
}
}//...
// create the tree and add a bunch of entities to it
var tree = new AABBTree();
for (i in 0...50) {
var type = (i % 2 == 0) ? "type_one" : "type_two";
var entity = new Entity(type, some pos and size);
entity.id = tree.insertLeaf(entity, entity.mbr.x, entity.mbr.y, entity.mbr.width, entity.mbr.height);
}// update an entity (if its position or size changed)
tree.updateLeaf(entity.id, new pos and size);// remove an entity
tree.removeLeaf(entity.id);// get all entities in the tree
var entities = tree.getLeavesData();// ... or walk through them
for (entity in tree) {
do some stuff
}// query the tree for entities overlapping the rect (x:-100, y:-100, w:200, h:200)
var results = tree.query(x, y, w, h);// query the tree for entities _fully contained_ in the rect (x:-100, y:-100, w:200, h:200)
var results = tree.query(x, y, w, h, true);// query the tree for entities intersecting the ray from (0, 0) to (100, 100)
var results = tree.rayCast(0, 0, 100, 100);// query the tree for entities intersecting the ray from (0, 0) to (100, 100)
// use a callback for filtering by "type_two" and append results to prevResults array
function rayCallback(entity:Entity, id:Int):HitBehaviour {
return (entity.type == "type_two") ? HitBehaviour.INCLUDE : HitBehaviour.SKIP;
}tree.rayCast(0, 0, 100, 100, prevResults, rayCallback);
```###VALIDATION CHECKS
By default compiling in DEBUG mode will enable a series of tests to ensure the structure's validity (will affect performance), while in RELEASE mode they won't be executed.You can disable the validation by passing `-DNO_TREE_CHECKS` to the compiler, or forcefully enable it with `-DTREE_CHECKS`.
The `isValidationEnabled` property will be set consequently.
###CREDITS
The code is heavily inspired by the implementations of a dynamic AABB tree by- Nathanael Presson (Bullet Physics - [http://bulletphysics.org](http://bulletphysics.org))
- Erin Catto (Box2D - [http://www.box2d.org](http://www.box2d.org))###LICENSE
This lib is developed by Giuseppe Di Mauro (azrafe7) and released under the MIT license. See the LICENSE file for details.