Struct box2d_rs::b2_dynamic_tree::B2dynamicTree
source · pub struct B2dynamicTree<UserDataType> { /* private fields */ }
Expand description
A dynamic AABB tree broad-phase, inspired by Nathanael Presson’s btDbvt. A dynamic tree arranges data in a binary tree to accelerate queries such as volume queries and ray casts. Leafs are proxies with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor so that the proxy AABB is bigger than the client object. This allows the client object to move by small amounts without triggering a tree update.
Nodes are pooled and relocatable, so we use node indices rather than pointers.
Implementations§
source§impl<UserDataType: Clone + Default> B2dynamicTree<UserDataType>
impl<UserDataType: Clone + Default> B2dynamicTree<UserDataType>
sourcepub fn create_proxy(&mut self, aabb: B2AABB, user_data: &UserDataType) -> i32
pub fn create_proxy(&mut self, aabb: B2AABB, user_data: &UserDataType) -> i32
destroy the tree, freeing the node pool. create a proxy. Provide a tight fitting AABB and a user_data pointer.
sourcepub fn destroy_proxy(&mut self, proxy_id: i32)
pub fn destroy_proxy(&mut self, proxy_id: i32)
destroy a proxy. This asserts if the id is invalid.
sourcepub fn move_proxy(
&mut self,
proxy_id: i32,
aabb1: B2AABB,
displacement: B2vec2
) -> bool
pub fn move_proxy( &mut self, proxy_id: i32, aabb1: B2AABB, displacement: B2vec2 ) -> bool
Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately.
@return true if the proxy was re-inserted.
sourcepub fn get_user_data(&self, proxy_id: i32) -> Option<UserDataType>
pub fn get_user_data(&self, proxy_id: i32) -> Option<UserDataType>
Get proxy user data.
@return the proxy user data or 0 if the id is invalid.
pub fn was_moved(&self, proxy_id: i32) -> bool
pub fn clear_moved(&mut self, proxy_id: i32)
sourcepub fn get_fat_aabb(&self, proxy_id: i32) -> B2AABB
pub fn get_fat_aabb(&self, proxy_id: i32) -> B2AABB
Get the fat AABB for a proxy.
sourcepub fn query<F: QueryCallback>(&self, callback: F, aabb: B2AABB)
pub fn query<F: QueryCallback>(&self, callback: F, aabb: B2AABB)
query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.
sourcepub fn ray_cast<T: RayCastCallback>(&self, callback: T, input: &B2rayCastInput)
pub fn ray_cast<T: RayCastCallback>(&self, callback: T, input: &B2rayCastInput)
Ray-cast against the proxies in the tree. This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree.
input
- the ray-cast input data. The ray extends from p1 to p1 + max_fraction * (p2 - p1).callback
- a callback class that is called for each proxy that is hit by the ray.
sourcepub fn get_height(&self) -> i32
pub fn get_height(&self) -> i32
Compute the height of the binary tree in O(n) time. Should not be called often.
sourcepub fn get_max_balance(&self) -> i32
pub fn get_max_balance(&self) -> i32
Get the maximum balance of an node in the tree. The balance is the difference in height of the two children of a node.
sourcepub fn get_area_ration(&self) -> f32
pub fn get_area_ration(&self) -> f32
Get the ratio of the sum of the node areas to the root area.
sourcepub fn rebuild_bottom_up(&mut self)
pub fn rebuild_bottom_up(&mut self)
Build an optimal tree. Very expensive. For testing.
sourcepub fn shift_origin(&mut self, new_origin: B2vec2)
pub fn shift_origin(&mut self, new_origin: B2vec2)
Shift the world origin. Useful for large worlds. The shift formula is: position -= new_origin
new_origin
- the new origin with respect to the old origin
Trait Implementations§
source§impl<UserDataType: Clone> Clone for B2dynamicTree<UserDataType>
impl<UserDataType: Clone> Clone for B2dynamicTree<UserDataType>
source§fn clone(&self) -> B2dynamicTree<UserDataType>
fn clone(&self) -> B2dynamicTree<UserDataType>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more