Pass Ogre Vector3s to playSound3D and updateListener

actorid
Chris Robinson 13 years ago
parent fefc8f86ab
commit fc167dbc83

@ -616,7 +616,7 @@ SoundPtr OpenAL_Output::playSound(const std::string &fname, float volume, float
return sound;
}
SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector3 &pos, float volume, float pitch,
float min, float max, bool loop)
{
throwALerror();
@ -643,7 +643,7 @@ SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const float *pos,
throw;
}
alSource3f(src, AL_POSITION, pos[0], pos[2], -pos[1]);
alSource3f(src, AL_POSITION, pos.x, pos.z, -pos.y);
alSource3f(src, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
alSource3f(src, AL_VELOCITY, 0.0f, 0.0f, 0.0f);
@ -710,15 +710,15 @@ SoundPtr OpenAL_Output::streamSound(const std::string &fname, float volume, floa
}
void OpenAL_Output::updateListener(const float *pos, const float *atdir, const float *updir)
void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir)
{
float orient[6] = {
atdir[0], atdir[2], -atdir[1],
updir[0], updir[2], -updir[1]
ALfloat orient[6] = {
atdir.x, atdir.z, -atdir.y,
updir.x, updir.z, -updir.y
};
mPos = Ogre::Vector3(pos[0], pos[1], pos[2]);
mPos = pos;
alListener3f(AL_POSITION, mPos[0], mPos[2], -mPos[1]);
alListener3f(AL_POSITION, mPos.x, mPos.z, -mPos.y);
alListenerfv(AL_ORIENTATION, orient);
throwALerror();
}

@ -41,11 +41,11 @@ namespace MWSound
virtual void deinit();
virtual SoundPtr playSound(const std::string &fname, float volume, float pitch, bool loop);
virtual SoundPtr playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop);
virtual SoundPtr playSound3D(const std::string &fname, const Ogre::Vector3 &pos,
float volume, float pitch, float min, float max, bool loop);
virtual SoundPtr streamSound(const std::string &fname, float volume, float pitch);
virtual void updateListener(const float *pos, const float *atdir, const float *updir);
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir);
OpenAL_Output& operator=(const OpenAL_Output &rhs);
OpenAL_Output(const OpenAL_Output &rhs);

@ -25,11 +25,11 @@ namespace MWSound
virtual void deinit() = 0;
virtual SoundPtr playSound(const std::string &fname, float volume, float pitch, bool loop) = 0;
virtual SoundPtr playSound3D(const std::string &fname, const float *pos, float volume, float pitch,
float min, float max, bool loop) = 0;
virtual SoundPtr playSound3D(const std::string &fname, const Ogre::Vector3 &pos,
float volume, float pitch, float min, float max, bool loop) = 0;
virtual SoundPtr streamSound(const std::string &fname, float volume, float pitch) = 0;
virtual void updateListener(const float *pos, const float *atdir, const float *updir) = 0;
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir) = 0;
Sound_Output& operator=(const Sound_Output &rhs);
Sound_Output(const Sound_Output &rhs);

@ -184,10 +184,11 @@ namespace MWSound
float basevol = 1.0f; /* TODO: volume settings */
std::string filePath = "Sound/"+filename;
const ESM::Position &pos = ptr.getCellRef().pos;
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
SoundPtr sound = mOutput->playSound3D(filePath, pos.pos, basevol, 1.0f,
SoundPtr sound = mOutput->playSound3D(filePath, objpos, basevol, 1.0f,
20.0f, 12750.0f, false);
sound->mPos = Ogre::Vector3(pos.pos[0], pos.pos[1], pos.pos[2]);
sound->mPos = objpos;
sound->mBaseVolume = basevol;
mActiveSounds[sound] = std::make_pair(ptr, std::string("_say_sound"));
@ -240,9 +241,10 @@ namespace MWSound
float min, max;
std::string file = lookup(soundId, basevol, min, max);
const ESM::Position &pos = ptr.getCellRef().pos;
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
sound = mOutput->playSound3D(file, pos.pos, volume*basevol, pitch, min, max, loop);
sound->mPos = Ogre::Vector3(pos.pos[0], pos.pos[1], pos.pos[2]);
sound = mOutput->playSound3D(file, objpos, volume*basevol, pitch, min, max, loop);
sound->mPos = objpos;
sound->mVolume = volume;
sound->mBaseVolume = basevol;
sound->mMinDistance = min;
@ -414,9 +416,9 @@ namespace MWSound
// The output handler is expecting vectors oriented like the game
// (that is, -Z goes down, +Y goes forward), but that's not what we
// get from Ogre's camera, so we have to convert.
float pos[3] = { nPos[0], -nPos[2], nPos[1] };
float at[3] = { nDir[0], -nDir[2], nDir[1] };
float up[3] = { nUp[0], -nUp[2], nUp[1] };
const Ogre::Vector3 pos(nPos[0], -nPos[2], nPos[1]);
const Ogre::Vector3 at(nDir[0], -nDir[2], nDir[1]);
const Ogre::Vector3 up(nUp[0], -nUp[2], nUp[1]);
mOutput->updateListener(pos, at, up);
// Check if any sounds are finished playing, and trash them

Loading…
Cancel
Save