ft (wip): random scene generation
This commit is contained in:
@@ -29,6 +29,16 @@ impl Sphere {
|
||||
material: mat,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn center(&self) -> &Vec3 {
|
||||
&self.center
|
||||
}
|
||||
|
||||
pub fn set_center(&mut self, center: Vec3) {
|
||||
if self.center != center {
|
||||
self.center = center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hittable for Sphere {
|
||||
@@ -60,4 +70,12 @@ impl Hittable for Sphere {
|
||||
fn normal_at(&self, p: &Vec3) -> Vec3 {
|
||||
(*p - self.center).get_unit()
|
||||
}
|
||||
|
||||
fn inside(&self, p: &Vec3) -> bool {
|
||||
(*p - self.center).length() < self.radius
|
||||
}
|
||||
|
||||
fn closest_on_surface(&self, p: &Vec3) -> Vec3 {
|
||||
self.normal_at(p) * self.radius
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,4 +5,7 @@ use crate::Vec3;
|
||||
pub trait Hittable {
|
||||
fn hit(&self, r: &Ray) -> Option<Hit>;
|
||||
fn normal_at(&self, p: &Vec3) -> Vec3;
|
||||
// fn intersect<H: Hittable>(&self, o: &H) -> bool;
|
||||
fn inside(&self, p: &Vec3) -> bool;
|
||||
fn closest_on_surface(&self, p: &Vec3) -> Vec3;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user