Skip to content

Commit

Permalink
surface normal interface
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjayakar committed Jan 9, 2021
1 parent bf851aa commit 5f3d04d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/scene/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ impl Object {

pub fn surface_normal(&self, point: Point) -> Vector {
match self {
Object::Triangle(triangle) => triangle.normal,
Object::Sphere(sphere) => (point - sphere.center).normalized(),
Object::Triangle(triangle) => triangle.surface_normal(),
Object::Sphere(sphere) => sphere.surface_normal(point),
}
}

Expand Down Expand Up @@ -259,6 +259,10 @@ impl Sphere {
point + (random_vector * self.radius)
}

fn surface_normal(&self, point: Point) -> Vector {
(point - self.center).normalized()
}

pub fn intersect(&self, ray: &Ray) -> Option<f64> {
let l: Vector = self.center - ray.origin;
let adj = l.dot(ray.direction);
Expand Down Expand Up @@ -327,6 +331,8 @@ impl Triangle {
None
}
}

fn surface_normal(&self) -> Vector { self.normal }
}

impl Bounded for Sphere {
Expand Down

0 comments on commit 5f3d04d

Please sign in to comment.