diff --git a/libs/geom/include/psemek/geom/camera.hpp b/libs/geom/include/psemek/geom/camera.hpp index 976e9443..9731dc41 100644 --- a/libs/geom/include/psemek/geom/camera.hpp +++ b/libs/geom/include/psemek/geom/camera.hpp @@ -60,6 +60,9 @@ namespace psemek::geom float far_clip; matrix projection() const override; + + // aspect_ratio = width / height + void set_fov(float fov_y, float aspect_ratio); }; struct spherical_camera diff --git a/libs/geom/source/camera.cpp b/libs/geom/source/camera.cpp index 117affce..cb433bc8 100644 --- a/libs/geom/source/camera.cpp +++ b/libs/geom/source/camera.cpp @@ -96,6 +96,12 @@ namespace psemek::geom return perspective(fov_x, fov_y, near_clip, far_clip).homogeneous_matrix(); } + void perspective_camera::set_fov(float fov_y, float aspect_ratio) + { + this->fov_y = fov_y; + fov_x = 2.f * std::atan(aspect_ratio * std::tan(fov_y / 2.f)); + } + matrix spherical_camera::view() const { return