aboutsummaryrefslogtreecommitdiff
path: root/src/scene/mod.rs
blob: f8c1e09776ec7ed5594b5815df9432ba24b12195 (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
//! Defines the scene type which contains all the objects in the scene.
//! 
//! Also handles finding intersections between rays and shapes
pub mod shapes;

mod scene;
pub use scene::*;

use crate::core::{Ray, Vector3f};
use crate::Float;

/// Returns the context of a intersection
pub struct Intersection {
    /// Normal vector at intersection
    pub n: Vector3f,
    pub p: Vector3f,
}

impl Intersection {
    pub fn norm_against_ray(&self, r: &Ray) -> Vector3f {
        if self.n.dot(&r.direction) < 0.0 {
            self.n
        } else {
            -self.n
        }
    }
}

/// Defines a common trait for objects in the scene
pub trait Hittable {
    fn intersect(&self, ray: &Ray) -> Option<Intersection>;
}