1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
use crate::material::Material;
use crate::ray::Ray;
use cgmath::{dot, Vector3};
pub struct Hit<'a> {
pub t: f64,
pub p: Vector3<f64>,
pub normal: Vector3<f64>,
pub front_face: bool,
pub material: &'a (dyn Material + std::marker::Sync),
}
impl<'a> Hit<'a> {
pub fn new(
ray: &Ray,
t: f64,
out_normal: Vector3<f64>,
material: &'a (dyn Material + std::marker::Sync),
) -> Hit<'a> {
let front_face = dot(ray.dir, out_normal) < 0.0;
let normal = if front_face { out_normal } else { -out_normal };
let p = ray.at(t);
Hit {
t,
p,
normal,
front_face,
material,
}
}
}
pub trait Hittable {
fn is_hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<Hit>;
}
|