From fc167dbc83b6312433d1469ec8222f22ac47e10b Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 30 Mar 2012 11:42:11 -0700 Subject: [PATCH] Pass Ogre Vector3s to playSound3D and updateListener --- apps/openmw/mwsound/openal_output.cpp | 16 ++++++++-------- apps/openmw/mwsound/openal_output.hpp | 6 +++--- apps/openmw/mwsound/sound_output.hpp | 6 +++--- apps/openmw/mwsound/soundmanager.cpp | 16 +++++++++------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index da1de3d14..9fda1470c 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -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(); } diff --git a/apps/openmw/mwsound/openal_output.hpp b/apps/openmw/mwsound/openal_output.hpp index f37f72cab..f4d4e90af 100644 --- a/apps/openmw/mwsound/openal_output.hpp +++ b/apps/openmw/mwsound/openal_output.hpp @@ -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); diff --git a/apps/openmw/mwsound/sound_output.hpp b/apps/openmw/mwsound/sound_output.hpp index e54f9016d..ed3dda2f3 100644 --- a/apps/openmw/mwsound/sound_output.hpp +++ b/apps/openmw/mwsound/sound_output.hpp @@ -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); diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index da7cb9d3b..005df3e7e 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -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