pub struct QueryOptions {
pub max_distance: f32,
pub layers: u32,
pub ignored_body: Option<RigidBodyHandle>,
pub sensors: SensorPolicy,
}Expand description
Reusable distance and filtering options for casts and direct overlap queries.
Construct with an explicit maximum distance; the initial policy queries all
membership layers, excludes sensors, and ignores no body. Builder methods
can be chained, or the named fields can be edited directly. Invalid numeric
inputs are rejected without changing the world: nearest casts return None,
while caller-buffer casts return QueryError.
use ferravex_physics::d3::{PhysicsWorld, QueryOptions};
let mut world = PhysicsWorld::default();
let player = world.add_ball([0.; 3], 0.5, true);
let wall = world.add_box([5., 0., 0.], [0.5; 3], false);
let options = QueryOptions::new(10.).layers(0b10).ignore_body(player);
let hit = world.raycast_with_options([0.; 3], [1., 0., 0.], options).unwrap();
assert_eq!(hit.body, Some(wall));
// Reuse the same filters for a camera-volume sweep.
let camera = world.spherecast_with_options([0.; 3], [1., 0., 0.], 0.25, options)
.unwrap();
assert!(camera.distance < hit.distance);Fields§
§max_distance: f32Maximum travel distance for casts, or maximum signed separation for direct overlap queries, in world units. Finite and nonnegative.
layers: u32A collider participates when its membership intersects these bits. Its collision-response filter is not consulted. Zero matches nothing.
ignored_body: Option<RigidBodyHandle>Exclude all compound children of this body. A removed handle does not exclude a new body that later reuses the same slot.
sensors: SensorPolicyWhether sensors, solid colliders, or both can be hit.
Implementations§
Source§impl QueryOptions
impl QueryOptions
Sourcepub const fn new(max_distance: f32) -> QueryOptions
pub const fn new(max_distance: f32) -> QueryOptions
Query up to max_distance world units with all layers and no sensors.
The query validates the distance, so construction does not panic.
Sourcepub const fn layers(self, mask: u32) -> QueryOptions
pub const fn layers(self, mask: u32) -> QueryOptions
Select collider membership bits; this has the same meaning as the
original PhysicsWorld::spherecast mask argument.
Sourcepub const fn ignore_body(self, body: RigidBodyHandle) -> QueryOptions
pub const fn ignore_body(self, body: RigidBodyHandle) -> QueryOptions
Exclude a body and all its compound children. Handles must come from the queried world; they do not encode a world identity.
Sourcepub const fn sensors(self, policy: SensorPolicy) -> QueryOptions
pub const fn sensors(self, policy: SensorPolicy) -> QueryOptions
Select sensors independently of the layer and body filters.
use ferravex_physics::d2::{
ColliderBuilder, PhysicsWorld, QueryOptions, RigidBodyBuilder, SensorPolicy,
};
let mut world = PhysicsWorld::default();
let (trigger, _) = world.insert(
RigidBodyBuilder::fixed(), ColliderBuilder::ball(1.).sensor(true),
);
let options = QueryOptions::new(5.).sensors(SensorPolicy::Only);
let hit = world.raycast_with_options([-3., 0.], [1., 0.], options).unwrap();
assert_eq!(hit.body, Some(trigger));Trait Implementations§
Source§impl Clone for QueryOptions
impl Clone for QueryOptions
Source§fn clone(&self) -> QueryOptions
fn clone(&self) -> QueryOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more