csci5607/assignment-1a/src/ray.rs

27 lines
700 B
Rust

use nalgebra::Vector3;
/// A normalized parametric Ray of the form (origin + direction * time)
///
/// That means at any time t: f64, the point represented by origin + direction *
/// time occurs on the ray.
#[derive(Debug)]
pub struct Ray {
pub origin: Vector3<f64>,
pub direction: Vector3<f64>,
}
impl Ray {
/// Construct a ray from endpoints
pub fn from_endpoints(start: Vector3<f64>, end: Vector3<f64>) -> Self {
let delta = (end - start).normalize();
Ray {
origin: start,
direction: delta,
}
}
/// Evaluate the ray at a certain point in time, yielding a point
pub fn eval(&self, time: f64) -> Vector3<f64> {
self.origin + self.direction * time
}
}