28 lines
402 B
Rust
28 lines
402 B
Rust
use glam::Vec3;
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct Ray {
|
|
pub base: Vec3,
|
|
pub dir: Vec3,
|
|
}
|
|
|
|
impl Ray {
|
|
pub fn new(base: Vec3, dir: Vec3) -> Self {
|
|
Ray { base, dir }
|
|
}
|
|
|
|
pub fn normalize(self) -> Self {
|
|
Self {
|
|
base: self.base,
|
|
dir: self.dir.normalize(),
|
|
}
|
|
}
|
|
|
|
pub fn advance(self, amount: f32) -> Self {
|
|
Self {
|
|
base: self.base + amount * self.dir,
|
|
dir: self.dir,
|
|
}
|
|
}
|
|
}
|