Skip to content

lukebitts/aabb-tree

Repository files navigation

Build Status

aabb-tree

Documentation

This crate is the implementation of a dynamic bounding volume tree based on axis aligned bounding boxes. It is a spatial structure with support for querying objects based on their position and size inside the tree. This work is based on Presson's btDbvt written for Bullet Physics and Catto's b2DynamicTree written for Box2D.

Example

extern crate aabb_tree;

use aabb_tree::{AabbTree};

fn main() {
	// Creates a new `AabbTree` where the elements are `i32`s.
	let mut tree : AabbTree<i32> = AabbTree::new();

	// `AabbTree::create_proxy` creates a proxy for an element. Here we are adding the number 0 to the
	// tree in the position (0, 0, 0) with a size of 2³.
	tree.create_proxy(((-1.0, -1.0, -1.0), (1.0, 1.0, 1.0)), 0);

	// `AabbTree::query_aabb` finds every node inside the AABB ((-10.0, -10.0, -10.0), (10.0, 10.0, 10.0))
	// and calls a callback for each result. The callback function returns
	// a `boolean` indicating whether the search should continue or not.
	tree.query_aabb(&((-10.0, -10.0, -10.0), (10.0, 10.0, 10.0)), |proxy|{
		assert_eq!(tree.user_data(proxy), Some(&0));
		true
	});
}

About

A dynamic bounding volume tree based on axis aligned bounding boxes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages