summaryrefslogtreecommitdiff
path: root/racer-tracer/src/geometry.rs
blob: 1cc7e28d782c333a139148af1ea7fb90c3722cc8 (plain)
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
36
37
38
39
40
41
pub mod sphere;

use std::sync::Arc;

use crate::material::Material;
use crate::ray::Ray;
use crate::vec3::Vec3;

pub struct HitRecord {
    pub point: Vec3,
    pub normal: Vec3,
    pub t: f64,
    pub front_face: bool,
    pub material: Arc<Box<dyn Material + Send + Sync>>,
}

impl HitRecord {
    fn new(point: Vec3, t: f64, material: Arc<Box<dyn Material + Send + Sync>>) -> Self {
        Self {
            point,
            normal: Vec3::default(),
            t,
            front_face: true,
            material,
        }
    }

    fn set_face_normal(&mut self, ray: &Ray, outward_normal: Vec3) {
        self.front_face = ray.direction().dot(&outward_normal) < 0.0;
        self.normal = if self.front_face {
            outward_normal
        } else {
            -outward_normal
        };
    }
}

pub trait Hittable {
    //pub trait Hittable {
    fn hit(&self, ray: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord>;
}