Replace Aggregate with Primitive and stub Primitive::transform()
All the implemntations of transform are just todo!()
This commit is contained in:
parent
fa713fc72d
commit
6e3a5dd1d8
|
|
@ -20,7 +20,7 @@ use vanrijn::materials::LambertianMaterial;
|
||||||
use vanrijn::math::Vec3;
|
use vanrijn::math::Vec3;
|
||||||
use vanrijn::mesh::load_obj;
|
use vanrijn::mesh::load_obj;
|
||||||
use vanrijn::partial_render_scene;
|
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::scene::Scene;
|
||||||
use vanrijn::util::TileIterator;
|
use vanrijn::util::TileIterator;
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}),
|
}),
|
||||||
)?;
|
)?;
|
||||||
println!("Building BVH...");
|
println!("Building BVH...");
|
||||||
let model_bvh: Box<dyn Aggregate> =
|
let model_bvh: Box<dyn Primitive> =
|
||||||
Box::new(BoundingVolumeHierarchy::build(model_object.as_mut_slice()));
|
Box::new(BoundingVolumeHierarchy::build(model_object.as_mut_slice()));
|
||||||
println!("Constructing Scene...");
|
println!("Constructing Scene...");
|
||||||
|
|
||||||
|
|
@ -183,7 +183,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//specular_strength: 1.0,
|
//specular_strength: 1.0,
|
||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
]) as Box<dyn Aggregate>,
|
]) as Box<dyn Primitive>,
|
||||||
model_bvh,
|
model_bvh,
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::math::Vec3;
|
use crate::math::{Affine3, Vec3};
|
||||||
|
|
||||||
use super::{
|
use super::{BoundingBox, HasBoundingBox, Intersect, IntersectP, IntersectionInfo, Primitive, Ray};
|
||||||
Aggregate, BoundingBox, HasBoundingBox, Intersect, IntersectP, IntersectionInfo, Primitive, Ray,
|
|
||||||
};
|
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::sync::Arc;
|
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<f64>) -> Box<dyn Primitive> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {}
|
mod test {}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::math::Vec3;
|
use crate::math::{Affine3,Vec3};
|
||||||
|
|
||||||
use super::materials::Material;
|
use super::materials::Material;
|
||||||
|
|
||||||
|
|
@ -121,23 +121,12 @@ pub trait HasBoundingBox: Send + Sync {
|
||||||
fn bounding_box(&self) -> BoundingBox;
|
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<f64>) -> Self;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/// A basic geometric primitive such as a sphere or a triangle
|
/// A basic geometric primitive such as a sphere or a triangle
|
||||||
pub trait Primitive: Intersect + HasBoundingBox {
|
pub trait Primitive: Intersect + HasBoundingBox {
|
||||||
// / Create a new object by applying the transformation to this object.
|
// / Create a new object by applying the transformation to this object.
|
||||||
//fn transform(&self, transformation: &Affine3) -> dyn Primitive;
|
fn transform(&self, transformation: &Affine3<f64>) -> Box<dyn Primitive>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Either a primitive or a collection of primitives
|
|
||||||
pub trait Aggregate: Intersect + HasBoundingBox {}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use quickcheck_macros::quickcheck;
|
use quickcheck_macros::quickcheck;
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,11 @@ impl HasBoundingBox for Plane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Primitive for Plane {}
|
impl Primitive for Plane {
|
||||||
|
fn transform(&self, transformation: &crate::math::Affine3<f64>) -> Box<dyn Primitive> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,11 @@ impl HasBoundingBox for Sphere {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Primitive for Sphere {}
|
impl Primitive for Sphere {
|
||||||
|
fn transform(&self, transformation: &crate::math::Affine3<f64>) -> Box<dyn Primitive> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,11 @@ impl HasBoundingBox for Triangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Primitive for Triangle {}
|
impl Primitive for Triangle {
|
||||||
|
fn transform(&self, transformation: &crate::math::Affine3<f64>) -> Box<dyn Primitive> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn indices_with_index_of_largest_element_last(v: &Vec3<f64>) -> [usize; 3] {
|
fn indices_with_index_of_largest_element_last(v: &Vec3<f64>) -> [usize; 3] {
|
||||||
#[allow(clippy::collapsible_else_if)]
|
#[allow(clippy::collapsible_else_if)]
|
||||||
|
|
|
||||||
|
|
@ -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<Box<dyn Primitive>> {
|
impl HasBoundingBox for Vec<Box<dyn Primitive>> {
|
||||||
fn bounding_box(&self) -> BoundingBox {
|
fn bounding_box(&self) -> BoundingBox {
|
||||||
|
|
@ -21,27 +22,8 @@ impl Intersect for Vec<Box<dyn Primitive>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aggregate for Vec<Box<dyn Primitive>> {}
|
impl Primitive for Vec<Box<dyn Primitive>> {
|
||||||
|
fn transform(&self, transformation: &Affine3<f64>) -> Box<dyn Primitive> {
|
||||||
impl HasBoundingBox for Vec<Box<dyn Aggregate>> {
|
todo!()
|
||||||
fn bounding_box(&self) -> BoundingBox {
|
|
||||||
self.iter().fold(BoundingBox::empty(), |acc, elem| {
|
|
||||||
acc.union(&elem.bounding_box())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Intersect for Vec<Box<dyn Aggregate>> {
|
|
||||||
fn intersect(&self, ray: &Ray) -> Option<IntersectionInfo> {
|
|
||||||
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<Box<dyn Aggregate>> {}
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::math::Vec3;
|
use crate::math::Vec3;
|
||||||
|
|
||||||
use crate::raycasting::Aggregate;
|
use crate::raycasting::Primitive;
|
||||||
|
|
||||||
pub struct Scene {
|
pub struct Scene {
|
||||||
pub camera_location: Vec3<f64>,
|
pub camera_location: Vec3<f64>,
|
||||||
pub objects: Vec<Box<dyn Aggregate>>,
|
pub objects: Vec<Box<dyn Primitive>>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue