Added epsilon to t to ensure rayremains within box

This commit is contained in:
STP
2023-11-17 14:11:22 -05:00
parent cf56edace6
commit 054a3d459f

View File

@@ -1,18 +1,17 @@
use crate::EPSILON; use crate::{EPSILON, EPSILON_VECTOR};
use nalgebra::{Matrix4, Point3, Vector3}; use nalgebra::{Matrix4, Point3, Unit, Vector3};
pub struct Ray { pub struct Ray {
pub a: Point3<f32>, pub a: Point3<f32>,
pub b: Vector3<f32>, pub b: Unit<Vector3<f32>>,
} }
impl Ray { impl Ray {
pub fn new(a: Point3<f32>, b: Vector3<f32>) -> Ray { pub fn new(a: Point3<f32>, b: Unit<Vector3<f32>>) -> Ray {
let b = b.normalize();
Ray { a, b } Ray { a, b }
} }
pub fn at_t(&self, t: f32) -> Point3<f32> { pub fn at_t(&self, t: f32) -> Point3<f32> {
self.a + self.b * t self.a + self.b.as_ref() * (t + EPSILON)
} }
} }