Skip to content

Commit 02a64e0

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

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class Display : public SubsystemInterface
8282
virtual void setHeight( UnsignedInt height ); ///< Sets the height of the display
8383
virtual UnsignedInt getWidth( void ) { return m_width; } ///< Returns the width of the display
8484
virtual UnsignedInt getHeight( void ) { return m_height; } ///< Returns the height of the display
85+
virtual Real getAspectRatio() { return (Real)m_width / (Real)m_height; }
8586
virtual void setBitDepth( UnsignedInt bitDepth ) { m_bitDepth = bitDepth; }
8687
virtual UnsignedInt getBitDepth( void ) { return m_bitDepth; }
8788
virtual void setWindowed( Bool windowed ) { m_windowed = windowed; } ///< set windowd/fullscreen flag

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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->setDefaultView(0.0f, 0.0f, 1.0f);
1567+
TheTacticalView->setZoomToDefault(true);
15631568
}
15641569
}
15651570
}

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 initialise the default view to update the max height if resolution was changed
2067+
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
20662068
TheTacticalView->setAngleAndPitchToDefault();
20672069
TheTacticalView->setZoomToDefault();
20682070

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ class W3DView : public View, public SubsystemInterface
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: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,10 +1924,26 @@ void W3DView::setAngleAndPitchToDefault( void )
19241924
//-------------------------------------------------------------------------------------------------
19251925
void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
19261926
{
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 = TheDisplay->getAspectRatio();
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+
19271941
// MDC - we no longer want to rotate maps (design made all of them right to begin with)
19281942
// m_defaultAngle = angle * M_PI/180.0f;
19291943
m_defaultPitchAngle = pitch;
1930-
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight*maxHeight;
1944+
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * aspectRatioScale * maxHeight ;
1945+
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight * aspectRatioScale;
1946+
19311947
if (m_minHeightAboveGround > m_maxHeightAboveGround)
19321948
m_maxHeightAboveGround = m_minHeightAboveGround;
19331949
}
@@ -1970,7 +1986,7 @@ void W3DView::setZoom(Real z)
19701986

19711987
//-------------------------------------------------------------------------------------------------
19721988
//-------------------------------------------------------------------------------------------------
1973-
void W3DView::setZoomToDefault( void )
1989+
void W3DView::setZoomToDefault( Bool softReset )
19741990
{
19751991
// default zoom has to be max, otherwise players will just zoom to max always
19761992

@@ -1986,12 +2002,16 @@ void W3DView::setZoomToDefault( void )
19862002
m_zoom = desiredZoom;
19872003
m_heightAboveGround = m_maxHeightAboveGround;
19882004

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

0 commit comments

Comments
 (0)