Skip to content

Commit aea77d0

Browse files
authored
bugfix(view): Fix ground level of bookmarks, replay camera and game world microphone (TheSuperHackers#2595)
1 parent aa2b09d commit aea77d0

16 files changed

Lines changed: 132 additions & 145 deletions

File tree

Core/GameEngine/Include/GameClient/View.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ class View : public Snapshot
187187
virtual Real getDefaultPitch() { return m_defaultPitch; } ///< Return current default camera pitch
188188
virtual void setAngleToDefault(); ///< Set the view angle back to default
189189
virtual void setPitchToDefault(); ///< Set the view pitch back to default
190-
void setPosition( const Coord3D *pos ) { m_pos = *pos; }
191-
void getPosition(Coord3D *pos) { *pos = m_pos;} ///< Returns position camera is looking at (z will be zero)
190+
void setPosition( const Coord3D &pos ) { m_pos = pos; }
191+
void setPosition2D( const Coord2D &pos ) { m_pos.x = pos.x; m_pos.y = pos.y; }
192+
const Coord3D &getPosition() const { return m_pos; } ///< Returns position camera is looking at
193+
Coord2D getPosition2D() const { Coord2D c = { m_pos.x, m_pos.y }; return c; } ///< Returns position camera is looking at
192194

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

@@ -201,7 +203,7 @@ class View : public Snapshot
201203
virtual void setOkToAdjustHeight( Bool val ) { m_okToAdjustHeight = val; } ///< Set this to adjust camera height
202204

203205
// TheSuperHackers @info Functions to call for user camera controls, not by the scripted camera.
204-
Bool userSetPosition(const Coord3D *pos) { return doUserAction(&View::setPosition, pos); }
206+
Bool userSetPosition(const Coord3D &pos) { return doUserAction(&View::setPosition, pos); }
205207
Bool userSetAngle(Real radians) { return doUserAction(&View::setAngle, radians); }
206208
Bool userSetAngleToDefault() { return doUserAction(&View::setAngleToDefault); }
207209
Bool userSetPitch(Real radians) { return doUserAction(&View::setPitch, radians); }
@@ -219,6 +221,8 @@ class View : public Snapshot
219221
Bool userSetCameraLockDrawable(Drawable *drawable) { return doUserAction(&View::setCameraLockDrawable, drawable); }
220222

221223
void lockUserControlUntilFrame(UnsignedInt frame) { m_userControlLockedUntilFrame = frame; } ///< Locks the user control over camera until the given frame is reached.
224+
225+
virtual void setUserControlled(Bool value) { m_isUserControlled = value; }
222226
Bool isUserControlLocked() const;
223227

224228
// for debugging
@@ -268,13 +272,9 @@ class View : public Snapshot
268272
virtual void xfer( Xfer *xfer ) override;
269273
virtual void loadPostProcess() override { }
270274

271-
const Coord3D *getPosition() const { return &m_pos; }
272-
273275
virtual View *prependViewToList( View *list ); ///< Prepend this view to the given list, return the new list
274276
virtual View *getNextView() { return m_next; } ///< Return next view in the set
275277

276-
virtual void setUserControlled(Bool value) { m_isUserControlled = value; }
277-
278278
private:
279279

280280
template<typename Function>
@@ -309,7 +309,7 @@ class View : public Snapshot
309309
UnsignedInt m_userControlLockedUntilFrame; ///< Locks the user control over camera until the given frame is reached
310310
Bool m_isUserControlled; ///< True if the user moved the camera last, false if the scripted camera moved the camera last
311311

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

@@ -363,12 +363,10 @@ class ViewLocation
363363
Real getPitch() const { return m_pitch; }
364364
Real getZoom() const { return m_zoom; }
365365

366-
void init(Real x, Real y, Real z, Real angle, Real pitch, Real zoom)
366+
void init(Coord3D pos, Real angle, Real pitch, Real zoom)
367367
{
368368
m_valid = true;
369-
m_pos.x = x;
370-
m_pos.y = y;
371-
m_pos.z = z;
369+
m_pos = pos;
372370
m_angle = angle;
373371
m_pitch = pitch;
374372
m_zoom = zoom;

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

Lines changed: 9 additions & 9 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 cameraPivot = TheTacticalView->getPosition();
287286
Real angle = TheTacticalView->getAngle();
288287
Matrix3D rot = Matrix3D::Identity;
289288
rot.Rotate_Z( angle );
290289
Vector3 forward( 0, 1, 0 );
291290
rot.mulVector3( forward );
292291

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

296296
Coord3D lookTo;
297297
lookTo.set(forward.X, forward.Y, forward.Z);
@@ -303,18 +303,18 @@ 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

309-
if( cameraPos.z <= desiredHeight || groundToCameraVector.z <= 0.0f )
309+
if( cameraPos.z <= desiredHeightAbs || groundToCameraVector.z <= 0.0f )
310310
{
311311
//Use the percentage calculation!
312312
bestScaleFactor = maxPercentage;
313313
}
314314
else
315315
{
316316
//Calculate the stopping position of the groundToCameraVector when we force z to be m_microphoneDesiredHeightAboveTerrain
317-
Real zScale = desiredHeight / groundToCameraVector.z;
317+
Real zScale = desiredHeightRel / groundToCameraVector.z;
318318

319319
//Use the smallest of the two scale calculations
320320
bestScaleFactor = MIN( maxPercentage, zScale );
@@ -324,8 +324,8 @@ 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+
Coord3D microphonePos;
328+
microphonePos.set( &cameraPivot );
329329
microphonePos.add( &groundToCameraVector );
330330

331331
//Viola! A properly placed microphone.

Core/GameEngine/Source/GameClient/View.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ View::View()
5858
m_snapImmediate = FALSE;
5959
m_terrainHeightAtPivot = 0.0f;
6060
m_zoom = 0.0f;
61-
m_pos.x = 0;
62-
m_pos.y = 0;
61+
m_pos.zero();
6362
m_width = 0;
6463
m_height = 0;
6564
m_angle = 0.0f;
@@ -90,8 +89,7 @@ void View::init()
9089
m_height = DEFAULT_VIEW_HEIGHT;
9190
m_originX = DEFAULT_VIEW_ORIGIN_X;
9291
m_originY = DEFAULT_VIEW_ORIGIN_Y;
93-
m_pos.x = 0;
94-
m_pos.y = 0;
92+
m_pos.zero();
9593
m_angle = 0.0f;
9694
m_cameraLock = INVALID_ID;
9795
m_cameraLockDrawable = nullptr;
@@ -136,12 +134,11 @@ void View::zoom( Real height )
136134
*/
137135
void View::lookAt( const Coord3D *o )
138136
{
139-
140137
/// @todo this needs to be changed to be 3D, this is still old 2D stuff
141-
Coord3D pos = *getPosition();
138+
Coord2D pos = getPosition2D();
142139
pos.x = o->x - m_width * 0.5f;
143140
pos.y = o->y - m_height * 0.5f;
144-
setPosition(&pos);
141+
setPosition2D(pos);
145142
}
146143

147144
/**
@@ -218,10 +215,7 @@ void View::setHeightAboveGround(Real z)
218215
*/
219216
void View::getLocation( ViewLocation *location )
220217
{
221-
222-
const Coord3D *pos = getPosition();
223-
location->init( pos->x, pos->y, pos->z, getAngle(), getPitch(), getZoom() );
224-
218+
location->init( getPosition(), getAngle(), getPitch(), getZoom() );
225219
}
226220

227221

@@ -232,11 +226,10 @@ void View::setLocation( const ViewLocation *location )
232226
{
233227
if ( location->isValid() )
234228
{
235-
setPosition(&location->getPosition());
229+
setPosition(location->getPosition());
236230
setAngle(location->getAngle());
237231
setPitch(location->getPitch());
238232
setZoom(location->getZoom());
239-
forceRedraw();
240233
}
241234

242235
}
@@ -302,8 +295,7 @@ void View::xfer( Xfer *xfer )
302295
setAngle( angle );
303296

304297
// view position
305-
Coord3D viewPos;
306-
getPosition( &viewPos );
298+
Coord3D viewPos = getPosition();
307299
xfer->xferReal( &viewPos.x );
308300
xfer->xferReal( &viewPos.y );
309301
xfer->xferReal( &viewPos.z );

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ typedef struct
5757
Real waySegLength[MAX_WAYPOINTS+2]; // Length of each segment;
5858
Real cameraAngle[MAX_WAYPOINTS+2]; // Camera Angle;
5959
Int timeMultiplier[MAX_WAYPOINTS+2]; // Time speedup factor.
60-
Real groundHeight[MAX_WAYPOINTS+1]; // Ground height.
6160
Real totalTimeMilliseconds; // Num of ms to do this movement.
6261
Real elapsedTimeMilliseconds; // Time since start.
6362
Real totalDistance; // Total length of paths.
@@ -280,7 +279,6 @@ class W3DView : public View, public SubsystemInterface
280279
Coord2D m_scrollAmount; ///< scroll speed
281280
Real m_scrollAmountCutoffSqr; ///< scroll speed at which we do not adjust height
282281

283-
Real m_groundLevel; ///< height of ground.
284282
#if PRESERVE_RETAIL_SCRIPTED_CAMERA
285283
// TheSuperHackers @tweak Uses the initial ground level for preserving the original look of the scripted camera,
286284
// 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)