Files
raytracing/src/objects/cube.rs
2026-05-12 18:20:06 +02:00

50 lines
1.2 KiB
Rust

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>>,
}
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 }
}
}
impl Hittable for Cube {
fn hit(&self, r: &Ray) -> Option<Hit> {
Hit::hit_list(&self.faces, r)
}
fn to_uv(&self, point: &Vec3) -> Vec3 {
// TODO: map to [0.1] relative to specific face
todo!()
}
}