1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use crate::Vec3; /// The Intersect trait. pub trait Intersect { fn intersect(&self, ray: &Ray) -> RayIntersection; } /// Represents an intersection of a ray with a primitive. #[derive(PartialEq, Debug)] pub enum RayIntersection { Miss, Tangent(f32), Hit(f32, f32), } /// A ray. pub struct Ray { pub origin: Vec3, pub direction: Vec3, } impl Ray { /// Creates a new ray. Clones the borrows components. pub fn new(origin: &Vec3, direction: &Vec3) -> Ray { Ray {origin: origin.clone(), direction: direction.clone()} } }