diff --git a/rtchallenge/src/shapes.rs b/rtchallenge/src/shapes.rs index 30eb8e3..1f64a98 100644 --- a/rtchallenge/src/shapes.rs +++ b/rtchallenge/src/shapes.rs @@ -261,9 +261,10 @@ impl Shape { /// assert_eq!(xs[0].object, &p); /// ``` pub fn intersect<'s>(shape: &'s Shape, ray: &Ray) -> Intersections<'s> { + let local_ray = ray.transform(shape.inverse_transform); match shape.geometry { - Geometry::Sphere => sphere::intersect(shape, ray), - Geometry::Plane => plane::intersect(shape, ray), + Geometry::Sphere => sphere::intersect(shape, &local_ray), + Geometry::Plane => plane::intersect(shape, &local_ray), } } @@ -275,7 +276,6 @@ mod sphere { tuples::{dot, Tuple}, }; pub fn intersect<'s>(shape: &'s Shape, ray: &Ray) -> Intersections<'s> { - let ray = ray.transform(shape.inverse_transform); let sphere_to_ray = ray.origin - Tuple::point(0., 0., 0.); let a = dot(ray.direction, ray.direction); let b = 2. * dot(ray.direction, sphere_to_ray);