Skip to content

[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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

valeronm
Copy link

The game doesn't support wide screens well because it has static horizontal field of view (FOV) and static maximum camera height. This means that for every resolution, the camera shows the same horizontal amount of terrain, but the vertical field of view becomes narrower for wider resolutions. So on wide screens, we get a center crop of what is visible on 4:3 resolutions (screenshots below).
To support wider screens, we need to have constant vertical FOV and calculate horizontal FOV based on the screen aspect ratio.

Changes

  • Added function W3DView::adjustFovToAspectRatio which is called every time when display resolution changes;
  • Function adjustFovToAspectRatio changes camera FOV differently based on aspect ratio:
    • when screen is wider than 4:3 it sets the fixed vertical FOV based on vFOV used for 4:3 screens (38.55°);
    • when screen narrower than 4:3 but still horizontal, it sets fixed hFOV used for 4:3 screens (50°) - this is what the game always uses now;
    • for portrait screens it uses varying 50° to 60° vFOV

Screenshots

1600 x 1200 - 4:3 (original)
1600 x 900 - 16:9 (original)
1600 x 900 - 16:9 (new logic)
3200 x 900 - 32:9 (new logic)
900 x 1600 - 9:16 (new logic)

Fixes #78
Depends on #460 to make wide resolutions selectable

@valeronm valeronm changed the title Adjust field of view based on aspect ratio [ZH] Adjust field of view based on aspect ratio Mar 26, 2025
@ElTioRata
Copy link

Can I ask why do you get less horizontal FOV on 9:16 compared to 4:3?

@DevGeniusCode
Copy link

Is the PR only for Zero Hour? Because I see changes in Generals too.

@DevGeniusCode DevGeniusCode added Bug Something is not working right Critical Severity: Minor < Major < Critical < Blocker ZeroHour Relates to Zero Hour labels Mar 26, 2025
@valeronm valeronm force-pushed the adjust_field_of_view_to_aspect_ratio branch from 7651a21 to cb3225e Compare March 27, 2025 01:09
@valeronm
Copy link
Author

valeronm commented Mar 27, 2025

Can I ask why do you get less horizontal FOV on 9:16 compared to 4:3?

This is done on purpose. The same horizontal FOV will allow seeing almost the entire map in portrait mode. I'm sure this is not an ideal fix for portrait modes, but it should be good enough until a better solution is implemented. One possible solution is to change the angle of the camera towards the terrain for portrait screens.

900 x 1600 with fixed hFOV used for 4:3 screens

Is the PR only for Zero Hour? Because I see changes in Generals too.

This PR depends on #460, so the current branch contains one commit from that PR, which includes changes for both Generals and Zero Hour. After merging #460, this PR will have changes for Zero Hour only.

@ElTioRata
Copy link

ElTioRata commented Mar 27, 2025

The same horizontal FOV will allow seeing almost the entire map in portrait mode.

Out of curiosity, how does it look on 1:1?

@valeronm
Copy link
Author

valeronm commented Mar 27, 2025

Out of curiosity, how does it look on 1:1?

I've made the spreadsheet with original and FOV values and also made the folder with screenshots for different aspect ratios.

@OmniBlade
Copy link

Can I ask why do you get less horizontal FOV on 9:16 compared to 4:3?

This is done on purpose. The same horizontal FOV will allow seeing almost the entire map in portrait mode. I'm sure this is not an ideal fix for portrait modes, but it should be good enough until a better solution is implemented. One possible solution is to change the angle of the camera towards the terrain for portrait screens.
900 x 1600 with fixed hFOV used for 4:3 screens

If you are playing on your phone maybe you need this :D

valeronm added a commit to valeronm/GeneralsGameCode that referenced this pull request Mar 30, 2025
@valeronm valeronm force-pushed the adjust_field_of_view_to_aspect_ratio branch from cb3225e to c52e1e8 Compare March 30, 2025 00:03
@valeronm valeronm force-pushed the adjust_field_of_view_to_aspect_ratio branch from c52e1e8 to 74e96ed Compare April 17, 2025 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working right Critical Severity: Minor < Major < Critical < Blocker ZeroHour Relates to Zero Hour
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Camera height does not scale properly along with aspect ratio of game resolution
4 participants