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): stop the camera rocking while a zoom is held on the cursor

Olcay Seygan7d25772f3000
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a3917187a..95089c23b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -788,6 +788,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- 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.
+- Zoomed in over uneven ground, the camera holds still. Keeping the spot under the pointer moved the camera over different ground, the camera then settled to a new height, which moved it again, and on hilly ground that went on forever as a slow rocking forward and back.
- 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.
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
index 988227d68..2eb3cd99b 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
@@ -291,6 +291,7 @@ private:
Bool m_zoomAnchorValid; ///< a wheel zoom is holding the ground under the cursor
ICoord2D m_zoomAnchorPixel; ///< the pixel the wheel was spun over
Coord3D m_zoomAnchorWorld; ///< the ground that has to stay under it
+ Real m_zoomAnchorTerrainHeight; ///< the ground height the zoom settles against while it is held
void holdZoomAnchor( Bool zoomMoved ); ///< move the camera so the anchored ground is back under its pixel
Bool isDoingScriptedCamera( void ) const; ///< True while any scripted camera movement owns the view
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index cd5d911f7..a40a65c0f 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -196,6 +196,7 @@ W3DView::W3DView()
m_recalcCamera = false;
m_zoomAnchorValid = false;
+ m_zoomAnchorTerrainHeight = 0.0f;
m_scrollWheelHeight = 0.0f;
} // end W3DView
@@ -1492,7 +1493,14 @@ void W3DView::update(void)
* underground or higher than the max allowed height. When the camera is at rest (not
* scrolling), the zoom will move toward matching the desired height.
*/
- m_terrainHeightUnderCamera = getHeightAroundPos(m_pos.x, m_pos.y);
+ //
+ // While a wheel zoom is held on the cursor, the ground height is the one under the camera when
+ // the wheel turned. Read afresh, it closed a loop: the settle moved the zoom, holdZoomAnchor
+ // moved the camera to keep the cursor's ground still, the camera stood over other ground, the
+ // highest of the five samples jumped, and the settle went the other way. Zoomed in on uneven
+ // ground that never stopped, and the camera rocked forward and back.
+ //
+ m_terrainHeightUnderCamera = m_zoomAnchorValid ? m_zoomAnchorTerrainHeight : getHeightAroundPos(m_pos.x, m_pos.y);
m_currentHeightAboveGround = m_cameraOffset.z * m_zoom - m_terrainHeightUnderCamera;
const Real zoomBeforeSettle = m_zoom;
//
@@ -2731,6 +2739,7 @@ void W3DView::anchorZoomAt( const ICoord2D *pixel )
{
m_zoomAnchorPixel = *pixel;
m_zoomAnchorValid = screenToTerrain( pixel, &m_zoomAnchorWorld );
+ m_zoomAnchorTerrainHeight = getHeightAroundPos( m_pos.x, m_pos.y );
}
//-------------------------------------------------------------------------------------------------