diff --git a/src/primitive.rs b/src/primitive.rs index b677a0a..9ef2bc9 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -104,7 +104,7 @@ impl BoundingBox { } } // PRIMITIVE TRAIT ----------------------------------------------------------------- -pub trait Primitive { +pub trait Primitive: Send + Sync { fn intersect_ray(&self, ray: &Ray) -> Option; fn intersect_bounding_box(&self, ray: &Ray) -> Option>; fn get_material(&self) -> Arc; @@ -495,7 +495,7 @@ impl Primitive for Rectangle { } // BOX ----------------------------------------------------------------- -pub struct Box { +pub struct Cube { width: f32, height: f32, depth: f32, @@ -503,11 +503,11 @@ pub struct Box { bounding_box: BoundingBox, } -impl Box { +impl Cube { fn new(width: f32, height: f32, depth: f32, material: Arc) -> Self { let trf = Point3::new(width / 2.0, height / 2.0, depth / 2.0); let bln = Point3::new(-width / 2.0, -height / 2.0, -depth / 2.0); - Box { + Cube { width, height, depth, @@ -516,11 +516,11 @@ impl Box { } } pub fn unit(material: Arc) -> Self { - Box::new(2.0, 2.0, 2.0, material) + Cube::new(2.0, 2.0, 2.0, material) } } -impl Primitive for Box { +impl Primitive for Cube { fn intersect_ray(&self, ray: &Ray) -> Option { // Compute the minimum and maximum t-values for each axis of the bounding box let t1 = (self.bounding_box.bln - ray.a).component_div(&ray.b); diff --git a/src/scene.rs b/src/scene.rs index bb2e784..3195be2 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -5,35 +5,25 @@ use nalgebra::Vector3; use std::sync::Arc; pub struct Scene { - pub primitives: Vec>, - pub lights: Vec>, - pub cameras: Vec>, + pub primitives: Arc>>, + pub lights: Arc>, + pub cameras: Arc>, pub ambient_light: Arc>, } impl Scene { - // Creates a new Scene with given parameters + // Creates a scene pub fn new( - primitives: Vec>, - lights: Vec>, - cameras: Vec>, - ambient_light: Arc>, + primitives: Vec>, + lights: Vec, + cameras: Vec, + ambient_light: Vector3, ) -> Self { Scene { - primitives, - lights, - cameras, - ambient_light, - } - } - - // Creates an empty Scene with default values - pub fn empty() -> Self { - Scene { - primitives: Vec::new(), - lights: Vec::new(), - cameras: Vec::new(), - ambient_light: Arc::new(Vector3::new(0.0, 0.0, 0.0)), + primitives: Arc::new(primitives), + lights: Arc::new(lights), + cameras: Arc::new(cameras), + ambient_light: Arc::new(ambient_light), } } }