ft (wip): random scene generation

This commit is contained in:
2026-04-25 05:20:15 +02:00
parent 5f2c419af5
commit ef8da70436
4 changed files with 113 additions and 23 deletions

View File

@@ -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
}
}

View File

@@ -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;
}