aboutsummaryrefslogtreecommitdiff
path: root/src/camera.rs
diff options
context:
space:
mode:
authorlamp2024-01-21 17:03:07 +0000
committerlamp2024-01-21 17:03:07 +0000
commit45fafbcd4b41a5388ece377c4e051b5846407288 (patch)
tree2192c471ca3b47671f0906e27f6f6088f40b3d8a /src/camera.rs
parent89a5c9a8a0cdf627cda0e31da454f83ca21315ce (diff)
fmt and tidy
Diffstat (limited to 'src/camera.rs')
-rw-r--r--src/camera.rs23
1 files changed, 16 insertions, 7 deletions
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::<f64>(),
}
}