diff --git a/src/main.rs b/src/main.rs index 44eb102..fc6ae5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use vanrijn::materials::LambertianMaterial; use vanrijn::math::Vec3; use vanrijn::mesh::load_obj; use vanrijn::partial_render_scene; -use vanrijn::raycasting::{Aggregate, BoundingVolumeHierarchy, Plane, Primitive, Sphere}; +use vanrijn::raycasting::{BoundingVolumeHierarchy, Plane, Primitive, Sphere}; use vanrijn::scene::Scene; use vanrijn::util::TileIterator; @@ -131,7 +131,7 @@ pub fn main() -> Result<(), Box> { }), )?; println!("Building BVH..."); - let model_bvh: Box = + let model_bvh: Box = Box::new(BoundingVolumeHierarchy::build(model_object.as_mut_slice())); println!("Constructing Scene..."); @@ -183,7 +183,7 @@ pub fn main() -> Result<(), Box> { //specular_strength: 1.0, }), )), - ]) as Box, + ]) as Box, model_bvh, ], }; diff --git a/src/raycasting/bounding_volume_hierarchy.rs b/src/raycasting/bounding_volume_hierarchy.rs index c3adf06..104706c 100644 --- a/src/raycasting/bounding_volume_hierarchy.rs +++ b/src/raycasting/bounding_volume_hierarchy.rs @@ -1,8 +1,6 @@ -use crate::math::Vec3; +use crate::math::{Affine3, Vec3}; -use super::{ - Aggregate, BoundingBox, HasBoundingBox, Intersect, IntersectP, IntersectionInfo, Primitive, Ray, -}; +use super::{BoundingBox, HasBoundingBox, Intersect, IntersectP, IntersectionInfo, Primitive, Ray}; use std::cmp::Ordering; use std::sync::Arc; @@ -125,7 +123,11 @@ impl HasBoundingBox for BoundingVolumeHierarchy { } } -impl Aggregate for BoundingVolumeHierarchy {} +impl Primitive for BoundingVolumeHierarchy { + fn transform(&self, transformation: &Affine3) -> Box { + todo!() + } +} #[cfg(test)] mod test {} diff --git a/src/raycasting/mod.rs b/src/raycasting/mod.rs index f9b0961..453a805 100644 --- a/src/raycasting/mod.rs +++ b/src/raycasting/mod.rs @@ -1,4 +1,4 @@ -use crate::math::Vec3; +use crate::math::{Affine3,Vec3}; use super::materials::Material; @@ -121,23 +121,12 @@ pub trait HasBoundingBox: Send + Sync { fn bounding_box(&self) -> BoundingBox; } -/// Any geometric object which can have an affine transformation applied to it -/// -/// Used for moving, rotating or scaling primitives -/*pub trait Transform { - /// Create a new object by applying the transformation to this object. - fn transform(&self, transformation: &Affine3) -> Self; -}*/ - /// A basic geometric primitive such as a sphere or a triangle pub trait Primitive: Intersect + HasBoundingBox { // / Create a new object by applying the transformation to this object. - //fn transform(&self, transformation: &Affine3) -> dyn Primitive; + fn transform(&self, transformation: &Affine3) -> Box; } -/// Either a primitive or a collection of primitives -pub trait Aggregate: Intersect + HasBoundingBox {} - #[cfg(test)] mod tests { use quickcheck_macros::quickcheck; diff --git a/src/raycasting/plane.rs b/src/raycasting/plane.rs index 2fb5712..02ff3c1 100644 --- a/src/raycasting/plane.rs +++ b/src/raycasting/plane.rs @@ -106,7 +106,11 @@ impl HasBoundingBox for Plane { } } -impl Primitive for Plane {} +impl Primitive for Plane { + fn transform(&self, transformation: &crate::math::Affine3) -> Box { + todo!() + } +} #[cfg(test)] mod tests { diff --git a/src/raycasting/sphere.rs b/src/raycasting/sphere.rs index d3ba4f4..e77e7b8 100644 --- a/src/raycasting/sphere.rs +++ b/src/raycasting/sphere.rs @@ -99,7 +99,11 @@ impl HasBoundingBox for Sphere { } } -impl Primitive for Sphere {} +impl Primitive for Sphere { + fn transform(&self, transformation: &crate::math::Affine3) -> Box { + todo!() + } +} #[cfg(test)] mod tests { diff --git a/src/raycasting/triangle.rs b/src/raycasting/triangle.rs index 77404c1..9b6e515 100644 --- a/src/raycasting/triangle.rs +++ b/src/raycasting/triangle.rs @@ -103,7 +103,11 @@ impl HasBoundingBox for Triangle { } } -impl Primitive for Triangle {} +impl Primitive for Triangle { + fn transform(&self, transformation: &crate::math::Affine3) -> Box { + todo!() + } +} fn indices_with_index_of_largest_element_last(v: &Vec3) -> [usize; 3] { #[allow(clippy::collapsible_else_if)] diff --git a/src/raycasting/vec_aggregate.rs b/src/raycasting/vec_aggregate.rs index 27786f4..dacb896 100644 --- a/src/raycasting/vec_aggregate.rs +++ b/src/raycasting/vec_aggregate.rs @@ -1,4 +1,5 @@ -use super::{Aggregate, BoundingBox, HasBoundingBox, Intersect, IntersectionInfo, Primitive, Ray}; +use super::{BoundingBox, HasBoundingBox, Intersect, IntersectionInfo, Primitive, Ray}; +use crate::math::Affine3; impl HasBoundingBox for Vec> { fn bounding_box(&self) -> BoundingBox { @@ -21,27 +22,8 @@ impl Intersect for Vec> { } } -impl Aggregate for Vec> {} - -impl HasBoundingBox for Vec> { - fn bounding_box(&self) -> BoundingBox { - self.iter().fold(BoundingBox::empty(), |acc, elem| { - acc.union(&elem.bounding_box()) - }) +impl Primitive for Vec> { + fn transform(&self, transformation: &Affine3) -> Box { + todo!() } } - -impl Intersect for Vec> { - fn intersect(&self, ray: &Ray) -> Option { - self.iter() - .flat_map(|aggregate| aggregate.intersect(ray)) - .min_by( - |a, b| match PartialOrd::partial_cmp(&a.distance, &b.distance) { - None => std::cmp::Ordering::Less, - Some(ordering) => ordering, - }, - ) - } -} - -impl Aggregate for Vec> {} diff --git a/src/scene.rs b/src/scene.rs index 1d4add7..33dd44e 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -1,8 +1,8 @@ use crate::math::Vec3; -use crate::raycasting::Aggregate; +use crate::raycasting::Primitive; pub struct Scene { pub camera_location: Vec3, - pub objects: Vec>, + pub objects: Vec>, }