diff --git a/src/query/ray/ray.rs b/src/query/ray/ray.rs index a38baf1c..7efe94ac 100644 --- a/src/query/ray/ray.rs +++ b/src/query/ray/ray.rs @@ -68,13 +68,17 @@ impl Ray { archive(as = "Self") )] pub struct RayIntersection { - /// The time of impact of the ray with the object. The exact contact point can be computed + /// The time of impact of the ray with the object. The exact contact point can be computed /// with: `ray.point_at(toi)` or equivalently `origin + dir * toi` where `origin` is the origin of the ray; /// `dir` is its direction and `toi` is the value of this field. pub toi: Real, /// The normal at the intersection point. /// + /// If the origin of the ray is inside of the shape and the shape is not solid, + /// the normal will point towards the interior of the shape. + /// Otherwise, the normal points outward. + /// /// If the `toi` is exactly zero, the normal might not be reliable. // XXX: use a Unit instead. pub normal: Vector, diff --git a/src/query/ray/ray_support_map.rs b/src/query/ray/ray_support_map.rs index 21d6c720..8db3e8bd 100644 --- a/src/query/ray/ray_support_map.rs +++ b/src/query/ray/ray_support_map.rs @@ -47,10 +47,14 @@ where simplex.reset(CSOPoint::single_point(supp - new_ray.origin.coords)); gjk::cast_local_ray(shape, simplex, &new_ray, shift + eps).and_then( - |(toi, normal)| { + |(toi, outward_normal)| { let toi = shift - toi; if toi <= max_toi { - Some(RayIntersection::new(toi, normal, FeatureId::Unknown)) + Some(RayIntersection::new( + toi, + -outward_normal, + FeatureId::Unknown, + )) } else { None }