From c6825a9881e686a790706e24acb99f1e44b4d486 Mon Sep 17 00:00:00 2001 From: Boondorl Date: Sat, 7 Jun 2025 22:42:48 -0400 Subject: [PATCH] Added ViewModelFOV field for models Allows manually setting FOV for models instead of scaling from 90 degrees. Positive values are exact FOVs while negative FOVs are scalars from 90. SCALEWEAPONFOV does not work with exact values since it automatically scales based on FOV. --- src/common/models/model.h | 1 + src/r_data/models.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/common/models/model.h b/src/common/models/model.h index 3fa293073..c2b379d2f 100644 --- a/src/common/models/model.h +++ b/src/common/models/model.h @@ -47,6 +47,7 @@ struct FSpriteModelFrame float xrotate, yrotate, zrotate; float rotationCenterX, rotationCenterY, rotationCenterZ; float rotationSpeed; + float viewModelFOV; private: unsigned int flags; public: diff --git a/src/r_data/models.cpp b/src/r_data/models.cpp index 166387cd9..8a469cf2b 100644 --- a/src/r_data/models.cpp +++ b/src/r_data/models.cpp @@ -250,12 +250,23 @@ void RenderHUDModel(FModelRenderer *renderer, DPSprite *psp, FVector3 translatio // 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) + if (smf->viewModelFOV <= 0.0f) { - fovscale = tan(players[consoleplayer].DesiredFOV * (0.5f * M_PI / 180.f)); - fovscale = 1.f + (fovscale - 1.f) * cl_scaleweaponfov; + if (smf->viewModelFOV < 0.0f) + fovscale = 1.0f / fabs(smf->viewModelFOV); + + // [Nash] Optional scale weapon FOV + if (smf_flags & MDL_SCALEWEAPONFOV) + { + float newScale = tan(players[consoleplayer].DesiredFOV * (0.5f * M_PI / 180.f)); + newScale = 1.f + (newScale - 1.f) * cl_scaleweaponfov; + fovscale *= newScale; + } + } + else if (players[consoleplayer].DesiredFOV != smf->viewModelFOV) + { + fovscale = tan(players[consoleplayer].DesiredFOV * (0.5f * M_PI / 180.f)) / tan(smf->viewModelFOV * (0.5f * M_PI / 180.f)); } // Scaling model (y scale for a sprite means height, i.e. z in the world!). @@ -935,6 +946,13 @@ void ParseModelDefLump(int Lump) { smf.flags |= MDL_MODELSAREATTACHMENTS; } + else if (sc.Compare("viewmodelfov")) + { + sc.MustGetFloat(); + smf.viewModelFOV = sc.Float; + if (smf.viewModelFOV > 0.0f) + smf.viewModelFOV = min(smf.viewModelFOV, 175.0f); + } else if (sc.Compare("rotating")) { smf.flags |= MDL_ROTATING;