ft: 10: metals

This commit is contained in:
djaidjai committed 2026-04-16 14:04:55 +02:00
1 parent e8f84b590b
commit b756cc394a
12 files changed
+199 -41

No files matched your search

+16 -4
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()))
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.