From 643708a9922cabe9b37329ee41a8668087dc92d7 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Sun, 20 Dec 2020 22:42:37 +0100 Subject: Add a camera class --- src/camera.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/camera.cpp (limited to 'src/camera.cpp') diff --git a/src/camera.cpp b/src/camera.cpp new file mode 100644 index 0000000..cd43359 --- /dev/null +++ b/src/camera.cpp @@ -0,0 +1,22 @@ +#include "camera.hpp" + +camera::camera(point3 position, double aspect_ratio, double focal_length) + : position(position), focal_length(focal_length) { + auto viewport_height = 2.0; + auto viewport_width = viewport_height * aspect_ratio; + + horizontal = vec3 { viewport_width, 0.0, 0.0 }; + vertical = vec3 { 0.0, viewport_height, 0.0 }; + + bottom_left_pixel = position - horizontal / 2.0 - vertical / 2.0 - vec3 { 0.0, 0.0, focal_length }; + + std::cerr << bottom_left_pixel << std::endl; +} + +ray camera::get_ray(double u, double v) const { + point3 viewport_pixel = bottom_left_pixel + u * horizontal + v * vertical; + return ray { + position, + viewport_pixel - position + }; +} -- cgit v1.3