mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 18:45:34 +00:00
SoundManager dependency on camera pos/dir
This commit is contained in:
parent
181d45661f
commit
b5bc7bc424
4 changed files with 38 additions and 33 deletions
|
@ -3,9 +3,13 @@
|
||||||
#include <OgreSceneNode.h>
|
#include <OgreSceneNode.h>
|
||||||
#include <OgreCamera.h>
|
#include <OgreCamera.h>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
#include "../mwworld/refdata.hpp"
|
#include "../mwworld/refdata.hpp"
|
||||||
|
|
||||||
|
#include "../mwsound/soundmanager.hpp"
|
||||||
|
|
||||||
namespace MWRender
|
namespace MWRender
|
||||||
{
|
{
|
||||||
Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node)
|
Player::Player (Ogre::Camera *camera, Ogre::SceneNode* node)
|
||||||
|
@ -33,6 +37,7 @@ namespace MWRender
|
||||||
yawNode->setOrientation(yr);
|
yawNode->setOrientation(yr);
|
||||||
|
|
||||||
controlFlip();
|
controlFlip();
|
||||||
|
updateListener();
|
||||||
|
|
||||||
return !mVanityModeEnabled;
|
return !mVanityModeEnabled;
|
||||||
}
|
}
|
||||||
|
@ -56,6 +61,7 @@ namespace MWRender
|
||||||
yawNode->yaw(Ogre::Degree(-rot.z));
|
yawNode->yaw(Ogre::Degree(-rot.z));
|
||||||
|
|
||||||
controlFlip();
|
controlFlip();
|
||||||
|
updateListener();
|
||||||
|
|
||||||
return !mVanityModeEnabled;
|
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;
|
bool mVanityModeEnabled;
|
||||||
|
|
||||||
void controlFlip();
|
void controlFlip();
|
||||||
|
void updateListener();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <OgreRoot.h>
|
|
||||||
|
|
||||||
#include <components/esm_store/store.hpp>
|
#include <components/esm_store/store.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
@ -492,34 +490,17 @@ namespace MWSound
|
||||||
MWWorld::Ptr player =
|
MWWorld::Ptr player =
|
||||||
MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
const ESM::Cell *cell = player.getCell()->cell;
|
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;
|
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;
|
env = Env_Underwater;
|
||||||
|
|
||||||
// The output handler is expecting vectors oriented like the game
|
mOutput->updateListener(
|
||||||
// (that is, -Z goes down, +Y goes forward), but that's not what we
|
mListenerPos,
|
||||||
// get from Ogre's camera, so we have to convert.
|
mListenerDir,
|
||||||
/*
|
Ogre::Vector3::UNIT_Z,
|
||||||
const Ogre::Vector3 pos(nPos[0], -nPos[2], nPos[1]);
|
env
|
||||||
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);
|
|
||||||
|
|
||||||
// Check if any sounds are finished playing, and trash them
|
// Check if any sounds are finished playing, and trash them
|
||||||
SoundMap::iterator snditer = mActiveSounds.begin();
|
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
|
// Default readAll implementation, for decoders that can't do anything
|
||||||
// better
|
// better
|
||||||
void Sound_Decoder::readAll(std::vector<char> &output)
|
void Sound_Decoder::readAll(std::vector<char> &output)
|
||||||
|
|
|
@ -7,19 +7,13 @@
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
|
#include <OgreVector3.h>
|
||||||
#include <OgreResourceGroupManager.h>
|
#include <OgreResourceGroupManager.h>
|
||||||
|
|
||||||
#include <components/settings/settings.hpp>
|
#include <components/settings/settings.hpp>
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace Ogre
|
|
||||||
{
|
|
||||||
class Root;
|
|
||||||
class Camera;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
class Sound_Output;
|
class Sound_Output;
|
||||||
|
@ -68,6 +62,9 @@ namespace MWSound
|
||||||
typedef std::map<SoundPtr,PtrIDPair> SoundMap;
|
typedef std::map<SoundPtr,PtrIDPair> SoundMap;
|
||||||
SoundMap mActiveSounds;
|
SoundMap mActiveSounds;
|
||||||
|
|
||||||
|
Ogre::Vector3 mListenerPos;
|
||||||
|
Ogre::Vector3 mListenerDir;
|
||||||
|
|
||||||
std::string lookup(const std::string &soundId,
|
std::string lookup(const std::string &soundId,
|
||||||
float &volume, float &min, float &max);
|
float &volume, float &min, float &max);
|
||||||
void streamMusicFull(const std::string& filename);
|
void streamMusicFull(const std::string& filename);
|
||||||
|
@ -145,6 +142,8 @@ namespace MWSound
|
||||||
///< Update the position of all sounds connected to the given object.
|
///< Update the position of all sounds connected to the given object.
|
||||||
|
|
||||||
void update(float duration);
|
void update(float duration);
|
||||||
|
|
||||||
|
void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue