ft: 10: metals

This commit is contained in:
2026-04-16 14:04:55 +02:00
parent e8f84b590b
commit b756cc394a
12 changed files with 199 additions and 41 deletions

View File

@@ -1,14 +1,26 @@
use crate::{objects::traits::Hittable, ray::Ray, vec3::Vec3};
use std::sync::Arc;
use crate::{
objects::{materials::traits::Material, traits::Hittable},
ray::Ray,
vec3::Vec3,
};
pub struct Hit {
t: f32,
p: Vec3,
n: Vec3,
mat: Arc<dyn Material>,
}
impl Hit {
pub fn new(t: f32, p: Vec3, n: Vec3) -> Hit {
Hit { t: t, p: p, n: n }
pub fn new(t: f32, p: Vec3, n: Vec3, mat: Arc<dyn Material>) -> Self {
Self {
t: t,
p: p,
n: n,
mat: mat,
}
}
pub fn t(&self) -> &f32 {
@@ -23,6 +35,10 @@ impl Hit {
&self.n
}
pub fn mat(&self) -> Arc<dyn Material> {
self.mat.clone()
}
pub fn hit_list<T: Hittable>(hittables: &Vec<T>, r: &Ray) -> Option<Hit> {
let mut closest: Option<Hit> = None;
for hittable in hittables {