~ttt/ray_tracing_in_one_weekend

ff8ef4e7cb6cb544d8660faf69a55d2a7798c8cb — Tomasz Kłak 4 years ago 69f8f79
ch 6.5 done
2 files changed, 41 insertions(+), 0 deletions(-)

A src/hittable_list.rs
M src/main.rs
A src/hittable_list.rs => src/hittable_list.rs +38 -0
@@ 0,0 1,38 @@
use crate::hittable::*;
use crate::ray::*;
use crate::vec3::*;
use std::sync::Arc;

#[derive(Clone)]
pub struct HittableList {
    objects: Vec<Arc<dyn Hittable>>,
}

impl HittableList {
    fn empty() -> Self {
        HittableList{ objects: vec![] }
    }

    fn clear(&mut self) {
        self.objects.clear();
    }

    fn add(&mut self, object: &Arc<dyn Hittable>) {
        self.objects.push(object.clone());
    }
}

impl Hittable for HittableList {
    fn hit(&self, r: &Ray, t_min: f64, t_max: f64) -> Option<HitRecord> {
        let mut temp_rec = None;
        let mut closest_so_far = t_max;

        for object in &self.objects {
            if let Some(hr) = object.hit(r, t_min, closest_so_far) {
                closest_so_far = hr.t;
                temp_rec = Some(hr);
            }
        }
        temp_rec
    }
}

M src/main.rs => src/main.rs +3 -0
@@ 7,6 7,9 @@ use ray::*;
mod hittable;
use hittable::*;

mod hittable_list;
use hittable_list::*;

mod sphere;
use sphere::*;