From 45fafbcd4b41a5388ece377c4e051b5846407288 Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 21 Jan 2024 17:03:07 +0000 Subject: fmt and tidy --- src/camera.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/camera.rs') diff --git a/src/camera.rs b/src/camera.rs index 55bf387..52c2011 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,6 +1,6 @@ use crate::ray::Ray; -use crate::vec3::{Point3, Vec3}; use crate::util::degrees_to_radians; +use crate::vec3::{Point3, Vec3}; pub struct Camera { origin: Point3, @@ -16,7 +16,17 @@ pub struct Camera { } impl Camera { - pub fn new(lookfrom: Point3, lookat: Point3, vup: Vec3, vfov: f64, aspect_ratio: f64, aperture: f64, focus_dist: f64, time_start: f64, time_end: f64) -> Camera { + pub fn new( + lookfrom: Point3, + lookat: Point3, + vup: Vec3, + vfov: f64, + aspect_ratio: f64, + aperture: f64, + focus_dist: f64, + time_start: f64, + time_end: f64, + ) -> Camera { let theta = degrees_to_radians(vfov); let h = (theta / 2.0).tan(); let viewport_height = 2.0 * h; @@ -30,10 +40,7 @@ impl Camera { let horizontal = focus_dist * viewport_width * &u; let vertical = focus_dist * viewport_height * &v; Camera { - lower_left_corner: &origin - - &horizontal / 2.0 - - &vertical / 2.0 - - focus_dist * &w, + lower_left_corner: &origin - &horizontal / 2.0 - &vertical / 2.0 - focus_dist * &w, origin, horizontal, vertical, @@ -51,7 +58,9 @@ impl Camera { let offset = &self.u * rd.x + &self.v * rd.y; Ray { origin: &self.origin + &offset, - direction: &self.lower_left_corner + s * &self.horizontal + t * &self.vertical - &self.origin - &offset, + direction: &self.lower_left_corner + s * &self.horizontal + t * &self.vertical + - &self.origin + - &offset, time: self.time_start + (self.time_end - self.time_start) * rand::random::(), } } -- cgit v1.2.3