aboutsummaryrefslogtreecommitdiff
path: root/src/scene/mod.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-07 14:25:06 +0100
committerJulian T <julian@jtle.dk>2021-02-07 14:26:20 +0100
commit33e747fa1c0957546c10e4d7b490ac7fbb0fd2d2 (patch)
tree515b2b2e017329cbcada60e898fb5795fbceb5cd /src/scene/mod.rs
parenta43ab40a75e9d4c6ee3fbdd583bc93574db19124 (diff)
Abstracted lambertian into material
Diffstat (limited to 'src/scene/mod.rs')
-rw-r--r--src/scene/mod.rs29
1 files changed, 11 insertions, 18 deletions
diff --git a/src/scene/mod.rs b/src/scene/mod.rs
index f8c1e09..cd07236 100644
--- a/src/scene/mod.rs
+++ b/src/scene/mod.rs
@@ -6,27 +6,20 @@ pub mod shapes;
mod scene;
pub use scene::*;
-use crate::core::{Ray, Vector3f};
-use crate::Float;
+use std::rc::Rc;
+use crate::core::Hittable;
+use crate::material::Material;
-/// Returns the context of a intersection
-pub struct Intersection {
- /// Normal vector at intersection
- pub n: Vector3f,
- pub p: Vector3f,
+pub struct Object {
+ pub shape: Box<dyn Hittable>,
+ pub mat: Rc<dyn Material>,
}
-impl Intersection {
- pub fn norm_against_ray(&self, r: &Ray) -> Vector3f {
- if self.n.dot(&r.direction) < 0.0 {
- self.n
- } else {
- -self.n
+impl Object {
+ pub fn new(mat: Rc<dyn Material>, shape: Box<dyn Hittable>) -> Self {
+ Object {
+ mat,
+ shape,
}
}
}
-
-/// Defines a common trait for objects in the scene
-pub trait Hittable {
- fn intersect(&self, ray: &Ray) -> Option<Intersection>;
-}