Support setting perspective camera fov by aspect ratio

This commit is contained in:
Nikita Lisitsa 2020-09-13 16:39:11 +03:00
parent 66f9878dd1
commit 3444ac9984
2 changed files with 9 additions and 0 deletions

View file

@ -60,6 +60,9 @@ namespace psemek::geom
float far_clip;
matrix<float, 4, 4> projection() const override;
// aspect_ratio = width / height
void set_fov(float fov_y, float aspect_ratio);
};
struct spherical_camera

View file

@ -96,6 +96,12 @@ namespace psemek::geom
return perspective<float, 3>(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<float, 4, 4> spherical_camera::view() const
{
return