diff options
Diffstat (limited to 'src/render/gl_3d.cpp')
| -rw-r--r-- | src/render/gl_3d.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/render/gl_3d.cpp b/src/render/gl_3d.cpp index 40162e8..8449500 100644 --- a/src/render/gl_3d.cpp +++ b/src/render/gl_3d.cpp @@ -21,13 +21,20 @@ void gl_3d_projection_setup( GL_SHADER_PROGRAM *_gl3d, VEC3 pos, F32 fov_deg, F3 GL3D* gl3d = (GL3D*)_gl3d; MAT4 proj, yaw_rot, pitch_rot, view, transl, tmp; - F32 fov_rad = m_deg2rad( fov_deg ); + F32 fov_y_rad = m_deg2rad( fov_deg ); F32 yaw_rad = m_deg2rad( remainderf( yaw + 90.f, 360.f ) ); F32 pitch_rad = m_deg2rad( remainderf( pitch , 360.f ) ); - gl3d->aspect = winsize.x / winsize.y; + gl3d->aspect = winsize.y > 0.f ? winsize.x / winsize.y : 1.f; + if( gl3d->aspect <= 0.000001f ) + gl3d->aspect = 1.f; + + const F32 min_fovy = m_deg2rad( 1.f ); + const F32 max_fovy = m_deg2rad( 179.f ); + if( fov_y_rad < min_fovy ) fov_y_rad = min_fovy; + if( fov_y_rad > max_fovy ) fov_y_rad = max_fovy; gl3d->winsize = winsize; - mat4_perspective( &proj, fov_rad, gl3d->aspect, near, far ); + mat4_perspective( &proj, fov_y_rad, gl3d->aspect, near, far ); mat4_rotation_y( &yaw_rot, -yaw_rad ); mat4_rotation_x( &pitch_rot, -pitch_rad ); mat4_translation( &transl, -pos.x, -pos.z, -pos.y ); |
