Skip to content

Commit f6c96d8

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

File tree

10 files changed

+57
-20
lines changed

10 files changed

+57
-20
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: 3 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,8 @@ 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 setZoomToMax();
193+
virtual void setZoomToDefault() { m_zoom = 1.0f; } ///< Set zoom to default value
193194
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
194195

195196
// 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->setZoomToMax();
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/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
void View::lockViewUntilFrame(UnsignedInt frame)
133138
{
134139
m_viewLockedUntilFrame = frame;

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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ 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
202+
virtual void setZoomToMax();
203+
virtual void setZoomToDefault(); ///< Set zoom to default value
203204

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

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

Lines changed: 31 additions & 10 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,10 +1983,8 @@ void W3DView::setZoom(Real z)
19701983

19711984
//-------------------------------------------------------------------------------------------------
19721985
//-------------------------------------------------------------------------------------------------
1973-
void W3DView::setZoomToDefault( void )
1986+
void W3DView::setZoomToMax()
19741987
{
1975-
// default zoom has to be max, otherwise players will just zoom to max always
1976-
19771988
// terrain height + desired height offset == cameraOffset * actual zoom
19781989
// find best approximation of max terrain height we can see
19791990
Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y);
@@ -1986,14 +1997,24 @@ void W3DView::setZoomToDefault( void )
19861997
m_zoom = desiredZoom;
19871998
m_heightAboveGround = m_maxHeightAboveGround;
19881999

2000+
m_cameraConstraintValid = false; // recalc it.
2001+
setCameraTransform();
2002+
}
2003+
2004+
//-------------------------------------------------------------------------------------------------
2005+
//-------------------------------------------------------------------------------------------------
2006+
void W3DView::setZoomToDefault()
2007+
{
2008+
// default zoom has to be max, otherwise players will just zoom to max always
2009+
2010+
// TheSuperHackers @info This function resets the camera so will cause scripted cameras to halt
19892011
m_doingMoveCameraOnWaypointPath = false;
19902012
m_CameraArrivedAtWaypointOnPathFlag = false;
19912013
m_doingRotateCamera = false;
19922014
m_doingPitchCamera = false;
19932015
m_doingZoomCamera = false;
19942016
m_doingScriptedCameraLock = false;
1995-
m_cameraConstraintValid = false; // recalc it.
1996-
setCameraTransform();
2017+
setZoomToMax();
19972018
}
19982019

19992020
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)