diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2020-12-20 22:42:37 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2020-12-20 22:42:37 +0100 |
| commit | 643708a9922cabe9b37329ee41a8668087dc92d7 (patch) | |
| tree | e4052ae5b08569d97af39afc8456852d836d6c9f /src/camera.cpp | |
| parent | 44c1eec63fc51d1a4eb888cde5e8f4b874876bab (diff) | |
Add a camera class
Diffstat (limited to 'src/camera.cpp')
| -rw-r--r-- | src/camera.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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 + }; +} |
