From ea311408ba179cc561918e6f43a523f7dccd59f4 Mon Sep 17 00:00:00 2001 From: Matthew Gordon Date: Sat, 20 Jun 2020 19:28:40 -0400 Subject: [PATCH] Add time parameter to allow animation --- src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8433f81..6378f01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use sdl2::rect::Rect; use sdl2::render::{Canvas, Texture}; use sdl2::Sdl; -use nalgebra::{convert, Point3, Rotation3, Vector3}; +use nalgebra::{convert, Point3, Rotation3, Translation3, Vector3}; use clap::Arg; @@ -29,6 +29,7 @@ struct CommandLineParameters { width: usize, height: usize, output_file: Option, + time: f64, } fn parse_args() -> CommandLineParameters { @@ -52,15 +53,24 @@ fn parse_args() -> CommandLineParameters { .takes_value(true) .required(false), ) + .arg( + Arg::with_name("time") + .long("time") + .value_name("SECONDS") + .takes_value(true) + .default_value("0"), + ) .get_matches(); let mut size_iter = matches.values_of("size").unwrap(); let width = size_iter.next().unwrap().parse().unwrap(); let height = size_iter.next().unwrap().parse().unwrap(); let output_file = matches.value_of_os("output_png").map(|f| PathBuf::from(f)); + let time = matches.value_of("time").unwrap().parse().unwrap(); CommandLineParameters { width, height, output_file, + time, } } @@ -136,7 +146,12 @@ pub fn main() -> Result<(), Box> { }), ) .iter() - .map(|elem| elem.transform(&convert(Rotation3::from_euler_angles(0.0, 0.0, 1.0)))) + .map(|elem| { + elem.transform(&convert( + Translation3::from(Vector3::new(0.25, 1.5, 2.5)) + * Rotation3::from_euler_angles(0.0, parameters.time * 0.02, 0.0), + )) + }) .map(|elem| Box::new(elem.clone()) as Box>) .collect(); /*println!("Building BVH...");