diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2020-03-29 13:26:54 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2020-03-29 13:26:54 +0200 |
commit | e007a1c511e0f1e2c0ae58d0368f057c05b72db3 (patch) | |
tree | 23ec581e8e5367a31ced4cdf3b4481592963902c /src/cgame | |
parent | b2b602040de53f1f4e1905e507e0aa740928f3e9 (diff) |
Better handling of cg_fov
The setting is combined with the original per-class FoV in a smarter way that'll prevent going over 180 degrees.
Diffstat (limited to 'src/cgame')
-rw-r--r-- | src/cgame/cg_view.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/cgame/cg_view.c b/src/cgame/cg_view.c index c50d81a..33a9c97 100644 --- a/src/cgame/cg_view.c +++ b/src/cgame/cg_view.c @@ -700,13 +700,17 @@ Fixed fov at intermissions, otherwise account for fov variable and zooms. #define FOVWARPTIME 400.0 +// Horizontal (linear) field of view to angular and back +#define HFOV(x) ( tan( (x) / 180.0f * M_PI / 2.0f ) ) +#define AFOV(x) ( 2.0f * atan2( x, 1.0f ) * 180.0f / M_PI ) + static int CG_CalcFov( void ) { float x; float phase; float v; int contents; - float fov_x, fov_y; + float hfov_mul, fov_x, fov_y; float zoomFov; float f; int inwater; @@ -820,10 +824,17 @@ static int CG_CalcFov( void ) fov_y += v; } + // clamp cg_fov to prevent graphical artifacts like seeing through walls + if ( cg_fov.value < 0.01f ) + hfov_mul = HFOV( 0.01f ); + else if ( cg_fov.value > 150.0f ) + hfov_mul = HFOV( 150.0f ); + else + hfov_mul = HFOV( cg_fov.value ); // set it - cg.refdef.fov_x = fov_x + ( cg_fov.integer - 90 ); - cg.refdef.fov_y = fov_y + ( cg_fov.integer - 90 ); + cg.refdef.fov_x = AFOV( HFOV( fov_x ) * hfov_mul ); + cg.refdef.fov_y = AFOV( HFOV( fov_y ) * hfov_mul ); if( !cg.zoomed ) cg.zoomSensitivity = 1; |