summaryrefslogtreecommitdiff
path: root/src/cgame
diff options
context:
space:
mode:
authorIronClawTrem <louie.nutman@gmail.com>2020-03-29 14:42:21 +0100
committerIronClawTrem <louie.nutman@gmail.com>2020-03-29 14:42:21 +0100
commit0092faa58e55ee8fd29e2887573bffbb8c5d7faa (patch)
treebb4c3fd6d631b7fbadf4fd5dfeb8d389b2838526 /src/cgame
parent95aac45e9a1e93b3016d7d221b4d8b43e3b556c4 (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.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/cgame/cg_view.c b/src/cgame/cg_view.c
index b80cc74..6201a91 100644
--- a/src/cgame/cg_view.c
+++ b/src/cgame/cg_view.c
@@ -707,13 +707,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;
@@ -827,10 +831,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;