1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-22 13:23:55 +00:00

Keep the sound output's listener updated with the camera position

This commit is contained in:
Chris Robinson 2012-03-17 06:18:59 -07:00
parent 2dabdcb9e5
commit a46f8ced05
3 changed files with 25 additions and 6 deletions

View file

@ -245,11 +245,8 @@ Sound* OpenAL_Output::StreamSound(const std::string &fname, std::auto_ptr<Sound_
void OpenAL_Output::UpdateListener(float pos[3], float atdir[3], float updir[3]) void OpenAL_Output::UpdateListener(float pos[3], float atdir[3], float updir[3])
{ {
alListener3f(AL_POSITION, pos[0], pos[2], -pos[1]); float orient[6] = { atdir[0], atdir[1], atdir[2], updir[0], updir[1], updir[2] };
ALfloat orient[6] = { alListenerfv(AL_POSITION, pos);
atdir[0], atdir[2], -atdir[1],
updir[0], updir[2], -updir[1]
};
alListenerfv(AL_ORIENTATION, orient); alListenerfv(AL_ORIENTATION, orient);
throwALerror(); throwALerror();
} }

View file

@ -305,7 +305,7 @@ namespace MWSound
updatePositions(ptr); updatePositions(ptr);
} }
void SoundManager::update(float duration) void SoundManager::updateRegionSound(float duration)
{ {
MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell();
static int total = 0; static int total = 0;
@ -363,4 +363,25 @@ namespace MWSound
pos += chance; pos += chance;
} }
} }
void SoundManager::update(float duration)
{
static float timePassed = 0.0;
timePassed += duration;
if(timePassed > (1.0f/30.0f))
{
timePassed = 0.0f;
Ogre::Camera *cam = mEnvironment.mWorld->getPlayer().getRenderer()->getCamera();
Ogre::Vector3 nPos, nDir, nUp;
nPos = cam->getRealPosition();
nDir = cam->getRealDirection();
nUp = cam->getRealUp();
Output->UpdateListener(&nPos[0], &nDir[0], &nUp[0]);
}
updateRegionSound(duration);
}
} }

View file

@ -62,6 +62,7 @@ namespace MWSound
bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const; bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const;
void removeCell(const MWWorld::Ptr::CellStore *cell); void removeCell(const MWWorld::Ptr::CellStore *cell);
void updatePositions(MWWorld::Ptr ptr); void updatePositions(MWWorld::Ptr ptr);
void updateRegionSound(float duration);
public: public:
SoundManager(Ogre::Root*, Ogre::Camera*, SoundManager(Ogre::Root*, Ogre::Camera*,