SoundManager dependency on camera pos/dir

actorid
greye 13 years ago
parent 181d45661f
commit b5bc7bc424

@ -3,9 +3,13 @@
#include <OgreSceneNode.h>
#include <OgreCamera.h>
#include "../mwbase/environment.hpp"
#include "../mwworld/ptr.hpp"
#include "../mwworld/refdata.hpp"
#include "../mwsound/soundmanager.hpp"
namespace MWRender
{
Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node)
@ -33,6 +37,7 @@ namespace MWRender
yawNode->setOrientation(yr);
controlFlip();
updateListener();
return !mVanityModeEnabled;
}
@ -56,6 +61,7 @@ namespace MWRender
yawNode->yaw(Ogre::Degree(-rot.z));
controlFlip();
updateListener();
return !mVanityModeEnabled;
}
@ -81,4 +87,16 @@ namespace MWRender
}
}
}
void Player::updateListener()
{
Ogre::Vector3 pos = mCamera->getRealPosition();
Ogre::Vector3 dir = mCamera->getRealDirection();
Ogre::Real xch;
xch = pos.y, pos.y = -pos.z, pos.z = xch;
xch = dir.y, dir.y = -dir.z, dir.z = xch;
MWBase::Environment::get().getSoundManager()->setListenerPosDir(pos, dir);
}
}

@ -28,6 +28,7 @@ namespace MWRender
bool mVanityModeEnabled;
void controlFlip();
void updateListener();
public:

@ -4,8 +4,6 @@
#include <algorithm>
#include <map>
#include <OgreRoot.h>
#include <components/esm_store/store.hpp>
#include "../mwbase/environment.hpp"
@ -492,34 +490,17 @@ namespace MWSound
MWWorld::Ptr player =
MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
const ESM::Cell *cell = player.getCell()->cell;
// Ogre::Camera *cam = MWBase::Environment::get().getWorld()->getPlayer().getRenderer()->getCamera();
Ogre::Vector3 pos, at, up = Ogre::Vector3::UNIT_Z;
float *fval = player.getRefData().getPosition().pos;
pos.x = fval[0], pos.y = fval[1], pos.z = fval[2];
fval = player.getRefData().getPosition().rot;
at.x = fval[0], at.y = fval[1], at.z = fval[2];
/*
nPos = cam->getRealPosition();
nDir = cam->getRealDirection();
nUp = cam->getRealUp();
*/
Environment env = Env_Normal;
if((cell->data.flags&cell->HasWater) && pos.z < cell->water)
if((cell->data.flags&cell->HasWater) && mListenerPos.z < cell->water)
env = Env_Underwater;
// 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.
/*
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, env);
mOutput->updateListener(
mListenerPos,
mListenerDir,
Ogre::Vector3::UNIT_Z,
env
);
// Check if any sounds are finished playing, and trash them
SoundMap::iterator snditer = mActiveSounds.begin();
@ -577,6 +558,12 @@ namespace MWSound
}
}
void SoundManager::setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir)
{
mListenerPos = pos;
mListenerDir = dir;
}
// Default readAll implementation, for decoders that can't do anything
// better
void Sound_Decoder::readAll(std::vector<char> &output)

@ -7,19 +7,13 @@
#include <boost/shared_ptr.hpp>
#include <OgreVector3.h>
#include <OgreResourceGroupManager.h>
#include <components/settings/settings.hpp>
#include "../mwworld/ptr.hpp"
namespace Ogre
{
class Root;
class Camera;
}
namespace MWSound
{
class Sound_Output;
@ -68,6 +62,9 @@ namespace MWSound
typedef std::map<SoundPtr,PtrIDPair> SoundMap;
SoundMap mActiveSounds;
Ogre::Vector3 mListenerPos;
Ogre::Vector3 mListenerDir;
std::string lookup(const std::string &soundId,
float &volume, float &min, float &max);
void streamMusicFull(const std::string& filename);
@ -145,6 +142,8 @@ namespace MWSound
///< Update the position of all sounds connected to the given object.
void update(float duration);
void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir);
};
}

Loading…
Cancel
Save