eoc9: make width and height CLI flags.
This commit is contained in:
parent
62ad827507
commit
c158d92252
@ -11,19 +11,24 @@ use rtchallenge::{camera::RenderStrategy, float::consts::PI, WHITE};
|
|||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(name = "eoc9")]
|
#[structopt(name = "eoc9")]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
/// Strategy for casting rays into image.
|
||||||
#[structopt(long, default_value = "rayon")]
|
#[structopt(long, default_value = "rayon")]
|
||||||
render_strategy: RenderStrategy,
|
render_strategy: RenderStrategy,
|
||||||
/// Number of samples per pixel. 0 renders from the center of the pixel, 1 or more samples N
|
/// Number of samples per pixel. 0 renders from the center of the pixel, 1 or more samples N
|
||||||
/// times randomly across the pixel.
|
/// times randomly across the pixel.
|
||||||
#[structopt(short, long, default_value = "0")]
|
#[structopt(short, long, default_value = "0")]
|
||||||
samples: usize,
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
let width = 2560;
|
|
||||||
let height = 1440;
|
|
||||||
|
|
||||||
let light1 = PointLightBuilder::default()
|
let light1 = PointLightBuilder::default()
|
||||||
.position(point(-5., 5., -5.))
|
.position(point(-5., 5., -5.))
|
||||||
@ -42,8 +47,8 @@ fn main() -> Result<()> {
|
|||||||
let to = point(0., 1., 0.);
|
let to = point(0., 1., 0.);
|
||||||
let up = point(0., 1., 0.);
|
let up = point(0., 1., 0.);
|
||||||
let camera = CameraBuilder::default()
|
let camera = CameraBuilder::default()
|
||||||
.hsize(width)
|
.hsize(opt.width)
|
||||||
.vsize(height)
|
.vsize(opt.height)
|
||||||
.field_of_view(PI / 4.)
|
.field_of_view(PI / 4.)
|
||||||
.transform(view_transform(from, to, up))
|
.transform(view_transform(from, to, up))
|
||||||
.render_strategy(opt.render_strategy)
|
.render_strategy(opt.render_strategy)
|
||||||
|
|||||||
@ -20,19 +20,24 @@ use rtchallenge::{
|
|||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
#[structopt(name = "eoc9")]
|
#[structopt(name = "eoc9")]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
/// Strategy for casting rays into image.
|
||||||
#[structopt(long, default_value = "rayon")]
|
#[structopt(long, default_value = "rayon")]
|
||||||
render_strategy: RenderStrategy,
|
render_strategy: RenderStrategy,
|
||||||
/// Number of samples per pixel. 0 renders from the center of the pixel, 1 or more samples N
|
/// Number of samples per pixel. 0 renders from the center of the pixel, 1 or more samples N
|
||||||
/// times randomly across the pixel.
|
/// times randomly across the pixel.
|
||||||
#[structopt(short, long, default_value = "0")]
|
#[structopt(short, long, default_value = "0")]
|
||||||
samples: usize,
|
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<()> {
|
fn main() -> Result<()> {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
let width = 2560;
|
|
||||||
let height = 1440;
|
|
||||||
|
|
||||||
let light_position = Tuple::point(-5., 5., -5.);
|
let light_position = Tuple::point(-5., 5., -5.);
|
||||||
let light_color = WHITE;
|
let light_color = WHITE;
|
||||||
@ -44,7 +49,7 @@ fn main() -> Result<()> {
|
|||||||
let light_color = Color::new(0.2, 0.2, 0.1);
|
let light_color = Color::new(0.2, 0.2, 0.1);
|
||||||
let light3 = PointLight::new(light_position, light_color);
|
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 from = Tuple::point(0., 1.5, -5.);
|
||||||
let to = Tuple::point(0., 1., 0.);
|
let to = Tuple::point(0., 1., 0.);
|
||||||
let up = Tuple::point(0., 1., 0.);
|
let up = Tuple::point(0., 1., 0.);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user