Skip to content

Commit 132815c

Browse files
committed
fix fov scaling on zoom
1 parent 9a88ab6 commit 132815c

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/game/client/view.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ extern ConVar sensitivity;
8484
#endif
8585

8686
ConVar zoom_sensitivity_ratio( "zoom_sensitivity_ratio", "1.0", FCVAR_ARCHIVE, "Additional mouse sensitivity scale factor applied when FOV is zoomed in." );
87+
ConVar zoom_sensitivity_scaling( "zoom_sensitivity_scaling", "1", FCVAR_ARCHIVE, "FOV zoom scaling algorithm to use: 1 - accurate scaling 0 - legacy scaling" );
8788

8889
CViewRender g_DefaultViewRender;
8990
IViewRender *view = NULL; // set in cldll_client_init.cpp if no mod creates their own
@@ -541,12 +542,25 @@ void CViewRender::OnRenderStart()
541542
// by a separate compensating factor
542543
if ( iDefaultFOV == 0 )
543544
{
544-
Assert(0); // would divide by zero, something is broken with iDefatulFOV
545+
Assert(0); // would divide by zero, something is broken with iDefaultFOV
545546
iDefaultFOV = 1;
546547
}
547-
gHUD.m_flFOVSensitivityAdjust =
548-
((float)localFOV / (float)iDefaultFOV) * // linear fov downscale
549-
zoom_sensitivity_ratio.GetFloat(); // sensitivity scale factor
548+
549+
float flScale;
550+
if ( zoom_sensitivity_scaling.GetBool() )
551+
{
552+
const float flHalfDefaultFOV = static_cast<float>( iDefaultFOV ) * 0.5f;
553+
const float flHalfLocalFOV = static_cast<float>( localFOV ) * 0.5f;
554+
const float flTanHalfDefaultFOV = tanf( DEG2RAD( flHalfDefaultFOV ) );
555+
const float flTanHalfLocalFOV = tanf( DEG2RAD( flHalfLocalFOV ) );
556+
flScale = flTanHalfLocalFOV / flTanHalfDefaultFOV; // actually correct scaling
557+
}
558+
else
559+
{
560+
flScale = static_cast<float>( localFOV ) / static_cast<float>( iDefaultFOV ); // "linear" scaling
561+
}
562+
563+
gHUD.m_flFOVSensitivityAdjust = flScale * zoom_sensitivity_ratio.GetFloat(); // sensitivity scale factor
550564
#ifndef _XBOX
551565
gHUD.m_flMouseSensitivity = gHUD.m_flFOVSensitivityAdjust * sensitivity.GetFloat(); // regular sensitivity
552566
#endif
@@ -728,12 +742,12 @@ void CViewRender::SetUpViews()
728742
float flFOVOffset = fDefaultFov - viewEye.fov;
729743

730744
//Adjust the viewmodel's FOV to move with any FOV offsets on the viewer's end
731-
float ViewmodelFOVZoomFactor = 1.0f;
745+
float flViewmodelFOVZoomFactor = 1.0f;
732746
if ( flFOVOffset != 0.0f )
733747
{
734-
ViewmodelFOVZoomFactor = tan(viewEye.fov * M_PI / 360.0f) / tan(fDefaultFov * M_PI / 360.0f);
748+
flViewmodelFOVZoomFactor = tanf( DEG2RAD( viewEye.fov * 0.5f ) ) / tanf( DEG2RAD( fDefaultFov * 0.5f ) );
735749
}
736-
viewEye.fovViewmodel = g_pClientMode->GetViewModelFOV() * ViewmodelFOVZoomFactor;
750+
viewEye.fovViewmodel = g_pClientMode->GetViewModelFOV() * flViewmodelFOVZoomFactor;
737751

738752
if ( UseVR() )
739753
{

0 commit comments

Comments
 (0)