finally random colors 🚀

This commit is contained in:
2026-02-14 04:27:54 +01:00
parent 5bdd7d8121
commit 25a3661fd0
3 changed files with 29 additions and 26 deletions

View File

@@ -1,21 +1,24 @@
use std::ops::Deref;
use crate::hittable::*;
use crate::material::Material;
use crate::vec3::*;
use crate::Ray;
pub struct Sphere<'a> {
pub struct Sphere {
center: Point3,
radius: f64,
mat_ptr: &'a dyn Material,
mat_ptr: Box<dyn Material>,
}
impl Sphere<'_> {
pub fn new<T: Material>(center: Point3, radius: f64, mat_ptr: &'static T) -> Self {
impl Sphere {
pub fn new<T: Material + 'static>(center: Point3, radius: f64, mat_ptr: Box<T>) -> Self {
Sphere {center, radius, mat_ptr}
}
}
impl Hittable for Sphere<'_> {
fn hit(&self, r: &crate::ray::Ray, t_min: f64, t_max: f64) -> Option<HitRecord<'_>> {
impl Hittable for Sphere {
fn hit(&self, r: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord<'_>> {
let oc = r.origin() - self.center;
let a = r.direction().length_squared();
let half_b = oc.dot(&r.direction());
@@ -51,7 +54,7 @@ impl Hittable for Sphere<'_> {
p: p,
normal: outward_normal,
front_face,
mat_ptr: self.mat_ptr,
mat_ptr: self.mat_ptr.deref(),
})
}
}