-
Notifications
You must be signed in to change notification settings - Fork 79
[ZH] Adjust field of view based on aspect ratio #518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,10 +226,48 @@ void W3DView::setWidth(Int width) | |
m_3DCamera->Get_Viewport(vMin,vMax); | ||
vMax.X=(Real)(m_originX+width)/(Real)TheDisplay->getWidth(); | ||
m_3DCamera->Set_Viewport(vMin,vMax); | ||
} | ||
|
||
// TheSuperHackers @tweak valeronm 25/03/2025 Adjusting FOV to look similar to what we have in in 4:3 (hFOV: 50, vFOV 38.55) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in in |
||
void W3DView::adjustFovToAspectRatio(const Int width, const Int height) | ||
{ | ||
static const Real fixedHFOV = 50.00f; | ||
static const Real fixedVFOV = 38.55f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use CONSTEXPR instead of static There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did the magical 38.55 come to be? |
||
|
||
//we want to maintain the same scale, so we'll need to adjust the fov. | ||
//default W3D fov for full-screen is 50 degrees. | ||
m_3DCamera->Set_View_Plane((Real)width/(Real)TheDisplay->getWidth()*DEG_TO_RADF(50.0f),-1); | ||
const Real aspectRatio = static_cast<Real>(width)/ static_cast<Real>(height); | ||
Real vFOVRad, hFOVRad; | ||
Bool drawEntireTerrain = false; | ||
if (aspectRatio >= 4.0f / 3.0f) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Multiplayer, I very much prefer we cap this at max 16/9, min 9/16, to not give these ultra screens a massive advantage, preferably configurable in GameData.ini, so that Mods can do their own setups. For Singleplayer and Replay it is fine to go wide with no limits. |
||
{ | ||
// Wider than 4:3 resolutions get fixed vFOV 38.55 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment repeats the code value that is assigned to fixedVFOV. This means the commented value can go out of sync when someone changes the code value. Prefer not baking values into comments, unless they definitely never change. |
||
vFOVRad = DEG_TO_RADF(fixedVFOV); | ||
hFOVRad = 2.0f * atan(tan(vFOVRad / 2.0f) * aspectRatio); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not mind a brief explanation in a comment for the math how the fov is scaled. |
||
drawEntireTerrain = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks suspicious. The GenTool implementation did not need this for up to 16:9. The original game also did not need this for 4:3. It will affect performance. |
||
} | ||
else if (aspectRatio >= 1.0) | ||
{ | ||
// Narrower than 4:3 but not yet portrait resolutions get fixed hFOV 50.0 | ||
hFOVRad = DEG_TO_RADF(fixedHFOV); | ||
vFOVRad = 2.0f * atan(tan(hFOVRad / 2.0f) / aspectRatio); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no cut in fov'ness between the different conditions? How does this work? |
||
} | ||
else | ||
{ | ||
// Portrait resolutions get fixed vFOV adjusted to aspect ratio | ||
// vFOV increases from 50.0 for 1:1 to 60.0 for 9:21 and then fixed 60.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for this fine tuning? |
||
static const Real adjMinRatio = 9.0f / 21.0f; | ||
static const Real adjValue = 10.0f; | ||
|
||
Real adjustment; | ||
if (aspectRatio < adjMinRatio) | ||
adjustment = adjValue; | ||
else | ||
adjustment = (1 - aspectRatio) * adjValue / (1 - adjMinRatio); | ||
vFOVRad = DEG_TO_RADF(50 + adjustment); | ||
hFOVRad = 2.0f * atan(tan(vFOVRad / 2.0f) * aspectRatio); | ||
drawEntireTerrain = true; | ||
} | ||
TheWritableGlobalData->m_drawEntireTerrain = drawEntireTerrain; | ||
m_3DCamera->Set_View_Plane(hFOVRad, vFOVRad); | ||
} | ||
|
||
//------------------------------------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add blank line before this