Merge remote-tracking branch 'scrawl/soundlistener'

This commit is contained in:
Marc Zinnschlag 2015-12-03 15:52:57 +01:00
commit 8b0659c4f2
9 changed files with 29 additions and 15 deletions

View file

@ -153,7 +153,7 @@ namespace MWBase
virtual void update(float duration) = 0; virtual void update(float duration) = 0;
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up) = 0; virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater) = 0;
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0; virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0;

View file

@ -387,6 +387,7 @@ namespace MWRender
osg::Vec3f focal, cameraPos; osg::Vec3f focal, cameraPos;
mCamera->getPosition(focal, cameraPos); mCamera->getPosition(focal, cameraPos);
mCurrentCameraPos = cameraPos;
if (mWater->isUnderwater(cameraPos)) if (mWater->isUnderwater(cameraPos))
{ {
setFogColor(mUnderwaterColor * mUnderwaterWeight + mFogColor * (1.f-mUnderwaterWeight)); setFogColor(mUnderwaterColor * mUnderwaterWeight + mFogColor * (1.f-mUnderwaterWeight));
@ -865,6 +866,11 @@ namespace MWRender
return mCamera.get(); return mCamera.get();
} }
const osg::Vec3f &RenderingManager::getCameraPosition() const
{
return mCurrentCameraPos;
}
void RenderingManager::togglePOV() void RenderingManager::togglePOV()
{ {
mCamera->toggleViewMode(); mCamera->toggleViewMode();

View file

@ -159,6 +159,7 @@ namespace MWRender
void resetCamera(); void resetCamera();
float getCameraDistance() const; float getCameraDistance() const;
Camera* getCamera(); Camera* getCamera();
const osg::Vec3f& getCameraPosition() const;
void togglePOV(); void togglePOV();
void togglePreviewMode(bool enable); void togglePreviewMode(bool enable);
bool toggleVanityMode(bool enable); bool toggleVanityMode(bool enable);
@ -188,6 +189,7 @@ namespace MWRender
std::auto_ptr<NpcAnimation> mPlayerAnimation; std::auto_ptr<NpcAnimation> mPlayerAnimation;
osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode; osg::ref_ptr<SceneUtil::PositionAttitudeTransform> mPlayerNode;
std::auto_ptr<Camera> mCamera; std::auto_ptr<Camera> mCamera;
osg::Vec3f mCurrentCameraPos;
osg::ref_ptr<StateUpdater> mStateUpdater; osg::ref_ptr<StateUpdater> mStateUpdater;

View file

@ -144,7 +144,9 @@ namespace MWScript
return; return;
} }
MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell(); MWWorld::CellStore *cell = MWMechanics::getPlayer().getCell();
if (cell->getCell()->hasWater()) if (cell->isExterior())
runtime.push(0.f); // vanilla oddity, return 0 even though water is actually at -1
else if (cell->getCell()->hasWater())
runtime.push (cell->getWaterLevel()); runtime.push (cell->getWaterLevel());
else else
runtime.push (-std::numeric_limits<float>::max()); runtime.push (-std::numeric_limits<float>::max());

View file

@ -946,16 +946,13 @@ namespace MWSound
mOutput->finishUpdate(); mOutput->finishUpdate();
} }
void SoundManager::setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up) void SoundManager::setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater)
{ {
mListenerPos = pos; mListenerPos = pos;
mListenerDir = dir; mListenerDir = dir;
mListenerUp = up; mListenerUp = up;
MWWorld::Ptr player = MWMechanics::getPlayer(); mListenerUnderwater = underwater;
const MWWorld::CellStore *cell = player.getCell();
mListenerUnderwater = ((cell->getCell()->mData.mFlags&ESM::Cell::HasWater) && mListenerPos.z() < cell->getWaterLevel());
} }
void SoundManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated) void SoundManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated)

View file

@ -218,7 +218,7 @@ namespace MWSound
virtual void update(float duration); virtual void update(float duration);
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up); virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up, bool underwater);
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated); virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);

View file

@ -296,6 +296,8 @@ namespace MWWorld
float CellStore::getWaterLevel() const float CellStore::getWaterLevel() const
{ {
if (isExterior())
return -1;
return mWaterLevel; return mWaterLevel;
} }

View file

@ -265,7 +265,7 @@ namespace MWWorld
mRendering.addCell(cell); mRendering.addCell(cell);
bool waterEnabled = cell->getCell()->hasWater() || cell->isExterior(); bool waterEnabled = cell->getCell()->hasWater() || cell->isExterior();
float waterLevel = cell->isExterior() ? -1.f : cell->getWaterLevel(); float waterLevel = cell->getWaterLevel();
mRendering.setWaterEnabled(waterEnabled); mRendering.setWaterEnabled(waterEnabled);
if (waterEnabled) if (waterEnabled)
{ {

View file

@ -1601,18 +1601,23 @@ namespace MWWorld
void World::updateSoundListener() void World::updateSoundListener()
{ {
const ESM::Position& refpos = getPlayerPtr().getRefData().getPosition(); const ESM::Position& refpos = getPlayerPtr().getRefData().getPosition();
osg::Vec3f playerPos = refpos.asVec3(); osg::Vec3f listenerPos;
playerPos.z() += 1.85f * mPhysics->getHalfExtents(getPlayerPtr()).z(); if (isFirstPerson())
listenerPos = mRendering->getCameraPosition();
else
listenerPos = refpos.asVec3() + osg::Vec3f(0, 0, 1.85f * mPhysics->getHalfExtents(getPlayerPtr()).z());
osg::Quat playerOrient = osg::Quat(refpos.rot[1], osg::Vec3f(0,-1,0)) * osg::Quat listenerOrient = osg::Quat(refpos.rot[1], osg::Vec3f(0,-1,0)) *
osg::Quat(refpos.rot[0], osg::Vec3f(-1,0,0)) * osg::Quat(refpos.rot[0], osg::Vec3f(-1,0,0)) *
osg::Quat(refpos.rot[2], osg::Vec3f(0,0,-1)); osg::Quat(refpos.rot[2], osg::Vec3f(0,0,-1));
osg::Vec3f forward = playerOrient * osg::Vec3f(0,1,0); osg::Vec3f forward = listenerOrient * osg::Vec3f(0,1,0);
osg::Vec3f up = playerOrient * osg::Vec3f(0,0,1); osg::Vec3f up = listenerOrient * osg::Vec3f(0,0,1);
MWBase::Environment::get().getSoundManager()->setListenerPosDir(playerPos, forward, up); bool underwater = isUnderwater(getPlayerPtr().getCell(), listenerPos);
MWBase::Environment::get().getSoundManager()->setListenerPosDir(listenerPos, forward, up, underwater);
} }
void World::updateWindowManager () void World::updateWindowManager ()