Fix hit determination inside a sphere
This commit is contained in:
@ -42,16 +42,16 @@ impl Hittable for Sphere {
|
||||
let discriminant = half_b * half_b - a * c;
|
||||
if discriminant < 0.0 { return None; }
|
||||
|
||||
let sqrtd = f64::sqrt(discriminant);
|
||||
let root = (-half_b - sqrtd) / a;
|
||||
let sqrtd = discriminant.sqrt();
|
||||
let mut root = (-half_b - sqrtd) / a;
|
||||
if root < t_min || t_max < root {
|
||||
let root = (-half_b + sqrtd) / a;
|
||||
root = (-half_b + sqrtd) / a;
|
||||
if root < t_min || t_max < root { return None; }
|
||||
}
|
||||
|
||||
let point = ray.at(root);
|
||||
let normal = (point - self.center) / self.radius;
|
||||
let front_face = ray.direction().dot(&normal) < 0.0;
|
||||
let dot = ray.direction().dot(&normal);
|
||||
let front_face = dot < 0.0;
|
||||
let normal = if front_face { normal } else { -normal };
|
||||
Some(HitRecord {
|
||||
point,
|
||||
|
Reference in New Issue
Block a user