* calculate fov against max of 3D viewport width, height for consistency

This commit is contained in:
Garux 2019-08-31 11:30:29 +03:00
parent 3bb51ba6b9
commit 6e42edd1cb

View File

@ -215,8 +215,13 @@ const float camera_t::near_z = 1.f;
camera_draw_mode camera_t::draw_mode = cd_texture; camera_draw_mode camera_t::draw_mode = cd_texture;
inline Matrix4 projection_for_camera( float near_z, float far_z, float fieldOfView, int width, int height ){ inline Matrix4 projection_for_camera( float near_z, float far_z, float fieldOfView, int width, int height ){
const float half_width = static_cast<float>( near_z * tan( degrees_to_radians( fieldOfView * 0.5 ) ) ); float half_width = static_cast<float>( near_z * tan( degrees_to_radians( fieldOfView * 0.5 ) ) );
const float half_height = half_width * ( static_cast<float>( height ) / static_cast<float>( width ) ); const bool swap = height > width;
if( swap )
std::swap( width, height );
float half_height = half_width * ( static_cast<float>( height ) / static_cast<float>( width ) );
if( swap )
std::swap( half_width, half_height );
return matrix4_frustum( return matrix4_frustum(
-half_width, -half_width,