ft: 4: ray class + simpl gradient
This commit is contained in:
27
src/ray.rs
Normal file
27
src/ray.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use crate::vec3::Vec3;
|
||||
|
||||
pub struct Ray {
|
||||
origin: Vec3,
|
||||
dir: Vec3,
|
||||
}
|
||||
|
||||
impl Ray {
|
||||
pub fn at(self, t: f32) -> Vec3 {
|
||||
self.origin + t * self.dir
|
||||
}
|
||||
|
||||
pub fn new(origin: Vec3, dir: Vec3) -> Ray {
|
||||
Ray {
|
||||
origin: origin,
|
||||
dir: dir,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn origin(&self) -> &Vec3 {
|
||||
&self.origin
|
||||
}
|
||||
|
||||
pub fn dir(&self) -> &Vec3 {
|
||||
&self.dir
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user