use nalgebra::{Point3, Unit, Vector3};
#[derive(Debug, Clone)]
pub struct Ray {
pub origin: Point3<f64>,
pub direction: Unit<Vector3<f64>>,
}
impl Ray {
pub fn new(origin: Point3<f64>, direction: Unit<Vector3<f64>>) -> Self {
Self { origin, direction }
}
pub fn at(&self, t: f64) -> Point3<f64> {
self.origin + self.direction.as_ref() * t
}
}
#[derive(Debug, Clone)]
pub struct HitRecord {
pub t: f64,
pub point: Point3<f64>,
pub normal: Unit<Vector3<f64>>,
pub front_face: bool,
pub material: crate::MaterialId,
}
impl HitRecord {
pub fn set_face_normal(&mut self, ray: &Ray, outward_normal: Unit<Vector3<f64>>) {
self.front_face = ray.direction.dot(outward_normal.as_ref()) < 0.0;
self.normal = if self.front_face {
outward_normal
} else {
Unit::new_unchecked(-outward_normal.into_inner())
};
}
}
#[derive(Debug, Clone)]
pub struct Photon {
pub ray: Ray,
pub energy: f64,
pub wavelength: f64,
pub bounces: u32,
}
impl Photon {
pub fn new(ray: Ray) -> Self {
Self {
ray,
energy: 1.0,
wavelength: 555.0,
bounces: 0,
}
}
}