diff --git a/rtchallenge/examples/eoc2.rs b/rtchallenge/examples/eoc2.rs index 8c0be9c..afcc7aa 100644 --- a/rtchallenge/examples/eoc2.rs +++ b/rtchallenge/examples/eoc2.rs @@ -3,6 +3,7 @@ use anyhow::{bail, Result}; use rtchallenge::{ canvas::Canvas, tuples::{Color, Tuple}, + Float, }; #[derive(Debug)] @@ -47,8 +48,8 @@ fn main() -> Result<()> { let bg = Color::new(0.2, 0.2, 0.2); let mut c = Canvas::new(w, h, bg); let mut i = 0; - let w = w as f32; - let h = h as f32; + let w = w as Float; + let h = h as Float; while p.position.y > 0. { p = tick(&e, &p); println!("tick {}: proj {:?}", i, p); diff --git a/rtchallenge/examples/eoc4.rs b/rtchallenge/examples/eoc4.rs index 4463a62..054888f 100644 --- a/rtchallenge/examples/eoc4.rs +++ b/rtchallenge/examples/eoc4.rs @@ -1,11 +1,11 @@ -use std::f32::consts::PI; - use anyhow::Result; use rtchallenge::{ canvas::Canvas, + float::consts::PI, matrices::Matrix4x4, tuples::{Color, Tuple}, + Float, }; fn draw_dot(c: &mut Canvas, x: usize, y: usize) { @@ -30,13 +30,13 @@ fn main() -> Result<()> { let rot_hour = Matrix4x4::rotation_z(-PI / 6.); let mut p = t * p; - let w = w as f32; - let h = h as f32; + let w = w as Float; + let h = h as Float; // The 'world' exists between -0.5 - 0.5 in X-Y plane. // To convert to screen space, we translate by 0.5, scale to canvas size, // and invert the Y-axis. let world_to_screen = - Matrix4x4::scaling(w as f32, -h as f32, 1.0) * Matrix4x4::translation(0.5, -0.5, 0.); + Matrix4x4::scaling(w as Float, -h as Float, 1.0) * Matrix4x4::translation(0.5, -0.5, 0.); for _ in 0..12 { let canvas_pixel = world_to_screen * p; draw_dot(&mut c, canvas_pixel.x as usize, canvas_pixel.y as usize); diff --git a/rtchallenge/examples/eoc5.rs b/rtchallenge/examples/eoc5.rs index e1d3251..c30baf5 100644 --- a/rtchallenge/examples/eoc5.rs +++ b/rtchallenge/examples/eoc5.rs @@ -6,6 +6,7 @@ use rtchallenge::{ rays::Ray, spheres::{intersect, Sphere}, tuples::{Color, Tuple}, + Float, }; fn main() -> Result<()> { @@ -16,7 +17,7 @@ fn main() -> Result<()> { let ray_origin = Tuple::point(0., 0., -5.); let wall_z = 10.; let wall_size = 7.; - let pixel_size = wall_size / w as f32; + let pixel_size = wall_size / w as Float; let half = wall_size / 2.; let color = Color::new(1., 0., 0.); let mut shape = Sphere::default(); @@ -25,9 +26,9 @@ fn main() -> Result<()> { ); for y in 0..h { - let world_y = half - pixel_size * y as f32; + let world_y = half - pixel_size * y as Float; for x in 0..w { - let world_x = -half + pixel_size * x as f32; + let world_x = -half + pixel_size * x as Float; let position = Tuple::point(world_x, world_y, wall_z); let r = Ray::new(ray_origin, (position - ray_origin).normalize()); let xs = intersect(&shape, &r); diff --git a/rtchallenge/examples/eoc6.rs b/rtchallenge/examples/eoc6.rs index 959c22f..c597296 100644 --- a/rtchallenge/examples/eoc6.rs +++ b/rtchallenge/examples/eoc6.rs @@ -7,7 +7,7 @@ use rtchallenge::{ rays::Ray, spheres::{intersect, Sphere}, tuples::{Color, Tuple}, - WHITE, + Float, WHITE, }; fn main() -> Result<()> { @@ -18,7 +18,7 @@ fn main() -> Result<()> { let ray_origin = Tuple::point(0., 0., -5.); let wall_z = 10.; let wall_size = 7.; - let pixel_size = wall_size / w as f32; + let pixel_size = wall_size / w as Float; let half = wall_size / 2.; let mut shape = Sphere::default(); shape.material = Material { @@ -33,9 +33,9 @@ fn main() -> Result<()> { let light = PointLight::new(light_position, light_color); let in_shadow = false; for y in 0..h { - let world_y = half - pixel_size * y as f32; + let world_y = half - pixel_size * y as Float; for x in 0..w { - let world_x = -half + pixel_size * x as f32; + let world_x = -half + pixel_size * x as Float; let position = Tuple::point(world_x, world_y, wall_z); let direction = (position - ray_origin).normalize(); let r = Ray::new(ray_origin, direction); diff --git a/rtchallenge/examples/eoc7.rs b/rtchallenge/examples/eoc7.rs index 959b005..c0ff874 100644 --- a/rtchallenge/examples/eoc7.rs +++ b/rtchallenge/examples/eoc7.rs @@ -1,10 +1,11 @@ -use std::{f32::consts::PI, time::Instant}; +use std::time::Instant; use anyhow::Result; use structopt::StructOpt; use rtchallenge::{ camera::{Camera, RenderStrategy}, + float::consts::PI, lights::PointLight, materials::Material, matrices::Matrix4x4, diff --git a/rtchallenge/examples/eoc8.rs b/rtchallenge/examples/eoc8.rs index 1749eeb..a2eb07a 100644 --- a/rtchallenge/examples/eoc8.rs +++ b/rtchallenge/examples/eoc8.rs @@ -1,10 +1,11 @@ -use std::{f32::consts::PI, time::Instant}; +use std::time::Instant; use anyhow::Result; use structopt::StructOpt; use rtchallenge::{ camera::{Camera, RenderStrategy}, + float::consts::PI, lights::PointLight, materials::Material, matrices::Matrix4x4, @@ -31,7 +32,7 @@ fn main() -> Result<()> { let light_position = Tuple::point(-10., 10., -10.); let light_color = WHITE; let light = PointLight::new(light_position, light_color); - let mut camera = Camera::new(width, height, PI / 4.); + let mut camera = Camera::new(width, height, PI / 2.); let from = Tuple::point(0., 1.5, -5.); let to = Tuple::point(0., 1., 0.); let up = Tuple::point(0., 1., 0.);