Files
addr2line
adler
adler32
ahash
aho_corasick
angle
approx
backtrace
bitflags
blender
bytemuck
byteorder
case
cast_trait
cfg_if
chrono
color
color_quant
const_fn
crc32fast
crossbeam
crossbeam_channel
crossbeam_deque
crossbeam_epoch
crossbeam_queue
crossbeam_skiplist
crossbeam_utils
darling
darling_core
darling_macro
dds
deflate
densevec
derive_builder
derive_builder_core
dot
downcast_rs
dual_quat
either
erased_serde
failure
failure_derive
fixedbitset
float_cmp
fnv
freeimage
freeimage_sys
freetype
freetype_gl_sys
freetype_sys
freetypegl
futures
futures_channel
futures_core
futures_executor
futures_io
futures_macro
futures_sink
futures_task
futures_util
async_await
future
io
lock
sink
stream
task
fxhash
generational_arena
generic_array
getrandom
gif
gimli
glfw
glfw_sys
glin
glin_derive
glsl
half
harfbuzz
harfbuzz_ft_sys
harfbuzz_sys
hashbrown
human_sort
ident_case
image
indexmap
instant
itertools
itoa
jpeg_decoder
lazy_static
libc
libm
lock_api
log
lut_parser
matrixmultiply
memchr
memoffset
meshopt
miniz_oxide
monotonic_clock
mopa
mutiny_derive
na
nalgebra
base
geometry
linalg
ncollide3d
bounding_volume
interpolation
partitioning
pipeline
procedural
query
algorithms
closest_points
contact
distance
nonlinear_time_of_impact
point
proximity
ray
time_of_impact
visitors
shape
transformation
utils
nom
num_complex
num_cpus
num_integer
num_iter
num_rational
num_traits
numext_constructor
numext_fixed_uint
numext_fixed_uint_core
numext_fixed_uint_hack
object
once_cell
parking_lot
parking_lot_core
pathfinding
pennereq
petgraph
pin_project_lite
pin_utils
png
polygon2
ppv_lite86
proc_macro2
proc_macro_crate
proc_macro_hack
proc_macro_nested
quote
rand
rand_chacha
rand_core
rand_distr
raw_window_handle
rawpointer
rayon
rayon_core
rect_packer
regex
regex_syntax
retain_mut
rin
rin_app
rin_blender
rin_core
rin_gl
rin_graphics
rin_gui
rin_material
rin_math
rin_postpo
rin_scene
rin_util
rin_window
rinblender
rinecs
rinecs_derive
rinecs_derive_utils
ringui_derive
rustc_demangle
rusty_pool
ryu
scopeguard
seitan
seitan_derive
semver
semver_parser
serde
serde_derive
serde_json
shaderdata_derive
simba
slab
slice_of_array
slotmap
smallvec
std140_data
streaming_iterator
strsim
syn
synstructure
thiserror
thiserror_impl
thread_local
tiff
time
toml
typenum
unchecked_unwrap
unicode_xid
vec2
vec3
weezl
x11
zlib_sys
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use na::RealField;

use crate::bounding_volume::{BoundingVolume, AABB};
use crate::math::Isometry;
use crate::pipeline::broad_phase::{BroadPhase, BroadPhaseProxyHandle, DBVTBroadPhase};
use crate::pipeline::narrow_phase::{
    CollisionObjectGraphIndex, DefaultContactDispatcher, DefaultProximityDispatcher,
    InteractionGraph, NarrowPhase,
};
use crate::pipeline::object::{CollisionObjectHandle, GeometricQueryType};
use crate::shape::Shape;

/// Registers a collision object handle so it can be taken into acconut by the broad-phase and the narrow-phase.
///
/// This tells the broad-phase and the interaction graph exists and allow them to perform some setup to accomodate
/// for a new collision object with the given `handle`, and known to currently have the given `position`, `shape` and `query_type`.
/// The result of this registration is a pair of handles that must be stored by the user as the will be needed for various
/// queries (on the broad-phase and interaction graph), as well as for freeing (using `remove_proxies`) the resources allocated here.
pub fn create_proxies<'a, N: RealField, Handle: CollisionObjectHandle>(
    handle: Handle,
    broad_phase: &mut (impl BroadPhase<N, AABB<N>, Handle> + ?Sized),
    interactions: &mut InteractionGraph<N, Handle>,
    position: &Isometry<N>,
    shape: &(impl Shape<N> + ?Sized),
    query_type: GeometricQueryType<N>,
) -> (BroadPhaseProxyHandle, CollisionObjectGraphIndex) {
    let mut aabb = shape.aabb(position);
    aabb.loosen(query_type.query_limit());

    let proxy_handle = broad_phase.create_proxy(aabb, handle);
    let graph_index = interactions.add_node(handle);

    (proxy_handle, graph_index)
}

/// Free all the resources allocated by the broad-phase and the interaction graph for the given proxy handles.
///
/// This will free the resoruces allocated by the `create_proxies` function. A special care should be
/// taken with the return value of this function.
///
/// # Return (important, please read)
///
/// Thus function either returns `None` or a pair composed of a collision object handle and a collision object graph index.
/// If `None` is returned, no extra work is required from the caller. If `Some` is returned, the it is necessary that
/// the collision object graph index of the collider identified by the returned handle is replaced by the returned
/// collision object graph index. This is caused by the fact that the indices used by the interaction graph to identify
///  collision objects are not stable wrt. the deletion of collision objects. Therefore, removing one collision object can
/// result in the collision object graph index of another collision object to be changed.
#[must_use = "The graph index of the collision object returned by this method has been changed to the returned graph index."]
pub fn remove_proxies<'a, N: RealField, Handle: CollisionObjectHandle>(
    broad_phase: &mut (impl BroadPhase<N, AABB<N>, Handle> + ?Sized),
    interactions: &mut InteractionGraph<N, Handle>,
    proxy_handle: BroadPhaseProxyHandle,
    graph_index: CollisionObjectGraphIndex,
) -> Option<(Handle, CollisionObjectGraphIndex)> {
    // NOTE: no need to notify handle the removed pairs because the node
    // will be removed from the interaction graph anyway.
    broad_phase.remove(&[proxy_handle], &mut |_, _| {});
    interactions
        .remove_node(graph_index)
        .map(|h| (h, graph_index))
}

/// Allocate a default narrow-phase, configured with the default contact and proximity dispatchers.
pub fn default_narrow_phase<N: RealField, Handle: CollisionObjectHandle>() -> NarrowPhase<N, Handle>
{
    let coll_dispatcher = Box::new(DefaultContactDispatcher::new());
    let prox_dispatcher = Box::new(DefaultProximityDispatcher::new());
    NarrowPhase::new(coll_dispatcher, prox_dispatcher)
}

/// Allocate a default broad-phase, configured with a default coherence margin (set to 0.01).
pub fn default_broad_phase<N: RealField, Handle: CollisionObjectHandle>(
) -> DBVTBroadPhase<N, AABB<N>, Handle> {
    let default_margin = 0.01f64;
    DBVTBroadPhase::new(na::convert(default_margin))
}

/// Allocate a default interaction graph.
pub fn default_interaction_graph<N: RealField, Handle: CollisionObjectHandle>(
) -> InteractionGraph<N, Handle> {
    InteractionGraph::new()
}