aboutsummaryrefslogtreecommitdiff
path: root/src/scene
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-03 17:54:03 +0100
committerJulian T <julian@jtle.dk>2021-02-03 17:54:03 +0100
commit9235e74dfbc41895a5f8807e1ab93508268a39ea (patch)
treeb8e85390b9e131736016dd2589d5e6ea14013552 /src/scene
parent977b0e4152433b2a68e2b97fe5fe2c0ff6fb20d8 (diff)
Base render of surface normal, and abstract shading and tracing to the
trace module
Diffstat (limited to 'src/scene')
-rw-r--r--src/scene/scene.rs2
-rw-r--r--src/scene/shapes/mod.rs8
-rw-r--r--src/scene/shapes/sphere.rs6
3 files changed, 14 insertions, 2 deletions
diff --git a/src/scene/scene.rs b/src/scene/scene.rs
index a2f5b88..33a7613 100644
--- a/src/scene/scene.rs
+++ b/src/scene/scene.rs
@@ -22,7 +22,7 @@ impl Scene {
self.shps.push(shp);
}
- pub fn intersect(&self, ray: Ray) -> Option<Intersection> {
+ pub fn intersect(&self, ray: &Ray) -> Option<Intersection> {
for shp in self.shps.iter() {
if let Some(t) = shp.intersect(&ray) {
return Some(Intersection {
diff --git a/src/scene/shapes/mod.rs b/src/scene/shapes/mod.rs
index 7fbb8db..9b6bdfd 100644
--- a/src/scene/shapes/mod.rs
+++ b/src/scene/shapes/mod.rs
@@ -2,9 +2,15 @@ mod sphere;
pub use sphere::Sphere;
-use crate::core::Ray;
+use crate::core::{Vector3f, Ray};
use crate::Float;
pub trait Shape {
fn intersect(&self, ray: &Ray) -> Option<Float>;
+
+ /// Calculates the normal at point
+ ///
+ /// Point is assumed to be on the circle.
+ /// The resulting vector is assumed to be normalized.
+ fn norm_at(&self, point: &Vector3f) -> Vector3f;
}
diff --git a/src/scene/shapes/sphere.rs b/src/scene/shapes/sphere.rs
index e30c1ec..da7f321 100644
--- a/src/scene/shapes/sphere.rs
+++ b/src/scene/shapes/sphere.rs
@@ -35,6 +35,12 @@ impl Shape for Sphere {
}
}
+
+ fn norm_at(&self, point: &Vector3f) -> Vector3f {
+ let mut v = *point - self.center;
+ v /= self.radius;
+ v
+ }
}
#[cfg(test)]