From 928b4191bf5a0d27da6d680ccaade7f94860359e Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Fri, 6 Jan 2023 22:59:27 +0100 Subject: =?UTF-8?q?=E2=98=81=20Add=20sky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racer-tracer/src/camera.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 racer-tracer/src/camera.rs (limited to 'racer-tracer/src/camera.rs') diff --git a/racer-tracer/src/camera.rs b/racer-tracer/src/camera.rs new file mode 100644 index 0000000..5f0abbb --- /dev/null +++ b/racer-tracer/src/camera.rs @@ -0,0 +1,34 @@ +use crate::image::Image; +use crate::vec3::Vec3; + +#[derive(Clone)] +pub struct Camera { + pub viewport_height: f64, + pub viewport_width: f64, + pub focal_length: f64, + pub origin: Vec3, + pub horizontal: Vec3, + pub vertical: Vec3, + pub lower_left_corner: Vec3, +} + +impl Camera { + pub fn new(image: &Image, viewport_height: f64, focal_length: f64) -> Camera { + let viewport_width = image.aspect_ratio * viewport_height; + let origin = Vec3::new(0.0, 0.0, 0.0); + let horizontal = Vec3::new(viewport_width, 0.0, 0.0); + let vertical = Vec3::new(0.0, viewport_height, 0.0); + Camera { + viewport_height, + viewport_width, + focal_length, + origin, + horizontal, + vertical, + lower_left_corner: origin + - horizontal / 2.0 + - vertical / 2.0 + - Vec3::new(0.0, 0.0, focal_length), + } + } +} -- cgit v1.2.3