ft: added cube
This commit is contained in:
49
src/objects/cube.rs
Normal file
49
src/objects/cube.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
objects::{materials::traits::Material, quad::Quad, traits::Hittable},
|
||||
ray::Ray,
|
||||
vec3::Vec3,
|
||||
};
|
||||
|
||||
use super::hit::Hit;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Cube {
|
||||
faces: Vec<Arc<dyn Hittable>>,
|
||||
material: Arc<dyn Material>,
|
||||
}
|
||||
|
||||
impl Cube {
|
||||
pub fn new(
|
||||
p1: Vec3,
|
||||
p2: Vec3,
|
||||
p3: Vec3,
|
||||
p4: Vec3,
|
||||
p5: Vec3,
|
||||
p6: Vec3,
|
||||
p7: Vec3,
|
||||
p8: Vec3,
|
||||
material: Arc<dyn Material>,
|
||||
) -> Self {
|
||||
let faces: Vec<Arc<dyn Hittable>> = vec![
|
||||
Arc::new(Quad::new(p1, p2, p3, p4, material.clone())),
|
||||
Arc::new(Quad::new(p1, p5, p6, p2, material.clone())),
|
||||
Arc::new(Quad::new(p2, p6, p7, p3, material.clone())),
|
||||
Arc::new(Quad::new(p5, p8, p4, p1, material.clone())),
|
||||
Arc::new(Quad::new(p5, p6, p7, p8, material.clone())),
|
||||
Arc::new(Quad::new(p4, p3, p7, p8, material.clone())),
|
||||
];
|
||||
Self { faces, material }
|
||||
}
|
||||
}
|
||||
|
||||
impl Hittable for Cube {
|
||||
fn hit(&self, r: &Ray) -> Option<Hit> {
|
||||
Hit::hit_list(&self.faces, r)
|
||||
}
|
||||
|
||||
fn normal_at(&self, p: &Vec3) -> Vec3 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user