From 823e75da887c0678afa4265440def73a7bb1f78a Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Mon, 10 Sep 2018 21:50:40 -0700 Subject: [PATCH] Add boolean for drawing book cover. --- rtiow/src/bin/tracer.rs | 102 ++++++++++++++++++++++++---------------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/rtiow/src/bin/tracer.rs b/rtiow/src/bin/tracer.rs index 81fd764..67ec0f1 100644 --- a/rtiow/src/bin/tracer.rs +++ b/rtiow/src/bin/tracer.rs @@ -13,6 +13,8 @@ use rtiow::ray::Ray; use rtiow::sphere::Sphere; use rtiow::vec3::Vec3; +const BOOK_COVER: bool = true; + fn color(r: Ray, world: &Hit, depth: usize) -> Vec3 { if let Some(rec) = world.hit(r, 0.001, std::f32::MAX) { let scatter_response = rec.material.scatter(&r, &rec); @@ -103,47 +105,65 @@ fn main() -> Result<(), std::io::Error> { let nx = 200; let ny = 100; let ns = 100; - let lookfrom = Vec3::new(3., 3., 2.); - let lookat = Vec3::new(0., 0., -1.); - let dist_to_focus = (lookfrom - lookat).length(); - let aperture = 2.; - let cam = Camera::new( - lookfrom, - lookat, - Vec3::new(0., 1., 0.), - 20., - nx as f32 / ny as f32, - aperture, - dist_to_focus, - ); - let world = HitableList::new(vec![ - Box::new(Sphere::new( - Vec3::new(0., 0., -1.), - 0.5, - Box::new(Lambertian::new(Vec3::new(0.1, 0.2, 0.5))), - )), - Box::new(Sphere::new( - Vec3::new(0., -100.5, -1.), - 100., - Box::new(Lambertian::new(Vec3::new(0.8, 0.8, 0.))), - )), - Box::new(Sphere::new( - Vec3::new(1., 0., -1.), - 0.5, - Box::new(Metal::new(Vec3::new(0.8, 0.6, 0.2), 0.2)), - )), - Box::new(Sphere::new( - Vec3::new(-1., 0., -1.), - 0.5, - Box::new(Dielectric::new(1.5)), - )), - Box::new(Sphere::new( - Vec3::new(-1., 0., -1.), - -0.45, - Box::new(Dielectric::new(1.5)), - )), - ]); - //let world = HitableList::new(random_scene()); + let (cam, world) = if BOOK_COVER { + let lookfrom = Vec3::new(13., 2., 3.); + let lookat = Vec3::new(0., 0., 0.); + let dist_to_focus = 10.; + let aperture = 0.1; + let cam = Camera::new( + lookfrom, + lookat, + Vec3::new(0., 1., 0.), + 20., + nx as f32 / ny as f32, + aperture, + dist_to_focus, + ); + let world = HitableList::new(random_scene()); + (cam, world) + } else { + let lookfrom = Vec3::new(3., 3., 2.); + let lookat = Vec3::new(0., 0., -1.); + let dist_to_focus = (lookfrom - lookat).length(); + let aperture = 2.; + let cam = Camera::new( + lookfrom, + lookat, + Vec3::new(0., 1., 0.), + 20., + nx as f32 / ny as f32, + aperture, + dist_to_focus, + ); + let world = HitableList::new(vec![ + Box::new(Sphere::new( + Vec3::new(0., 0., -1.), + 0.5, + Box::new(Lambertian::new(Vec3::new(0.1, 0.2, 0.5))), + )), + Box::new(Sphere::new( + Vec3::new(0., -100.5, -1.), + 100., + Box::new(Lambertian::new(Vec3::new(0.8, 0.8, 0.))), + )), + Box::new(Sphere::new( + Vec3::new(1., 0., -1.), + 0.5, + Box::new(Metal::new(Vec3::new(0.8, 0.6, 0.2), 0.2)), + )), + Box::new(Sphere::new( + Vec3::new(-1., 0., -1.), + 0.5, + Box::new(Dielectric::new(1.5)), + )), + Box::new(Sphere::new( + Vec3::new(-1., 0., -1.), + -0.45, + Box::new(Dielectric::new(1.5)), + )), + ]); + (cam, world) + }; println!("P3\n{} {}\n255", nx, ny); for j in (0..ny).rev() { for i in 0..nx {