Skip to content

Commit a076193

Browse files
committed
fix(view): Adjust default camera height to compensate for screen aspect ratio
1 parent 476a57c commit a076193

10 files changed

Lines changed: 74 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
@@ -168,7 +168,8 @@ class View : public Snapshot
168168
virtual Bool isTimeFrozen(){ return false;} ///< Freezes time during the next camera movement.
169169
virtual Int getTimeMultiplier() {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) {}; // TheSuperHackers @todo Replace with setDefaultPitch(), setMaxHeightScale()
171+
virtual void setCameraHeightAboveGroundLimitsToDefault(Real heightScale = 1.0f) {};
172+
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) {};
172173
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn=0.0f, Real easeOut=0.0f ) {};
173174
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn=0.0f, Real easeOut=0.0f ) {};
174175

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

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
@@ -205,12 +205,14 @@ class W3DView : public View, public SubsystemInterface
205205
virtual Int getTimeMultiplier() override {return m_timeMultiplier;};///< Get the time multiplier.
206206
virtual void setTimeMultiplier(Int multiple) override {m_timeMultiplier = multiple;}; ///< Set the time multiplier.
207207
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) override;
208+
virtual void setCameraHeightAboveGroundLimitsToDefault(Real heightScale = 1.0f) override;
208209
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn, Real easeOut ) override;
209210
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn, Real easeOut ) override;
210211

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

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

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,6 +2084,31 @@ void W3DView::setPitchToDefault()
20842084
m_recalcCamera = true;
20852085
}
20862086

2087+
//-------------------------------------------------------------------------------------------------
2088+
//-------------------------------------------------------------------------------------------------
2089+
void W3DView::setCameraHeightAboveGroundLimitsToDefault(Real heightScale)
2090+
{
2091+
// TheSuperHackers @fix Mauller Adjust the camera height to compensate for the screen aspect ratio
2092+
Real baseAspectRatio = (Real)DEFAULT_DISPLAY_WIDTH / (Real)DEFAULT_DISPLAY_HEIGHT;
2093+
Real currentAspectRatio = (Real)TheTacticalView->getWidth() / (Real)TheTacticalView->getHeight();
2094+
Real aspectRatioScale = 0.0f;
2095+
2096+
if (currentAspectRatio > baseAspectRatio)
2097+
{
2098+
aspectRatioScale = fabs(( 1 + ( currentAspectRatio - baseAspectRatio) ));
2099+
}
2100+
else
2101+
{
2102+
aspectRatioScale = fabs(( 1 - ( baseAspectRatio - currentAspectRatio) ));
2103+
}
2104+
2105+
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * aspectRatioScale * heightScale;
2106+
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight * aspectRatioScale;
2107+
2108+
if (m_minHeightAboveGround > m_maxHeightAboveGround)
2109+
m_maxHeightAboveGround = m_minHeightAboveGround;
2110+
}
2111+
20872112
//-------------------------------------------------------------------------------------------------
20882113
//-------------------------------------------------------------------------------------------------
20892114
void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
@@ -2127,12 +2152,29 @@ void W3DView::setZoom(Real z)
21272152

21282153
//-------------------------------------------------------------------------------------------------
21292154
//-------------------------------------------------------------------------------------------------
2130-
void W3DView::setZoomToDefault()
2155+
void W3DView::setZoomToMax()
21312156
{
2132-
// default zoom has to be max, otherwise players will just zoom to max always
2157+
// terrain height + desired height offset == cameraOffset * actual zoom
2158+
// find best approximation of max terrain height we can see
2159+
Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y);
2160+
2161+
Real desiredHeight = (terrainHeightMax + m_maxHeightAboveGround);
2162+
Real desiredZoom = desiredHeight / getCameraOffsetZ();
2163+
2164+
//DEBUG_LOG(("W3DView::setZoomToDefault() Current zoom: %g Desired zoom: %g", m_zoom, desiredZoom));
2165+
2166+
m_zoom = desiredZoom;
21332167
m_heightAboveGround = m_maxHeightAboveGround;
2134-
m_zoom = getMaxZoom(m_pos.x, m_pos.y);
21352168

2169+
m_cameraAreaConstraintsValid = false; // recalc it.
2170+
m_recalcCamera = true;
2171+
}
2172+
2173+
//-------------------------------------------------------------------------------------------------
2174+
//-------------------------------------------------------------------------------------------------
2175+
void W3DView::setZoomToDefault()
2176+
{
2177+
// default zoom has to be max, otherwise players will just zoom to max always
21362178
stopDoingScriptedCamera();
21372179
m_CameraArrivedAtWaypointOnPathFlag = false;
21382180
m_cameraAreaConstraintsValid = false;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ class GlobalData : public SubsystemInterface
188188
#if PRESERVE_RETAIL_SCRIPTED_CAMERA
189189
Real m_cameraHeight;
190190
#endif
191+
192+
// TheSuperHackers @info Max and Min camera height for the original 4:3 view, these are then scaled for other aspect ratios.
191193
Real m_maxCameraHeight;
192194
Real m_minCameraHeight;
195+
193196
Real m_terrainHeightAtEdgeOfMap;
194197
Real m_unitDamagedThresh;
195198
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
@@ -2063,9 +2063,12 @@ void GameLogic::startNewGame( Bool loadingSaveGame )
20632063
// update the loadscreen
20642064
updateLoadProgress(LOAD_PROGRESS_POST_PRELOAD_ASSETS);
20652065

2066+
// TheSuperHackers @info Initialize the camera height limits to default if the resolution was changed
2067+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
20662068
TheTacticalView->setAngleToDefault();
20672069
TheTacticalView->setPitchToDefault();
20682070
TheTacticalView->setZoomToDefault();
2071+
TheTacticalView->setZoomToMax();
20692072

20702073
if( TheRecorder )
20712074
TheRecorder->initControls();

0 commit comments

Comments
 (0)