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,19 +1,31 @@
use core::f32::math::sqrt;
use std::sync::Arc;
use crate::objects::hit::Hit;
use crate::objects::materials::traits::Material;
use crate::objects::traits::Hittable;
use crate::Vec3;
pub struct Sphere {
center: Vec3,
radius: f32,
material: Arc<dyn Material>,
}
impl Sphere {
pub fn new(center: Vec3, radius: f32) -> Sphere {
Sphere {
pub fn new(center: Vec3, r: f32, mat: Arc<dyn Material>) -> Self {
Self {
center: center,
radius: radius,
radius: r,
material: mat,
}
}
pub fn xyz(x: f32, y: f32, z: f32, r: f32, mat: Arc<dyn Material>) -> Self {
Self {
center: Vec3::new(x, y, z),
radius: r,
material: mat,
}
}
}
@@ -31,7 +43,7 @@ impl Hittable for Sphere {
} else {
let t = (h - sqrt(d)) / a;
let p = r.at(t);
Some(Hit::new(t, p, self.normal_at(&p)))
Some(Hit::new(t, p, self.normal_at(&p), self.material.clone()))
}
}