scene_queries_intersection_test
Intersection tests will find all the colliders with a shape intersecting a given shape. This can be useful for, e.g., selecting all the objects that intersect a given area. There are two kind of intersection tests:
- The exact intersection test
QueryPipeline::intersections_with_shapesearches for all the colliders with shapes intersecting the given shape. - The approximate intersection test
QueryPipeline::colliders_with_aabb_intersecting_aabbsearches for all the colliders with an AABB intersecting the given AABB. This does not check if the actual shapes of these colliders intersect the AABB.
info
See the ray-casting section for details about intersection tests between a ray and the colliders on the scene. And see the point projection section for details about the intersection test between the colliders and a point.
- Example 2D
- Example 3D
let shape = Cuboid::new(vector![1.0, 2.0]);
let shape_pos = Isometry::new(vector![0.0, 1.0], 0.2);
let filter = QueryFilter::default();
let query_pipeline = broad_phase.as_query_pipeline(
narrow_phase.query_dispatcher(),
rigid_body_set,
collider_set,
filter,
);
for (handle, _) in query_pipeline.intersect_shape(shape_pos, &shape) {
println!("The collider {:?} intersects our shape.", handle);
}
let aabb = Aabb::new(point![-1.0, -2.0], point![1.0, 2.0]);
for (handle, _) in query_pipeline.intersect_aabb_conservative(aabb) {
println!("The collider {:?} has an AABB intersecting our test AABB", handle);
}
let shape = Cuboid::new(vector![1.0, 2.0, 3.0]);
let shape_pos = Isometry::new(vector![0.0, 1.0, 0.0], vector![0.2, 0.7, 0.1]);
let filter = QueryFilter::default();
let query_pipeline = broad_phase.as_query_pipeline(
narrow_phase.query_dispatcher(),
rigid_body_set,
collider_set,
filter,
);
for (handle, _) in query_pipeline.intersect_shape(shape_pos, &shape) {
println!("The collider {:?} intersects our shape.", handle);
}
let aabb = Aabb::new(point![-1.0, -2.0, -3.0], point![1.0, 2.0, 3.0]);
for (handle, _) in query_pipeline.intersect_aabb_conservative(aabb) {
println!("The collider {:?} has an AABB intersecting our test AABB", handle);
}
It is possible to only apply the scene query to a subsets of the colliders using a query filter