ncollide3d/pipeline/glue/
setup.rs1use na::RealField;
2
3use crate::bounding_volume::{BoundingVolume, AABB};
4use crate::math::Isometry;
5use crate::pipeline::broad_phase::{BroadPhase, BroadPhaseProxyHandle, DBVTBroadPhase};
6use crate::pipeline::narrow_phase::{
7 CollisionObjectGraphIndex, DefaultContactDispatcher, DefaultProximityDispatcher,
8 InteractionGraph, NarrowPhase,
9};
10use crate::pipeline::object::{CollisionObjectHandle, GeometricQueryType};
11use crate::shape::Shape;
12
13pub fn create_proxies<'a, N: RealField + Copy, Handle: CollisionObjectHandle>(
20 handle: Handle,
21 broad_phase: &mut (impl BroadPhase<N, AABB<N>, Handle> + ?Sized),
22 interactions: &mut InteractionGraph<N, Handle>,
23 position: &Isometry<N>,
24 shape: &(impl Shape<N> + ?Sized),
25 query_type: GeometricQueryType<N>,
26) -> (BroadPhaseProxyHandle, CollisionObjectGraphIndex) {
27 let mut aabb = shape.aabb(position);
28 aabb.loosen(query_type.query_limit());
29
30 let proxy_handle = broad_phase.create_proxy(aabb, handle);
31 let graph_index = interactions.add_node(handle);
32
33 (proxy_handle, graph_index)
34}
35
36#[must_use = "The graph index of the collision object returned by this method has been changed to the returned graph index."]
50pub fn remove_proxies<'a, N: RealField + Copy, Handle: CollisionObjectHandle>(
51 broad_phase: &mut (impl BroadPhase<N, AABB<N>, Handle> + ?Sized),
52 interactions: &mut InteractionGraph<N, Handle>,
53 proxy_handle: BroadPhaseProxyHandle,
54 graph_index: CollisionObjectGraphIndex,
55) -> Option<(Handle, CollisionObjectGraphIndex)> {
56 broad_phase.remove(&[proxy_handle], &mut |_, _| {});
59 interactions
60 .remove_node(graph_index)
61 .map(|h| (h, graph_index))
62}
63
64pub fn default_narrow_phase<N: RealField + Copy, Handle: CollisionObjectHandle>(
66) -> NarrowPhase<N, Handle> {
67 let coll_dispatcher = Box::new(DefaultContactDispatcher::new());
68 let prox_dispatcher = Box::new(DefaultProximityDispatcher::new());
69 NarrowPhase::new(coll_dispatcher, prox_dispatcher)
70}
71
72pub fn default_broad_phase<N: RealField + Copy, Handle: CollisionObjectHandle>(
74) -> DBVTBroadPhase<N, AABB<N>, Handle> {
75 let default_margin = 0.01f64;
76 DBVTBroadPhase::new(na::convert(default_margin))
77}
78
79pub fn default_interaction_graph<N: RealField + Copy, Handle: CollisionObjectHandle>(
81) -> InteractionGraph<N, Handle> {
82 InteractionGraph::new()
83}