feat(sphere): inner intersection

This commit is contained in:
2026-03-31 23:01:55 +02:00
parent fc40e0b798
commit 3cb3e4a8fa
2 changed files with 44 additions and 24 deletions

View File

@@ -1,3 +1,5 @@
use nalgebra::distance;
use super::types::{Intersect, Material, Point3, Ray, Scalar, Vector3};
extern crate nalgebra as na;
@@ -52,12 +54,21 @@ impl Intersect for Sphere {
if t < Scalar::MAX {
let isect_pt: Point3 = ray.origin + ray.direction * t;
return Some((
isect_pt,
(isect_pt - self.center) / self.radius,
t,
self.material.clone(),
));
if c >= 0.0 {
return Some((
isect_pt,
(isect_pt - self.center) / self.radius,
t,
self.material.clone(),
));
} else {
return Some((
isect_pt,
-(isect_pt - self.center) / self.radius,
t,
self.material.clone(),
));
}
}
}