latest update
This commit is contained in:
@@ -43,7 +43,7 @@ fn ray_color(r: &Ray, world: &mut dyn Hittable, depth: i32) -> Color {
|
||||
fn main() {
|
||||
// Image
|
||||
let aspect_ratio: f64 = 1.0 / 1.0;
|
||||
let image_width: i32 = 1024;
|
||||
let image_width: i32 = 512;
|
||||
let image_height: i32 = (image_width as f64 / aspect_ratio as f64) as i32;
|
||||
let samples_per_pixel: i32 = 100;
|
||||
let max_depth: i32 = 4;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,18 @@
|
||||
use crate::hittable::*;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::{hittable::*, material};
|
||||
use crate::material::Material;
|
||||
use crate::vec3::*;
|
||||
|
||||
pub struct Sphere {
|
||||
center: Point3,
|
||||
radius: f64
|
||||
radius: f64,
|
||||
mat_ptr: Rc<Material>,
|
||||
}
|
||||
|
||||
impl Sphere {
|
||||
pub fn new(center: Point3, radius: f64) -> Self {
|
||||
Sphere {center, radius}
|
||||
pub fn new(center: Point3, radius: f64, mat_ptr: Rc<Material>) -> Self {
|
||||
Sphere {center, radius, mat_ptr}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +40,7 @@ impl Hittable for Sphere {
|
||||
rec.p = r.at(rec.t);
|
||||
let outward_normal = (rec.p - self.center) / self.radius;
|
||||
rec.set_face_normal(r, &outward_normal);
|
||||
rec.mat_ptr = self.mat_ptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user