Changed Box to be Cube as it was interfering with Box

This commit is contained in:
STP
2023-11-17 18:37:40 -05:00
parent ab3705d575
commit 87e82e4eea
2 changed files with 18 additions and 28 deletions

View File

@@ -104,7 +104,7 @@ impl BoundingBox {
} }
} }
// PRIMITIVE TRAIT ----------------------------------------------------------------- // PRIMITIVE TRAIT -----------------------------------------------------------------
pub trait Primitive { pub trait Primitive: Send + Sync {
fn intersect_ray(&self, ray: &Ray) -> Option<Intersection>; fn intersect_ray(&self, ray: &Ray) -> Option<Intersection>;
fn intersect_bounding_box(&self, ray: &Ray) -> Option<Point3<f32>>; fn intersect_bounding_box(&self, ray: &Ray) -> Option<Point3<f32>>;
fn get_material(&self) -> Arc<Material>; fn get_material(&self) -> Arc<Material>;
@@ -495,7 +495,7 @@ impl Primitive for Rectangle {
} }
// BOX ----------------------------------------------------------------- // BOX -----------------------------------------------------------------
pub struct Box { pub struct Cube {
width: f32, width: f32,
height: f32, height: f32,
depth: f32, depth: f32,
@@ -503,11 +503,11 @@ pub struct Box {
bounding_box: BoundingBox, bounding_box: BoundingBox,
} }
impl Box { impl Cube {
fn new(width: f32, height: f32, depth: f32, material: Arc<Material>) -> Self { fn new(width: f32, height: f32, depth: f32, material: Arc<Material>) -> Self {
let trf = Point3::new(width / 2.0, height / 2.0, depth / 2.0); 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); let bln = Point3::new(-width / 2.0, -height / 2.0, -depth / 2.0);
Box { Cube {
width, width,
height, height,
depth, depth,
@@ -516,11 +516,11 @@ impl Box {
} }
} }
pub fn unit(material: Arc<Material>) -> Self { pub fn unit(material: Arc<Material>) -> 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<Intersection> { fn intersect_ray(&self, ray: &Ray) -> Option<Intersection> {
// Compute the minimum and maximum t-values for each axis of the bounding box // 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); let t1 = (self.bounding_box.bln - ray.a).component_div(&ray.b);

View File

@@ -5,35 +5,25 @@ use nalgebra::Vector3;
use std::sync::Arc; use std::sync::Arc;
pub struct Scene { pub struct Scene {
pub primitives: Vec<Arc<dyn Primitive>>, pub primitives: Arc<Vec<Box<dyn Primitive>>>,
pub lights: Vec<Arc<Light>>, pub lights: Arc<Vec<Light>>,
pub cameras: Vec<Arc<Camera>>, pub cameras: Arc<Vec<Camera>>,
pub ambient_light: Arc<Vector3<f32>>, pub ambient_light: Arc<Vector3<f32>>,
} }
impl Scene { impl Scene {
// Creates a new Scene with given parameters // Creates a scene
pub fn new( pub fn new(
primitives: Vec<Arc<dyn Primitive>>, primitives: Vec<Box<dyn Primitive>>,
lights: Vec<Arc<Light>>, lights: Vec<Light>,
cameras: Vec<Arc<Camera>>, cameras: Vec<Camera>,
ambient_light: Arc<Vector3<f32>>, ambient_light: Vector3<f32>,
) -> Self { ) -> Self {
Scene { Scene {
primitives, primitives: Arc::new(primitives),
lights, lights: Arc::new(lights),
cameras, cameras: Arc::new(cameras),
ambient_light, ambient_light: Arc::new(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)),
} }
} }
} }