pub trait Raycast {
// Required method
fn raycast(
&self,
local_ray: Ray,
max_distance: Real,
discard_inside_hit: bool,
) -> Option<RaycastHitResult>;
}Expand description
Trait for objects that can be intersected by rays.
This trait defines the interface for ray casting operations against geometric shapes.
Implementations should compute the closest intersection point between a ray and the shape,
returning None if there is no intersection.
§Examples
use phys_raycast::{Raycast, RaycastHitResult};
use phys_geom::{Ray, shape::Sphere, math::{Point3, Vec3}};
let sphere = Sphere::new(1.0);
let ray = Ray::new(Point3::new(-2.0, 0.0, 0.0), Vec3::x_axis());
if let Some(hit) = sphere.raycast(ray, 10.0, false) {
assert_eq!(hit.distance, 1.0);
assert_eq!(hit.normal, -Vec3::x_axis());
}Required Methods§
Sourcefn raycast(
&self,
local_ray: Ray,
max_distance: Real,
discard_inside_hit: bool,
) -> Option<RaycastHitResult>
fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>
Casts a ray against this shape and returns the closest hit.
§Arguments
local_ray- Ray in the shape’s local coordinate spacemax_distance- Maximum distance to check for intersectionsdiscard_inside_hit- If true, returns None when ray origin is inside the shape
§Returns
Some(RaycastHitResult) if there is an intersection within max_distance,
otherwise None.
§Implementation Notes
- The ray should be in the shape’s local coordinate system
- Only intersections with
distance >= 0.0should be considered - When
discard_inside_hitis true and the ray origin is inside the shape, the method should returnNonerather than a hit at distance 0