In first person mode, attach sound listener to the camera

openmw-38
scrawl 9 years ago
parent 77965501d4
commit 86881bcf39

@ -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;

@ -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();

@ -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;

@ -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)

@ -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);

@ -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);
bool underwater = isUnderwater(getPlayerPtr().getCell(), listenerPos);
MWBase::Environment::get().getSoundManager()->setListenerPosDir(playerPos, forward, up); MWBase::Environment::get().getSoundManager()->setListenerPosDir(listenerPos, forward, up, underwater);
} }
void World::updateWindowManager () void World::updateWindowManager ()

Loading…
Cancel
Save