Skip to content

Commit

Permalink
- Added 'ScaleWeaponFOV' flag to MODELDEF. Affects weapon models only…
Browse files Browse the repository at this point in the history
…; will scale the model along with the user's FOV to reduce distortion.

- Additionally, a 'cl_scaleweaponfov' CVar has been added to allow users to further fine-tune the weapon model scale with higher FOVs
  • Loading branch information
nashmuhandes authored and coelckers committed Mar 8, 2022
1 parent ab27d1d commit 1785788
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/g_cvars.cpp
Expand Up @@ -161,3 +161,5 @@ CUSTOM_CVAR(String, language, "auto", CVAR_ARCHIVE | CVAR_NOINITCALL | CVAR_GLOB
UpdateGenericUI(ui_generic);
I_UpdateWindowTitle();
}

CVAR(Float, cl_scaleweaponfov, 1.0f, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
14 changes: 13 additions & 1 deletion src/r_data/models.cpp
Expand Up @@ -193,8 +193,16 @@ void RenderHUDModel(FModelRenderer *renderer, DPSprite *psp, float ofsX, float o
// but we need to position it correctly in the world for light to work properly.
VSMatrix objectToWorldMatrix = renderer->GetViewToWorldMatrix();

// [Nash] Optional scale weapon FOV
float fovscale = 1.0f;
if (smf->flags & MDL_SCALEWEAPONFOV)
{
fovscale = tan(players[consoleplayer].DesiredFOV * (0.5f * M_PI / 180.f));
fovscale = 1.f + (fovscale - 1.f) * cl_scaleweaponfov;
}

// Scaling model (y scale for a sprite means height, i.e. z in the world!).
objectToWorldMatrix.scale(smf->xscale, smf->zscale, smf->yscale);
objectToWorldMatrix.scale(smf->xscale, smf->zscale, smf->yscale / fovscale);

// Aplying model offsets (model offsets do not depend on model scalings).
objectToWorldMatrix.translate(smf->xoffset / smf->xscale, smf->zoffset / smf->zscale, smf->yoffset / smf->yscale);
Expand Down Expand Up @@ -528,6 +536,10 @@ static void ParseModelDefLump(int Lump)
{
smf.flags |= MDL_NOPERPIXELLIGHTING;
}
else if (sc.Compare("scaleweaponfov"))
{
smf.flags |= MDL_SCALEWEAPONFOV;
}
else if (sc.Compare("rotating"))
{
smf.flags |= MDL_ROTATING;
Expand Down
3 changes: 3 additions & 0 deletions src/r_data/models.h
Expand Up @@ -56,6 +56,7 @@ enum
MDL_DONTCULLBACKFACES = 256,
MDL_USEROTATIONCENTER = 512,
MDL_NOPERPIXELLIGHTING = 1024, // forces a model to not use per-pixel lighting. useful for voxel-converted-to-model objects.
MDL_SCALEWEAPONFOV = 2048, // scale weapon view model with higher user FOVs
};

FSpriteModelFrame * FindModelFrame(const PClass * ti, int sprite, int frame, bool dropped);
Expand Down Expand Up @@ -109,4 +110,6 @@ void BSPWalkCircle(FLevelLocals *Level, float x, float y, float radiusSquared, c
void RenderModel(FModelRenderer* renderer, float x, float y, float z, FSpriteModelFrame* smf, AActor* actor, double ticFrac);
void RenderHUDModel(FModelRenderer* renderer, DPSprite* psp, float ofsX, float ofsY);

EXTERN_CVAR(Float, cl_scaleweaponfov)

#endif

0 comments on commit 1785788

Please sign in to comment.