mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-22 07:53:52 +00:00
Keep the sound output's listener updated with the camera position
This commit is contained in:
parent
2dabdcb9e5
commit
a46f8ced05
3 changed files with 25 additions and 6 deletions
|
@ -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])
|
||||
{
|
||||
alListener3f(AL_POSITION, pos[0], pos[2], -pos[1]);
|
||||
ALfloat orient[6] = {
|
||||
atdir[0], atdir[2], -atdir[1],
|
||||
updir[0], updir[2], -updir[1]
|
||||
};
|
||||
float orient[6] = { atdir[0], atdir[1], atdir[2], updir[0], updir[1], updir[2] };
|
||||
alListenerfv(AL_POSITION, pos);
|
||||
alListenerfv(AL_ORIENTATION, orient);
|
||||
throwALerror();
|
||||
}
|
||||
|
|
|
@ -305,7 +305,7 @@ namespace MWSound
|
|||
updatePositions(ptr);
|
||||
}
|
||||
|
||||
void SoundManager::update(float duration)
|
||||
void SoundManager::updateRegionSound(float duration)
|
||||
{
|
||||
MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell();
|
||||
static int total = 0;
|
||||
|
@ -363,4 +363,25 @@ namespace MWSound
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ namespace MWSound
|
|||
bool isPlaying(MWWorld::Ptr ptr, const std::string &id) const;
|
||||
void removeCell(const MWWorld::Ptr::CellStore *cell);
|
||||
void updatePositions(MWWorld::Ptr ptr);
|
||||
void updateRegionSound(float duration);
|
||||
|
||||
public:
|
||||
SoundManager(Ogre::Root*, Ogre::Camera*,
|
||||
|
|
Loading…
Reference in a new issue