Skip to content

Commit ec0c082

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

10 files changed

Lines changed: 74 additions & 16 deletions

File tree

Core/GameEngine/Include/GameClient/View.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class View : public Snapshot
172172
virtual Bool isTimeFrozen(){ return false;} ///< Freezes time during the next camera movement.
173173
virtual Int getTimeMultiplier() {return 1;}; ///< Get the time multiplier.
174174
virtual void setTimeMultiplier(Int multiple) {}; ///< Set the time multiplier.
175-
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) {}; // TheSuperHackers @todo Replace with setDefaultPitch(), setMaxHeightScale()
175+
virtual void setCameraHeightAboveGroundLimitsToDefault(Real heightScale = 1.0f) {};
176+
virtual void setDefaultView(Real pitch, Real angle, Real maxHeight) {};
176177
virtual void zoomCamera( Real finalZoom, Int milliseconds, Real easeIn=0.0f, Real easeOut=0.0f ) {};
177178
virtual void pitchCamera( Real finalPitch, Int milliseconds, Real easeIn=0.0f, Real easeOut=0.0f ) {};
178179

@@ -202,6 +203,7 @@ class View : public Snapshot
202203
virtual Real getHeightAboveGround() { return m_heightAboveGround; }
203204
virtual void setHeightAboveGround(Real z);
204205
virtual void zoom( Real height ); ///< Zoom in/out, closer to the ground, limit to min, or farther away from the ground, limit to max
206+
virtual void setZoomToMax();
205207
virtual void setZoomToDefault() { m_zoom = 1.0f; } ///< Set zoom to default value
206208
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
207209

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

214215
virtual void setHeightAboveGround(Real z) override;
215216
virtual void setZoom(Real z) override;
216-
virtual void setZoomToDefault() override; ///< Set zoom to default value
217+
virtual void setZoomToMax() override;
218+
virtual void setZoomToDefault() override; ///< Set zoom to default value - TheSuperHackers @info This function resets the camera so will cause scripted cameras to halt
217219

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

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,31 @@ void W3DView::setPitchToDefault()
21792179
m_recalcCamera = true;
21802180
}
21812181

2182+
//-------------------------------------------------------------------------------------------------
2183+
//-------------------------------------------------------------------------------------------------
2184+
void W3DView::setCameraHeightAboveGroundLimitsToDefault(Real heightScale)
2185+
{
2186+
// TheSuperHackers @fix Mauller Adjust the camera height to compensate for the screen aspect ratio
2187+
Real baseAspectRatio = (Real)DEFAULT_DISPLAY_WIDTH / (Real)DEFAULT_DISPLAY_HEIGHT;
2188+
Real currentAspectRatio = (Real)TheTacticalView->getWidth() / (Real)TheTacticalView->getHeight();
2189+
Real aspectRatioScale = 0.0f;
2190+
2191+
if (currentAspectRatio > baseAspectRatio)
2192+
{
2193+
aspectRatioScale = fabs(( 1 + ( currentAspectRatio - baseAspectRatio) ));
2194+
}
2195+
else
2196+
{
2197+
aspectRatioScale = fabs(( 1 - ( baseAspectRatio - currentAspectRatio) ));
2198+
}
2199+
2200+
m_maxHeightAboveGround = TheGlobalData->m_maxCameraHeight * aspectRatioScale * heightScale;
2201+
m_minHeightAboveGround = TheGlobalData->m_minCameraHeight * aspectRatioScale;
2202+
2203+
if (m_minHeightAboveGround > m_maxHeightAboveGround)
2204+
m_maxHeightAboveGround = m_minHeightAboveGround;
2205+
}
2206+
21822207
//-------------------------------------------------------------------------------------------------
21832208
//-------------------------------------------------------------------------------------------------
21842209
void W3DView::setDefaultView(Real pitch, Real angle, Real maxHeight)
@@ -2222,12 +2247,29 @@ void W3DView::setZoom(Real z)
22222247

22232248
//-------------------------------------------------------------------------------------------------
22242249
//-------------------------------------------------------------------------------------------------
2225-
void W3DView::setZoomToDefault()
2250+
void W3DView::setZoomToMax()
22262251
{
2227-
// default zoom has to be max, otherwise players will just zoom to max always
2252+
// terrain height + desired height offset == cameraOffset * actual zoom
2253+
// find best approximation of max terrain height we can see
2254+
Real terrainHeightMax = getHeightAroundPos(m_pos.x, m_pos.y);
2255+
2256+
Real desiredHeight = (terrainHeightMax + m_maxHeightAboveGround);
2257+
Real desiredZoom = desiredHeight / getCameraOffsetZ();
2258+
2259+
//DEBUG_LOG(("W3DView::setZoomToDefault() Current zoom: %g Desired zoom: %g", m_zoom, desiredZoom));
2260+
2261+
m_zoom = desiredZoom;
22282262
m_heightAboveGround = m_maxHeightAboveGround;
2229-
m_zoom = getMaxZoom(m_pos.x, m_pos.y);
22302263

2264+
m_cameraAreaConstraintsValid = false; // recalc it.
2265+
m_recalcCamera = true;
2266+
}
2267+
2268+
//-------------------------------------------------------------------------------------------------
2269+
//-------------------------------------------------------------------------------------------------
2270+
void W3DView::setZoomToDefault()
2271+
{
2272+
// default zoom has to be max, otherwise players will just zoom to max always
22312273
stopDoingScriptedCamera();
22322274
m_CameraArrivedAtWaypointOnPathFlag = false;
22332275
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
@@ -880,6 +880,11 @@ static void saveOptions()
880880

881881
TheInGameUI->recreateControlBar();
882882
TheInGameUI->refreshCustomUiResources();
883+
884+
// TheSuperHackers @info Only update the camera limits and set the zoom to max to not interfere with the scripted camera on the shellmap
885+
// The tactical view gets reset at game start, this is here so the shell map looks correct once the resolution is adjusted
886+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
887+
TheTacticalView->setZoomToMax();
883888
}
884889
}
885890
}

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +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(
1380-
DEG_TO_RADF(TheGlobalData->m_cameraPitch),
1381-
DEG_TO_RADF(TheGlobalData->m_cameraYaw),
1382-
1.0f);
1379+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
13831380
}
13841381

13851382
/** @todo this may be the wrong place to create the sidebar, but for now
@@ -2150,10 +2147,7 @@ void InGameUI::reset()
21502147
// reset the command bar
21512148
TheControlBar->reset();
21522149

2153-
TheTacticalView->setDefaultView(
2154-
DEG_TO_RADF(TheGlobalData->m_cameraPitch),
2155-
DEG_TO_RADF(TheGlobalData->m_cameraYaw),
2156-
1.0f);
2150+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
21572151

21582152
ResetInGameChat();
21592153

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,15 +4603,17 @@ void ScriptActions::doCameraStopTetherNamed()
46034603
//-------------------------------------------------------------------------------------------------
46044604
/** doCameraSetDefault */
46054605
//-------------------------------------------------------------------------------------------------
4606-
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real maxHeight)
4606+
void ScriptActions::doCameraSetDefault(Real pitch, Real angle, Real heighScale)
46074607
{
46084608
#if PRESERVE_RETAIL_SCRIPTED_CAMERA
46094609
// TheSuperHackers @tweak To preserve the original scripted camera values, offset them by default ones.
46104610
pitch = -pitch + ViewDefaultPitchRadians;
46114611
angle = angle + ViewDefaultYawRadians;
46124612
#endif
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,9 +2085,12 @@ void GameLogic::tryStartNewGame( Bool loadingSaveGame )
20852085
// update the loadscreen
20862086
updateLoadProgress(LOAD_PROGRESS_POST_PRELOAD_ASSETS);
20872087

2088+
// TheSuperHackers @info Initialize the camera height limits to default if the resolution was changed
2089+
TheTacticalView->setCameraHeightAboveGroundLimitsToDefault();
20882090
TheTacticalView->setAngleToDefault();
20892091
TheTacticalView->setPitchToDefault();
20902092
TheTacticalView->setZoomToDefault();
2093+
TheTacticalView->setZoomToMax();
20912094

20922095
if( TheRecorder )
20932096
TheRecorder->initControls();

0 commit comments

Comments
 (0)