summaryrefslogtreecommitdiff
path: root/racer-tracer/src/camera.rs
diff options
context:
space:
mode:
Diffstat (limited to 'racer-tracer/src/camera.rs')
-rw-r--r--racer-tracer/src/camera.rs48
1 files changed, 33 insertions, 15 deletions
diff --git a/racer-tracer/src/camera.rs b/racer-tracer/src/camera.rs
index 438c18d..18b1d1a 100644
--- a/racer-tracer/src/camera.rs
+++ b/racer-tracer/src/camera.rs
@@ -6,19 +6,21 @@ use crate::vec3::Vec3;
#[derive(Clone)]
pub struct Camera {
- pub viewport_height: f64,
- pub viewport_width: f64,
- pub origin: Vec3,
- pub horizontal: Vec3,
- pub vertical: Vec3,
- pub upper_left_corner: Vec3,
- pub forward: Vec3,
- pub right: Vec3,
- pub up: Vec3,
- pub scene_up: Vec3,
- pub lens_radius: f64,
- pub focus_distance: f64,
- pub aspect_ratio: f64,
+ viewport_height: f64,
+ viewport_width: f64,
+ origin: Vec3,
+ horizontal: Vec3,
+ vertical: Vec3,
+ upper_left_corner: Vec3,
+ forward: Vec3,
+ right: Vec3,
+ up: Vec3,
+ scene_up: Vec3,
+ lens_radius: f64,
+ focus_distance: f64,
+ aspect_ratio: f64,
+ vfov: f64,
+ aperture: f64,
}
impl Camera {
@@ -57,6 +59,8 @@ impl Camera {
lens_radius: aperture * 0.5,
focus_distance,
aspect_ratio: image.aspect_ratio,
+ vfov,
+ aperture,
}
}
@@ -71,14 +75,24 @@ impl Camera {
}
pub fn set_fov(&mut self, vfov: f64) {
- let h = (degrees_to_radians(vfov) / 2.0).tan();
+ self.vfov = vfov;
+ let h = (degrees_to_radians(self.vfov) / 2.0).tan();
self.viewport_height = 2.0 * h;
self.viewport_width = self.aspect_ratio * self.viewport_height;
self.update_viewport();
}
+ pub fn get_vfov(&self) -> f64 {
+ self.vfov
+ }
+
pub fn set_aperture(&mut self, aperture: f64) {
- self.lens_radius = aperture * 0.5;
+ self.aperture = aperture;
+ self.lens_radius = self.aperture * 0.5;
+ }
+
+ pub fn get_aperture(&self) -> f64 {
+ self.aperture
}
pub fn set_focus_distance(&mut self, focus_distance: f64) {
@@ -86,6 +100,10 @@ impl Camera {
self.update_viewport();
}
+ pub fn get_focus_distance(&self) -> f64 {
+ self.focus_distance
+ }
+
pub fn get_ray(&self, u: f64, v: f64) -> Ray {
let ray_direction = self.lens_radius * random_in_unit_disk();
let offset = self.right * ray_direction.x() + self.up * ray_direction.y();