ft: 10: metals
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user