ft: 10: metals
This commit is contained in:
@@ -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