Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions Core/GameEngine/Include/GameClient/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ class View : public Snapshot
virtual Real getDefaultPitch() { return m_defaultPitch; } ///< Return current default 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; }
Comment thread
Mauller marked this conversation as resolved.
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

Expand All @@ -201,7 +203,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); }
Expand Down Expand Up @@ -268,8 +270,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

Expand Down Expand Up @@ -309,7 +309,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
Comment thread
Mauller marked this conversation as resolved.
Int m_width, m_height; ///< Dimensions of the view
Int m_originX, m_originY; ///< Location of top/left view corner

Expand Down Expand Up @@ -363,12 +363,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;
Expand Down
18 changes: 9 additions & 9 deletions Core/GameEngine/Source/Common/Audio/GameAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,16 @@ void AudioManager::reset()
//-------------------------------------------------------------------------------------------------
void AudioManager::update()
{
Coord3D groundPos, microphonePos;
TheTacticalView->getPosition( &groundPos );
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 desiredHeightRel = m_audioSettings->m_microphoneDesiredHeightAboveTerrain;
const Real desiredHeightAbs = desiredHeightRel + cameraPivot.z;
const Real maxPercentage = m_audioSettings->m_microphoneMaxPercentageBetweenGroundAndCamera;

Coord3D lookTo;
lookTo.set(forward.X, forward.Y, forward.Z);
Expand All @@ -303,18 +303,18 @@ 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 )
if( cameraPos.z <= desiredHeightAbs || groundToCameraVector.z <= 0.0f )
{
//Use the percentage calculation!
bestScaleFactor = maxPercentage;
}
else
{
//Calculate the stopping position of the groundToCameraVector when we force z to be m_microphoneDesiredHeightAboveTerrain
Real zScale = desiredHeight / groundToCameraVector.z;
Real zScale = desiredHeightRel / groundToCameraVector.z;

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

//Viola! A properly placed microphone.
Expand Down
22 changes: 7 additions & 15 deletions Core/GameEngine/Source/GameClient/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ View::View()
m_snapImmediate = FALSE;
m_terrainHeightAtPivot = 0.0f;
m_zoom = 0.0f;
m_pos.x = 0;
m_pos.y = 0;
m_pos.zero();
m_width = 0;
m_height = 0;
m_angle = 0.0f;
Expand Down Expand Up @@ -90,8 +89,7 @@ void View::init()
m_height = DEFAULT_VIEW_HEIGHT;
m_originX = DEFAULT_VIEW_ORIGIN_X;
m_originY = DEFAULT_VIEW_ORIGIN_Y;
m_pos.x = 0;
m_pos.y = 0;
m_pos.zero();
m_angle = 0.0f;
m_cameraLock = INVALID_ID;
m_cameraLockDrawable = nullptr;
Expand Down Expand Up @@ -136,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);
}

/**
Expand Down Expand Up @@ -218,10 +215,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() );
}


Expand All @@ -232,11 +226,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();
}

}
Expand Down Expand Up @@ -302,8 +295,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 );
Expand Down
2 changes: 0 additions & 2 deletions Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DView.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ typedef struct
Real waySegLength[MAX_WAYPOINTS+2]; // Length of each segment;
Real cameraAngle[MAX_WAYPOINTS+2]; // Camera Angle;
Int timeMultiplier[MAX_WAYPOINTS+2]; // Time speedup factor.
Real groundHeight[MAX_WAYPOINTS+1]; // Ground height.
Real totalTimeMilliseconds; // Num of ms to do this movement.
Real elapsedTimeMilliseconds; // Time since start.
Real totalDistance; // Total length of paths.
Expand Down Expand Up @@ -280,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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading
Loading