Add boolean for drawing book cover.
This commit is contained in:
parent
f2c5cf48ad
commit
823e75da88
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user