raytracing-rs

https://raytracing.github.io in Rust

git clone https://code.pdelong.com/raytracing-rs.git

 1use crate::math::Interval;
 2use crate::math::NormalizedVec3;
 3use crate::math::NotNanF64;
 4use crate::math::Point;
 5use crate::math::Ray;
 6
 7mod list;
 8mod sphere;
 9
10pub struct HitRecord {
11    pub point: Point,
12    pub normal: NormalizedVec3,
13    pub t: NotNanF64,
14    pub front_face: bool,
15}
16
17impl HitRecord {
18    fn new(r: &Ray, point: Point, outward_normal: NormalizedVec3, t: NotNanF64) -> HitRecord {
19        let front_face = r.dir.dot(&outward_normal) < 0.;
20        HitRecord {
21            point,
22            normal: if front_face {
23                outward_normal
24            } else {
25                -outward_normal
26            },
27            t,
28            front_face,
29        }
30    }
31}
32
33pub trait Hittable: Send {
34    fn hit(&self, r: &Ray, range: &Interval) -> Option<HitRecord>;
35}
36
37pub use list::HittableList;
38pub use sphere::Sphere;