This commit is contained in:
2023-02-01 22:30:20 +01:00
parent 0a70a1e1de
commit 560b2b1196
5 changed files with 21 additions and 27 deletions

View File

@@ -1,22 +1,20 @@
use std::rc::Rc;
use crate::{hittable::*, material};
use crate::hittable::*;
use crate::material::Material;
use crate::vec3::*;
pub struct Sphere {
pub struct Sphere<'a> {
center: Point3,
radius: f64,
mat_ptr: Rc<Material>,
mat_ptr: &'a dyn Material,
}
impl Sphere {
pub fn new(center: Point3, radius: f64, mat_ptr: Rc<Material>) -> Self {
impl Sphere<'_> {
pub fn new<T: Material>(center: Point3, radius: f64, mat_ptr: &T) -> Self {
Sphere {center, radius, mat_ptr}
}
}
impl Hittable for Sphere {
impl Hittable for Sphere<'_> {
fn hit(&mut self, r: &crate::ray::Ray, t_min: f64, t_max: f64, rec: &mut HitRecord) -> bool {
let oc = r.origin() - self.center;
let a = r.direction().length_squared();