aboutsummaryrefslogtreecommitdiffstats
path: root/src/camera.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/camera.cpp')
-rw-r--r--src/camera.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index 027ad1e..54c847d 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -10,18 +10,29 @@ camera::camera(
float aspect_ratio,
float aperture,
float focus_dist
- ) : position(position), lens_radius(aperture / 2.0) {
+ ) : position(position), lens_radius(aperture / 2.0), fov(v_fov), focus_distance(focus_dist) {
- auto forward = (target - position).unit();
+ forward = (target - position).unit();
right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit();
up = right.cross(forward).unit();
- auto h = tan(deg_to_rad(v_fov) / 2.0);
+ auto h = tan(deg_to_rad(fov) / 2.0);
auto viewport_height = 2.0 * h;
auto viewport_width = viewport_height * aspect_ratio;
horizontal = focus_dist * viewport_width * right;
vertical = focus_dist * viewport_height * up;
- first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_dist * forward;
+ first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward;
+}
+
+void camera::set_aspect_ratio(float aspect_ratio) {
+ auto h = tan(deg_to_rad(fov) / 2.0);
+ auto viewport_height = 2.0 * h;
+ auto viewport_width = viewport_height * aspect_ratio;
+
+ horizontal = focus_distance * viewport_width * right;
+ vertical = focus_distance * viewport_height * up;
+
+ first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward;
}