Skip to content

Commit eca5e53

Browse files
committed
fix(view): Adjust default camera height based on aspect ratio
1 parent 632e1b9 commit eca5e53

File tree

10 files changed

+57
-19
lines changed

10 files changed

+57
-19
lines changed

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/GameClient/View.h

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

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

192193
// for debugging

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(void);
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
@@ -1622,6 +1622,11 @@ static void saveOptions( void )
16221622

16231623
TheInGameUI->recreateControlBar();
16241624
TheInGameUI->refreshCustomUiResources();
1625+
1626+
// TheSuperHackers @info Only update the camera limits and set the zoom to max to not interfere with the scripted camera on the shellmap
1627+
// The tactical view gets reset at game start, this is here so the shell map looks correct once the resolution is adjusted
1628+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
1629+
TheTacticalView->setZoomToMax();
16251630
}
16261631
}
16271632
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ void InGameUI::init( void )
12831283
TheTacticalView->setWidth( TheDisplay->getWidth() );
12841284
TheTacticalView->setHeight( TheDisplay->getHeight() );
12851285
}
1286-
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
1286+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
12871287

12881288
/** @todo this may be the wrong place to create the sidebar, but for now
12891289
this is where it lives */
@@ -2052,7 +2052,7 @@ void InGameUI::reset( void )
20522052
// reset the command bar
20532053
TheControlBar->reset();
20542054

2055-
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
2055+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
20562056

20572057
ResetInGameChat();
20582058

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->setCameraHeightAboveGroundLimitsToDefault(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
@@ -2077,6 +2077,8 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
20772077
// update the loadscreen
20782078
updateLoadProgress(LOAD_PROGRESS_POST_PRELOAD_ASSETS);
20792079

2080+
// TheSuperHackers @info Initialize the camera height limits to default if the resolution was changed
2081+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
20802082
TheTacticalView->setAngleAndPitchToDefault();
20812083
TheTacticalView->setZoomToDefault();
20822084

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

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

197197
virtual void setHeightAboveGround(Real z);
198198
virtual void setZoom(Real z);
199-
virtual void setZoomToDefault( void ); ///< Set zoom to default value
199+
virtual void setZoomToMax();
200+
virtual void setZoomToDefault(); ///< Set zoom to default value - TheSuperHackers @info This function resets the camera so will cause scripted cameras to halt
200201

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

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

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

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

19721985
//-------------------------------------------------------------------------------------------------
19731986
//-------------------------------------------------------------------------------------------------
1974-
void W3DView::setZoomToDefault( void )
1987+
void W3DView::setZoomToMax()
19751988
{
1976-
// default zoom has to be max, otherwise players will just zoom to max always
1977-
19781989
// terrain height + desired height offset == cameraOffset * actual zoom
19791990
// find best approximation of max terrain height we can see
19801991
Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y);
@@ -1987,14 +1998,22 @@ void W3DView::setZoomToDefault( void )
19871998
m_zoom = desiredZoom;
19881999
m_heightAboveGround = m_maxHeightAboveGround;
19892000

2001+
m_cameraConstraintValid = false; // recalc it.
2002+
setCameraTransform();
2003+
}
2004+
2005+
//-------------------------------------------------------------------------------------------------
2006+
//-------------------------------------------------------------------------------------------------
2007+
void W3DView::setZoomToDefault()
2008+
{
2009+
// default zoom has to be max, otherwise players will just zoom to max always
19902010
m_doingMoveCameraOnWaypointPath = false;
19912011
m_CameraArrivedAtWaypointOnPathFlag = false;
19922012
m_doingRotateCamera = false;
19932013
m_doingPitchCamera = false;
19942014
m_doingZoomCamera = false;
19952015
m_doingScriptedCameraLock = false;
1996-
m_cameraConstraintValid = false; // recalc it.
1997-
setCameraTransform();
2016+
setZoomToMax();
19982017
}
19992018

20002019
//-------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)