Skip to content

Commit 74e96ed

Browse files
committed
[ZH] Adjust field of view for differnt from 4:3 resolutions (#518)
1 parent 46665b2 commit 74e96ed

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/View.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ class View : public Snapshot
232232
virtual void forceCameraConstraintRecalc(void) {}
233233
virtual void setGuardBandBias( const Coord2D *gb ) = 0;
234234

235+
virtual void adjustFovToAspectRatio(const Int width, const Int height) { };
236+
235237
protected:
236238

237239
friend class Display;

GeneralsMD/Code/GameEngine/Source/GameClient/Display.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ Bool Display::setDisplayMode( UnsignedInt xres, UnsignedInt yres, UnsignedInt bi
161161
TheTacticalView->setHeight((Real)oldViewHeight/(Real)oldDisplayHeight*(Real)yres);
162162
TheTacticalView->setOrigin((Real)oldViewOriginX/(Real)oldDisplayWidth*(Real)xres,
163163
(Real)oldViewOriginY/(Real)oldDisplayHeight*(Real)yres);
164+
165+
// TheSuperHackers @tweak valeronm 25/03/2025 Adjust camera FOV according to display resolution
166+
TheTacticalView->adjustFovToAspectRatio(xres, yres);
167+
164168
return TRUE;
165169
}
166170

GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,15 @@ void InGameUI::init( void )
11651165
TheTacticalView->init();
11661166
TheDisplay->attachView( TheTacticalView );
11671167

1168+
Int displayWidth = TheDisplay->getWidth();
1169+
Int displayHeight = TheDisplay->getHeight();
11681170
// make the tactical display the full screen width for now
1169-
TheTacticalView->setWidth( TheDisplay->getWidth());
1171+
TheTacticalView->setWidth(displayWidth);
11701172
// make the tactical display 0.76 of full screen so no drawing under GUI.
1171-
TheTacticalView->setHeight( TheDisplay->getHeight() * 0.77f);
1173+
TheTacticalView->setHeight(displayHeight * 0.77f);
1174+
1175+
// TheSuperHackers @tweak valeronm 25/03/2025 Adjust camera FOV according to display resolution
1176+
TheTacticalView->adjustFovToAspectRatio(displayWidth, displayHeight);
11721177
}
11731178
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
11741179

GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ class W3DView : public View, public SubsystemInterface
232232

233233
virtual void setGuardBandBias( const Coord2D *gb ) { m_guardBandBias.x = gb->x; m_guardBandBias.y = gb->y; }
234234

235-
235+
virtual void adjustFovToAspectRatio(const Int width, const Int height);
236236
private:
237237

238238
CameraClass *m_3DCamera; ///< camera representation for 3D scene

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,48 @@ void W3DView::setWidth(Int width)
226226
m_3DCamera->Get_Viewport(vMin,vMax);
227227
vMax.X=(Real)(m_originX+width)/(Real)TheDisplay->getWidth();
228228
m_3DCamera->Set_Viewport(vMin,vMax);
229+
}
230+
231+
// TheSuperHackers @tweak valeronm 25/03/2025 Adjusting FOV to look similar to what we have in in 4:3 (hFOV: 50, vFOV 38.55)
232+
void W3DView::adjustFovToAspectRatio(const Int width, const Int height)
233+
{
234+
static const Real fixedHFOV = 50.00f;
235+
static const Real fixedVFOV = 38.55f;
229236

230-
//we want to maintain the same scale, so we'll need to adjust the fov.
231-
//default W3D fov for full-screen is 50 degrees.
232-
m_3DCamera->Set_View_Plane((Real)width/(Real)TheDisplay->getWidth()*DEG_TO_RADF(50.0f),-1);
237+
const Real aspectRatio = static_cast<Real>(width)/ static_cast<Real>(height);
238+
Real vFOVRad, hFOVRad;
239+
Bool drawEntireTerrain = false;
240+
if (aspectRatio >= 4.0f / 3.0f)
241+
{
242+
// Wider than 4:3 resolutions get fixed vFOV 38.55
243+
vFOVRad = DEG_TO_RADF(fixedVFOV);
244+
hFOVRad = 2.0f * atan(tan(vFOVRad / 2.0f) * aspectRatio);
245+
drawEntireTerrain = true;
246+
}
247+
else if (aspectRatio >= 1.0)
248+
{
249+
// Narrower than 4:3 but not yet portrait resolutions get fixed hFOV 50.0
250+
hFOVRad = DEG_TO_RADF(fixedHFOV);
251+
vFOVRad = 2.0f * atan(tan(hFOVRad / 2.0f) / aspectRatio);
252+
}
253+
else
254+
{
255+
// Portrait resolutions get fixed vFOV adjusted to aspect ratio
256+
// vFOV increases from 50.0 for 1:1 to 60.0 for 9:21 and then fixed 60.0
257+
static const Real adjMinRatio = 9.0f / 21.0f;
258+
static const Real adjValue = 10.0f;
259+
260+
Real adjustment;
261+
if (aspectRatio < adjMinRatio)
262+
adjustment = adjValue;
263+
else
264+
adjustment = (1 - aspectRatio) * adjValue / (1 - adjMinRatio);
265+
vFOVRad = DEG_TO_RADF(50 + adjustment);
266+
hFOVRad = 2.0f * atan(tan(vFOVRad / 2.0f) * aspectRatio);
267+
drawEntireTerrain = true;
268+
}
269+
TheWritableGlobalData->m_drawEntireTerrain = drawEntireTerrain;
270+
m_3DCamera->Set_View_Plane(hFOVRad, vFOVRad);
233271
}
234272

235273
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)