Raycast

Trait Raycast 

Source
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§

Source

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 space
  • max_distance - Maximum distance to check for intersections
  • discard_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.0 should be considered
  • When discard_inside_hit is true and the ray origin is inside the shape, the method should return None rather than a hit at distance 0

Implementations on Foreign Types§

Source§

impl Raycast for Capsule

Source§

fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>

Source§

impl Raycast for Cuboid

Source§

fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>

Source§

impl Raycast for Cylinder

Source§

fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>

Source§

impl Raycast for InfinitePlane

Source§

fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>

Source§

impl Raycast for Sphere

Source§

fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>

Source§

impl Raycast for Triangle

Source§

fn raycast( &self, local_ray: Ray, max_distance: Real, discard_inside_hit: bool, ) -> Option<RaycastHitResult>

Implementors§