ft: added cube

This commit is contained in:
2026-05-02 12:57:45 +02:00
parent e7018a84ed
commit c3d37f4758
6 changed files with 99 additions and 25 deletions

49
src/objects/cube.rs Normal file
View 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!()
}
}