Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(w3ddevice): keep the camera above the ground and the radar box under it

Olcay Seygan622add8dd91a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c34934ed6..83c9945ba 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -325,6 +325,9 @@ found and fixed — EA's own, not port damage.**
- The zoom-out ceiling is the same for everyone; no setting buys you a wider view.
- The wheel covers that whole range in about six notches instead of thirty-eight.
- Zoom toward the cursor works; the spot under your pointer stays there.
+- The camera stays above the ground. Zoomed in on a slope it used to end up inside the hill it was looking over, and the world opened up along the near plane.
+- The far edge of the view opens with the height, instead of stopping at a distance fixed for the stock zoom - which is what put black beyond the terrain when you zoom out past it.
+- The box on the radar follows the camera when you pan. It only ever redrew itself when the zoom or the angle changed, so scrolling left it behind.
- The camera turns in whole 45-degree steps, instantly, while you hold the key.
- Edge scrolling works windowed, and scroll speed no longer follows your frame rate.
- Taking over another base no longer squeezes the picture into the top four fifths of the screen.
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Radar.h b/GeneralsMD/Code/GameEngine/Include/Common/Radar.h
index 8dc12d227..1ab8a1530 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/Radar.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/Radar.h
@@ -214,6 +214,9 @@ public:
virtual void draw( Int pixelX, Int pixelY, Int width, Int height ) = 0; ///< draw the radar
+ /// the camera moved, turned or zoomed - whatever the radar draws from it is stale now
+ virtual void notifyViewChanged( void ) {}
+
/// empty the entire shroud
virtual void clearShroud() = 0;
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
index 1362701ae..edc1ec2a0 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
@@ -69,6 +69,8 @@ public:
virtual void refreshTerrain( TerrainLogic *terrain );
+ virtual void notifyViewChanged( void ); ///< the camera view changed
+
protected:
void drawSingleBeaconEvent( Int pixelX, Int pixelY, Int width, Int height, Int index );
@@ -116,8 +118,6 @@ protected:
// translate real world coords to integer radar spots
//
Bool m_reconstructViewBox; ///< true when we need to reconstruct the box
- Real m_viewAngle; ///< camera angle used for the view box we have
- Real m_viewZoom; ///< camera zoom used for the view box we have
ICoord2D m_viewBox[ 4 ]; ///< radar cell points for the 4 corners of view box
std::list<const Coord3D *> m_cachedHeroPosList; //< cache of hero positions for drawing icons in radar overlay
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
index e3fa6e3dd..feba4c71d 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
@@ -217,14 +217,6 @@ void W3DRadar::reconstructViewBox( void )
} // end for i
- //
- // save the camera settings for this view box, we will need to make it again only
- // if some of these change
- //
- m_viewAngle = TheTacticalView->getAngle();
- Coord3D pos;
- TheTacticalView->getPosition( &pos );
- m_viewZoom = TheTacticalView->getZoom();
m_reconstructViewBox = FALSE;
} // end reconstructViewBox
@@ -846,8 +838,6 @@ W3DRadar::W3DRadar( void )
m_textureHeight = RADAR_CELL_HEIGHT;
m_reconstructViewBox = TRUE;
- m_viewAngle = 0.0f;
- m_viewZoom = 0.0f;
for( Int i = 0; i < 4; i++ )
{
@@ -1447,13 +1437,10 @@ void W3DRadar::draw( Int pixelX, Int pixelY, Int width, Int height )
// draw any radar events
drawEvents( ul.x, ul.y, scaledWidth, scaledHeight );
- // see if we need to reconstruct the view box
- if( TheTacticalView->getZoom() != m_viewZoom )
- m_reconstructViewBox = TRUE;
- if( TheTacticalView->getAngle() != m_viewAngle )
- m_reconstructViewBox = TRUE;
-
- if( m_reconstructViewBox == TRUE )
+ // The box used to be rebuilt only when the zoom or the angle had changed, so panning the
+ // camera left it where it was until you happened to zoom or turn. The view tells us now,
+ // whatever it was that moved.
+ if( m_reconstructViewBox )
reconstructViewBox();
// draw the view region on top of the radar reconstructing if necessary
@@ -1624,3 +1611,10 @@ void W3DRadar::refreshTerrain( TerrainLogic *terrain )
*
*/
+
+// ------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------------
+void W3DRadar::notifyViewChanged( void )
+{
+ m_reconstructViewBox = TRUE;
+}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index 3901abdb6..d1390d183 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -39,6 +39,7 @@
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "Common/BuildAssistant.h"
#include "Common/GlobalData.h"
+#include "Common/Radar.h"
#include "Common/Module.h"
#include "Common/RandomValue.h"
#include "Common/ThingTemplate.h"
@@ -413,6 +414,22 @@ void W3DView::buildCameraTransform( Matrix3D *transform )
}
}
+ // Keep the eye above the ground. Zoomed right in on a slope, or pitched up, the camera ends up
+ // inside the hill it is looking over and the near plane cuts the world open. Lift both the eye
+ // and what it is looking at by the same amount, so the shot is the same shot, just above the
+ // dirt. The height is sampled around the point rather than at it, so a bumpy slope does not
+ // make the camera jitter.
+ if( TheTerrainLogic ) // the view is built once before the terrain exists
+ {
+ const Real minAcceptableCameraHeight = getHeightAroundPos( sourcePos.X, sourcePos.Y ) + MAP_XY_FACTOR;
+ if( sourcePos.Z < minAcceptableCameraHeight )
+ {
+ const Real repositionZ = minAcceptableCameraHeight - sourcePos.Z;
+ sourcePos.Z += repositionZ;
+ targetPos.Z += repositionZ;
+ }
+ }
+
//m_3DCamera->Set_View_Plane(DEG_TO_RADF(50.0f));
//DEBUG_LOG(("zoom %f, SourceZ %f, posZ %f, groundLevel %f CamOffZ %f\n",
// zoom, sourcePos.Z, pos.z, groundLevel,m_cameraOffset.z));
@@ -589,8 +606,17 @@ void W3DView::setCameraTransform( void )
Real nearZ, farZ;
// m_3DCamera->Get_Clip_Planes(nearZ, farZ);
// Set the near to MAP_XY_FACTOR. Improves zbuffer resolution.
- nearZ = MAP_XY_FACTOR;
- farZ = 1200.0f;
+ nearZ = MAP_XY_FACTOR;
+
+ // 1200 was a number, not a distance: at the stock ceiling and pitch the far plane already cuts
+ // the terrain the game means to draw, and this fork zooms further out than the stock game did.
+ // Take the distance the terrain is actually drawn over instead, and open it with the height -
+ // at twice the height you see twice as far.
+ static const Real VIEW_DEFAULT_MAX_HEIGHT_ABOVE_TERRAIN = 310.0f;
+ farZ = (WorldHeightMap::NORMAL_DRAW_WIDTH * 1.08f) * MAP_XY_FACTOR;
+ const Real heightMultiplier = m_heightAboveGround / VIEW_DEFAULT_MAX_HEIGHT_ABOVE_TERRAIN;
+ if (heightMultiplier > 1.0f)
+ farZ *= heightMultiplier;
if (m_useRealZoomCam) //WST 10.19.2002
{
@@ -601,9 +627,9 @@ void W3DView::setCameraTransform( void )
}
else
{
- if ((TheGlobalData && TheGlobalData->m_drawEntireTerrain) || (m_FXPitch<0.95f || m_zoom>1.05))
+ if ((TheGlobalData && TheGlobalData->m_drawEntireTerrain) || m_FXPitch<0.95f)
{ //need to extend far clip plane so entire terrain can be visible
- farZ *= MAP_XY_FACTOR;
+ farZ *= 10.0f;
}
}
@@ -639,16 +665,21 @@ void W3DView::setCameraTransform( void )
buildCameraTransform( &cameraTransform );
m_3DCamera->Set_Transform( cameraTransform );
- if (TheTerrainRenderObject)
+ if (TheTerrainRenderObject)
{
RefRenderObjListIterator *it = W3DDisplay::m_3DScene->createLightsIterator();
TheTerrainRenderObject->updateCenter(m_3DCamera, it);
- if (it)
+ if (it)
{
W3DDisplay::m_3DScene->destroyLightsIterator(it);
it = NULL;
}
}
+
+ // tell the radar its view box is stale, whatever it was that moved - it used to work that out
+ // itself by comparing the zoom and the angle, so panning left the box behind
+ if (TheRadar)
+ TheRadar->notifyViewChanged();
}
//-------------------------------------------------------------------------------------------------