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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gameclient): cap director panes on what each pane shows
Olcay Seygan36e77428fd81
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.hindex 4dc8f47e7..055666e25 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ObserverCamera.h@@ -163,25 +163,44 @@ void ObserverCamera_paneCircles( const Real *rays, Int count, Int width, Int heiReal ObserverCamera_extentAround( const std::vector< DirectorHeat > &things, const Coord2D &around, Real reach, Real least );/// where a pixel of a width by height picture falls on flat ground, from where its four corners fall/// (top left, top right, bottom right, bottom left), through the plane's projection, which is exact-/// for a perspective camera over flat ground. A camera moved away from the point it looks at by a-/// zoom moves every corner, and every pixel's ground, out from that point by the same factor+/// for a perspective camera over flat groundCoord2D ObserverCamera_pixelToGround( const Coord2D &pixel, Int width, Int height, const Coord2D *corners );/// the other way: the pixel a point on the ground is drawn atCoord2D ObserverCamera_groundToPixel( const Coord2D &ground, Int width, Int height, const Coord2D *corners );+/// how the screen's corners fall on the ground, from the point the view looks at, at any zoom. The eye+/// stands (zoom - zoomAtPivot) times a fixed offset back from a target above the look point, so where+/// a corner falls on the target's own height scales with that, and the ground below it adds a shift+/// along the corner's ray that no zoom changes+struct ObserverCameraGround+{+ Coord2D perZoom[ 4 ];+ Coord2D shift[ 4 ];+ Real zoomAtPivot;+};+/// the corners of ground at zoom+void ObserverCamera_cornersAtZoom( const ObserverCameraGround &ground, Real zoom, Coord2D *corners );/// the point a camera whose corners are these, measured from the point it looks at, looks at to draw/// subject on pixel; every pane camera is placed through thisCoord2D ObserverCamera_lookPoint( const Coord2D &subject, const Coord2D &pixel, Int width, Int height, const Coord2D *corners );/// how far round a circle on the screen reaches on the ground, the nearest of its four sides, with the/// corners as aboveReal ObserverCamera_groundRadius( const Coord2D ¢re, Real radius, Int width, Int height, const Coord2D *corners );-/// the zoom that fits a subject extent across on the ground into a circle that reaches groundRadiusAtOne-/// at zoom 1, with a margin; never under nearest or over farthest-Real ObserverCamera_fitZoom( Real extent, Real groundRadiusAtOne, Real nearest, Real farthest );+/// the lowest zoom from nearest to farthest at which the circle round centre reaches a subject extent+/// across on the ground with a margin; farthest when none does+Real ObserverCamera_fitZoom( Real extent, const Coord2D ¢re, Real radius, Int width, Int height,+ const ObserverCameraGround &ground, Real nearest, Real farthest );+/// the corners of what pane shows of a width by height picture, the rays meeting at origin: its wedge+/// cut by the screen's edges, at most eight points; the number of them+Int ObserverCamera_panePolygon( const Real *rays, Int count, Int pane, const Coord2D &origin, Int width, Int height,+ Coord2D *vertices );+/// look moved the least that keeps the ground under every vertex of a pane, drawn through corners+/// from look, inside the map+Coord2D ObserverCamera_keepPaneInMap( const Coord2D &look, const Coord2D *vertices, Int vertexCount, Int width, Int height,+ const Coord2D *corners, const Region2D &map );/// the highest zoom, from nearest up to wanted, at which a camera putting subject on pixel shows no-/// ground past the map; nearest when none does. cornersAtOne are the corners at zoom 1, from the-/// point the camera looks at-Real ObserverCamera_zoomInMap( const Coord2D &subject, const Coord2D &pixel, Int width, Int height,- const Coord2D *cornersAtOne, const Region2D &map, Real nearest, Real wanted );+/// ground past the map anywhere in the pane's vertices; nearest when none does+Real ObserverCamera_zoomInMap( const Coord2D &subject, const Coord2D &pixel, const Coord2D *vertices, Int vertexCount,+ Int width, Int height, const ObserverCameraGround &ground, const Region2D &map, Real nearest, Real wanted );/// how far an animation of length frames that started on start is on frame, eased in and out, 0 to 1Real ObserverCamera_easeFrames( UnsignedInt frame, UnsignedInt start, UnsignedInt length );/// the dark edge each side of the gold of a line between panes and of the radar's frame, in pixels@@ -263,7 +282,9 @@ private:Bool takenByHand( const ViewLocation ¤t ) const;Coord2D keepInMap( const Coord2D &place, const ViewLocation ¤t ) const;void measureCorners( void );- Coord2D paneLookPoint( const Coord2D &subject, const Coord2D &pixel, Real zoom ) const;+ Coord2D paneLookPoint( Int pane, const Coord2D &subject, const Coord2D &pixel, Real zoom, Real *shifted ) const;+ void logPanes( UnsignedInt frame ) const;+ void pickIntroBases( void );Region2D mapRegion( void ) const;void updateSplit( void );void updateIntroPlaces( void );@@ -330,7 +351,8 @@ private:Bool m_paneFitValid; ///< m_paneFit holds a fit of these panesUnsignedInt m_paneFitFrame; ///< the logic frame m_paneFit last moved onCoord2D m_radarHalf; ///< half the framed radar's size, taken from its last draw- Coord2D m_cornersAtOne[ 4 ]; ///< where the screen's corners fall on the ground from the look point, at zoom 1+ ObserverCameraGround m_ground; ///< where the screen's corners fall on the ground at any zoom, measured each update+ Real m_paneShifted[ OBSERVER_MOST_PANES ]; ///< how far the map moved each pane's look point off its subject last frameCoord2D m_paneOrigin; ///< where the rays meet now, in pixelsReal m_cornerRadarSlide;IRegion2D m_radarFrame;diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h b/GeneralsMD/Code/GameEngine/Include/GameClient/View.hindex ea4fb0b03..57da782bd 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/View.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/View.h@@ -258,6 +258,9 @@ public:virtual void addScreenDistortion( const Coord3D *epicenter, const ScreenDistortionInfo &info ) { }virtual Real getFXPitch( void ) const { return 1.0f; } ///< returns the FX pitch angle+ /// how the eye stands back with the zoom: (zoom - zoomAtPivot) times a fixed offset from the point+ /// looked at, which stands pivotHeight above zero+ virtual void getZoomPivot( Real *zoomAtPivot, Real *pivotHeight ) const { *zoomAtPivot = 0.0f; *pivotHeight = 0.0f; }virtual void forceCameraConstraintRecalc(void) {}virtual void applyCameraConstraint( void ) {} ///< move the look point inside the camera constraint now, where the next draw wouldvirtual void setGuardBandBias( const Coord2D *gb ) = 0;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cppindex 020f5c71e..813a2341e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/ObserverCamera.cpp@@ -661,24 +661,121 @@ Real ObserverCamera_groundRadius( const Coord2D ¢re, Real radius, Int width,}//--------------------------------------------------------------------------------------------------/** The ground a circle reaches grows with the zoom, the camera standing that much further back. */+void ObserverCamera_cornersAtZoom( const ObserverCameraGround &ground, Real zoom, Coord2D *corners )+{+ const Real out = zoom - ground.zoomAtPivot;+ for( Int corner = 0; corner < 4; corner++ )+ {+ corners[ corner ].x = ground.perZoom[ corner ].x * out + ground.shift[ corner ].x;+ corners[ corner ].y = ground.perZoom[ corner ].y * out + ground.shift[ corner ].y;+ }+}+//--------------------------------------------------------------------------------------------------Real ObserverCamera_fitZoom( Real extent, Real groundRadiusAtOne, Real nearest, Real farthest )+/** The ground a circle reaches grows with the zoom, the camera standing further back; the lowest+ * zoom that reaches far enough is found by halving. */+//-------------------------------------------------------------------------------------------------+Real ObserverCamera_fitZoom( Real extent, const Coord2D ¢re, Real radius, Int width, Int height,+ const ObserverCameraGround &ground, Real nearest, Real farthest ){- const Real zoom = extent * ( 1.0f + PANE_FIT_MARGIN ) / groundRadiusAtOne;- return min( max( zoom, nearest ), farthest );+ enum { HALVINGS = 14 };+ const Real needed = extent * ( 1.0f + PANE_FIT_MARGIN );+ Real lowest = nearest;+ Real highest = farthest;+ for( Int halving = 0; halving < HALVINGS; halving++ )+ {+ const Real tried = halving == 0 ? nearest : ( lowest + highest ) * 0.5f;+ Coord2D corners[ 4 ];+ ObserverCamera_cornersAtZoom( ground, tried, corners );+ if( ObserverCamera_groundRadius( centre, radius, width, height, corners ) >= needed )+ {+ highest = tried;+ if( halving == 0 )+ break;+ }+ else+ {+ lowest = tried;+ }+ }+ return highest;}//--------------------------------------------------------------------------------------------------/** The corners at zoom 1 taken out to a zoom: every one moves out from the look point by it. */+/** The wedge from origin between the pane's two rays, cut by the screen: where the rays meet if that+ * is on the screen, the screen's corners inside the wedge, and where each ray leaves the screen.+ * A wedge of 180 degrees or less and the screen are both convex, so these are all its corners. *///--------------------------------------------------------------------------------------------------static void scaleCorners( const Coord2D *cornersAtOne, Real zoom, Coord2D *corners )+Int ObserverCamera_panePolygon( const Real *rays, Int count, Int pane, const Coord2D &origin, Int width, Int height,+ Coord2D *vertices ){+ const Coord2D screen[ 4 ] = { { 0.0f, 0.0f }, { (Real)width, 0.0f }, { (Real)width, (Real)height }, { 0.0f, (Real)height } };+ Int found = 0;+ if( count < 2 )+ {+ for( Int corner = 0; corner < 4; corner++ )+ vertices[ found++ ] = screen[ corner ];+ return found;+ }++ const Bool originOnScreen = origin.x >= 0.0f && origin.x <= width && origin.y >= 0.0f && origin.y <= height;+ if( originOnScreen )+ vertices[ found++ ] = origin;for( Int corner = 0; corner < 4; corner++ ){- corners[ corner ].x = cornersAtOne[ corner ].x * zoom;- corners[ corner ].y = cornersAtOne[ corner ].y * zoom;+ if( ObserverCamera_paneOf( screen[ corner ].x, screen[ corner ].y, origin.x, origin.y, rays, count ) == pane )+ vertices[ found++ ] = screen[ corner ];}+ const Int bounds[ 2 ] = { pane, ( pane + 1 ) % count };+ for( Int side = 0; side < 2; side++ )+ {+ const Real angle = rays[ bounds[ side ] ] * PI / 180.0f;+ const Real alongX = cosf( angle );+ const Real alongY = -sinf( angle );+ // the stretch of the ray inside the screen, as distances along it+ Real enter = 0.0f;+ Real leave = 1.0e9f;+ const Real start[ 2 ] = { origin.x, origin.y };+ const Real along[ 2 ] = { alongX, alongY };+ const Real high[ 2 ] = { (Real)width, (Real)height };+ for( Int axis = 0; axis < 2; axis++ )+ {+ if( fabs( along[ axis ] ) < 1.0e-6f )+ {+ if( start[ axis ] < 0.0f || start[ axis ] > high[ axis ] )+ enter = leave + 1.0f;+ continue;+ }+ const Real atLow = ( 0.0f - start[ axis ] ) / along[ axis ];+ const Real atHigh = ( high[ axis ] - start[ axis ] ) / along[ axis ];+ enter = max( enter, min( atLow, atHigh ) );+ leave = min( leave, max( atLow, atHigh ) );+ }+ if( enter > leave )+ continue;+ if( !originOnScreen )+ {+ vertices[ found ].x = origin.x + alongX * enter;+ vertices[ found ].y = origin.y + alongY * enter;+ found++;+ }+ vertices[ found ].x = origin.x + alongX * leave;+ vertices[ found ].y = origin.y + alongY * leave;+ found++;+ }+ return found;+}++//-------------------------------------------------------------------------------------------------+/** The ground under each vertex, from look, held inside the map the way the screen's corners are. */+//-------------------------------------------------------------------------------------------------+Coord2D ObserverCamera_keepPaneInMap( const Coord2D &look, const Coord2D *vertices, Int vertexCount, Int width, Int height,+ const Coord2D *corners, const Region2D &map )+{+ Coord2D grounds[ 8 ];+ for( Int vertex = 0; vertex < vertexCount; vertex++ )+ grounds[ vertex ] = ObserverCamera_pixelToGround( vertices[ vertex ], width, height, corners );+ return ObserverCamera_keepInMap( look, grounds, vertexCount, map );}//-------------------------------------------------------------------------------------------------@@ -695,12 +792,12 @@ Coord2D ObserverCamera_lookPoint( const Coord2D &subject, const Coord2D &pixel,}//--------------------------------------------------------------------------------------------------/** The look point that puts subject on pixel is subject less pixel's ground from the screen's middle,- * and the map keeps it where the screen shows nothing past the edge. Showing more ground the- * higher it stands, the highest zoom that needs no keeping is found by halving. */+/** The look point that puts subject on pixel, and the map keeps it where the pane shows nothing past+ * the edge. Showing more ground the higher it stands, the highest zoom that needs no keeping is+ * found by halving. *///--------------------------------------------------------------------------------------------------Real ObserverCamera_zoomInMap( const Coord2D &subject, const Coord2D &pixel, Int width, Int height,- const Coord2D *cornersAtOne, const Region2D &map, Real nearest, Real wanted )+Real ObserverCamera_zoomInMap( const Coord2D &subject, const Coord2D &pixel, const Coord2D *vertices, Int vertexCount,+ Int width, Int height, const ObserverCameraGround &ground, const Region2D &map, Real nearest, Real wanted ){enum { HALVINGS = 12 };const Real kept = 1.0f;@@ -711,9 +808,9 @@ Real ObserverCamera_zoomInMap( const Coord2D &subject, const Coord2D &pixel, Intfor( Int halving = 0; halving <= HALVINGS; halving++ ){Coord2D corners[ 4 ];- scaleCorners( cornersAtOne, tried, corners );+ ObserverCamera_cornersAtZoom( ground, tried, corners );const Coord2D look = ObserverCamera_lookPoint( subject, pixel, width, height, corners );- const Coord2D inMap = ObserverCamera_keepInMap( look, corners, 4, map );+ const Coord2D inMap = ObserverCamera_keepPaneInMap( look, vertices, vertexCount, width, height, corners, map );const Bool clear = fabs( inMap.x - look.x ) <= kept && fabs( inMap.y - look.y ) <= kept;if( clear ){@@ -808,7 +905,11 @@ void ObserverCamera::reset( void )m_paneFitFrame = 0;m_radarHalf.x = m_radarHalf.y = 0.0f;for( Int corner = 0; corner < 4; corner++ )- m_cornersAtOne[ corner ].x = m_cornersAtOne[ corner ].y = 0.0f;+ {+ m_ground.perZoom[ corner ].x = m_ground.perZoom[ corner ].y = 0.0f;+ m_ground.shift[ corner ].x = m_ground.shift[ corner ].y = 0.0f;+ }+ m_ground.zoomAtPivot = 0.0f;m_paneOrigin.x = m_paneOrigin.y = 0.0f;m_cornerRadarSlide = 0.0f;m_radarFrame.lo.x = m_radarFrame.lo.y = m_radarFrame.hi.x = m_radarFrame.hi.y = 0;@@ -821,6 +922,7 @@ void ObserverCamera::reset( void )m_paneRadii[ pane ] = 0.0f;m_paneExtent[ pane ] = PANE_FIT_LEAST_EXTENT;m_paneFit[ pane ] = 1.0f;+ m_paneShifted[ pane ] = 0.0f;m_paneGlide[ pane ] = ViewLocation();m_paneVelocity[ pane ].x = m_paneVelocity[ pane ].y = m_paneVelocity[ pane ].z = 0.0f;m_paneVelocity[ pane ].angle = m_paneVelocity[ pane ].pitch = m_paneVelocity[ pane ].zoom = 0.0f;@@ -1037,37 +1139,50 @@ Region2D ObserverCamera::mapRegion( void ) const}//--------------------------------------------------------------------------------------------------/** Where the screen's corners fall on the ground from the point the view looks at, brought to zoom 1.- * Taken before this frame moves the view, so the corners and the zoom are the ones the last picture- * was drawn with; the last draw of a frame is always pane 0's. */+/** Where the screen's corners fall from the point the view looks at, as m_ground: on the height of+ * the camera's target they scale with the eye's distance, and the ground under the look point adds+ * each ray's own shift. Taken before this frame moves the view, so the corners and the zoom are+ * the ones the last picture was drawn with; the last draw of a frame is always pane 0's. *///-------------------------------------------------------------------------------------------------void ObserverCamera::measureCorners( void ){Coord3D at;TheTacticalView->getPosition( &at );- Coord3D world[ 4 ];- TheTacticalView->getScreenCornerWorldPointsAtZ( &world[ 0 ], &world[ 1 ], &world[ 2 ], &world[ 3 ],+ Real pivotHeight = 0.0f;+ TheTacticalView->getZoomPivot( &m_ground.zoomAtPivot, &pivotHeight );+ Coord3D onPivot[ 4 ];+ TheTacticalView->getScreenCornerWorldPointsAtZ( &onPivot[ 0 ], &onPivot[ 1 ], &onPivot[ 2 ], &onPivot[ 3 ], pivotHeight );+ Coord3D onGround[ 4 ];+ TheTacticalView->getScreenCornerWorldPointsAtZ( &onGround[ 0 ], &onGround[ 1 ], &onGround[ 2 ], &onGround[ 3 ],TheTerrainLogic->getGroundHeight( at.x, at.y ) );- const Real zoom = TheTacticalView->getZoom();+ const Real out = TheTacticalView->getZoom() - m_ground.zoomAtPivot;for( Int corner = 0; corner < 4; corner++ ){- m_cornersAtOne[ corner ].x = ( world[ corner ].x - at.x ) / zoom;- m_cornersAtOne[ corner ].y = ( world[ corner ].y - at.y ) / zoom;+ m_ground.perZoom[ corner ].x = ( onPivot[ corner ].x - at.x ) / out;+ m_ground.perZoom[ corner ].y = ( onPivot[ corner ].y - at.y ) / out;+ m_ground.shift[ corner ].x = onGround[ corner ].x - onPivot[ corner ].x;+ m_ground.shift[ corner ].y = onGround[ corner ].y - onPivot[ corner ].y;}}//--------------------------------------------------------------------------------------------------/** The point a camera at zoom looks at to draw subject on pixel, kept where it shows no ground past- * the map at that zoom. The same projection the fit was worked out with, so a subject stays on its- * circle's centre at every zoom. */+/** The point a camera at zoom looks at to draw subject on pixel, moved the least that keeps what the+ * pane shows now, its wedge round the meeting point where it is, inside the map. The same+ * projection the fit was worked out with, so a subject stays on its circle's centre at every zoom.+ * shifted is how far the map moved it. *///--------------------------------------------------------------------------------------------------Coord2D ObserverCamera::paneLookPoint( const Coord2D &subject, const Coord2D &pixel, Real zoom ) const+Coord2D ObserverCamera::paneLookPoint( Int pane, const Coord2D &subject, const Coord2D &pixel, Real zoom, Real *shifted ) const{const Int width = TheDisplay->getWidth();const Int height = TheDisplay->getHeight();Coord2D corners[ 4 ];- scaleCorners( m_cornersAtOne, zoom, corners );- return ObserverCamera_keepInMap( ObserverCamera_lookPoint( subject, pixel, width, height, corners ), corners, 4, mapRegion() );+ ObserverCamera_cornersAtZoom( m_ground, zoom, corners );+ Coord2D vertices[ 8 ];+ const Int vertexCount = ObserverCamera_panePolygon( m_paneRays, m_paneCount, pane, m_paneOrigin, width, height, vertices );+ const Coord2D look = ObserverCamera_lookPoint( subject, pixel, width, height, corners );+ const Coord2D kept = ObserverCamera_keepPaneInMap( look, vertices, vertexCount, width, height, corners, mapRegion() );+ *shifted = sqrtf( ( kept.x - look.x ) * ( kept.x - look.x ) + ( kept.y - look.y ) * ( kept.y - look.y ) );+ return kept;}//-------------------------------------------------------------------------------------------------@@ -1232,8 +1347,8 @@ void ObserverCamera::advancePanes( UnsignedInt frame )}//--------------------------------------------------------------------------------------------------/** The opening's panes: where each player's things crowd, his base at the start and his army once it- * is bigger than the base. */+/** The opening's panes: how far each player's things spread round his fixed subject, his base and+ * the army beside it. *///-------------------------------------------------------------------------------------------------void ObserverCamera::updateIntroPlaces( void ){@@ -1254,11 +1369,70 @@ void ObserverCamera::updateIntroPlaces( void )sights[ pane ].push_back( heat );}}+ for( Int pane = 0; pane < m_paneCount; pane++ )+ m_paneExtent[ pane ] = ObserverCamera_extentAround( sights[ pane ], m_paneSubject[ pane ], PANE_INTRO_REACH, PANE_FIT_LEAST_EXTENT );+}++//-------------------------------------------------------------------------------------------------+/** The opening's subjects, fixed for the whole of it: each player's command centre, his start, or+ * where his things crowd when he has none. Following the crowd let a pane wander off after the+ * first units to leave the base. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::pickIntroBases( void )+{+ std::vector< DirectorHeat > sights[ OBSERVER_MOST_PANES ];+ Bool based[ OBSERVER_MOST_PANES ];+ for( Int pane = 0; pane < m_paneCount; pane++ )+ based[ pane ] = FALSE;+ for( Object *obj = TheGameLogic->getFirstObject(); obj != NULL; obj = obj->getNextObject() )+ {+ const Int cost = obj->getTemplate()->friend_getBuildCost();+ if( obj->isEffectivelyDead() )+ continue;+ for( Int pane = 0; pane < m_paneCount; pane++ )+ {+ if( obj->getControllingPlayer() != m_panePlayers[ pane ] )+ continue;+ if( !based[ pane ] && obj->isKindOf( KINDOF_COMMANDCENTER ) )+ {+ based[ pane ] = TRUE;+ m_paneSubject[ pane ].x = obj->getPosition()->x;+ m_paneSubject[ pane ].y = obj->getPosition()->y;+ }+ if( cost <= 0 )+ continue;+ DirectorHeat heat;+ heat.position.x = obj->getPosition()->x;+ heat.position.y = obj->getPosition()->y;+ heat.weight = ObserverCamera_sightWeight( cost, obj->isKindOf( KINDOF_STRUCTURE ), FALSE, FALSE ) + 1.0f;+ sights[ pane ].push_back( heat );+ }+ }for( Int pane = 0; pane < m_paneCount; pane++ ){+ if( based[ pane ] )+ continue;Real heat = 0.0f;ObserverCamera_hottestPlace( sights[ pane ], &m_paneSubject[ pane ], &heat );- m_paneExtent[ pane ] = ObserverCamera_extentAround( sights[ pane ], m_paneSubject[ pane ], PANE_INTRO_REACH, PANE_FIT_LEAST_EXTENT );+ }+}++//-------------------------------------------------------------------------------------------------+/** Every 30 logic frames while there are panes: each one's subject, its zoom now and with the panes+ * all in, and how far the map moved its look point off the subject, so a recording that drifts+ * says whether the subject moved or the map pushed the camera. */+//-------------------------------------------------------------------------------------------------+void ObserverCamera::logPanes( UnsignedInt frame ) const+{+ enum { PANE_LOG_FRAMES = 30 };+ if( m_paneCount < 2 || frame % PANE_LOG_FRAMES != 0 )+ return;+ for( Int pane = 0; pane < m_paneCount; pane++ )+ {+ const Coord2D &subject = pane == 0 && !m_intro ? m_panesLeftPlace : m_paneSubject[ pane ];+ DEBUG_LOG(( "OBSCAM frame %u pane %d subject (%.0f,%.0f) extent %.0f zoom %.2f fit %.2f base %.2f map shift %.0f\n",+ frame, pane, subject.x, subject.y, m_paneExtent[ pane ], paneZoom( pane ), m_paneFit[ pane ], m_paneBaseZoom,+ m_paneShifted[ pane ] ));}}@@ -1297,14 +1471,20 @@ void ObserverCamera::fitPanes( UnsignedInt frame )const Int width = TheDisplay->getWidth();const Int height = TheDisplay->getHeight();const Region2D map = mapRegion();+ Coord2D middle;+ middle.x = width * 0.5f;+ middle.y = height * 0.5f;const Bool moves = frame != m_paneFitFrame;m_paneFitFrame = frame;for( Int pane = 0; pane < m_paneCount; pane++ ){- const Real reach = ObserverCamera_groundRadius( m_paneCentres[ pane ], m_paneRadii[ pane ], width, height, m_cornersAtOne );- const Real fitted = ObserverCamera_fitZoom( m_paneExtent[ pane ], reach, m_paneBaseZoom, m_paneBaseZoom * PANE_FIT_FARTHEST );- const Real wanted = ObserverCamera_zoomInMap( subjects[ pane ], m_paneCentres[ pane ], width, height, m_cornersAtOne,- map, m_paneBaseZoom, fitted );+ const Real fitted = ObserverCamera_fitZoom( m_paneExtent[ pane ], m_paneCentres[ pane ], m_paneRadii[ pane ], width, height,+ m_ground, m_paneBaseZoom, m_paneBaseZoom * PANE_FIT_FARTHEST );+ // what the pane shows with them all in, the rays meeting in the middle+ Coord2D vertices[ 8 ];+ const Int vertexCount = ObserverCamera_panePolygon( m_paneRays, m_paneCount, pane, middle, width, height, vertices );+ const Real wanted = ObserverCamera_zoomInMap( subjects[ pane ], m_paneCentres[ pane ], vertices, vertexCount, width, height,+ m_ground, map, m_paneBaseZoom, fitted );const Bool mapLowers = wanted < fitted && wanted < m_paneFit[ pane ];if( !m_paneFitValid )m_paneFit[ pane ] = wanted;@@ -1363,7 +1543,7 @@ void ObserverCamera::stepPaneCameras( const ViewLocation &step, Real elapsedSecoCoord2D glided;glided.x = m_paneGlide[ pane ].getPosition().x;glided.y = m_paneGlide[ pane ].getPosition().y;- const Coord2D camera = paneLookPoint( glided, pixel, zoom );+ const Coord2D camera = paneLookPoint( pane, glided, pixel, zoom, &m_paneShifted[ pane ] );m_paneView[ pane ].init( camera.x, camera.y, at.z, step.getAngle(), step.getPitch(), zoom );}}@@ -1661,6 +1841,8 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )const Bool introStarting = !m_introDone;measureCorners();advancePanes( frame );+ if( m_intro && introStarting )+ pickIntroBases();if( m_intro && ( introStarting || frame % DIRECTOR_SCAN_FRAMES == 0 ) )updateIntroPlaces();}@@ -1733,7 +1915,7 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )Coord2D pixel;pixel.x = TheDisplay->getWidth() * 0.5f + fromMiddle.x;pixel.y = TheDisplay->getHeight() * 0.5f + fromMiddle.y;- sitBack = paneLookPoint( sitBack, pixel, step.getZoom() );+ sitBack = paneLookPoint( 0, sitBack, pixel, step.getZoom(), &m_paneShifted[ 0 ] );}m_mainOffset.x = step.getPosition().x - sitBack.x;m_mainOffset.y = step.getPosition().y - sitBack.y;@@ -1747,4 +1929,6 @@ void ObserverCamera::update( UnsignedInt nowMilliseconds )m_driving = TRUE;stepPaneCameras( step, elapsed / MILLISECONDS_PER_SECOND );+ if( TheGlobalData->m_directorRecord )+ logPanes( TheGameLogic->getFrame() );}diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.hindex b871d1e5d..187574efd 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h@@ -226,6 +226,9 @@ public:virtual void addScreenDistortion( const Coord3D *epicenter, const ScreenDistortionInfo &info );virtual Real getFXPitch( void ) const { return m_FXPitch; } ///< returns the FX pitch angle+ /// buildCameraTransform scales the offset by zoom and then by 1 - groundLevel / (offset.z * zoom),+ /// which is zoom - groundLevel / offset.z, round a target at groundLevel+ virtual void getZoomPivot( Real *zoomAtPivot, Real *pivotHeight ) const { *zoomAtPivot = m_groundLevel / m_cameraOffset.z; *pivotHeight = m_groundLevel; }virtual Bool setViewFilterMode(enum FilterModes filterMode); ///< Turns on viewport special effect (black & white mode)virtual Bool setViewFilter(enum FilterTypes filter); ///< Turns on viewport special effect (black & white mode)diff --git a/GeneralsMD/Code/Tests/test_observer_camera.inc b/GeneralsMD/Code/Tests/test_observer_camera.incindex 08781280e..8130b884c 100644--- a/GeneralsMD/Code/Tests/test_observer_camera.inc+++ b/GeneralsMD/Code/Tests/test_observer_camera.inc@@ -467,19 +467,37 @@ TEST(a_subject_spreads_as_far_as_its_farthest_thing_within_reach)TEST(a_pane_zooms_out_to_fit_its_subject_and_no_further_than_the_cap){- // a circle reaching 400 on the ground at zoom 1; 300 with its 15 percent margin fits closer than- // the director's own, which is as close as a pane comes- CHECK_NEAR( ObserverCamera_fitZoom( 300.0f, 400.0f, 1.0f, 2.0f ), 1.0f, 0.0001f );- CHECK_NEAR( ObserverCamera_fitZoom( 600.0f, 400.0f, 1.0f, 2.0f ), 1.725f, 0.001f );- CHECK_NEAR( ObserverCamera_fitZoom( 2000.0f, 400.0f, 1.0f, 2.0f ), 2.0f, 0.0001f );+ ObserverCameraGround ground;+ const Coord2D atOne[ 4 ] = { { -400.0f, 400.0f }, { 400.0f, 400.0f }, { 300.0f, -200.0f }, { -300.0f, -200.0f } };+ for( Int corner = 0; corner < 4; corner++ )+ {+ ground.perZoom[ corner ] = atOne[ corner ];+ ground.shift[ corner ].x = ground.shift[ corner ].y = 0.0f;+ }+ ground.zoomAtPivot = 0.0f;+ const Coord2D centre = { 640.0f, 360.0f };+ Coord2D corners[ 4 ];+ ObserverCamera_cornersAtZoom( ground, 1.0f, corners );+ const Real reachAtOne = ObserverCamera_groundRadius( centre, 200.0f, 1280, 720, corners );+ // a subject that fits at the director's own zoom is not brought closer+ CHECK_NEAR( ObserverCamera_fitZoom( reachAtOne * 0.5f, centre, 200.0f, 1280, 720, ground, 1.0f, 2.0f ), 1.0f, 0.0001f );+ // one 1.5 times the circle's reach, with its 15 percent margin, needs 1.725 times as far out+ CHECK_NEAR( ObserverCamera_fitZoom( reachAtOne * 1.5f, centre, 200.0f, 1280, 720, ground, 1.0f, 3.0f ), 1.725f, 0.001f );+ CHECK_NEAR( ObserverCamera_fitZoom( reachAtOne * 5.0f, centre, 200.0f, 1280, 720, ground, 1.0f, 2.0f ), 2.0f, 0.001f );// a smaller circle needs the camera further out- CHECK( ObserverCamera_fitZoom( 600.0f, 300.0f, 1.0f, 3.0f ) > ObserverCamera_fitZoom( 600.0f, 400.0f, 1.0f, 3.0f ) );+ CHECK( ObserverCamera_fitZoom( reachAtOne, centre, 150.0f, 1280, 720, ground, 1.0f, 3.0f )+ > ObserverCamera_fitZoom( reachAtOne, centre, 200.0f, 1280, 720, ground, 1.0f, 3.0f ) );}-/// where a pixel of a 1280x720 picture falls on flat ground for a pinhole camera looking down at 50-/// degrees on the origin from distance away, the way the game's view stands over the ground-static Coord2D castPixel( Real x, Real y, Real distance )+/// the game's view as buildCameraTransform makes it: a pinhole looking down at 50 degrees on a target+/// TARGET_HEIGHT above zero, its eye (zoom - ZOOM_AT_PIVOT) times 400 back from it+static const Real TARGET_HEIGHT = 10.0f;+static const Real ZOOM_AT_PIVOT = 0.3f;++/// where a pixel of a 1280x720 picture falls on a plane at planeHeight for that view at zoom+static Coord2D castPixel( Real x, Real y, Real zoom, Real planeHeight ){+ const Real distance = ( zoom - ZOOM_AT_PIVOT ) * 400.0f;const Real pitch = 50.0f * PI / 180.0f;const Real halfWide = 0.6f;const Real halfHigh = 0.6f * 720.0f / 1280.0f;@@ -487,31 +505,70 @@ static Coord2D castPixel( Real x, Real y, Real distance )const Real upY = sinf( pitch ), upZ = cosf( pitch );const Real right = ( 2.0f * x / 1280.0f - 1.0f ) * halfWide;const Real up = ( 1.0f - 2.0f * y / 720.0f ) * halfHigh;- const Real eyeY = -distance * forwardY, eyeZ = -distance * forwardZ;+ const Real eyeY = -distance * forwardY, eyeZ = TARGET_HEIGHT - distance * forwardZ;const Real rayX = right, rayY = forwardY + up * upY, rayZ = forwardZ + up * upZ;- const Real along = -eyeZ / rayZ;+ const Real along = ( planeHeight - eyeZ ) / rayZ;Coord2D ground;ground.x = rayX * along;ground.y = eyeY + rayY * along;return ground;}-static void castCorners( Real distance, Coord2D *corners )+static void castCorners( Real zoom, Real planeHeight, Coord2D *corners )+{+ corners[ 0 ] = castPixel( 0.0f, 0.0f, zoom, planeHeight );+ corners[ 1 ] = castPixel( 1280.0f, 0.0f, zoom, planeHeight );+ corners[ 2 ] = castPixel( 1280.0f, 720.0f, zoom, planeHeight );+ corners[ 3 ] = castPixel( 0.0f, 720.0f, zoom, planeHeight );+}++/// what measureCorners takes from the view at zoom over ground at groundHeight+static ObserverCameraGround measureCast( Real zoom, Real groundHeight )+{+ ObserverCameraGround ground;+ Coord2D onPivot[ 4 ];+ Coord2D onGround[ 4 ];+ castCorners( zoom, TARGET_HEIGHT, onPivot );+ castCorners( zoom, groundHeight, onGround );+ for( Int corner = 0; corner < 4; corner++ )+ {+ ground.perZoom[ corner ].x = onPivot[ corner ].x / ( zoom - ZOOM_AT_PIVOT );+ ground.perZoom[ corner ].y = onPivot[ corner ].y / ( zoom - ZOOM_AT_PIVOT );+ ground.shift[ corner ].x = onGround[ corner ].x - onPivot[ corner ].x;+ ground.shift[ corner ].y = onGround[ corner ].y - onPivot[ corner ].y;+ }+ ground.zoomAtPivot = ZOOM_AT_PIVOT;+ return ground;+}++TEST(corners_measured_at_one_zoom_say_where_they_fall_at_another){- corners[ 0 ] = castPixel( 0.0f, 0.0f, distance );- corners[ 1 ] = castPixel( 1280.0f, 0.0f, distance );- corners[ 2 ] = castPixel( 1280.0f, 720.0f, distance );- corners[ 3 ] = castPixel( 0.0f, 720.0f, distance );+ // ground 110 above the camera's target, which is how the old scaling about the look point went+ // wrong: the top corners, nearly level, moved furthest+ const ObserverCameraGround ground = measureCast( 1.0f, 120.0f );+ const Real zooms[] = { 1.0f, 1.4f, 2.0f };+ for( Int index = 0; index < 3; index++ )+ {+ Coord2D cast[ 4 ];+ castCorners( zooms[ index ], 120.0f, cast );+ Coord2D predicted[ 4 ];+ ObserverCamera_cornersAtZoom( ground, zooms[ index ], predicted );+ for( Int corner = 0; corner < 4; corner++ )+ {+ CHECK_NEAR( predicted[ corner ].x, cast[ corner ].x, 0.5f );+ CHECK_NEAR( predicted[ corner ].y, cast[ corner ].y, 0.5f );+ }+ }}TEST(the_four_corners_project_every_pixel_onto_flat_ground_exactly){Coord2D corners[ 4 ];- castCorners( 400.0f, corners );+ castCorners( 1.3f, 120.0f, corners );const Coord2D pixels[] = { { 900.0f, 200.0f }, { 150.0f, 650.0f }, { 640.0f, 360.0f }, { 1200.0f, 40.0f } };for( Int index = 0; index < 4; index++ ){- const Coord2D cast = castPixel( pixels[ index ].x, pixels[ index ].y, 400.0f );+ const Coord2D cast = castPixel( pixels[ index ].x, pixels[ index ].y, 1.3f, 120.0f );const Coord2D projected = ObserverCamera_pixelToGround( pixels[ index ], 1280, 720, corners );CHECK_NEAR( projected.x, cast.x, 0.5f );CHECK_NEAR( projected.y, cast.y, 0.5f );@@ -519,69 +576,86 @@ TEST(the_four_corners_project_every_pixel_onto_flat_ground_exactly)CHECK_NEAR( back.x, pixels[ index ].x, 0.05f );CHECK_NEAR( back.y, pixels[ index ].y, 0.05f );}- // twice as far back, every pixel's ground is twice as far from the point looked at- Coord2D farther[ 4 ];- castCorners( 800.0f, farther );- for( Int corner = 0; corner < 4; corner++ )- {- CHECK_NEAR( farther[ corner ].x, corners[ corner ].x * 2.0f, 0.5f );- CHECK_NEAR( farther[ corner ].y, corners[ corner ].y * 2.0f, 0.5f );- }}TEST(a_subject_put_on_its_circle_centre_stays_there_at_every_zoom){// the look point the pane cameras use, subject less the pixel's ground at that zoom, drawn back- // through the camera of that zoom, lands on the pixel it was put on- Coord2D atOne[ 4 ];- castCorners( 400.0f, atOne );+ // through the real camera of that zoom, lands on the pixel it was put on+ const ObserverCameraGround ground = measureCast( 1.0f, 120.0f );const Coord2D subject = { 3000.0f, 2000.0f };const Coord2D centre = { 293.0f, 293.0f };const Real zooms[] = { 1.0f, 1.3f, 1.7f, 2.0f };for( Int index = 0; index < 4; index++ ){Coord2D corners[ 4 ];- for( Int corner = 0; corner < 4; corner++ )- {- corners[ corner ].x = atOne[ corner ].x * zooms[ index ];- corners[ corner ].y = atOne[ corner ].y * zooms[ index ];- }+ ObserverCamera_cornersAtZoom( ground, zooms[ index ], corners );const Coord2D look = ObserverCamera_lookPoint( subject, centre, 1280, 720, corners );+ Coord2D cast[ 4 ];+ castCorners( zooms[ index ], 120.0f, cast );Coord2D fromLook;fromLook.x = subject.x - look.x;fromLook.y = subject.y - look.y;- const Coord2D drawn = ObserverCamera_groundToPixel( fromLook, 1280, 720, corners );- CHECK_NEAR( drawn.x, centre.x, 0.05f );- CHECK_NEAR( drawn.y, centre.y, 0.05f );- // and the circle reaches further on the ground the further out the camera stands- CHECK_NEAR( ObserverCamera_groundRadius( centre, 200.0f, 1280, 720, corners ),- ObserverCamera_groundRadius( centre, 200.0f, 1280, 720, atOne ) * zooms[ index ], 0.5f );+ const Coord2D drawn = ObserverCamera_groundToPixel( fromLook, 1280, 720, cast );+ CHECK_NEAR( drawn.x, centre.x, 0.5f );+ CHECK_NEAR( drawn.y, centre.y, 0.5f );+ }+}++TEST(a_pane_shows_its_wedge_cut_by_the_screen)+{+ Real rays[ OBSERVER_MOST_PANES ];+ ObserverCamera_paneLayout( 2, rays );+ const Coord2D middle = { 640.0f, 360.0f };+ Coord2D vertices[ 8 ];+ // the upper left half: the meeting point, the two left corners and where the diagonal leaves the+ // top and the bottom+ CHECK_EQ( ObserverCamera_panePolygon( rays, 2, 0, middle, 1280, 720, vertices ), 5 );+ Bool top = FALSE;+ Bool bottom = FALSE;+ for( Int vertex = 0; vertex < 5; vertex++ )+ {+ top = top || ( fabs( vertices[ vertex ].x - 1000.0f ) < 0.5f && fabs( vertices[ vertex ].y ) < 0.5f );+ bottom = bottom || ( fabs( vertices[ vertex ].x - 280.0f ) < 0.5f && fabs( vertices[ vertex ].y - 720.0f ) < 0.5f );}+ CHECK( top );+ CHECK( bottom );+ // with no panes it is the whole screen+ CHECK_EQ( ObserverCamera_panePolygon( rays, 1, 0, middle, 1280, 720, vertices ), 4 );}TEST(a_pane_comes_down_to_the_zoom_that_shows_no_ground_past_the_map){- Coord2D atOne[ 4 ];- castCorners( 400.0f, atOne );+ const ObserverCameraGround ground = measureCast( 1.0f, 120.0f );Region2D map;map.lo.x = map.lo.y = 0.0f;map.hi.x = map.hi.y = 3000.0f;const Coord2D middlePixel = { 640.0f, 360.0f };- const Coord2D middle = { 1500.0f, 1500.0f };- const Coord2D nearEdge = { 400.0f, 1500.0f };+ Real rays[ OBSERVER_MOST_PANES ];+ Coord2D screen[ 8 ];+ const Int screenCount = ObserverCamera_panePolygon( rays, 1, 0, middlePixel, 1280, 720, screen );+// in the middle of a big map the cap is free- CHECK_NEAR( ObserverCamera_zoomInMap( middle, middlePixel, 1280, 720, atOne, map, 1.0f, 1.5f ), 1.5f, 0.0001f );- // near its edge the pane comes down to where the screen's left corners just reach the edge- const Real kept = ObserverCamera_zoomInMap( nearEdge, middlePixel, 1280, 720, atOne, map, 1.0f, 3.0f );- CHECK( kept < 3.0f );- Real leftmost = atOne[ 0 ].x;- for( Int corner = 1; corner < 4; corner++ )- leftmost = min( leftmost, atOne[ corner ].x );- const Coord2D onMiddle = ObserverCamera_pixelToGround( middlePixel, 1280, 720, atOne );- CHECK_NEAR( nearEdge.x - onMiddle.x * kept + leftmost * kept, 0.0f, 2.0f );+ const Coord2D middle = { 1500.0f, 1500.0f };+ CHECK_NEAR( ObserverCamera_zoomInMap( middle, middlePixel, screen, screenCount, 1280, 720, ground, map, 1.0f, 1.5f ), 1.5f, 0.0001f );++ // near the far edge only the top of the screen, which reaches furthest, leaves the map: the+ // middle stays on it at any zoom, and the zoom comes down to where the top just touches the edge+ const Coord2D nearTop = { 1500.0f, 2550.0f };+ const Real kept = ObserverCamera_zoomInMap( nearTop, middlePixel, screen, screenCount, 1280, 720, ground, map, 1.0f, 3.0f );+ CHECK( kept > 1.0f && kept < 3.0f );+ Coord2D cast[ 4 ];+ castCorners( kept, 120.0f, cast );+ Coord2D corners[ 4 ];+ ObserverCamera_cornersAtZoom( ground, kept, corners );+ const Coord2D look = ObserverCamera_lookPoint( nearTop, middlePixel, 1280, 720, corners );+ const Real topEdge = look.y + max( cast[ 0 ].y, cast[ 1 ].y );+ CHECK_NEAR( topEdge, 3000.0f, 3.0f );+ CHECK( nearTop.y < 3000.0f );+// and a subject that cannot be shown without the edge at any zoom gets the nearestconst Coord2D pastEdge = { 10.0f, 1500.0f };- CHECK_NEAR( ObserverCamera_zoomInMap( pastEdge, middlePixel, 1280, 720, atOne, map, 1.0f, 2.0f ), 1.0f, 0.0001f );+ CHECK_NEAR( ObserverCamera_zoomInMap( pastEdge, middlePixel, screen, screenCount, 1280, 720, ground, map, 1.0f, 2.0f ), 1.0f, 0.0001f );}TEST(pane_lines_grow_with_the_picture_and_the_join_keeps_all_of_them)