Skip to content

Commit 271ca5b

Browse files
committed
fix(view): Adjust default camera height based on aspect ratio
1 parent cb57c1b commit 271ca5b

File tree

9 files changed

+48
-23
lines changed

9 files changed

+48
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class GlobalData : public SubsystemInterface
189189
Real m_cameraPitch;
190190
Real m_cameraYaw;
191191
Real m_cameraHeight;
192-
Real m_maxCameraHeight;
192+
Real m_maxCameraHeight; // TheSuperHackers @info Max camera height for the original 4:3 view, this is then scaled for other aspect ratios.
193193
Real m_minCameraHeight;
194194
Real m_terrainHeightAtEdgeOfMap;
195195
Real m_unitDamagedThresh;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class View : public Snapshot
171171
virtual Bool isTimeFrozen(void){ return false;} ///< Freezes time during the next camera movement.
172172
virtual Int getTimeMultiplier(void) {return 1;}; ///< Get the time multiplier.
173173
virtual void setTimeMultiplier(Int multiple) {}; ///< Set the time multiplier.
174-
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) {};
174+
virtual void setDefaultCameraHeight(Real heightScale = 1.0f) {};
175175
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn, Real easeOut ) {};
176176
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn, Real easeOut ) {};
177177

@@ -189,7 +189,7 @@ class View : public Snapshot
189189
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
190190
virtual void setHeightAboveGround(Real z);
191191
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
192-
virtual void setZoomToDefault( void ) { m_zoom = 1.0f; } ///< Set zoom to default value
192+
virtual void setZoomToDefault( Bool softReset = false ) { m_zoom = 1.0f; } ///< Set zoom to default value
193193
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
194194

195195
// for debugging

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

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

115115
void doCameraTetherNamed(const AsciiString& unit, Bool snapToUnit, Real play);
116116
void doCameraStopTetherNamed(void);
117-
void doCameraSetDefault(Real pitch, Real angle, Real maxHeight);
117+
void doCameraSetDefault(Real pitch, Real angle, Real heighScale);
118118

119119
void doOversizeTheTerrain(Int amount);
120120
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
@@ -1560,6 +1560,11 @@ static void saveOptions( void )
15601560

15611561
TheInGameUI->recreateControlBar();
15621562
TheInGameUI->refreshCustomUiResources();
1563+
1564+
// TheSuperHackers @info Only update the default view and soft reset the zoom otherwise it throws off the scripted camera in the shellmap
1565+
// The view gets reset at game start, this is here so the shell map looks correct once the resolution is adjusted
1566+
TheTacticalView->setDefaultCameraHeight();
1567+
TheTacticalView->setZoomToDefault(true);
15631568
}
15641569
}
15651570
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ void InGameUI::init( void )
12491249
TheTacticalView->setWidth( TheDisplay->getWidth() );
12501250
TheTacticalView->setHeight( TheDisplay->getHeight() );
12511251
}
1252-
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
1252+
TheTacticalView->setDefaultCameraHeight();
12531253

12541254
/** @todo this may be the wrong place to create the sidebar, but for now
12551255
this is where it lives */
@@ -2000,7 +2000,7 @@ void InGameUI::reset( void )
20002000
// reset the command bar
20012001
TheControlBar->reset();
20022002

2003-
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
2003+
TheTacticalView->setDefaultCameraHeight();
20042004

20052005
ResetInGameChat();
20062006

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4609,9 +4609,11 @@ void ScriptActions::doCameraStopTetherNamed(void)
46094609
//-------------------------------------------------------------------------------------------------
46104610
/** doCameraSetDefault */
46114611
//-------------------------------------------------------------------------------------------------
4612-
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real maxHeight)
4612+
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real heighScale)
46134613
{
4614-
TheTacticalView->setDefaultView(pitch, angle, maxHeight);
4614+
TheTacticalView->setDefaultCameraHeight(heighScale);
4615+
TheTacticalView->setPitch(pitch);
4616+
TheTacticalView->setAngle(angle);
46154617
}
46164618

46174619
//-------------------------------------------------------------------------------------------------

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,8 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
20632063
// update the loadscreen
20642064
updateLoadProgress(LOAD_PROGRESS_POST_PRELOAD_ASSETS);
20652065

2066+
// TheSuperHackers @info Initialize the default view to update the max height if the resolution was changed
2067+
TheTacticalView->setDefaultCameraHeight();
20662068
TheTacticalView->setAngleAndPitchToDefault();
20672069
TheTacticalView->setZoomToDefault();
20682070

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,13 @@ class W3DView : public View, public SubsystemInterface
193193
virtual void Add_Camera_Shake(const Coord3D & position,float radius, float duration, float power); //WST 10.18.2002
194194
virtual Int getTimeMultiplier(void) {return m_timeMultiplier;};///< Get the time multiplier.
195195
virtual void setTimeMultiplier(Int multiple) {m_timeMultiplier = multiple;}; ///< Set the time multiplier.
196-
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight);
196+
virtual void setDefaultCameraHeight(Real heightScale = 1.0f);
197197
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn, Real easeOut );
198198
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn, Real easeOut );
199199

200200
virtual void setHeightAboveGround(Real z);
201201
virtual void setZoom(Real z);
202-
virtual void setZoomToDefault( void ); ///< Set zoom to default value
203-
202+
virtual void setZoomToDefault( Bool softReset = false ); ///< Set zoom to default value
204203
virtual void setFieldOfView( Real angle ); ///< Set the horizontal field of view angle
205204

206205
virtual WorldToScreenReturn worldToScreenTriReturn( const Coord3D *w, ICoord2D *s ); ///< Transform world coordinate "w" into screen coordinate "s"

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,12 +1922,25 @@ void W3DView::setAngleAndPitchToDefault( void )
19221922

19231923
//-------------------------------------------------------------------------------------------------
19241924
//-------------------------------------------------------------------------------------------------
1925-
void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
1925+
void W3DView::setDefaultCameraHeight(Real heightScale)
19261926
{
1927-
// MDC - we no longer want to rotate maps (design made all of them right to begin with)
1928-
// m_defaultAngle = angle * M_PI/180.0f;
1929-
m_defaultPitchAngle = pitch;
1930-
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight*maxHeight;
1927+
// TheSuperHackers @fix Mauller Adjust the max camera height to compensate for the screen aspect ratio
1928+
Real baseAspectRatio = (Real)DEFAULT_DISPLAY_WIDTH / (Real)DEFAULT_DISPLAY_HEIGHT;
1929+
Real currentAspectRatio = (Real)TheTacticalView->getWidth() / (Real)TheTacticalView->getHeight();
1930+
Real aspectRatioScale = 0.0f;
1931+
1932+
if (currentAspectRatio > baseAspectRatio)
1933+
{
1934+
aspectRatioScale = fabs(( 1 + ( currentAspectRatio - baseAspectRatio) ));
1935+
}
1936+
else
1937+
{
1938+
aspectRatioScale = fabs(( 1 - ( baseAspectRatio - currentAspectRatio) ));
1939+
}
1940+
1941+
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * aspectRatioScale * heightScale;
1942+
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight * aspectRatioScale;
1943+
19311944
if (m_minHeightAboveGround > m_maxHeightAboveGround)
19321945
m_maxHeightAboveGround = m_minHeightAboveGround;
19331946
}
@@ -1970,7 +1983,7 @@ void W3DView::setZoom(Real z)
19701983

19711984
//-------------------------------------------------------------------------------------------------
19721985
//-------------------------------------------------------------------------------------------------
1973-
void W3DView::setZoomToDefault( void )
1986+
void W3DView::setZoomToDefault( Bool softReset )
19741987
{
19751988
// default zoom has to be max, otherwise players will just zoom to max always
19761989

@@ -1986,12 +1999,16 @@ void W3DView::setZoomToDefault( void )
19861999
m_zoom = desiredZoom;
19872000
m_heightAboveGround = m_maxHeightAboveGround;
19882001

1989-
m_doingMoveCameraOnWaypointPath = false;
1990-
m_CameraArrivedAtWaypointOnPathFlag = false;
1991-
m_doingRotateCamera = false;
1992-
m_doingPitchCamera = false;
1993-
m_doingZoomCamera = false;
1994-
m_doingScriptedCameraLock = false;
2002+
// TheSuperHackers @info A soft reset does not interfere with scripted cameras but resets zoom to max
2003+
if (!softReset) {
2004+
m_doingMoveCameraOnWaypointPath = false;
2005+
m_CameraArrivedAtWaypointOnPathFlag = false;
2006+
m_doingRotateCamera = false;
2007+
m_doingPitchCamera = false;
2008+
m_doingZoomCamera = false;
2009+
m_doingScriptedCameraLock = false;
2010+
}
2011+
19952012
m_cameraConstraintValid = false; // recalc it.
19962013
setCameraTransform();
19972014
}

0 commit comments

Comments
 (0)