Skip to content

Commit

Permalink
Added bxt_fix_widescreen_fov (thank to Muty for the idea) (#448)
Browse files Browse the repository at this point in the history
* Added bxt_fix_widescreen_fov (thank to Muty for the idea)

* Allow to work 'bxt_fix_widescreen_fov' in combination with 'bxt_force_fov'
  • Loading branch information
SmileyAG authored Jul 23, 2023
1 parent e3c4e3c commit abf3d6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions BunnymodXT/cvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
X(bxt_viewmodel_semitransparent, "0") \
X(bxt_clear_color, "") \
X(bxt_force_fov, "0") \
X(bxt_fix_widescreen_fov, "0") \
X(bxt_force_clear, "0") \
X(bxt_fix_mouse_horizontal_limit, "0") \
X(bxt_hud_game_color, "") \
Expand Down
19 changes: 19 additions & 0 deletions BunnymodXT/modules/HwDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5133,7 +5133,10 @@ void HwDLL::RegisterCVarsAndCommandsIfNeeded()
RegisterCVar(CVars::bxt_tas_ducktap_priority);

if (ORIG_R_SetFrustum && scr_fov_value)
{
RegisterCVar(CVars::bxt_force_fov);
RegisterCVar(CVars::bxt_fix_widescreen_fov);
}

if (ORIG_R_DrawViewModel)
RegisterCVar(CVars::bxt_viewmodel_fov);
Expand Down Expand Up @@ -7451,6 +7454,22 @@ HOOK_DEF_0(HwDLL, void, __cdecl, R_SetFrustum)
if (CVars::bxt_force_fov.GetFloat() >= 1.0)
*scr_fov_value = CVars::bxt_force_fov.GetFloat();

if (CVars::bxt_fix_widescreen_fov.GetBool())
{
float ScreenWidth = static_cast<float>(CustomHud::GetScreenInfo().iWidth);
float ScreenHeight = static_cast<float>(CustomHud::GetScreenInfo().iHeight);

float def_aspect_ratio = 3.0f / 4.0f;
float our_aspect_ratio = ScreenWidth / ScreenHeight;

float fov = *scr_fov_value;
float calculated_fov = static_cast<float>(std::atan(std::tan(fov*M_PI / 360.0f) * def_aspect_ratio * our_aspect_ratio) * 360.0f/M_PI);

*scr_fov_value = std::clamp(calculated_fov, 10.0f, 150.0f); // Engine does the clamp of FOV if less 10 or higher than 150, let's do it too!

// Although, it could be extended to 1 for min. value and 180 for max. value
}

ORIG_R_SetFrustum();
}

Expand Down

0 comments on commit abf3d6c

Please # to comment.