[−][src]Trait obscura::Intersect
The Intersect trait.
Required methods
fn intersect(&self, ray: &Ray) -> RayIntersection
Implementors
impl Intersect for Sphere
[src]
fn intersect(&self, ray: &Ray) -> RayIntersection
[src]
Intersect ray with sphere. Return t or t1,t2 where intersection point p = ray.origin + t * ray.direction
Examples
use obscura::{Sphere, Vec3, Ray, RayIntersection, Intersect}; let origin = Vec3::zero(); let target: Sphere = Sphere::new( &Vec3::new(2.0, 0.0, 0.0), 1.0 ); // A ray that intersects the sphere twice. let ray1: Ray = Ray::new( &origin, &Vec3::new(1.0, 0.0, 0.0) ); if let RayIntersection::Hit(t1, t2) = Sphere::intersect(&target, &ray1) { assert_eq!(t1, 1.0); assert_eq!(t2, 3.0); } else { panic!("Oh no!"); } // A ray which never intersects the sphere. let ray2: Ray = Ray::new( &origin, &Vec3::new(0.0, 0.0, 1.0) ); let result = Sphere::intersect(&target, &ray2); assert_eq!(result, RayIntersection::Miss);