Skip to content

Commit

Permalink
tweak gun fov instead of world fov, fixed cl_avidemo_streams_viewmode…
Browse files Browse the repository at this point in the history
…l dvar,

+ cg_fov_gun :: Adjust gun fov separately (wont effect world fov)
+ cg_fov_tweaks :: Enable gun fov tweaks
+ dvar "cl_avidemo_streams_viewmodel" should now work as expected
  • Loading branch information
xoxor4d committed Jul 14, 2021
1 parent 2db60a0 commit 663e1c0
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/Components/Modules/Gui_Devgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,8 +737,8 @@ namespace Components

ImGui::Indent(8.0f); SPACING(0.0f, 4.0f);

ImGui::Checkbox("Tweak World FOV", Gui::DvarGetSet<bool*>(Dvars::cg_fov_world_tweaks));
ImGui::DragFloat("World FOV", Gui::DvarGetSet<float*>(Dvars::cg_fov_world), 0.05f, 20.0f, 160.0f, "%.2f");
ImGui::Checkbox("Tweak Gun FOV", Gui::DvarGetSet<bool*>(Dvars::cg_fov_tweaks));
ImGui::DragFloat("Gun FOV", Gui::DvarGetSet<float*>(Dvars::cg_fov_gun), 0.05f, 20.0f, 160.0f, "%.2f");

const auto cg_fov = Game::Dvar_FindVar("cg_fov");
const auto cg_fovScale = Game::Dvar_FindVar("cg_fovScale");
Expand Down
13 changes: 9 additions & 4 deletions src/Components/Modules/Mvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Components
int streams_currentView = 0;
int client_msec = 0;


void Screenshot(std::string prefix = "recording")
{
std::string mod_name, demo_name = "";
Expand Down Expand Up @@ -55,6 +56,7 @@ namespace Components
backbuffer->Release();
}


void toggle_greenscreen(bool state)
{
auto r_clear = Game::Dvar_FindVar("r_clear");
Expand Down Expand Up @@ -108,6 +110,7 @@ namespace Components
}
}


void toggle_depthmap(bool state)
{
if (state)
Expand All @@ -120,6 +123,7 @@ namespace Components
}
}


// called from D3D9Ex::D3D9Device::BeginScene()
void Mvm::avidemo_streams()
{
Expand Down Expand Up @@ -192,9 +196,9 @@ namespace Components
case 3:
toggle_greenscreen(0);

if (Dvars::cl_avidemo_streams_viewmodel && !Dvars::cl_avidemo_streams_viewmodel->current.enabled)
if (Dvars::cl_avidemo_streams_viewmodel)
{
Game::Dvar_SetValue(cg_drawGun, false);
Game::Dvar_SetValue(cg_drawGun, Dvars::cl_avidemo_streams_viewmodel->current.enabled);
}

streams_prepare = true;
Expand All @@ -215,9 +219,9 @@ namespace Components
toggle_depthmap(1);
}

if (Dvars::cl_avidemo_streams_viewmodel && Dvars::cl_avidemo_streams_viewmodel->current.enabled)
if (Dvars::cl_avidemo_streams_viewmodel)
{
Game::Dvar_SetValue(cg_drawGun, false);
Game::Dvar_SetValue(cg_drawGun, Dvars::cl_avidemo_streams_viewmodel->current.enabled);
}

streams_prepare = true;
Expand All @@ -242,6 +246,7 @@ namespace Components
{
toggle_greenscreen(1);
Game::Dvar_SetValue(cg_draw2D, true);
Game::Dvar_SetValue(cg_drawGun, false);
}

streams_prepare = true;
Expand Down
97 changes: 19 additions & 78 deletions src/Components/Modules/_Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1165,26 +1165,6 @@ namespace Components
#pragma warning(push)
#pragma warning(disable: 6385)
#pragma warning(disable: 6386)
void MatrixMultiply44(const float(*in1)[4], const float(*in2)[4], float(*out)[4])
{
(*out)[0] = ((((*in1)[0] * (*in2)[0]) + ((*in1)[1] * (*in2)[4])) + ((*in1)[2] * (*in2)[8])) + ((*in1)[3] * (*in2)[12]);
(*out)[1] = ((((*in1)[0] * (*in2)[1]) + ((*in1)[1] * (*in2)[5])) + ((*in1)[2] * (*in2)[9])) + ((*in1)[3] * (*in2)[13]);
(*out)[2] = ((((*in1)[0] * (*in2)[2]) + ((*in1)[1] * (*in2)[6])) + ((*in1)[2] * (*in2)[10])) + ((*in1)[3] * (*in2)[14]);
(*out)[3] = ((((*in1)[0] * (*in2)[3]) + ((*in1)[1] * (*in2)[7])) + ((*in1)[2] * (*in2)[11])) + ((*in1)[3] * (*in2)[15]);
(*out)[4] = ((((*in1)[4] * (*in2)[0]) + ((*in1)[5] * (*in2)[4])) + ((*in1)[6] * (*in2)[8])) + ((*in1)[7] * (*in2)[12]);
(*out)[5] = ((((*in1)[4] * (*in2)[1]) + ((*in1)[5] * (*in2)[5])) + ((*in1)[6] * (*in2)[9])) + ((*in1)[7] * (*in2)[13]);
(*out)[6] = ((((*in1)[4] * (*in2)[2]) + ((*in1)[5] * (*in2)[6])) + ((*in1)[6] * (*in2)[10])) + ((*in1)[7] * (*in2)[14]);
(*out)[7] = ((((*in1)[4] * (*in2)[3]) + ((*in1)[5] * (*in2)[7])) + ((*in1)[6] * (*in2)[11])) + ((*in1)[7] * (*in2)[15]);
(*out)[8] = ((((*in1)[8] * (*in2)[0]) + ((*in1)[9] * (*in2)[4])) + ((*in1)[10] * (*in2)[8])) + ((*in1)[11] * (*in2)[12]);
(*out)[9] = ((((*in1)[8] * (*in2)[1]) + ((*in1)[9] * (*in2)[5])) + ((*in1)[10] * (*in2)[9])) + ((*in1)[11] * (*in2)[13]);
(*out)[10] = ((((*in1)[8] * (*in2)[2]) + ((*in1)[9] * (*in2)[6])) + ((*in1)[10] * (*in2)[10])) + ((*in1)[11] * (*in2)[14]);
(*out)[11] = ((((*in1)[8] * (*in2)[3]) + ((*in1)[9] * (*in2)[7])) + ((*in1)[10] * (*in2)[11])) + ((*in1)[11] * (*in2)[15]);
(*out)[12] = ((((*in1)[12] * (*in2)[0]) + ((*in1)[13] * (*in2)[4])) + ((*in1)[14] * (*in2)[8])) + ((*in1)[15] * (*in2)[12]);
(*out)[13] = ((((*in1)[12] * (*in2)[1]) + ((*in1)[13] * (*in2)[5])) + ((*in1)[14] * (*in2)[9])) + ((*in1)[15] * (*in2)[13]);
(*out)[14] = ((((*in1)[12] * (*in2)[2]) + ((*in1)[13] * (*in2)[6])) + ((*in1)[14] * (*in2)[10])) + ((*in1)[15] * (*in2)[14]);
(*out)[15] = ((((*in1)[12] * (*in2)[3]) + ((*in1)[13] * (*in2)[7])) + ((*in1)[14] * (*in2)[11])) + ((*in1)[15] * (*in2)[15]);
}

void InfinitePerspectiveMatrix(const float tanHalfFovX, const float tanHalfFovY, const float zNear, float(*mtx)[4])
{
(*mtx)[0] = 0.99951172f / tanHalfFovX;
Expand All @@ -1193,41 +1173,12 @@ namespace Components
(*mtx)[11] = 1.0f;
(*mtx)[14] = 0.99951171875f * -zNear;
}

void MatrixForViewer(const float* origin, const float(*axis)[3], float(*mtx)[4])
{
// [0][0] to [3][0]
(*mtx)[0] = -(*axis)[3];
(*mtx)[4] = -(*axis)[4];
(*mtx)[8] = -(*axis)[5];
(*mtx)[12] = -((*origin * (*mtx)[0]) + (origin[1] * (*mtx)[4]) + (origin[2] * (*mtx)[8]));

// [0][1] to [3][1]
(*mtx)[1] = (*axis)[6];
(*mtx)[5] = (*axis)[7];
(*mtx)[9] = (*axis)[8];
(*mtx)[13] = -((*origin * (*mtx)[1]) + (origin[1] * (*mtx)[5]) + (origin[2] * (*mtx)[9]));

// [0][2] to [3][2]
(*mtx)[2] = (*axis)[0];
(*mtx)[6] = (*axis)[1];
(*mtx)[10] = (*axis)[2];
(*mtx)[14] = -((*origin * (*mtx)[2]) + (origin[1] * (*mtx)[6]) + (origin[2] * (*mtx)[10]));

// [0][3] to [3][3]
(*mtx)[3] = 0.0f;
(*mtx)[7] = 0.0f;
(*mtx)[11] = 0.0f;
(*mtx)[15] = 1.0f;
}
#pragma warning(pop)

// rewrite of CG_GetViewFov()
float calculate_worldfov_with_zoom(float fov_val)
float calculate_gunfov_with_zoom(float fov_val)
{
float calc_fov;

const auto& cg_fovScale = Game::Dvar_FindVar("cg_fovScale");
const auto& cg_fovMin = Game::Dvar_FindVar("cg_fovMin");

unsigned int offhand_index = Game::cgs->predictedPlayerState.offHandIndex;
Expand Down Expand Up @@ -1288,41 +1239,31 @@ namespace Components
calc_fov = 55.0f;
}

float calc_fov_out = cg_fovScale->current.value * calc_fov;

if (cg_fovMin->current.value - calc_fov_out >= 0.0f)
if (cg_fovMin->current.value - calc_fov >= 0.0f)
{
calc_fov_out = cg_fovMin->current.value;
calc_fov = cg_fovMin->current.value;
}

return calc_fov_out;
return calc_fov;
}

void set_worldfov(Game::GfxViewParms* viewParms)
void set_gunfov(Game::GfxViewParms* viewParms)
{
if(Dvars::cg_fov_world_tweaks && Dvars::cg_fov_world_tweaks->current.enabled)
if(Dvars::cg_fov_tweaks && Dvars::cg_fov_tweaks->current.enabled)
{
// calc world fov + weapon zoom
const float world_fov = calculate_worldfov_with_zoom(Dvars::cg_fov_world->current.value);
const float w_fov = 0.75f * tanf(world_fov * 0.01745329238474369f * 0.5f);
// calc gun fov (includes weapon zoom)
const float gun_fov = calculate_gunfov_with_zoom(Dvars::cg_fov_gun->current.value);
const float w_fov = 0.75f * tanf(gun_fov * 0.01745329238474369f * 0.5f);

const float tanHalfX = ((float)Game::cgs->refdef.width / (float)Game::cgs->refdef.height) * w_fov;
const float tanHalfX = (static_cast<float>(Game::cgs->refdef.width) / static_cast<float>(Game::cgs->refdef.height)) * w_fov;
const float tanHalfY = w_fov;

// calc viewmatrix
float view_mtx[4][4] = { 0.0f };
MatrixForViewer(viewParms->origin, viewParms->axis, view_mtx);

// calc projection matrix
float proj_mtx[4][4] = { 0.0f };
float proj_mtx[4][4] = {};
InfinitePerspectiveMatrix(tanHalfX, tanHalfY, viewParms->zNear, proj_mtx);

// calc viewprojection matrix
float viewproj_mtx[4][4] = { 0.0f };
MatrixMultiply44(view_mtx, proj_mtx, viewproj_mtx);

// only overwrite the projection matrix ;)
memcpy(viewParms->viewProjectionMatrix.m, viewproj_mtx, sizeof(Game::GfxMatrix));
memcpy(viewParms->projectionMatrix.m, proj_mtx, sizeof(Game::GfxMatrix));
}
}

Expand All @@ -1333,7 +1274,7 @@ namespace Components
{
pushad;
push edi; // viewParms
call set_worldfov;
call set_gunfov;
add esp, 4;
popad;

Expand Down Expand Up @@ -1554,15 +1495,15 @@ namespace Components
Utils::Hook::Nop(0x5FAA05, 6);
Utils::Hook(0x5FAA05, R_SetViewParmsForScene_stub, HOOK_JUMP).install()->quick();

Dvars::cg_fov_world_tweaks = Game::Dvar_RegisterBool(
/* name */ "cg_fov_world_tweaks",
/* desc */ "Enable world fov tweaks",
Dvars::cg_fov_tweaks = Game::Dvar_RegisterBool(
/* name */ "cg_fov_tweaks",
/* desc */ "Enable gun fov tweaks",
/* default */ false,
/* flags */ Game::dvar_flags::saved);

Dvars::cg_fov_world = Game::Dvar_RegisterFloat(
/* name */ "cg_fov_world",
/* desc */ "Adjust world fov separately (wont effect viewmodel fov)",
Dvars::cg_fov_gun = Game::Dvar_RegisterFloat(
/* name */ "cg_fov_gun",
/* desc */ "Adjust gun fov separately (wont effect world fov)",
/* default */ 65.0f,
/* minVal */ 20.0f,
/* maxVal */ 160.0f,
Expand Down
4 changes: 2 additions & 2 deletions src/Game/Dvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ namespace Dvars
Game::dvar_s* r_fogTweaksStart = nullptr;
Game::dvar_s* r_fogTweaksDensity = nullptr;

Game::dvar_s* cg_fov_world = nullptr;
Game::dvar_s* cg_fov_world_tweaks = nullptr;
Game::dvar_s* cg_fov_gun = nullptr;
Game::dvar_s* cg_fov_tweaks = nullptr;

// Debug Collision
Game::dvar_s* r_drawCollision = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/Game/Dvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ namespace Dvars
extern Game::dvar_s* r_fogTweaksStart;
extern Game::dvar_s* r_fogTweaksDensity;

extern Game::dvar_s* cg_fov_world;
extern Game::dvar_s* cg_fov_world_tweaks;
extern Game::dvar_s* cg_fov_gun;
extern Game::dvar_s* cg_fov_tweaks;

// Debug collision
extern Game::dvar_s* r_drawCollision;
Expand Down
2 changes: 1 addition & 1 deletion src/version.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* Automatically generated by premake5. */

#define IW3X_BUILDNUMBER 3423.0
#define IW3X_BUILDNUMBER 3424.0

0 comments on commit 663e1c0

Please sign in to comment.