pub struct Sweep {
pub start: Vec3,
pub end: Vec3,
pub radius: f32,
}Expand description
A sphere-center segment. Equal endpoints perform a stationary overlap check.
Use Sweep::new to check inputs, or Sweep::probe to also check adapter
results and obtain distances and a padded placement.
Fields§
§start: Vec3§end: Vec3§radius: f32Implementations§
Source§impl Sweep
impl Sweep
Sourcepub fn new(start: Vec3, end: Vec3, radius: f32) -> Result<Sweep, CameraError>
pub fn new(start: Vec3, end: Vec3, radius: f32) -> Result<Sweep, CameraError>
Construct a checked probe with finite endpoints in [-1e6, 1e6] on
each axis and a finite radius in 0.001..=1000.
Invalid inputs return CameraError::InvalidQuery. Zero-length
segments are valid and must still be sent to the collision query.
use ferravex_math::Vec3;
use ferravex_play::camera::{CameraError, Sweep};
let point = Sweep::new(Vec3::ZERO, Vec3::ZERO, 0.25)?;
assert!(point.valid());
assert_eq!(Sweep::new(Vec3::ZERO, Vec3::Z, 0.),
Err(CameraError::InvalidQuery));pub fn valid(self) -> bool
Sourcepub fn probe(
self,
query: &(impl CollisionQuery + ?Sized),
padding: f32,
) -> Result<SweepOutcome, CameraError>
pub fn probe( self, query: &(impl CollisionQuery + ?Sized), padding: f32, ) -> Result<SweepOutcome, CameraError>
Run exactly one query and report travel available before the first hit.
padding is a finite distance in 0..=10, matching camera obstruction
settings. It retreats along the segment only when a hit is reported;
it does not enlarge the probe or change a clear endpoint. Zero padding
permits contact. A blocked start has no permitted placement: this
method does not depenetrate or search for an escape route.
Invalid sweep/padding or an invalid adapter fraction returns
CameraError::InvalidQuery; adapter errors propagate unchanged.
A stationary query still runs, and may return only None or Some(0).
Storage and query count are constant; slice adapters retain their
MAX_BLOCKERS budget. Custom adapters determine geometric accuracy.
use ferravex_math::Vec3;
use ferravex_play::camera::{Blocker, CameraError, NoObstructions, Sweep};
let sweep = Sweep::new(Vec3::ZERO, Vec3::Z * 10., 0.25)?;
let wall = [Blocker::Plane { normal: -Vec3::Z, offset: -5. }];
let hit = sweep.probe(&wall[..], 0.25)?;
assert_eq!(hit.requested_distance, 10.);
assert_eq!(hit.hit_fraction, Some(0.475));
assert_eq!(hit.allowed_distance, 4.5);
assert_eq!(hit.allowed_position, Some(Vec3::Z * 4.5));
assert!(!hit.starts_blocked());
let clear = sweep.probe(&NoObstructions, 0.25)?;
assert_eq!(clear.hit_fraction, None);
assert_eq!(clear.allowed_position, Some(sweep.end));