latest update

This commit is contained in:
2023-01-30 17:18:16 +01:00
parent 899e8b7228
commit b764470c77
4 changed files with 34 additions and 12 deletions

View File

@@ -1,13 +1,30 @@
use crate::hittable::HitRecord;
use crate::ray::Ray;
use crate::rtweekend::*;
use crate::hittable_list::*;
use crate::vec3::Color;
use crate::ray::{Ray, self};
use crate::vec3::{Color, random_unit_vector};
pub struct Material {
}
trait Scatter {
fn scatter(r_in: &Ray, rec: HitRecord, attenuation: &Color, scattered: &Ray) -> bool;
fn scatter(&self, r_in: &Ray, rec: HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool;
}
pub struct Lambertian {
albedo: Color,
}
impl Lambertian {
pub fn new(a: &Color) -> Self {
Lambertian { albedo: *a }
}
}
impl Scatter for Lambertian {
fn scatter(&self, r_in: &Ray, rec: HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool {
let scatter_direction = rec.normal + random_unit_vector();
scattered = &mut Ray::new(rec.p, scatter_direction);
attenuation = &mut self.albedo;
return true;
}
}