Skip to content

Commit f0dc49b

Browse files
committed
fix(view): Adjust default camera height based on aspect ratio
1 parent 637dbba commit f0dc49b

10 files changed

Lines changed: 64 additions & 10 deletions

File tree

Core/GameEngine/Include/GameClient/View.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ class View : public Snapshot
167167
virtual Bool isTimeFrozen(){ return false;} ///< Freezes time during the next camera movement.
168168
virtual Int getTimeMultiplier() {return 1;}; ///< Get the time multiplier.
169169
virtual void setTimeMultiplier(Int multiple) {}; ///< Set the time multiplier.
170-
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) {}; // TheSuperHackers @todo Replace with setDefaultPitch(), setMaxHeightScale()
170+
virtual void setCameraHeightAboveGroundLimitsToDefault(Real heightScale = 1.0f) {};
171+
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) {};
171172
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn=0.0f, Real easeOut=0.0f ) {};
172173
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn=0.0f, Real easeOut=0.0f ) {};
173174

@@ -190,6 +191,7 @@ class View : public Snapshot
190191
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
191192
virtual void setHeightAboveGround(Real z);
192193
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
194+
virtual void setZoomToMax();
193195
virtual void setZoomToDefault() { m_zoom = 1.0f; } ///< Set zoom to default value
194196
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
195197

Core/GameEngine/Source/GameClient/View.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ void View::zoom( Real height )
129129
setHeightAboveGround(getHeightAboveGround() + height);
130130
}
131131

132+
void View::setZoomToMax()
133+
{
134+
setHeightAboveGround(getHeightAboveGround() + m_maxHeightAboveGround);
135+
}
136+
132137
/**
133138
* Center the view on the given coordinate.
134139
*/

Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ class W3DView : public View, public SubsystemInterface
204204
virtual Int getTimeMultiplier() {return m_timeMultiplier;};///< Get the time multiplier.
205205
virtual void setTimeMultiplier(Int multiple) {m_timeMultiplier = multiple;}; ///< Set the time multiplier.
206206
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight);
207+
virtual void setCameraHeightAboveGroundLimitsToDefault(Real heightScale = 1.0f);
207208
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn, Real easeOut );
208209
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn, Real easeOut );
209210

210211
virtual void setHeightAboveGround(Real z);
211212
virtual void setZoom(Real z);
212-
virtual void setZoomToDefault(); ///< Set zoom to default value
213+
virtual void setZoomToMax();
214+
virtual void setZoomToDefault(); ///< Set zoom to default value - TheSuperHackers @info This function resets the camera so will cause scripted cameras to halt
213215

214216
virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
215217

Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,31 @@ void W3DView::setPitchToDefault()
18941894
m_recalcCamera = true;
18951895
}
18961896

1897+
//-------------------------------------------------------------------------------------------------
1898+
//-------------------------------------------------------------------------------------------------
1899+
void W3DView::setCameraHeightAboveGroundLimitsToDefault(Real heightScale)
1900+
{
1901+
// TheSuperHackers @fix Mauller Adjust the camera height to compensate for the screen aspect ratio
1902+
Real baseAspectRatio = (Real)DEFAULT_DISPLAY_WIDTH / (Real)DEFAULT_DISPLAY_HEIGHT;
1903+
Real currentAspectRatio = (Real)TheTacticalView->getWidth() / (Real)TheTacticalView->getHeight();
1904+
Real aspectRatioScale = 0.0f;
1905+
1906+
if (currentAspectRatio > baseAspectRatio)
1907+
{
1908+
aspectRatioScale = fabs(( 1 + ( currentAspectRatio - baseAspectRatio) ));
1909+
}
1910+
else
1911+
{
1912+
aspectRatioScale = fabs(( 1 - ( baseAspectRatio - currentAspectRatio) ));
1913+
}
1914+
1915+
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * aspectRatioScale * heightScale;
1916+
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight * aspectRatioScale;
1917+
1918+
if (m_minHeightAboveGround > m_maxHeightAboveGround)
1919+
m_maxHeightAboveGround = m_minHeightAboveGround;
1920+
}
1921+
18971922
//-------------------------------------------------------------------------------------------------
18981923
//-------------------------------------------------------------------------------------------------
18991924
void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
@@ -1937,10 +1962,8 @@ void W3DView::setZoom(Real z)
19371962

19381963
//-------------------------------------------------------------------------------------------------
19391964
//-------------------------------------------------------------------------------------------------
1940-
void W3DView::setZoomToDefault()
1965+
void W3DView::setZoomToMax()
19411966
{
1942-
// default zoom has to be max, otherwise players will just zoom to max always
1943-
19441967
// terrain height + desired height offset == cameraOffset * actual zoom
19451968
// find best approximation of max terrain height we can see
19461969
Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y);
@@ -1953,6 +1976,15 @@ void W3DView::setZoomToDefault()
19531976
m_zoom = desiredZoom;
19541977
m_heightAboveGround = m_maxHeightAboveGround;
19551978

1979+
m_cameraAreaConstraintsValid = false; // recalc it.
1980+
m_recalcCamera = true;
1981+
}
1982+
1983+
//-------------------------------------------------------------------------------------------------
1984+
//-------------------------------------------------------------------------------------------------
1985+
void W3DView::setZoomToDefault()
1986+
{
1987+
// default zoom has to be max, otherwise players will just zoom to max always
19561988
stopDoingScriptedCamera();
19571989
m_CameraArrivedAtWaypointOnPathFlag = false;
19581990
m_cameraAreaConstraintsValid = false;

GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ class GlobalData : public SubsystemInterface
186186
Real m_cameraPitch;
187187
Real m_cameraYaw;
188188
Real m_cameraHeight;
189+
190+
// TheSuperHackers @info Max and Min camera height for the original 4:3 view, these are then scaled for other aspect ratios.
189191
Real m_maxCameraHeight;
190192
Real m_minCameraHeight;
193+
191194
Real m_terrainHeightAtEdgeOfMap;
192195
Real m_unitDamagedThresh;
193196
Real m_unitReallyDamagedThresh;

GeneralsMD/Code/GameEngine/Include/GameLogic/ScriptActions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class ScriptActions : public ScriptActionsInterface
111111

112112
void doCameraTetherNamed(const AsciiString& unit, Bool snapToUnit, Real play);
113113
void doCameraStopTetherNamed();
114-
void doCameraSetDefault(Real pitch, Real angle, Real maxHeight);
114+
void doCameraSetDefault(Real pitch, Real angle, Real heighScale);
115115

116116
void doOversizeTheTerrain(Int amount);
117117
void doMoveCameraAlongWaypointPath(const AsciiString& waypoint, Real sec, Real cameraStutterSec, Real easeIn, Real easeOut);

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,11 @@ static void saveOptions()
848848

849849
TheInGameUI->recreateControlBar();
850850
TheInGameUI->refreshCustomUiResources();
851+
852+
// TheSuperHackers @info Only update the camera limits and set the zoom to max to not interfere with the scripted camera on the shellmap
853+
// The tactical view gets reset at game start, this is here so the shell map looks correct once the resolution is adjusted
854+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
855+
TheTacticalView->setZoomToMax();
851856
}
852857
}
853858
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ void InGameUI::init()
13761376
// make the tactical display the full screen width and height
13771377
TheTacticalView->setWidth( TheDisplay->getWidth() );
13781378
TheTacticalView->setHeight( TheDisplay->getHeight() );
1379-
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
1379+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
13801380
}
13811381

13821382
/** @todo this may be the wrong place to create the sidebar, but for now
@@ -2147,7 +2147,7 @@ void InGameUI::reset()
21472147
// reset the command bar
21482148
TheControlBar->reset();
21492149

2150-
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
2150+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
21512151

21522152
ResetInGameChat();
21532153

GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,9 +4601,11 @@ void ScriptActions::doCameraStopTetherNamed()
46014601
//-------------------------------------------------------------------------------------------------
46024602
/** doCameraSetDefault */
46034603
//-------------------------------------------------------------------------------------------------
4604-
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real maxHeight)
4604+
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real heighScale)
46054605
{
4606-
TheTacticalView->setDefaultView(pitch, angle, maxHeight);
4606+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault(heighScale);
4607+
TheTacticalView->setPitch(pitch);
4608+
TheTacticalView->setAngle(angle);
46074609
}
46084610

46094611
//-------------------------------------------------------------------------------------------------

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,9 +2026,12 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
20262026
// update the loadscreen
20272027
updateLoadProgress(LOAD_PROGRESS_POST_PRELOAD_ASSETS);
20282028

2029+
// TheSuperHackers @info Initialize the camera height limits to default if the resolution was changed
2030+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
20292031
TheTacticalView->setAngleToDefault();
20302032
TheTacticalView->setPitchToDefault();
20312033
TheTacticalView->setZoomToDefault();
2034+
TheTacticalView->setZoomToMax();
20322035

20332036
if( TheRecorder )
20342037
TheRecorder->initControls();

0 commit comments

Comments
 (0)