Add boolean for drawing book cover.

This commit is contained in:
Bill Thiede 2018-09-10 21:50:40 -07:00
parent f2c5cf48ad
commit 823e75da88

View File

@ -13,6 +13,8 @@ use rtiow::ray::Ray;
use rtiow::sphere::Sphere; use rtiow::sphere::Sphere;
use rtiow::vec3::Vec3; use rtiow::vec3::Vec3;
const BOOK_COVER: bool = true;
fn color(r: Ray, world: &Hit, depth: usize) -> Vec3 { fn color(r: Ray, world: &Hit, depth: usize) -> Vec3 {
if let Some(rec) = world.hit(r, 0.001, std::f32::MAX) { if let Some(rec) = world.hit(r, 0.001, std::f32::MAX) {
let scatter_response = rec.material.scatter(&r, &rec); let scatter_response = rec.material.scatter(&r, &rec);
@ -103,6 +105,23 @@ fn main() -> Result<(), std::io::Error> {
let nx = 200; let nx = 200;
let ny = 100; let ny = 100;
let ns = 100; let ns = 100;
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 lookfrom = Vec3::new(3., 3., 2.);
let lookat = Vec3::new(0., 0., -1.); let lookat = Vec3::new(0., 0., -1.);
let dist_to_focus = (lookfrom - lookat).length(); let dist_to_focus = (lookfrom - lookat).length();
@ -143,7 +162,8 @@ fn main() -> Result<(), std::io::Error> {
Box::new(Dielectric::new(1.5)), Box::new(Dielectric::new(1.5)),
)), )),
]); ]);
//let world = HitableList::new(random_scene()); (cam, world)
};
println!("P3\n{} {}\n255", nx, ny); println!("P3\n{} {}\n255", nx, ny);
for j in (0..ny).rev() { for j in (0..ny).rev() {
for i in 0..nx { for i in 0..nx {