Skip to main content

rpt/shape/
plane.rs

1use rand::rngs::StdRng;
2
3use super::{HitRecord, Ray, Shape};
4
5/// A plane represented by the linear equation x • normal = value
6#[derive(Copy, Clone)]
7pub struct Plane {
8    /// The normal vector
9    pub normal: glm::DVec3,
10
11    /// The distance from the origin
12    pub value: f64,
13}
14
15impl Shape for Plane {
16    /// Ray-plane intersection
17    fn intersect(&self, ray: &Ray, t_min: f64, record: &mut HitRecord) -> bool {
18        let cosine = self.normal.dot(&ray.dir);
19        if cosine.abs() < 1e-8 {
20            // Parallel ray and plane
21            return false;
22        }
23
24        let time = (self.value - self.normal.dot(&ray.origin)) / cosine;
25        if time >= t_min && time < record.time {
26            record.time = time;
27            record.normal = -self.normal.normalize() * cosine.signum();
28            true
29        } else {
30            false
31        }
32    }
33
34    fn sample(&self, _target: &glm::DVec3, _rng: &mut StdRng) -> (glm::DVec3, glm::DVec3, f64) {
35        unimplemented!()
36    }
37}