-
Notifications
You must be signed in to change notification settings - Fork 161
fix(view): Adjust default camera height to compensate for screen aspect ratio #1711
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1877,6 +1877,31 @@ void W3DView::setPitchToDefault( void ) | |||||||||||||||||||||||||||||||||
| m_recalcCamera = true; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| void W3DView::setCameraHeightAboveGroundLimitsToDefault(Real heightScale) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| // TheSuperHackers @fix Mauller Adjust the camera height to compensate for the screen aspect ratio | ||||||||||||||||||||||||||||||||||
| Real baseAspectRatio = (Real)DEFAULT_DISPLAY_WIDTH / (Real)DEFAULT_DISPLAY_HEIGHT; | ||||||||||||||||||||||||||||||||||
| Real currentAspectRatio = (Real)TheTacticalView->getWidth() / (Real)TheTacticalView->getHeight(); | ||||||||||||||||||||||||||||||||||
| Real aspectRatioScale = 0.0f; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (currentAspectRatio > baseAspectRatio) | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| aspectRatioScale = fabs(( 1 + ( currentAspectRatio - baseAspectRatio) )); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| aspectRatioScale = fabs(( 1 - ( baseAspectRatio - currentAspectRatio) )); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1889
to
+1896
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. style: unnecessary
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
Line: 1942:1949
Comment:
**style:** unnecessary `fabs()` wraps expressions that are already positive by construction
```suggestion
if (currentAspectRatio > baseAspectRatio)
{
aspectRatioScale = 1 + (currentAspectRatio - baseAspectRatio);
}
else
{
aspectRatioScale = 1 - (baseAspectRatio - currentAspectRatio);
}
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * aspectRatioScale * heightScale; | ||||||||||||||||||||||||||||||||||
| m_minHeightAboveGround = TheGlobalData->m_minCameraHeight * aspectRatioScale; | ||||||||||||||||||||||||||||||||||
|
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. On map Defcon6 with 16:9 resolution, I can see black top edges when scrolling quickly. These are the edges of the rendered height map (a rectangle). Can you also look into scaling the terrain draw area? I do not yet know how this code works exactly but you can start looking around If you do not want to do it in this change, then a follow up is also ok.
Author
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 should be possible, i think i have seen it in the camera code elsewhere.
Author
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. So i have implemented a 1.5x scaling factor to the world height map draw area when a wide aspect ratio is used. I used a fixed scaling factor since when using an aspect ratio based scale it would often increase the draw area well beyond the size of the map itself. |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (m_minHeightAboveGround > m_maxHeightAboveGround) | ||||||||||||||||||||||||||||||||||
| m_maxHeightAboveGround = m_minHeightAboveGround; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight) | ||||||||||||||||||||||||||||||||||
|
|
@@ -1927,10 +1952,8 @@ void W3DView::setZoom(Real z) | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| void W3DView::setZoomToDefault( void ) | ||||||||||||||||||||||||||||||||||
| void W3DView::setZoomToMax() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| // default zoom has to be max, otherwise players will just zoom to max always | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // terrain height + desired height offset == cameraOffset * actual zoom | ||||||||||||||||||||||||||||||||||
| // find best approximation of max terrain height we can see | ||||||||||||||||||||||||||||||||||
| Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y); | ||||||||||||||||||||||||||||||||||
|
|
@@ -1943,6 +1966,15 @@ void W3DView::setZoomToDefault( void ) | |||||||||||||||||||||||||||||||||
| m_zoom = desiredZoom; | ||||||||||||||||||||||||||||||||||
| m_heightAboveGround = m_maxHeightAboveGround; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| m_cameraAreaConstraintsValid = false; // recalc it. | ||||||||||||||||||||||||||||||||||
| m_recalcCamera = true; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| //------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| void W3DView::setZoomToDefault() | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1974
to
+1976
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. Default zoom no longer set
Prompt To Fix With AIThis is a comment left during a code review.
Path: Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
Line: 1970:1972
Comment:
**Default zoom no longer set**
`W3DView::setZoomToDefault()` now only resets scripted-camera state but doesn’t actually set the zoom/height anymore (the zoom-setting logic was moved into `setZoomToMax()`), while call sites (e.g. game start) still call `setZoomToDefault()` expecting it to establish the default zoom. As-is, the “default” zoom/height will depend on whatever the previous camera state was unless `setZoomToMax()` is also invoked at every default-reset site. Either restore zoom/height setup inside `setZoomToDefault()` (and have `setZoomToMax()` be a helper) or ensure every `setZoomToDefault()` call site also calls `setZoomToMax()`.
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||||||||
| // default zoom has to be max, otherwise players will just zoom to max always | ||||||||||||||||||||||||||||||||||
| m_doingMoveCameraOnWaypointPath = false; | ||||||||||||||||||||||||||||||||||
| m_CameraArrivedAtWaypointOnPathFlag = false; | ||||||||||||||||||||||||||||||||||
| m_doingRotateCamera = false; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -111,7 +111,7 @@ class ScriptActions : public ScriptActionsInterface | |||||
|
|
||||||
| void doCameraTetherNamed(const AsciiString& unit, Bool snapToUnit, Real play); | ||||||
| void doCameraStopTetherNamed(void); | ||||||
| void doCameraSetDefault(Real pitch, Real angle, Real maxHeight); | ||||||
| void doCameraSetDefault(Real pitch, Real angle, Real heighScale); | ||||||
|
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. syntax: typo:
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptActions.h
Line: 114:114
Comment:
**syntax:** typo: `heighScale` should be `heightScale`
```suggestion
void doCameraSetDefault(Real pitch, Real angle, Real heightScale);
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
|
|
||||||
| void doOversizeTheTerrain(Int amount); | ||||||
| void doMoveCameraAlongWaypointPath(const AsciiString& waypoint, Real sec, Real cameraStutterSec, Real easeIn, Real easeOut); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -1377,7 +1377,7 @@ void InGameUI::init( void ) | |||||||
| TheTacticalView->setWidth( TheDisplay->getWidth() ); | ||||||||
| TheTacticalView->setHeight( TheDisplay->getHeight() ); | ||||||||
| } | ||||||||
| TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f); | ||||||||
| TheTacticalView->setCameraHeightAboveGroundLimitsToDefault(); | ||||||||
|
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. Missing
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Line: 1380:1380
Comment:
Missing `setZoomToMax()` call after `setCameraHeightAboveGroundLimitsToDefault()`. Similar to `GameLogic::startNewGame()` and `OptionsMenu::saveOptions()`, this should call `setZoomToMax()` to actually set the camera height.
```suggestion
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
TheTacticalView->setZoomToMax();
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||
|
|
||||||||
| /** @todo this may be the wrong place to create the sidebar, but for now | ||||||||
| this is where it lives */ | ||||||||
|
|
@@ -2147,7 +2147,7 @@ void InGameUI::reset( void ) | |||||||
| // reset the command bar | ||||||||
| TheControlBar->reset(); | ||||||||
|
|
||||||||
| TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f); | ||||||||
| TheTacticalView->setCameraHeightAboveGroundLimitsToDefault(); | ||||||||
|
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. Missing
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
Line: 2150:2150
Comment:
Missing `setZoomToMax()` call after `setCameraHeightAboveGroundLimitsToDefault()`. Without this, the camera zoom won't be properly initialized during reset.
```suggestion
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
TheTacticalView->setZoomToMax();
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||
|
|
||||||||
| ResetInGameChat(); | ||||||||
|
|
||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4607,9 +4607,11 @@ void ScriptActions::doCameraStopTetherNamed(void) | |||||
| //------------------------------------------------------------------------------------------------- | ||||||
| /** doCameraSetDefault */ | ||||||
| //------------------------------------------------------------------------------------------------- | ||||||
| void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real maxHeight) | ||||||
| void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real heighScale) | ||||||
|
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. syntax: typo:
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp
Line: 4611:4611
Comment:
**syntax:** typo: `heighScale` should be `heightScale`
```suggestion
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real heightScale)
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||
| { | ||||||
| TheTacticalView->setDefaultView(pitch, angle, maxHeight); | ||||||
| TheTacticalView->setCameraHeightAboveGroundLimitsToDefault(heighScale); | ||||||
| TheTacticalView->setPitch(pitch); | ||||||
| TheTacticalView->setAngle(angle); | ||||||
| } | ||||||
|
|
||||||
| //------------------------------------------------------------------------------------------------- | ||||||
|
|
||||||
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.
logic: incorrectly adds
m_maxHeightAboveGroundto current height instead of setting height to maxPrompt To Fix With AI