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): hold the isometric camera's height over hills

Olcay Seygan9a55599ea315
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9e6e5daf..5c44a44ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -170,7 +170,7 @@ found and fixed — EA's own, not port damage.**
- A box drawn with Ctrl held takes those units back out of your selection instead of replacing it, so a group is trimmed by dragging over the corner of it rather than picked again from scratch. Held with Alt the box keeps only what can shoot: drag across your base and you get the tanks, not the dozers and supply trucks standing among them. Both are drag-only, and a single click still means exactly what it always did.
- A box dragged over your army and your economy together takes the army. The dozers, workers, supply trucks and hackers standing among the tanks stay where they are, and ambulances and troop carriers go with the soldiers they look after. A box with nobody military in it takes the workers the way it always did. Legacy keeps the old box.
- The three buttons each do one thing now. Left selects, and only selects. Right gives orders, and nothing it does moves the camera. The camera is on the middle button, and it scrolls the way the right button used to: the spot you pressed on stays put, and the further you pull away from it the faster the map runs. Hold Ctrl and the same drag turns the view instead. The wheel zooms toward whatever the cursor is over and the screen edges still scroll. The classic scheme, where left both selected and commanded and right scrolled and deselected, is gone rather than switched off, and the two checkboxes that used to choose between them are out of the options screen.
-- An isometric camera, on Options > Controls. It looks at the battlefield from far off through a narrow lens, so a tank at the top of the screen is drawn the same size as one at the bottom and a base reads like a city-builder's plan instead of shrinking into the distance. It buys no extra sight. The normal camera's corners, edges and centre are laid over the isometric screen as closely as a flat picture allows, hills and ultrawide screens included: the normal camera still sees a little more at the far corners and the isometric one the same amount more at the near corners, because a perspective view is wider at the back than at the front and an isometric one is not. You still turn and zoom it the way you always did, and the box takes effect the moment you tick it, mid-match included.
+- An isometric camera, on Options > Controls. It looks at the battlefield from far off through a narrow lens, so a tank at the top of the screen is drawn the same size as one at the bottom and a base reads like a city-builder's plan instead of shrinking into the distance. It buys no extra sight. The normal camera's corners, edges and centre are laid over the isometric screen as closely as a flat picture allows, hills and ultrawide screens included: the normal camera still sees a little more at the far corners and the isometric one the same amount more at the near corners, because a perspective view is wider at the back than at the front and an isometric one is not. Pan across a ridge and the picture holds its size and its angle; it does not rise and dip with the ground under it. You still turn and zoom it the way you always did, and the box takes effect the moment you tick it, mid-match included.
- Drag the right button and you draw a line: the selection spreads itself evenly along it, in the order the units already stand, so a column arrives as a firing line instead of a queue. It is the line you actually drew, curves and all, however far you keep drawing it: a long sweep used to give up partway through and finish as one straight run to the cursor, and now it holds its shape to the end. Letting go over the sidebar finishes the order rather than leaving the line stuck to the cursor. Draw the line with the left button while attack move is armed and the whole line is an attack move: artillery spread across a front, each gun firing on what walks into it, instead of one clump on one spot. The left button, because that is what attack move is aimed with; with F armed a right drag draws nothing. Armed with attack instead, every unit fires on its own station along the line, which is a barrage laid across a ridge in one drag. This is what the right button freed up. `FormationDrag = no` in Options.ini turns it off if you would rather a slipped click did nothing.
- Selected units draw a thread to wherever they are going, with the pointer, tinted, sitting on the spot. Every order draws one: move, attack move, attack, force fire, ground fire, enter, dock, repair, heal, capture, hack, guard, a waypoint path. Green for a move, pink for an attack-move, red for anything that shoots, so a group told three different things reads as three different colours. Units standing together and headed the same way share one thread, from the middle of the knot to the middle of where they are going, so twenty tanks sent across the map draw one line instead of twenty laid on top of each other; a selection spread over the map draws one per knot, and a flank sent on its own still shows. An angry mob draws one thread for the whole mob, not one per rioter. An attack move and a shot at the ground both point at the spot you clicked: the attack move's thread used to wander off to whichever free ground each unit was steering for, and ground fire pointed at the middle of the nearest map cell. An attack move stays pink from start to finish, too. A unit that stopped to fight used to swing its thread onto the enemy it was fighting, and only swung it back to your destination once the enemy was dead. A dot and a ring stood in for the pointer for a while, and players asked for the pointer back. It is not a flash at the moment of the order: the line is asked of the unit every frame, so it lasts until the unit gets there, changes its mind or leaves your selection, and it shows on the formation line while you are still drawing it. A unit that has walked off the edge of the screen still draws its line, which is how you see where the half of your army you cannot see is headed. The animated ring the ground used to sprout wherever you clicked is gone: it flashed for a second and told you nothing the marker sitting on the destination does not, and that marker stays for as long as the order does. A marker that has just appeared slides the last few pixels up out of the bottom right and fades in as it lands, over about an eighth of a second, so a fresh order catches your eye without anything flashing. Aircraft draw their thread from the click, not from the moment they leave the runway. A plane parked on its airfield answers an order by starting its takeoff and puts the order itself aside until the wheels are up, so the taxi and the climb, which is exactly the stretch where you are wondering whether the strike went out at all, used to show nothing.
- A unit standing guard draws its marker on the ground it is guarding. A guard order clears the unit's goal on the way in, so every guard marker used to sit in the bottom left corner of the map with a thread running the whole way across it, whatever the unit was actually watching.
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
index e9823de7b..c5a020a19 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp
@@ -671,52 +671,23 @@ void W3DView::stopDoingScriptedCamera( void )
m_doingScriptedCameraLock = false;
}
-//-------------------------------------------------------------------------------------------------
-// Where a descending ray from the eye first meets the terrain, walked a cell at a time and then
-// halved down to a tenth of a unit. Terrain never goes below zero, so a ray that gets there
-// without meeting it stops there. The terrain's own Cast_Ray tests every triangle under the
-// ray's bounding rectangle, which for a shallow ray across the screen is thousands of them.
-static Vector3 groundUnderRay( const Vector3& eye, const Vector3& direction )
-{
- const Real step = MAP_XY_FACTOR;
- const Int halvings = 7;
- Real below = 0.0f;
- Real above = 0.0f;
- for( ;; )
- {
- const Vector3 point = eye + direction * below;
- if( point.Z <= 0.0f || point.Z <= TheTerrainLogic->getGroundHeight( point.X, point.Y ) )
- break;
- above = below;
- below += step;
- }
- for( Int halving = 0; halving < halvings; ++halving )
- {
- const Real middle = ( above + below ) * 0.5f;
- const Vector3 point = eye + direction * middle;
- if( point.Z <= TheTerrainLogic->getGroundHeight( point.X, point.Y ) )
- below = middle;
- else
- above = middle;
- }
- return eye + direction * below;
-}
-
//-------------------------------------------------------------------------------------------------
// The isometric camera's frame, fitted to what the perspective camera sees. The perspective
-// frame's four corners, the middles of its four edges and its centre are cast onto the terrain,
-// and the isometric frame is the one that puts those nine points closest to the same places on
+// frame's four corners, the middles of its four edges and its centre are cast onto a flat plane at
+// the view's ground level, and the isometric frame is the one that puts those nine points closest to the same places on
// its own screen, measured in world units. An orthographic frame is a rectangle on the view plane
// and the perspective one lands on the ground as a trapezoid, so the corners cannot all meet: the
// fit leaves the perspective frame a little more at the far corners and the isometric one the
// same amount more at the near corners, and neither camera reaches further than the other. The
-// heading is the player's; the fit picks the look-at point, the width and the elevation.
+// heading is the player's; the fit picks the look-at point, the width and the elevation. The
+// plane is flat on purpose: cast onto the terrain, a hill passing under the frame changed the
+// width and the elevation, and the picture jumped in and out while the player panned over it.
class IsometricFrameFit
{
public:
enum { POINT_COUNT = 9 };
- IsometricFrameFit( const Matrix3D& perspective, Real tanHalfWidth, Real heightOverWidth )
+ IsometricFrameFit( const Matrix3D& perspective, Real groundLevel, Real tanHalfWidth, Real heightOverWidth )
: m_heightOverWidth( heightOverWidth )
{
// a corner ray at the horizon would reach no ground at all
@@ -745,7 +716,7 @@ public:
flat.Normalize();
direction = flat * cos( shallowestRay ) + Vector3( 0.0f, 0.0f, -sin( shallowestRay ) );
}
- const Vector3 ground = groundUnderRay( eye, direction );
+ const Vector3 ground = eye + direction * ( ( groundLevel - eye.Z ) / direction.Z );
m_screenX[ point ] = (Real)column;
m_screenY[ point ] = (Real)row;
m_acrossScreen[ point ] = Vector3::Dot_Product( ground, m_right );
@@ -935,7 +906,7 @@ void W3DView::setCameraTransform( void )
// the tallest thing standing on the frame's ground, above and below the depth it spans
const Real depthMargin = 1000.0f;
- const IsometricFrameFit fit(cameraTransform, tan(perspectiveFov * 0.5f), (Real)getHeight() / (Real)getWidth());
+ const IsometricFrameFit fit(cameraTransform, m_groundLevel, tan(perspectiveFov * 0.5f), (Real)getHeight() / (Real)getWidth());
const Vector3 target = fit.getTarget();
const Real distance = fit.getHalfWidth() / tan(isometricFov * 0.5f);
const Real depthSpread = fit.getDepthSpread();
@@ -1741,7 +1712,13 @@ void W3DView::update(void)
// 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);
+ // The isometric camera holds its height over the view's ground level instead, for the reason
+ // IsometricFrameFit gives: following the hills made the picture grow and shrink under the pan.
+ //
+ if (TheGlobalData->m_isometricCamera)
+ m_terrainHeightUnderCamera = m_groundLevel;
+ else
+ 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;
//