Skip to content

Commit d815113

Browse files
committed
bugfix(view): Fix ground level of bookmarks, replay camera and game world microphone
By merging View::m_groundLevel into View::m_pos::z
1 parent b7fcf9f commit d815113

11 files changed

Lines changed: 94 additions & 121 deletions

File tree

Core/GameEngine/Include/GameClient/View.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ class View : public Snapshot
181181
virtual Real getPitch() { return m_pitch; } ///< Return current camera pitch
182182
virtual void setAngleToDefault(); ///< Set the view angle back to default
183183
virtual void setPitchToDefault(); ///< Set the view pitch back to default
184-
void setPosition( const Coord3D *pos ) { m_pos = *pos; }
185-
void getPosition(Coord3D *pos) { *pos = m_pos;} ///< Returns position camera is looking at (z will be zero)
184+
void setPosition( const Coord3D &pos ) { m_pos = pos; }
185+
void setPosition2D( const Coord2D &pos ) { m_pos.x = pos.x; m_pos.y = pos.y; }
186+
const Coord3D &getPosition() const { return m_pos; } ///< Returns position camera is looking at
187+
Coord2D getPosition2D() const { Coord2D c = { m_pos.x, m_pos.y }; return c; } ///< Returns position camera is looking at
186188

187189
virtual const Coord3D& get3DCameraPosition() const = 0; ///< Returns the actual camera position
188190

@@ -195,7 +197,7 @@ class View : public Snapshot
195197
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
196198

197199
// TheSuperHackers @info Functions to call for user camera controls, not by the scripted camera.
198-
Bool userSetPosition(const Coord3D *pos) { return doUserAction(&View::setPosition, pos); }
200+
Bool userSetPosition(const Coord3D &pos) { return doUserAction(&View::setPosition, pos); }
199201
Bool userSetAngle(Real radians) { return doUserAction(&View::setAngle, radians); }
200202
Bool userSetAngleToDefault() { return doUserAction(&View::setAngleToDefault); }
201203
Bool userSetPitch(Real radians) { return doUserAction(&View::setPitch, radians); }
@@ -261,8 +263,6 @@ class View : public Snapshot
261263
virtual void xfer( Xfer *xfer ) override;
262264
virtual void loadPostProcess() override { }
263265

264-
const Coord3D *getPosition() const { return &m_pos; }
265-
266266
virtual View *prependViewToList( View *list ); ///< Prepend this view to the given list, return the new list
267267
virtual View *getNextView() { return m_next; } ///< Return next view in the set
268268

@@ -302,7 +302,7 @@ class View : public Snapshot
302302
UnsignedInt m_userControlLockedUntilFrame; ///< Locks the user control over camera until the given frame is reached
303303
Bool m_isUserControlled; ///< True if the user moved the camera last, false if the scripted camera moved the camera last
304304

305-
Coord3D m_pos; ///< Pivot of the camera, in world coordinates // TheSuperHackers @todo Make this Coord2D or use the Z component
305+
Coord3D m_pos; ///< Pivot of the camera, in world coordinates
306306
Int m_width, m_height; ///< Dimensions of the view
307307
Int m_originX, m_originY; ///< Location of top/left view corner
308308

@@ -356,12 +356,10 @@ class ViewLocation
356356
Real getPitch() const { return m_pitch; }
357357
Real getZoom() const { return m_zoom; }
358358

359-
void init(Real x, Real y, Real z, Real angle, Real pitch, Real zoom)
359+
void init(Coord3D pos, Real angle, Real pitch, Real zoom)
360360
{
361361
m_valid = true;
362-
m_pos.x = x;
363-
m_pos.y = y;
364-
m_pos.z = z;
362+
m_pos = pos;
365363
m_angle = angle;
366364
m_pitch = pitch;
367365
m_zoom = zoom;

Core/GameEngine/Source/Common/Audio/GameAudio.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,16 @@ void AudioManager::reset()
282282
//-------------------------------------------------------------------------------------------------
283283
void AudioManager::update()
284284
{
285-
Coord3D groundPos, microphonePos;
286-
TheTacticalView->getPosition( &groundPos );
285+
Coord3D microphonePos;
286+
Coord3D cameraPivot = TheTacticalView->getPosition();
287287
Real angle = TheTacticalView->getAngle();
288288
Matrix3D rot = Matrix3D::Identity;
289289
rot.Rotate_Z( angle );
290290
Vector3 forward( 0, 1, 0 );
291291
rot.mulVector3( forward );
292292

293-
Real desiredHeight = m_audioSettings->m_microphoneDesiredHeightAboveTerrain;
294-
Real maxPercentage = m_audioSettings->m_microphoneMaxPercentageBetweenGroundAndCamera;
293+
const Real desiredHeight = m_audioSettings->m_microphoneDesiredHeightAboveTerrain + cameraPivot.z;
294+
const Real maxPercentage = m_audioSettings->m_microphoneMaxPercentageBetweenGroundAndCamera;
295295

296296
Coord3D lookTo;
297297
lookTo.set(forward.X, forward.Y, forward.Z);
@@ -303,7 +303,7 @@ void AudioManager::update()
303303
Coord3D cameraPos = TheTacticalView->get3DCameraPosition();
304304
Coord3D groundToCameraVector;
305305
groundToCameraVector.set( &cameraPos );
306-
groundToCameraVector.sub( &groundPos );
306+
groundToCameraVector.sub( &cameraPivot );
307307
Real bestScaleFactor;
308308

309309
if( cameraPos.z <= desiredHeight || groundToCameraVector.z <= 0.0f )
@@ -324,8 +324,7 @@ void AudioManager::update()
324324
groundToCameraVector.scale( bestScaleFactor );
325325

326326
//Set the microphone to be the ground position adjusted for terrain plus the vector we just calculated.
327-
groundPos.z = TheTerrainLogic->getGroundHeight( groundPos.x, groundPos.y );
328-
microphonePos.set( &groundPos );
327+
microphonePos.set( &cameraPivot );
329328
microphonePos.add( &groundToCameraVector );
330329

331330
//Viola! A properly placed microphone.

Core/GameEngine/Source/GameClient/View.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ void View::zoom( Real height )
134134
*/
135135
void View::lookAt( const Coord3D *o )
136136
{
137-
138137
/// @todo this needs to be changed to be 3D, this is still old 2D stuff
139-
Coord3D pos = *getPosition();
138+
Coord2D pos = getPosition2D();
140139
pos.x = o->x - m_width * 0.5f;
141140
pos.y = o->y - m_height * 0.5f;
142-
setPosition(&pos);
141+
setPosition2D(pos);
143142
}
144143

145144
/**
@@ -203,10 +202,7 @@ void View::setHeightAboveGround(Real z)
203202
*/
204203
void View::getLocation( ViewLocation *location )
205204
{
206-
207-
const Coord3D *pos = getPosition();
208-
location->init( pos->x, pos->y, pos->z, getAngle(), getPitch(), getZoom() );
209-
205+
location->init( getPosition(), getAngle(), getPitch(), getZoom() );
210206
}
211207

212208

@@ -217,11 +213,10 @@ void View::setLocation( const ViewLocation *location )
217213
{
218214
if ( location->isValid() )
219215
{
220-
setPosition(&location->getPosition());
216+
setPosition(location->getPosition());
221217
setAngle(location->getAngle());
222218
setPitch(location->getPitch());
223219
setZoom(location->getZoom());
224-
forceRedraw();
225220
}
226221

227222
}
@@ -287,8 +282,7 @@ void View::xfer( Xfer *xfer )
287282
setAngle( angle );
288283

289284
// view position
290-
Coord3D viewPos;
291-
getPosition( &viewPos );
285+
Coord3D viewPos = getPosition();
292286
xfer->xferReal( &viewPos.x );
293287
xfer->xferReal( &viewPos.y );
294288
xfer->xferReal( &viewPos.z );

Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ class W3DView : public View, public SubsystemInterface
279279
Coord2D m_scrollAmount; ///< scroll speed
280280
Real m_scrollAmountCutoffSqr; ///< scroll speed at which we do not adjust height
281281

282-
Real m_groundLevel; ///< height of ground.
283282
#if PRESERVE_RETAIL_SCRIPTED_CAMERA
284283
// TheSuperHackers @tweak Uses the initial ground level for preserving the original look of the scripted camera,
285284
// because alterations to the ground level do affect the positioning in subtle ways.

Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ void MilesAudioManager::audioDebugDisplay(DebugDisplayInterface *dd, void *, FIL
134134
AIL_MSS_version(buffer, 128);
135135
}
136136

137-
Coord3D lookPos;
138-
TheTacticalView->getPosition( &lookPos );
139-
lookPos.z = TheTerrainLogic->getGroundHeight( lookPos.x, lookPos.y );
137+
Coord3D lookPos = TheTacticalView->getPosition();
140138
const Coord3D *mikePos = TheAudio->getListenerPosition();
141139
Coord3D distanceVector = TheTacticalView->get3DCameraPosition();
142140
distanceVector.sub( mikePos );

0 commit comments

Comments
 (0)