From d815113a6a58295053825a17dfbbb52b842cf2b2 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Sun, 12 Apr 2026 12:27:43 +0200 Subject: [PATCH] bugfix(view): Fix ground level of bookmarks, replay camera and game world microphone By merging View::m_groundLevel into View::m_pos::z --- Core/GameEngine/Include/GameClient/View.h | 18 +-- .../Source/Common/Audio/GameAudio.cpp | 13 +- Core/GameEngine/Source/GameClient/View.cpp | 16 +- .../Include/W3DDevice/GameClient/W3DView.h | 1 - .../MilesAudioDevice/MilesAudioManager.cpp | 4 +- .../Source/W3DDevice/GameClient/W3DView.cpp | 147 ++++++++---------- .../GameClient/MessageStream/CommandXlat.cpp | 3 +- .../MessageStream/SelectionXlat.cpp | 5 +- .../GameLogic/ScriptEngine/ScriptActions.cpp | 3 +- .../GameLogic/System/GameLogicDispatch.cpp | 2 +- .../W3DDevice/GameClient/W3DDisplay.cpp | 3 +- 11 files changed, 94 insertions(+), 121 deletions(-) diff --git a/Core/GameEngine/Include/GameClient/View.h b/Core/GameEngine/Include/GameClient/View.h index 8eb96ce97aa..62780b25d3b 100644 --- a/Core/GameEngine/Include/GameClient/View.h +++ b/Core/GameEngine/Include/GameClient/View.h @@ -181,8 +181,10 @@ class View : public Snapshot virtual Real getPitch() { return m_pitch; } ///< Return current camera pitch virtual void setAngleToDefault(); ///< Set the view angle back to default virtual void setPitchToDefault(); ///< Set the view pitch back to default - void setPosition( const Coord3D *pos ) { m_pos = *pos; } - void getPosition(Coord3D *pos) { *pos = m_pos;} ///< Returns position camera is looking at (z will be zero) + void setPosition( const Coord3D &pos ) { m_pos = pos; } + void setPosition2D( const Coord2D &pos ) { m_pos.x = pos.x; m_pos.y = pos.y; } + const Coord3D &getPosition() const { return m_pos; } ///< Returns position camera is looking at + Coord2D getPosition2D() const { Coord2D c = { m_pos.x, m_pos.y }; return c; } ///< Returns position camera is looking at virtual const Coord3D& get3DCameraPosition() const = 0; ///< Returns the actual camera position @@ -195,7 +197,7 @@ class View : public Snapshot virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height // TheSuperHackers @info Functions to call for user camera controls, not by the scripted camera. - Bool userSetPosition(const Coord3D *pos) { return doUserAction(&View::setPosition, pos); } + Bool userSetPosition(const Coord3D &pos) { return doUserAction(&View::setPosition, pos); } Bool userSetAngle(Real radians) { return doUserAction(&View::setAngle, radians); } Bool userSetAngleToDefault() { return doUserAction(&View::setAngleToDefault); } Bool userSetPitch(Real radians) { return doUserAction(&View::setPitch, radians); } @@ -261,8 +263,6 @@ class View : public Snapshot virtual void xfer( Xfer *xfer ) override; virtual void loadPostProcess() override { } - const Coord3D *getPosition() const { return &m_pos; } - virtual View *prependViewToList( View *list ); ///< Prepend this view to the given list, return the new list virtual View *getNextView() { return m_next; } ///< Return next view in the set @@ -302,7 +302,7 @@ class View : public Snapshot UnsignedInt m_userControlLockedUntilFrame; ///< Locks the user control over camera until the given frame is reached Bool m_isUserControlled; ///< True if the user moved the camera last, false if the scripted camera moved the camera last - Coord3D m_pos; ///< Pivot of the camera, in world coordinates // TheSuperHackers @todo Make this Coord2D or use the Z component + Coord3D m_pos; ///< Pivot of the camera, in world coordinates Int m_width, m_height; ///< Dimensions of the view Int m_originX, m_originY; ///< Location of top/left view corner @@ -356,12 +356,10 @@ class ViewLocation Real getPitch() const { return m_pitch; } Real getZoom() const { return m_zoom; } - void init(Real x, Real y, Real z, Real angle, Real pitch, Real zoom) + void init(Coord3D pos, Real angle, Real pitch, Real zoom) { m_valid = true; - m_pos.x = x; - m_pos.y = y; - m_pos.z = z; + m_pos = pos; m_angle = angle; m_pitch = pitch; m_zoom = zoom; diff --git a/Core/GameEngine/Source/Common/Audio/GameAudio.cpp b/Core/GameEngine/Source/Common/Audio/GameAudio.cpp index 0da135a86a4..bb999f73949 100644 --- a/Core/GameEngine/Source/Common/Audio/GameAudio.cpp +++ b/Core/GameEngine/Source/Common/Audio/GameAudio.cpp @@ -282,16 +282,16 @@ void AudioManager::reset() //------------------------------------------------------------------------------------------------- void AudioManager::update() { - Coord3D groundPos, microphonePos; - TheTacticalView->getPosition( &groundPos ); + Coord3D microphonePos; + Coord3D cameraPivot = TheTacticalView->getPosition(); Real angle = TheTacticalView->getAngle(); Matrix3D rot = Matrix3D::Identity; rot.Rotate_Z( angle ); Vector3 forward( 0, 1, 0 ); rot.mulVector3( forward ); - Real desiredHeight = m_audioSettings->m_microphoneDesiredHeightAboveTerrain; - Real maxPercentage = m_audioSettings->m_microphoneMaxPercentageBetweenGroundAndCamera; + const Real desiredHeight = m_audioSettings->m_microphoneDesiredHeightAboveTerrain + cameraPivot.z; + const Real maxPercentage = m_audioSettings->m_microphoneMaxPercentageBetweenGroundAndCamera; Coord3D lookTo; lookTo.set(forward.X, forward.Y, forward.Z); @@ -303,7 +303,7 @@ void AudioManager::update() Coord3D cameraPos = TheTacticalView->get3DCameraPosition(); Coord3D groundToCameraVector; groundToCameraVector.set( &cameraPos ); - groundToCameraVector.sub( &groundPos ); + groundToCameraVector.sub( &cameraPivot ); Real bestScaleFactor; if( cameraPos.z <= desiredHeight || groundToCameraVector.z <= 0.0f ) @@ -324,8 +324,7 @@ void AudioManager::update() groundToCameraVector.scale( bestScaleFactor ); //Set the microphone to be the ground position adjusted for terrain plus the vector we just calculated. - groundPos.z = TheTerrainLogic->getGroundHeight( groundPos.x, groundPos.y ); - microphonePos.set( &groundPos ); + microphonePos.set( &cameraPivot ); microphonePos.add( &groundToCameraVector ); //Viola! A properly placed microphone. diff --git a/Core/GameEngine/Source/GameClient/View.cpp b/Core/GameEngine/Source/GameClient/View.cpp index 10945559379..6d6b8857c03 100644 --- a/Core/GameEngine/Source/GameClient/View.cpp +++ b/Core/GameEngine/Source/GameClient/View.cpp @@ -134,12 +134,11 @@ void View::zoom( Real height ) */ void View::lookAt( const Coord3D *o ) { - /// @todo this needs to be changed to be 3D, this is still old 2D stuff - Coord3D pos = *getPosition(); + Coord2D pos = getPosition2D(); pos.x = o->x - m_width * 0.5f; pos.y = o->y - m_height * 0.5f; - setPosition(&pos); + setPosition2D(pos); } /** @@ -203,10 +202,7 @@ void View::setHeightAboveGround(Real z) */ void View::getLocation( ViewLocation *location ) { - - const Coord3D *pos = getPosition(); - location->init( pos->x, pos->y, pos->z, getAngle(), getPitch(), getZoom() ); - + location->init( getPosition(), getAngle(), getPitch(), getZoom() ); } @@ -217,11 +213,10 @@ void View::setLocation( const ViewLocation *location ) { if ( location->isValid() ) { - setPosition(&location->getPosition()); + setPosition(location->getPosition()); setAngle(location->getAngle()); setPitch(location->getPitch()); setZoom(location->getZoom()); - forceRedraw(); } } @@ -287,8 +282,7 @@ void View::xfer( Xfer *xfer ) setAngle( angle ); // view position - Coord3D viewPos; - getPosition( &viewPos ); + Coord3D viewPos = getPosition(); xfer->xferReal( &viewPos.x ); xfer->xferReal( &viewPos.y ); xfer->xferReal( &viewPos.z ); diff --git a/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h b/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h index e4603a3970b..c3c2fc97974 100644 --- a/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h +++ b/Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h @@ -279,7 +279,6 @@ class W3DView : public View, public SubsystemInterface Coord2D m_scrollAmount; ///< scroll speed Real m_scrollAmountCutoffSqr; ///< scroll speed at which we do not adjust height - Real m_groundLevel; ///< height of ground. #if PRESERVE_RETAIL_SCRIPTED_CAMERA // TheSuperHackers @tweak Uses the initial ground level for preserving the original look of the scripted camera, // because alterations to the ground level do affect the positioning in subtle ways. diff --git a/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp b/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp index b0107b96d0e..3a541494959 100644 --- a/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp +++ b/Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp @@ -134,9 +134,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL AIL_MSS_version(buffer, 128); } - Coord3D lookPos; - TheTacticalView->getPosition( &lookPos ); - lookPos.z = TheTerrainLogic->getGroundHeight( lookPos.x, lookPos.y ); + Coord3D lookPos = TheTacticalView->getPosition(); const Coord3D *mikePos = TheAudio->getListenerPosition(); Coord3D distanceVector = TheTacticalView->get3DCameraPosition(); distanceVector.sub( mikePos ); diff --git a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp index a6159c2b685..ef1e95865c7 100644 --- a/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp +++ b/Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DView.cpp @@ -141,9 +141,9 @@ W3DView::W3DView() m_3DCamera = nullptr; m_2DCamera = nullptr; - m_groundLevel = 10.0f; + #if PRESERVE_RETAIL_SCRIPTED_CAMERA - m_initialGroundLevel = m_groundLevel; + m_initialGroundLevel = 10.0f; #endif m_viewFilterMode = FM_VIEW_DEFAULT; @@ -250,12 +250,10 @@ void W3DView::setOrigin( Int x, Int y) #define MIN_CAPPED_ZOOM (0.5f) //WST 10.19.2002. JSC integrated 5/20/03. void W3DView::buildCameraPosition( Vector3& sourcePos, Vector3& targetPos ) { - Real groundLevel = m_groundLevel; // 93.0f; - - Real zoom = getZoom(); - Real angle = getAngle(); - Real pitch = getPitch(); - Coord3D pos = *getPosition(); + const Real zoom = getZoom(); + const Real angle = getAngle(); + const Real pitch = getPitch(); + Coord3D pos = getPosition(); // add in the camera shake, if any pos.x += m_shakeOffset.x; @@ -280,12 +278,9 @@ void W3DView::buildCameraPosition( Vector3& sourcePos, Vector3& targetPos ) sourcePos.Z *= zoom; } - // camera looking at origin - targetPos.X = 0; - targetPos.Y = 0; - targetPos.Z = 0; - - const Real heightScale = 1.0f - (groundLevel / sourcePos.Z); + // TheSuperHackers @info Scales the source position later by this much + // to achieve the intended camera height. Must not scale before pitching! + const Real heightScale = 1.0f - (pos.z / sourcePos.Z); // construct a matrix to rotate around the up vector by the given angle const Matrix3D angleTransform( Vector3( 0.0f, 0.0f, 1.0f ), angle ); @@ -305,9 +300,9 @@ void W3DView::buildCameraPosition( Vector3& sourcePos, Vector3& targetPos ) sourcePos *= heightScale; // set look at position - targetPos.X += pos.x; - targetPos.Y += pos.y; - targetPos.Z += groundLevel; + targetPos.X = pos.x; + targetPos.Y = pos.y; + targetPos.Z = pos.z; // translate to world space sourcePos += targetPos; @@ -404,9 +399,8 @@ void W3DView::buildCameraTransform( Matrix3D *transform, const Vector3 &sourcePo // WST 10.22.2002. Update the Listener positions used by audio system //-------------------------------------------------------------------- Vector3 position = transform->Get_Translation(); - Coord3D coord; - coord.set(position.X, position.Y, position.Z); - View::setPosition(&coord); + Coord3D coord = { position.X, position.Y, position.Z }; + View::setPosition(coord); break; } } @@ -441,14 +435,14 @@ Bool W3DView::zoomCameraToDesiredHeight() // This is essential to correctly center the camera above the ground when playing. Bool W3DView::movePivotToGround() { - const Real groundLevel = m_groundLevel; + const Real groundLevel = m_pos.z; const Real groundLevelDiff = m_terrainHeightAtPivot - groundLevel; if (fabs(groundLevelDiff) > 0.1f) { const Real fpsRatio = TheFramePacer->getBaseOverUpdateFpsRatio(); const Real adjustFactor = std::min(TheGlobalData->m_cameraAdjustSpeed * fpsRatio, 1.0f); // Adjust the ground level. This will change the world height of the camera. - m_groundLevel += groundLevelDiff * adjustFactor; + m_pos.z += groundLevelDiff * adjustFactor; // Reposition the camera relative to its pitch. // This effectively zooms the camera in the view direction together with the ground level change. @@ -476,10 +470,10 @@ Bool W3DView::movePivotToGround() repositionStrength = WWMath::Clamp(repositionStrength, 0.0f, 1.0f); posDiff *= repositionStrength; - Coord3D pos = *getPosition(); + Coord2D pos = getPosition2D(); pos.x += posDiff.X * adjustFactor; pos.y += posDiff.Y * adjustFactor; - setPosition(&pos); + setPosition2D(pos); } return true; @@ -539,7 +533,7 @@ void W3DView::calcCameraAreaConstraints() Matrix3D prevCameraTransform = m_3DCamera->Get_Transform(); m_3DCamera->Set_Transform(cameraTransform); - Real offset = calcCameraAreaOffset(m_groundLevel); + Real offset = calcCameraAreaOffset(m_pos.z); offset = std::min(offset, (mapRegion.hi.x - mapRegion.lo.x) / 2); offset = std::min(offset, (mapRegion.hi.y - mapRegion.lo.y) / 2); @@ -602,17 +596,17 @@ Real W3DView::calcCameraAreaOffset(Real maxEdgeZ) void W3DView::clipCameraIntoAreaConstraints() { constexpr const Real eps = 1e-6f; - Coord3D pos = *getPosition(); + Coord2D pos = getPosition2D(); pos.x = clamp(m_cameraAreaConstraints.lo.x + eps, pos.x, m_cameraAreaConstraints.hi.x - eps); pos.y = clamp(m_cameraAreaConstraints.lo.y + eps, pos.y, m_cameraAreaConstraints.hi.y - eps); - setPosition(&pos); + setPosition2D(pos); } //------------------------------------------------------------------------------------------------- Bool W3DView::isWithinCameraAreaConstraints() const { - const Coord3D* pos = getPosition(); - return m_cameraAreaConstraints.isInRegion(pos->x, pos->y); + const Coord3D &pos = getPosition(); + return m_cameraAreaConstraints.isInRegion(pos.x, pos.y); } //------------------------------------------------------------------------------------------------- @@ -660,7 +654,7 @@ Real W3DView::getCameraOffsetZ() const } #endif - return m_groundLevel + TheGlobalData->m_maxCameraHeight; + return m_pos.z + TheGlobalData->m_maxCameraHeight; } //------------------------------------------------------------------------------------------------- @@ -676,7 +670,7 @@ Real W3DView::getDesiredHeight(Real x, Real y) const } #endif - return m_groundLevel + m_heightAboveGround; + return m_pos.z + m_heightAboveGround; } //------------------------------------------------------------------------------------------------- @@ -690,7 +684,7 @@ Real W3DView::getMaxHeight(Real x, Real y) const } #endif - return m_groundLevel + m_maxHeightAboveGround; + return m_pos.z + m_maxHeightAboveGround; } //------------------------------------------------------------------------------------------------- @@ -770,14 +764,11 @@ void W3DView::init() setName("W3DView"); // set default camera "look at" point Coord3D pos; - pos.x = 87.0f; - pos.y = 77.0f; - pos.z = 0; + pos.x = 87.0f * MAP_XY_FACTOR; + pos.y = 77.0f * MAP_XY_FACTOR; + pos.z = 10.0f; - pos.x *= MAP_XY_FACTOR; - pos.y *= MAP_XY_FACTOR; - - setPosition(&pos); + setPosition(pos); // create our 3D camera m_3DCamera = NEW_REF( CameraClass, () ); @@ -820,7 +811,7 @@ void W3DView::reset() // Just move the camera to zero. It'll get repositioned at the beginning of the next game anyways. Coord3D arbitraryPos = { 0, 0, 0 }; - setPosition(&arbitraryPos); + setPosition(arbitraryPos); setAngleToDefault(); setPitchToDefault(); setZoomToDefault(); @@ -1190,13 +1181,13 @@ Bool W3DView::updateCameraMovements() } if (hasScriptedState(Scripted_Rotate)) { - m_previousLookAtPosition = *getPosition(); + m_previousLookAtPosition = getPosition(); rotateCameraOneFrame(); didUpdate = true; } else if (hasScriptedState(Scripted_MoveOnWaypointPath)) { - m_previousLookAtPosition = *getPosition(); + m_previousLookAtPosition = getPosition(); // TheSuperHackers @tweak The scripted camera movement is now decoupled from the render update. // The scripted camera will still move when the time is frozen, but not when the game is halted. moveAlongWaypointPath(TheFramePacer->getLogicTimeStepMilliseconds(FramePacer::IgnoreFrozenTime)); @@ -1362,7 +1353,7 @@ void W3DView::update() } else { Coord3D objpos = *cameraLockObj->getPosition(); - Coord3D curpos = *getPosition(); + Coord3D curpos = getPosition(); // don't "snap" directly to the pos, but move there smoothly. Real snapThreshSqr = sqr(TheGlobalData->m_partitionCellSize); Real curDistSqr = sqr(curpos.x - objpos.x) + sqr(curpos.y - objpos.y); @@ -1405,9 +1396,9 @@ void W3DView::update() } } if (!(TheScriptEngine->isTimeFrozenDebug() || TheScriptEngine->isTimeFrozenScript()) && !TheGameLogic->isGamePaused()) { - m_previousLookAtPosition = *getPosition(); + m_previousLookAtPosition = getPosition(); } - setPosition(&curpos); + setPosition(curpos); if (m_lockType == LOCK_FOLLOW) { @@ -1435,7 +1426,7 @@ void W3DView::update() if (m_snapImmediate) m_snapImmediate = FALSE; - m_groundLevel = objpos.z; + m_pos.z = objpos.z; didScriptedMovement = true; m_recalcCamera = true; } @@ -1685,13 +1676,13 @@ void W3DView::calcDeltaScroll(Coord2D &screenDelta) { screenDelta.x = 0; screenDelta.y = 0; - Vector3 prevPos(m_previousLookAtPosition.x,m_previousLookAtPosition.y, m_groundLevel); + Vector3 prevPos(m_previousLookAtPosition.x, m_previousLookAtPosition.y, m_pos.z); Vector3 prevScreen; if (m_3DCamera->Project( prevScreen, prevPos ) != CameraClass::INSIDE_FRUSTUM) { return; } - Vector3 pos(m_pos.x,m_pos.y, m_groundLevel); + Vector3 pos(m_pos.x, m_pos.y, m_pos.z); Vector3 screen; if (m_3DCamera->Project( screen, pos ) != CameraClass::INSIDE_FRUSTUM) { @@ -1873,7 +1864,9 @@ void W3DView::draw() if( TheGlobalData->m_debugCamera ) { UnsignedInt c = 0xaaffffff; - Coord3D worldPos = *getPosition(); + Coord3D worldPos; + worldPos.x = getPosition().x; + worldPos.y = getPosition().y; worldPos.z = TheTerrainLogic->getGroundHeight(worldPos.x, worldPos.y); Coord3D p1, p2; @@ -2014,12 +2007,11 @@ void W3DView::scrollBy( const Coord2D *delta ) world.Z = worldEnd.Z - worldStart.Z; // scroll by delta - Coord3D pos = *getPosition(); + Coord2D pos = getPosition2D(); pos.x += world.X; pos.y += world.Y; //DEBUG_LOG(("Delta %.2f, %.2f", world.X, world.Z)); - // no change to z - setPosition(&pos); + setPosition2D(pos); //m_cameraConstraintValid = false; // pos change does NOT invalidate cam constraints @@ -2493,8 +2485,10 @@ void W3DView::lookAt( const Coord3D *o ) } } - pos.z = 0; - setPosition(&pos); + + setPosition(pos); + + resetPivotToGround(); removeScriptedState(Scripted_Rotate | Scripted_CameraLock | Scripted_MoveOnWaypointPath); m_CameraArrivedAtWaypointOnPathFlag = false; @@ -2520,7 +2514,7 @@ void W3DView::initHeightForMap() //------------------------------------------------------------------------------------------------- void W3DView::resetPivotToGround( void ) { - m_groundLevel = getHeightAroundPos(m_pos.x, m_pos.y); + m_pos.z = getHeightAroundPos(m_pos.x, m_pos.y); m_cameraAreaConstraintsValid = false; // possible ground level change invalidates camera constraints m_recalcCamera = true; } @@ -2531,11 +2525,11 @@ void W3DView::resetPivotToGround( void ) //------------------------------------------------------------------------------------------------- void W3DView::moveCameraTo(const Coord3D *o, Int milliseconds, Int shutter, Bool orient, Real easeIn, Real easeOut) { - m_mcwpInfo.waypoints[0] = *getPosition(); + m_mcwpInfo.waypoints[0] = getPosition(); m_mcwpInfo.cameraAngle[0] = getAngle(); m_mcwpInfo.waySegLength[0] = 0; - m_mcwpInfo.waypoints[1] = *getPosition(); + m_mcwpInfo.waypoints[1] = getPosition(); m_mcwpInfo.waySegLength[1] = 0; m_mcwpInfo.waypoints[2] = *o; @@ -2625,7 +2619,7 @@ void W3DView::rotateCameraTowardPosition(const Coord3D *pLoc, Int milliseconds, if (m_rcInfo.numFrames < 1) { m_rcInfo.numFrames = 1; } - Coord3D curPos = *getPosition(); + Coord2D curPos = getPosition2D(); Vector2 dir(pLoc->x-curPos.x, pLoc->y-curPos.y); const Real dirLength = dir.Length(); if (dirLength<0.1f) return; @@ -2984,10 +2978,10 @@ void W3DView::moveCameraAlongWaypointPath(Waypoint *pWay, Int milliseconds, Int { const Real MIN_DELTA = MAP_XY_FACTOR; - m_mcwpInfo.waypoints[0] = *getPosition(); + m_mcwpInfo.waypoints[0] = getPosition(); m_mcwpInfo.cameraAngle[0] = getAngle(); m_mcwpInfo.waySegLength[0] = 0; - m_mcwpInfo.waypoints[1] = *getPosition(); + m_mcwpInfo.waypoints[1] = getPosition(); m_mcwpInfo.numWaypoints = 1; if (milliseconds<1) milliseconds = 1; m_mcwpInfo.totalTimeMilliseconds = milliseconds; @@ -3065,7 +3059,7 @@ void W3DView::setupWaypointPath(Bool orient) Real factor2 = curDistance / m_mcwpInfo.totalDistance; Real factor1 = 1.0-factor2; m_mcwpInfo.timeMultiplier[i] = m_timeMultiplier; - m_mcwpInfo.groundHeight[i] = m_groundLevel*factor1 + newGround*factor2; + m_mcwpInfo.groundHeight[i] = m_pos.z*factor1 + newGround*factor2; curDistance += m_mcwpInfo.waySegLength[i]; //DEBUG_LOG(("New Index %d, angle %.2f", i, m_mcwpInfo.cameraAngle[i]*180/PI)); } @@ -3300,11 +3294,11 @@ void W3DView::moveAlongWaypointPath(Real milliseconds) m_freezeTimeForCameraMovement = false; View::setAngle(m_mcwpInfo.cameraAngle[m_mcwpInfo.numWaypoints]); - m_groundLevel = m_mcwpInfo.groundHeight[m_mcwpInfo.numWaypoints]; - - Coord3D pos = m_mcwpInfo.waypoints[m_mcwpInfo.numWaypoints]; - pos.z = 0; - setPosition(&pos); + Coord3D pos; + pos.x = m_mcwpInfo.waypoints[m_mcwpInfo.numWaypoints].x; + pos.y = m_mcwpInfo.waypoints[m_mcwpInfo.numWaypoints].y; + pos.z = m_mcwpInfo.groundHeight[m_mcwpInfo.numWaypoints]; + setPosition(pos); // Note - assuming that the scripter knows what he is doing, we adjust the constraints so that // the scripted action can occur. m_cameraAreaConstraints.lo.x = minf(m_cameraAreaConstraints.lo.x, pos.x); @@ -3372,9 +3366,6 @@ void W3DView::moveAlongWaypointPath(Real milliseconds) m_mcwpInfo.timeMultiplier[m_mcwpInfo.curSegment+1]*factor2; m_timeMultiplier = REAL_TO_INT_FLOOR(0.5 + timeMultiplier); - m_groundLevel = m_mcwpInfo.groundHeight[m_mcwpInfo.curSegment]*factor1 + - m_mcwpInfo.groundHeight[m_mcwpInfo.curSegment+1]*factor2; - Coord3D start, mid, end; if (factor<0.5) { start = m_mcwpInfo.waypoints[m_mcwpInfo.curSegment-1]; @@ -3409,13 +3400,12 @@ void W3DView::moveAlongWaypointPath(Real milliseconds) result.y += factor*(end.y-start.y); result.x += (1-factor)*factor*(mid.x-end.x + mid.x-start.x); result.y += (1-factor)*factor*(mid.y-end.y + mid.y-start.y); - result.z = 0; + result.z = m_mcwpInfo.groundHeight[m_mcwpInfo.curSegment]*factor1 + + m_mcwpInfo.groundHeight[m_mcwpInfo.curSegment+1]*factor2; /* - static Real prevGround = 0; - DEBUG_LOG(("Dx %.2f, dy %.2f, DeltaANgle = %.2f, %.2f DeltaGround %.2f", m_pos.x-result.x, m_pos.y-result.y, deltaAngle, m_groundLevel, m_groundLevel-prevGround)); - prevGround = m_groundLevel; + DEBUG_LOG(("Dx %.2f, dy %.2f, DeltaANgle = %.2f, %.2f DeltaGround %.2f", m_pos.x-result.x, m_pos.y-result.y, deltaAngle, result.z, result.z-m_pos.z)); */ - setPosition(&result); + setPosition(result); // Note - assuming that the scripter knows what he is doing, we adjust the constraints so that // the scripted action can occur. m_cameraAreaConstraints.lo.x = minf(m_cameraAreaConstraints.lo.x, result.x); @@ -3469,12 +3459,11 @@ void W3DView::shake( const Coord3D *epicenter, CameraShakeType shakeType ) } // intensity falls off with distance - const Coord3D *viewPos = getPosition(); - Coord3D d; - d.x = epicenter->x - viewPos->x; - d.y = epicenter->y - viewPos->y; /// @todo make this 3D once we have the real "lookat" spot - //d.z = epicenter->z - viewPos->z; + const Coord2D viewPos = getPosition2D(); + Coord2D d; + d.x = epicenter->x - viewPos.x; + d.y = epicenter->y - viewPos.y; Real dist = (Real)sqrt( d.x*d.x + d.y*d.y ); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp index 089b1566bc0..4b40889fc1b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp @@ -4315,8 +4315,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage mode = FM_VIEW_MB_PAN_ALPHA; } saturate = !saturate; - Coord3D curpos; - TheTacticalView->getPosition(&curpos); + Coord3D curpos = TheTacticalView->getPosition(); curpos.x += 200; curpos.y += 200; TheTacticalView->setViewFilterPos(&curpos); diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp index cd859531ab1..3bd19e0762e 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp @@ -976,7 +976,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa // 3) 3-D camera position has changed m_deselectFeedbackAnchor = msg->getArgument( 0 )->pixel; m_lastClick = (UnsignedInt) msg->getArgument( 2 )->integer; - TheTacticalView->getPosition(&m_deselectDownCameraPosition); + m_deselectDownCameraPosition = TheTacticalView->getPosition(); break; } @@ -984,8 +984,7 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessa //----------------------------------------------------------------------------- case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP: { - Coord3D cameraPos; - TheTacticalView->getPosition(&cameraPos); + Coord3D cameraPos = TheTacticalView->getPosition(); cameraPos.sub(&m_deselectDownCameraPosition); ICoord2D pixel = msg->getArgument( 0 )->pixel; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp index 9321f800c2a..cfcb4c948db 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/ScriptEngine/ScriptActions.cpp @@ -5128,8 +5128,7 @@ void ScriptActions::doRadarRevertNormal() //------------------------------------------------------------------------------------------------- void ScriptActions::doScreenShake( UnsignedInt intensity ) { - Coord3D pos; - TheTacticalView->getPosition( &pos ); + Coord3D pos = TheTacticalView->getPosition(); TheTacticalView->shake( &pos, (View::CameraShakeType)intensity ); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp index abcfa873397..04c364ab8b9 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp @@ -1966,7 +1966,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData ) // TheSuperHackers @info Definitely call in user mode to ensure the camera operates with auto-zoom // over terrain elevations, because the Replay Camera does not store the absolute camera location, // but key parameters relative to the terrain height at the camera pivot. - TheTacticalView->userSetPosition(&pos); + TheTacticalView->userSetPosition(pos); TheTacticalView->userSetAngle(angle); TheTacticalView->userSetPitch(pitch); TheTacticalView->userSetZoom(zoom); diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp index 6a17841b0fa..cebdfdc4f5e 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp @@ -1227,8 +1227,7 @@ void W3DDisplay::gatherDebugStats() m_displayStrings[TerrainStats]->setText( unibuffer ); // misc debug info - Coord3D camPos; - TheTacticalView->getPosition(&camPos); + Coord3D camPos = TheTacticalView->getPosition(); Real zoom = TheTacticalView->getZoom(); Real pitch = TheTacticalView->getPitch(); Real FXPitch = TheTacticalView->getFXPitch();