diff options
author | Julian T <julian@jtle.dk> | 2021-02-06 17:27:42 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-06 17:27:42 +0100 |
commit | 0d5e6bd9363d5ed5c4f28174819fc0f5fd9aa586 (patch) | |
tree | f9ecafe7350ad616486e509ed55904295f505f83 /src/scene/mod.rs | |
parent | 1e83ea211055eb234b89c69b5d03602e3fcb98fb (diff) |
Reorganized scene module, and fixed bug in sphere intersect
Diffstat (limited to 'src/scene/mod.rs')
-rw-r--r-- | src/scene/mod.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 7c77412..f8c1e09 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -5,3 +5,28 @@ pub mod shapes; mod scene; pub use scene::*; + +use crate::core::{Ray, Vector3f}; +use crate::Float; + +/// Returns the context of a intersection +pub struct Intersection { + /// Normal vector at intersection + pub n: Vector3f, + pub p: Vector3f, +} + +impl Intersection { + pub fn norm_against_ray(&self, r: &Ray) -> Vector3f { + if self.n.dot(&r.direction) < 0.0 { + self.n + } else { + -self.n + } + } +} + +/// Defines a common trait for objects in the scene +pub trait Hittable { + fn intersect(&self, ray: &Ray) -> Option<Intersection>; +} |