eoc9: make width and height CLI flags.

This commit is contained in:
Bill Thiede 2021-07-23 22:18:20 -07:00
parent 62ad827507
commit c158d92252
2 changed files with 17 additions and 7 deletions

View File

@ -11,19 +11,24 @@ use rtchallenge::{camera::RenderStrategy, float::consts::PI, WHITE};
#[derive(StructOpt, Debug)]
#[structopt(name = "eoc9")]
struct Opt {
/// Strategy for casting rays into image.
#[structopt(long, default_value = "rayon")]
render_strategy: RenderStrategy,
/// Number of samples per pixel. 0 renders from the center of the pixel, 1 or more samples N
/// times randomly across the pixel.
#[structopt(short, long, default_value = "0")]
samples: usize,
/// Rendered image width in pixels.
#[structopt(short, long, default_value = "2560")]
width: usize,
/// Rendered image height in pixels.
#[structopt(short, long, default_value = "1440")]
height: usize,
}
fn main() -> Result<()> {
let start = Instant::now();
let opt = Opt::from_args();
let width = 2560;
let height = 1440;
let light1 = PointLightBuilder::default()
.position(point(-5., 5., -5.))
@ -42,8 +47,8 @@ fn main() -> Result<()> {
let to = point(0., 1., 0.);
let up = point(0., 1., 0.);
let camera = CameraBuilder::default()
.hsize(width)
.vsize(height)
.hsize(opt.width)
.vsize(opt.height)
.field_of_view(PI / 4.)
.transform(view_transform(from, to, up))
.render_strategy(opt.render_strategy)

View File

@ -20,19 +20,24 @@ use rtchallenge::{
#[derive(StructOpt, Debug)]
#[structopt(name = "eoc9")]
struct Opt {
/// Strategy for casting rays into image.
#[structopt(long, default_value = "rayon")]
render_strategy: RenderStrategy,
/// Number of samples per pixel. 0 renders from the center of the pixel, 1 or more samples N
/// times randomly across the pixel.
#[structopt(short, long, default_value = "0")]
samples: usize,
/// Rendered image width in pixels.
#[structopt(short, long, default_value = "2560")]
width: usize,
/// Rendered image height in pixels.
#[structopt(short, long, default_value = "1440")]
height: usize,
}
fn main() -> Result<()> {
let start = Instant::now();
let opt = Opt::from_args();
let width = 2560;
let height = 1440;
let light_position = Tuple::point(-5., 5., -5.);
let light_color = WHITE;
@ -44,7 +49,7 @@ fn main() -> Result<()> {
let light_color = Color::new(0.2, 0.2, 0.1);
let light3 = PointLight::new(light_position, light_color);
let mut camera = Camera::new(width, height, PI / 4.);
let mut camera = Camera::new(opt.width, opt.height, PI / 4.);
let from = Tuple::point(0., 1.5, -5.);
let to = Tuple::point(0., 1., 0.);
let up = Tuple::point(0., 1., 0.);