mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-01 00:32:52 +00:00
Readded sound listener
This commit is contained in:
parent
ccab8cc9a1
commit
7a3bc69df7
@ -7,11 +7,6 @@
|
|||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
|
||||||
namespace Ogre
|
|
||||||
{
|
|
||||||
class Vector3;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
class CellStore;
|
class CellStore;
|
||||||
@ -125,7 +120,7 @@ namespace MWBase
|
|||||||
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
||||||
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||||
|
|
||||||
virtual MWBase::SoundPtr playManualSound3D(const Ogre::Vector3& initialPos, const std::string& soundId,
|
virtual MWBase::SoundPtr playManualSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||||
float volume, float pitch, PlayType type, PlayMode mode, float offset=0) = 0;
|
float volume, float pitch, PlayType type, PlayMode mode, float offset=0) = 0;
|
||||||
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated manually using Sound::setPosition.
|
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated manually using Sound::setPosition.
|
||||||
|
|
||||||
@ -162,7 +157,7 @@ namespace MWBase
|
|||||||
|
|
||||||
virtual void update(float duration) = 0;
|
virtual void update(float duration) = 0;
|
||||||
|
|
||||||
virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up) = 0;
|
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up) = 0;
|
||||||
|
|
||||||
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0;
|
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated) = 0;
|
||||||
|
|
||||||
|
@ -802,6 +802,14 @@ namespace MWPhysics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Actor *PhysicsSystem::getActor(const MWWorld::Ptr &ptr)
|
||||||
|
{
|
||||||
|
ActorMap::iterator found = mActors.find(ptr);
|
||||||
|
if (found != mActors.end())
|
||||||
|
return found->second;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsSystem::updateScale(const MWWorld::Ptr &ptr)
|
void PhysicsSystem::updateScale(const MWWorld::Ptr &ptr)
|
||||||
{
|
{
|
||||||
ObjectMap::iterator found = mObjects.find(ptr);
|
ObjectMap::iterator found = mObjects.find(ptr);
|
||||||
|
@ -53,6 +53,11 @@ namespace MWPhysics
|
|||||||
void disableWater();
|
void disableWater();
|
||||||
|
|
||||||
void addObject (const MWWorld::Ptr& ptr, const std::string& mesh);
|
void addObject (const MWWorld::Ptr& ptr, const std::string& mesh);
|
||||||
|
void addActor (const MWWorld::Ptr& ptr, const std::string& mesh);
|
||||||
|
|
||||||
|
void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
|
||||||
|
|
||||||
|
Actor* getActor(const MWWorld::Ptr& ptr);
|
||||||
|
|
||||||
// Object or Actor
|
// Object or Actor
|
||||||
void remove (const MWWorld::Ptr& ptr);
|
void remove (const MWWorld::Ptr& ptr);
|
||||||
@ -61,9 +66,6 @@ namespace MWPhysics
|
|||||||
void updateRotation (const MWWorld::Ptr& ptr);
|
void updateRotation (const MWWorld::Ptr& ptr);
|
||||||
void updatePosition (const MWWorld::Ptr& ptr);
|
void updatePosition (const MWWorld::Ptr& ptr);
|
||||||
|
|
||||||
void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
|
|
||||||
|
|
||||||
void addActor (const MWWorld::Ptr& ptr, const std::string& mesh);
|
|
||||||
|
|
||||||
void addHeightField (float* heights, int x, int y, float triSize, float sqrtVerts);
|
void addHeightField (float* heights, int x, int y, float triSize, float sqrtVerts);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include <OgreSceneNode.h>
|
#include <osg/PositionAttitudeTransform>
|
||||||
|
|
||||||
#include <components/esm/loadcell.hpp>
|
#include <components/esm/loadcell.hpp>
|
||||||
|
|
||||||
@ -519,17 +519,17 @@ namespace MWScript
|
|||||||
for (int i=0; i<count; ++i)
|
for (int i=0; i<count; ++i)
|
||||||
{
|
{
|
||||||
ESM::Position ipos = actor.getRefData().getPosition();
|
ESM::Position ipos = actor.getRefData().getPosition();
|
||||||
Ogre::Vector3 pos(ipos.pos[0],ipos.pos[1],ipos.pos[2]);
|
osg::Vec3f pos(ipos.asVec3());
|
||||||
Ogre::Quaternion rot(Ogre::Radian(-ipos.rot[2]), Ogre::Vector3::UNIT_Z);
|
osg::Quat rot(ipos.rot[2], osg::Vec3f(0,0,-1));
|
||||||
if(direction == 0) pos = pos + distance*rot.yAxis();
|
if(direction == 0) pos = pos + (rot * osg::Vec3f(0,1,0)) * distance;
|
||||||
else if(direction == 1) pos = pos - distance*rot.yAxis();
|
else if(direction == 1) pos = pos - (rot * osg::Vec3f(0,1,0)) * distance;
|
||||||
else if(direction == 2) pos = pos - distance*rot.xAxis();
|
else if(direction == 2) pos = pos - (rot * osg::Vec3f(1,0,0)) * distance;
|
||||||
else if(direction == 3) pos = pos + distance*rot.xAxis();
|
else if(direction == 3) pos = pos + (rot * osg::Vec3f(1,0,0)) * distance;
|
||||||
else throw std::runtime_error ("direction must be 0,1,2 or 3");
|
else throw std::runtime_error ("direction must be 0,1,2 or 3");
|
||||||
|
|
||||||
ipos.pos[0] = pos.x;
|
ipos.pos[0] = pos.x();
|
||||||
ipos.pos[1] = pos.y;
|
ipos.pos[1] = pos.y();
|
||||||
ipos.pos[2] = pos.z;
|
ipos.pos[2] = pos.z();
|
||||||
|
|
||||||
if (actor.getClass().isActor())
|
if (actor.getClass().isActor())
|
||||||
{
|
{
|
||||||
@ -670,29 +670,30 @@ namespace MWScript
|
|||||||
Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
|
Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
|
||||||
runtime.pop();
|
runtime.pop();
|
||||||
|
|
||||||
Ogre::Vector3 posChange;
|
osg::Vec3f posChange;
|
||||||
if (axis == "x")
|
if (axis == "x")
|
||||||
{
|
{
|
||||||
posChange=Ogre::Vector3(movement, 0, 0);
|
posChange=osg::Vec3f(movement, 0, 0);
|
||||||
}
|
}
|
||||||
else if (axis == "y")
|
else if (axis == "y")
|
||||||
{
|
{
|
||||||
posChange=Ogre::Vector3(0, movement, 0);
|
posChange=osg::Vec3f(0, movement, 0);
|
||||||
}
|
}
|
||||||
else if (axis == "z")
|
else if (axis == "z")
|
||||||
{
|
{
|
||||||
posChange=Ogre::Vector3(0, 0, movement);
|
posChange=osg::Vec3f(0, 0, movement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw std::runtime_error ("invalid movement axis: " + axis);
|
throw std::runtime_error ("invalid movement axis: " + axis);
|
||||||
|
|
||||||
if (!ptr.getRefData().getBaseNodeOld())
|
// is it correct that disabled objects can't be Move-d?
|
||||||
|
if (!ptr.getRefData().getBaseNode())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Ogre::Vector3 diff = ptr.getRefData().getBaseNodeOld()->getOrientation() * posChange;
|
osg::Vec3f diff = ptr.getRefData().getBaseNode()->getAttitude() * posChange;
|
||||||
Ogre::Vector3 worldPos(ptr.getRefData().getPosition().pos);
|
osg::Vec3f worldPos(ptr.getRefData().getPosition().asVec3());
|
||||||
worldPos += diff;
|
worldPos += diff;
|
||||||
MWBase::Environment::get().getWorld()->moveObject(ptr, worldPos.x, worldPos.y, worldPos.z);
|
MWBase::Environment::get().getWorld()->moveObject(ptr, worldPos.x(), worldPos.y(), worldPos.z());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "loudness.hpp"
|
#include "loudness.hpp"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "soundmanagerimp.hpp"
|
#include "soundmanagerimp.hpp"
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
@ -28,7 +30,7 @@ namespace MWSound
|
|||||||
value = ((char)(data[sample*advance]^0x80))/128.f;
|
value = ((char)(data[sample*advance]^0x80))/128.f;
|
||||||
else if (type == SampleType_Int16)
|
else if (type == SampleType_Int16)
|
||||||
{
|
{
|
||||||
value = *reinterpret_cast<const Ogre::int16*>(&data[sample*advance]);
|
value = *reinterpret_cast<const uint16_t*>(&data[sample*advance]);
|
||||||
value /= float(std::numeric_limits<Ogre::int16>::max());
|
value /= float(std::numeric_limits<Ogre::int16>::max());
|
||||||
}
|
}
|
||||||
else if (type == SampleType_Float32)
|
else if (type == SampleType_Float32)
|
||||||
|
@ -271,7 +271,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder, float basevol, float pitch, int flags)
|
OpenAL_SoundStream::OpenAL_SoundStream(OpenAL_Output &output, ALuint src, DecoderPtr decoder, float basevol, float pitch, int flags)
|
||||||
: Sound(Ogre::Vector3(0.0f), 1.0f, basevol, pitch, 1.0f, 1000.0f, flags)
|
: Sound(osg::Vec3f(0.f, 0.f, 0.f), 1.0f, basevol, pitch, 1.0f, 1000.0f, flags)
|
||||||
, mOutput(output), mSource(src), mSamplesQueued(0), mDecoder(decoder), mIsFinished(true), mIsInitialBatchEnqueued(false)
|
, mOutput(output), mSource(src), mSamplesQueued(0), mDecoder(decoder), mIsFinished(true), mIsInitialBatchEnqueued(false)
|
||||||
{
|
{
|
||||||
throwALerror();
|
throwALerror();
|
||||||
@ -505,7 +505,7 @@ private:
|
|||||||
OpenAL_Sound& operator=(const OpenAL_Sound &rhs);
|
OpenAL_Sound& operator=(const OpenAL_Sound &rhs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf, const Ogre::Vector3& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags);
|
OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf, const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags);
|
||||||
virtual ~OpenAL_Sound();
|
virtual ~OpenAL_Sound();
|
||||||
|
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
@ -524,14 +524,14 @@ class OpenAL_Sound3D : public OpenAL_Sound
|
|||||||
OpenAL_Sound3D& operator=(const OpenAL_Sound &rhs);
|
OpenAL_Sound3D& operator=(const OpenAL_Sound &rhs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OpenAL_Sound3D(OpenAL_Output &output, ALuint src, ALuint buf, const Ogre::Vector3& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
OpenAL_Sound3D(OpenAL_Output &output, ALuint src, ALuint buf, const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
||||||
: OpenAL_Sound(output, src, buf, pos, vol, basevol, pitch, mindist, maxdist, flags)
|
: OpenAL_Sound(output, src, buf, pos, vol, basevol, pitch, mindist, maxdist, flags)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
OpenAL_Sound::OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf, const Ogre::Vector3& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
OpenAL_Sound::OpenAL_Sound(OpenAL_Output &output, ALuint src, ALuint buf, const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
||||||
: Sound(pos, vol, basevol, pitch, mindist, maxdist, flags)
|
: Sound(pos, vol, basevol, pitch, mindist, maxdist, flags)
|
||||||
, mOutput(output), mSource(src), mBuffer(buf)
|
, mOutput(output), mSource(src), mBuffer(buf)
|
||||||
{
|
{
|
||||||
@ -628,7 +628,7 @@ void OpenAL_Sound3D::update()
|
|||||||
{
|
{
|
||||||
ALfloat gain = mVolume*mBaseVolume;
|
ALfloat gain = mVolume*mBaseVolume;
|
||||||
ALfloat pitch = mPitch;
|
ALfloat pitch = mPitch;
|
||||||
if(mPos.squaredDistance(mOutput.mPos) > mMaxDistance*mMaxDistance)
|
if((mPos - mOutput.mPos).length2() > mMaxDistance*mMaxDistance)
|
||||||
gain = 0.0f;
|
gain = 0.0f;
|
||||||
else if(!(mFlags&MWBase::SoundManager::Play_NoEnv) && mOutput.mLastEnvironment == Env_Underwater)
|
else if(!(mFlags&MWBase::SoundManager::Play_NoEnv) && mOutput.mLastEnvironment == Env_Underwater)
|
||||||
{
|
{
|
||||||
@ -867,7 +867,7 @@ MWBase::SoundPtr OpenAL_Output::playSound(const std::string &fname, float vol, f
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
buf = getBuffer(fname).mALBuffer;
|
buf = getBuffer(fname).mALBuffer;
|
||||||
sound.reset(new OpenAL_Sound(*this, src, buf, Ogre::Vector3(0.0f), vol, basevol, pitch, 1.0f, 1000.0f, flags));
|
sound.reset(new OpenAL_Sound(*this, src, buf, osg::Vec3f(0.f, 0.f, 0.f), vol, basevol, pitch, 1.0f, 1000.0f, flags));
|
||||||
}
|
}
|
||||||
catch(std::exception&)
|
catch(std::exception&)
|
||||||
{
|
{
|
||||||
@ -892,7 +892,7 @@ MWBase::SoundPtr OpenAL_Output::playSound(const std::string &fname, float vol, f
|
|||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWBase::SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const Ogre::Vector3 &pos, float vol, float basevol, float pitch,
|
MWBase::SoundPtr OpenAL_Output::playSound3D(const std::string &fname, const osg::Vec3f &pos, float vol, float basevol, float pitch,
|
||||||
float min, float max, int flags, float offset, bool extractLoudness)
|
float min, float max, int flags, float offset, bool extractLoudness)
|
||||||
{
|
{
|
||||||
boost::shared_ptr<OpenAL_Sound> sound;
|
boost::shared_ptr<OpenAL_Sound> sound;
|
||||||
@ -967,7 +967,7 @@ MWBase::SoundPtr OpenAL_Output::streamSound(DecoderPtr decoder, float volume, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env)
|
void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env)
|
||||||
{
|
{
|
||||||
mPos = pos;
|
mPos = pos;
|
||||||
mLastEnvironment = env;
|
mLastEnvironment = env;
|
||||||
@ -975,10 +975,10 @@ void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3
|
|||||||
if(mContext)
|
if(mContext)
|
||||||
{
|
{
|
||||||
ALfloat orient[6] = {
|
ALfloat orient[6] = {
|
||||||
atdir.x, atdir.y, atdir.z,
|
atdir.x(), atdir.y(), atdir.z(),
|
||||||
updir.x, updir.y, updir.z
|
updir.x(), updir.y(), updir.z()
|
||||||
};
|
};
|
||||||
alListener3f(AL_POSITION, mPos.x, mPos.y, mPos.z);
|
alListener3f(AL_POSITION, mPos.x(), mPos.y(), mPos.z());
|
||||||
alListenerfv(AL_ORIENTATION, orient);
|
alListenerfv(AL_ORIENTATION, orient);
|
||||||
throwALerror();
|
throwALerror();
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,11 @@ namespace MWSound
|
|||||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||||
virtual MWBase::SoundPtr playSound(const std::string &fname, float vol, float basevol, float pitch, int flags, float offset);
|
virtual MWBase::SoundPtr playSound(const std::string &fname, float vol, float basevol, float pitch, int flags, float offset);
|
||||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||||
virtual MWBase::SoundPtr playSound3D(const std::string &fname, const Ogre::Vector3 &pos,
|
virtual MWBase::SoundPtr playSound3D(const std::string &fname, const osg::Vec3f &pos,
|
||||||
float vol, float basevol, float pitch, float min, float max, int flags, float offset, bool extractLoudness=false);
|
float vol, float basevol, float pitch, float min, float max, int flags, float offset, bool extractLoudness=false);
|
||||||
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float volume, float pitch, int flags);
|
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float volume, float pitch, int flags);
|
||||||
|
|
||||||
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env);
|
virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env);
|
||||||
|
|
||||||
virtual void pauseSounds(int types);
|
virtual void pauseSounds(int types);
|
||||||
virtual void resumeSounds(int types);
|
virtual void resumeSounds(int types);
|
||||||
|
@ -15,7 +15,7 @@ namespace MWSound
|
|||||||
Sound(const Sound &rhs);
|
Sound(const Sound &rhs);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Ogre::Vector3 mPos;
|
osg::Vec3f mPos;
|
||||||
float mVolume; /* NOTE: Real volume = mVolume*mBaseVolume */
|
float mVolume; /* NOTE: Real volume = mVolume*mBaseVolume */
|
||||||
float mBaseVolume;
|
float mBaseVolume;
|
||||||
float mPitch;
|
float mPitch;
|
||||||
@ -31,7 +31,7 @@ namespace MWSound
|
|||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
virtual bool isPlaying() = 0;
|
virtual bool isPlaying() = 0;
|
||||||
virtual double getTimeOffset() = 0;
|
virtual double getTimeOffset() = 0;
|
||||||
void setPosition(const Ogre::Vector3 &pos) { mPos = pos; }
|
void setPosition(const osg::Vec3f &pos) { mPos = pos; }
|
||||||
void setVolume(float volume) { mVolume = volume; }
|
void setVolume(float volume) { mVolume = volume; }
|
||||||
void setFadeout(float duration) { mFadeOutTime=duration; }
|
void setFadeout(float duration) { mFadeOutTime=duration; }
|
||||||
void setLoudnessVector(const std::vector<float>& loudnessVector, float loudnessFPS);
|
void setLoudnessVector(const std::vector<float>& loudnessVector, float loudnessFPS);
|
||||||
@ -44,7 +44,7 @@ namespace MWSound
|
|||||||
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
{ return (MWBase::SoundManager::PlayType)(mFlags&MWBase::SoundManager::Play_TypeMask); }
|
||||||
|
|
||||||
|
|
||||||
Sound(const Ogre::Vector3& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
Sound(const osg::Vec3f& pos, float vol, float basevol, float pitch, float mindist, float maxdist, int flags)
|
||||||
: mPos(pos)
|
: mPos(pos)
|
||||||
, mVolume(vol)
|
, mVolume(vol)
|
||||||
, mBaseVolume(basevol)
|
, mBaseVolume(basevol)
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <OgreVector3.h>
|
|
||||||
|
|
||||||
#include "soundmanagerimp.hpp"
|
#include "soundmanagerimp.hpp"
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
@ -27,11 +25,11 @@ namespace MWSound
|
|||||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||||
virtual MWBase::SoundPtr playSound(const std::string &fname, float vol, float basevol, float pitch, int flags, float offset) = 0;
|
virtual MWBase::SoundPtr playSound(const std::string &fname, float vol, float basevol, float pitch, int flags, float offset) = 0;
|
||||||
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
/// @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||||
virtual MWBase::SoundPtr playSound3D(const std::string &fname, const Ogre::Vector3 &pos,
|
virtual MWBase::SoundPtr playSound3D(const std::string &fname, const osg::Vec3f &pos,
|
||||||
float vol, float basevol, float pitch, float min, float max, int flags, float offset, bool extractLoudness=false) = 0;
|
float vol, float basevol, float pitch, float min, float max, int flags, float offset, bool extractLoudness=false) = 0;
|
||||||
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float volume, float pitch, int flags) = 0;
|
virtual MWBase::SoundPtr streamSound(DecoderPtr decoder, float volume, float pitch, int flags) = 0;
|
||||||
|
|
||||||
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env) = 0;
|
virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env) = 0;
|
||||||
|
|
||||||
virtual void pauseSounds(int types) = 0;
|
virtual void pauseSounds(int types) = 0;
|
||||||
virtual void resumeSounds(int types) = 0;
|
virtual void resumeSounds(int types) = 0;
|
||||||
@ -41,7 +39,7 @@ namespace MWSound
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool mInitialized;
|
bool mInitialized;
|
||||||
Ogre::Vector3 mPos;
|
osg::Vec3f mPos;
|
||||||
|
|
||||||
Sound_Output(SoundManager &mgr)
|
Sound_Output(SoundManager &mgr)
|
||||||
: mManager(mgr)
|
: mManager(mgr)
|
||||||
|
@ -268,7 +268,7 @@ namespace MWSound
|
|||||||
float basevol = volumeFromType(Play_TypeVoice);
|
float basevol = volumeFromType(Play_TypeVoice);
|
||||||
std::string filePath = "Sound/"+filename;
|
std::string filePath = "Sound/"+filename;
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
const ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const Ogre::Vector3 objpos(pos.pos);
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
|
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
static const float fAudioMinDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMinDistanceMult")->getFloat();
|
static const float fAudioMinDistanceMult = world->getStore().get<ESM::GameSetting>().find("fAudioMinDistanceMult")->getFloat();
|
||||||
@ -396,9 +396,9 @@ namespace MWSound
|
|||||||
float min, max;
|
float min, max;
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
std::string file = lookup(soundId, volume, min, max);
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
const ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const Ogre::Vector3 objpos(pos.pos);
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
|
|
||||||
if ((mode & Play_RemoveAtDistance) && mListenerPos.squaredDistance(objpos) > 2000*2000)
|
if ((mode & Play_RemoveAtDistance) && (mListenerPos-objpos).length2() > 2000*2000)
|
||||||
{
|
{
|
||||||
return MWBase::SoundPtr();
|
return MWBase::SoundPtr();
|
||||||
}
|
}
|
||||||
@ -416,7 +416,7 @@ namespace MWSound
|
|||||||
return sound;
|
return sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWBase::SoundPtr SoundManager::playManualSound3D(const Ogre::Vector3& initialPos, const std::string& soundId,
|
MWBase::SoundPtr SoundManager::playManualSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||||
float volume, float pitch, PlayType type, PlayMode mode, float offset)
|
float volume, float pitch, PlayType type, PlayMode mode, float offset)
|
||||||
{
|
{
|
||||||
MWBase::SoundPtr sound;
|
MWBase::SoundPtr sound;
|
||||||
@ -666,11 +666,11 @@ namespace MWSound
|
|||||||
if(!ptr.isEmpty())
|
if(!ptr.isEmpty())
|
||||||
{
|
{
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
const ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const Ogre::Vector3 objpos(pos.pos);
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
snditer->first->setPosition(objpos);
|
snditer->first->setPosition(objpos);
|
||||||
|
|
||||||
if ((snditer->first->mFlags & Play_RemoveAtDistance)
|
if ((snditer->first->mFlags & Play_RemoveAtDistance)
|
||||||
&& mListenerPos.squaredDistance(Ogre::Vector3(ptr.getRefData().getPosition().pos)) > 2000*2000)
|
&& (mListenerPos - ptr.getRefData().getPosition().asVec3()).length2() > 2000*2000)
|
||||||
{
|
{
|
||||||
mActiveSounds.erase(snditer++);
|
mActiveSounds.erase(snditer++);
|
||||||
continue;
|
continue;
|
||||||
@ -728,7 +728,7 @@ namespace MWSound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up)
|
void SoundManager::setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up)
|
||||||
{
|
{
|
||||||
mListenerPos = pos;
|
mListenerPos = pos;
|
||||||
mListenerDir = dir;
|
mListenerDir = dir;
|
||||||
@ -738,7 +738,7 @@ namespace MWSound
|
|||||||
MWBase::Environment::get().getWorld()->getPlayerPtr();
|
MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
const MWWorld::CellStore *cell = player.getCell();
|
const MWWorld::CellStore *cell = player.getCell();
|
||||||
|
|
||||||
mListenerUnderwater = ((cell->getCell()->mData.mFlags&ESM::Cell::HasWater) && mListenerPos.z < cell->getWaterLevel());
|
mListenerUnderwater = ((cell->getCell()->mData.mFlags&ESM::Cell::HasWater) && mListenerPos.z() < cell->getWaterLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated)
|
void SoundManager::updatePtr(const MWWorld::Ptr &old, const MWWorld::Ptr &updated)
|
||||||
|
@ -55,9 +55,9 @@ namespace MWSound
|
|||||||
MWBase::SoundPtr mUnderwaterSound;
|
MWBase::SoundPtr mUnderwaterSound;
|
||||||
|
|
||||||
bool mListenerUnderwater;
|
bool mListenerUnderwater;
|
||||||
Ogre::Vector3 mListenerPos;
|
osg::Vec3f mListenerPos;
|
||||||
Ogre::Vector3 mListenerDir;
|
osg::Vec3f mListenerDir;
|
||||||
Ogre::Vector3 mListenerUp;
|
osg::Vec3f mListenerUp;
|
||||||
|
|
||||||
int mPausedSoundTypes;
|
int mPausedSoundTypes;
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ namespace MWSound
|
|||||||
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified.
|
||||||
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
///< @param offset Value from [0,1] meaning from which fraction the sound the playback starts.
|
||||||
|
|
||||||
virtual MWBase::SoundPtr playManualSound3D(const Ogre::Vector3& initialPos, const std::string& soundId,
|
virtual MWBase::SoundPtr playManualSound3D(const osg::Vec3f& initialPos, const std::string& soundId,
|
||||||
float volume, float pitch, PlayType type, PlayMode mode, float offset=0);
|
float volume, float pitch, PlayType type, PlayMode mode, float offset=0);
|
||||||
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated manually using Sound::setPosition.
|
///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated manually using Sound::setPosition.
|
||||||
|
|
||||||
@ -171,7 +171,7 @@ namespace MWSound
|
|||||||
|
|
||||||
virtual void update(float duration);
|
virtual void update(float duration);
|
||||||
|
|
||||||
virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up);
|
virtual void setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up);
|
||||||
|
|
||||||
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
|
virtual void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add (const Ptr& itemPtr
|
|||||||
MWWorld::Ptr item = *it;
|
MWWorld::Ptr item = *it;
|
||||||
|
|
||||||
// we may have copied an item from the world, so reset a few things first
|
// we may have copied an item from the world, so reset a few things first
|
||||||
item.getRefData().setBaseNodeOld(NULL); // Especially important, otherwise scripts on the item could think that it's actually in a cell
|
item.getRefData().setBaseNode(NULL); // Especially important, otherwise scripts on the item could think that it's actually in a cell
|
||||||
ESM::Position pos;
|
ESM::Position pos;
|
||||||
pos.rot[0] = 0;
|
pos.rot[0] = 0;
|
||||||
pos.rot[1] = 0;
|
pos.rot[1] = 0;
|
||||||
|
@ -6,18 +6,14 @@
|
|||||||
#include <OgreVector3.h>
|
#include <OgreVector3.h>
|
||||||
|
|
||||||
#include <components/esm/effectlist.hpp>
|
#include <components/esm/effectlist.hpp>
|
||||||
#include <components/nifogre/ogrenifloader.hpp>
|
|
||||||
|
|
||||||
#include "../mwbase/soundmanager.hpp"
|
#include "../mwbase/soundmanager.hpp"
|
||||||
|
|
||||||
#include "ptr.hpp"
|
#include "ptr.hpp"
|
||||||
|
|
||||||
namespace OEngine
|
namespace MWPhysics
|
||||||
{
|
{
|
||||||
namespace Physic
|
class PhysicsSystem;
|
||||||
{
|
|
||||||
class PhysicEngine;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Loading
|
namespace Loading
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include "../mwclass/door.hpp"
|
#include "../mwclass/door.hpp"
|
||||||
|
|
||||||
#include "../mwphysics/physicssystem.hpp"
|
#include "../mwphysics/physicssystem.hpp"
|
||||||
|
#include "../mwphysics/actor.hpp"
|
||||||
|
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
#include "manualref.hpp"
|
#include "manualref.hpp"
|
||||||
@ -1314,7 +1315,7 @@ namespace MWWorld
|
|||||||
{
|
{
|
||||||
ESM::Position pos (ptr.getRefData().getPosition());
|
ESM::Position pos (ptr.getRefData().getPosition());
|
||||||
|
|
||||||
if(!ptr.getRefData().getBaseNodeOld())
|
if(!ptr.getRefData().getBaseNode())
|
||||||
{
|
{
|
||||||
// will be adjusted when Ptr's cell becomes active
|
// will be adjusted when Ptr's cell becomes active
|
||||||
return;
|
return;
|
||||||
@ -1596,9 +1597,9 @@ namespace MWWorld
|
|||||||
performUpdateSceneQueries ();
|
performUpdateSceneQueries ();
|
||||||
|
|
||||||
updateWindowManager ();
|
updateWindowManager ();
|
||||||
|
*/
|
||||||
updateSoundListener();
|
updateSoundListener();
|
||||||
|
/*
|
||||||
if (!paused && mPlayer->getPlayer().getCell()->isExterior())
|
if (!paused && mPlayer->getPlayer().getCell()->isExterior())
|
||||||
{
|
{
|
||||||
ESM::Position pos = mPlayer->getPlayer().getRefData().getPosition();
|
ESM::Position pos = mPlayer->getPlayer().getRefData().getPosition();
|
||||||
@ -1611,17 +1612,21 @@ namespace MWWorld
|
|||||||
|
|
||||||
void World::updateSoundListener()
|
void World::updateSoundListener()
|
||||||
{
|
{
|
||||||
/*
|
const ESM::Position& refpos = getPlayerPtr().getRefData().getPosition();
|
||||||
Ogre::Vector3 playerPos = mPlayer->getPlayer().getRefData().getBaseNodeOld()->getPosition();
|
osg::Vec3f playerPos = refpos.asVec3();
|
||||||
|
|
||||||
const OEngine::Physic::PhysicActor *actor = mPhysEngine->getCharacter(getPlayerPtr().getRefData().getHandle());
|
const MWPhysics::Actor* actor = mPhysics->getActor(getPlayerPtr());
|
||||||
if(actor) playerPos.z += 1.85f * actor->getHalfExtents().z;
|
if (actor)
|
||||||
Ogre::Quaternion playerOrient = Ogre::Quaternion(Ogre::Radian(getPlayerPtr().getRefData().getPosition().rot[2]), Ogre::Vector3::NEGATIVE_UNIT_Z) *
|
playerPos.z() += 1.85f * actor->getHalfExtents().z();
|
||||||
Ogre::Quaternion(Ogre::Radian(getPlayerPtr().getRefData().getPosition().rot[0]), Ogre::Vector3::NEGATIVE_UNIT_X) *
|
|
||||||
Ogre::Quaternion(Ogre::Radian(getPlayerPtr().getRefData().getPosition().rot[1]), Ogre::Vector3::NEGATIVE_UNIT_Y);
|
osg::Quat playerOrient = osg::Quat(refpos.rot[1], osg::Vec3f(0,-1,0)) *
|
||||||
MWBase::Environment::get().getSoundManager()->setListenerPosDir(playerPos, playerOrient.yAxis(),
|
osg::Quat(refpos.rot[0], osg::Vec3f(-1,0,0)) *
|
||||||
playerOrient.zAxis());
|
osg::Quat(refpos.rot[2], osg::Vec3f(0,0,-1));
|
||||||
*/
|
|
||||||
|
osg::Vec3f forward = playerOrient * osg::Vec3f(0,1,0);
|
||||||
|
osg::Vec3f up = playerOrient * osg::Vec3f(0,0,1);
|
||||||
|
|
||||||
|
MWBase::Environment::get().getSoundManager()->setListenerPosDir(playerPos, forward, up);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::updateWindowManager ()
|
void World::updateWindowManager ()
|
||||||
@ -1987,9 +1992,9 @@ namespace MWWorld
|
|||||||
&& isLevitationEnabled())
|
&& isLevitationEnabled())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
//const OEngine::Physic::PhysicActor *actor = 0;//mPhysEngine->getCharacter(ptr.getRefData().getHandle());
|
const MWPhysics::Actor* actor = mPhysics->getActor(ptr);
|
||||||
//if(!actor || !actor->getCollisionMode())
|
if(!actor || !actor->getCollisionMode())
|
||||||
// return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2027,10 +2032,10 @@ namespace MWWorld
|
|||||||
const float *fpos = object.getRefData().getPosition().pos;
|
const float *fpos = object.getRefData().getPosition().pos;
|
||||||
Ogre::Vector3 pos(fpos[0], fpos[1], fpos[2]);
|
Ogre::Vector3 pos(fpos[0], fpos[1], fpos[2]);
|
||||||
|
|
||||||
//const OEngine::Physic::PhysicActor *actor = 0;//mPhysEngine->getCharacter(object.getRefData().getHandle());
|
const MWPhysics::Actor* actor = mPhysics->getActor(object);
|
||||||
//if (actor)
|
if (actor)
|
||||||
{
|
{
|
||||||
// pos.z += heightRatio*2*actor->getHalfExtents().z;
|
pos.z += heightRatio*2*actor->getHalfExtents().z();
|
||||||
}
|
}
|
||||||
|
|
||||||
return isUnderwater(object.getCell(), pos);
|
return isUnderwater(object.getCell(), pos);
|
||||||
@ -2134,17 +2139,16 @@ namespace MWWorld
|
|||||||
CellStore *currentCell = mWorldScene->getCurrentCell();
|
CellStore *currentCell = mWorldScene->getCurrentCell();
|
||||||
|
|
||||||
Ptr player = mPlayer->getPlayer();
|
Ptr player = mPlayer->getPlayer();
|
||||||
//RefData &refdata = player.getRefData();
|
RefData &refdata = player.getRefData();
|
||||||
//Ogre::Vector3 playerPos(refdata.getPosition().pos);
|
Ogre::Vector3 playerPos(refdata.getPosition().pos);
|
||||||
|
|
||||||
/*
|
const MWPhysics::Actor* actor = mPhysics->getActor(player);
|
||||||
const OEngine::Physic::PhysicActor *physactor = mPhysEngine->getCharacter(refdata.getHandle());
|
if (!actor)
|
||||||
if (!physactor)
|
|
||||||
throw std::runtime_error("can't find player");
|
throw std::runtime_error("can't find player");
|
||||||
|
|
||||||
if((!physactor->getOnGround()&&physactor->getCollisionMode()) || isUnderwater(currentCell, playerPos) || isWalkingOnWater(player))
|
if((!actor->getOnGround()&&actor->getCollisionMode()) || isUnderwater(currentCell, playerPos) || isWalkingOnWater(player))
|
||||||
return 2;
|
return 2;
|
||||||
*/
|
|
||||||
if((currentCell->getCell()->mData.mFlags&ESM::Cell::NoSleep) ||
|
if((currentCell->getCell()->mData.mFlags&ESM::Cell::NoSleep) ||
|
||||||
player.getClass().getNpcStats(player).isWerewolf())
|
player.getClass().getNpcStats(player).isWerewolf())
|
||||||
return 1;
|
return 1;
|
||||||
@ -2359,9 +2363,10 @@ namespace MWWorld
|
|||||||
{
|
{
|
||||||
if (!targetActor.getRefData().isEnabled() || !actor.getRefData().isEnabled())
|
if (!targetActor.getRefData().isEnabled() || !actor.getRefData().isEnabled())
|
||||||
return false; // cannot get LOS unless both NPC's are enabled
|
return false; // cannot get LOS unless both NPC's are enabled
|
||||||
if (!targetActor.getRefData().getBaseNodeOld() || !targetActor.getRefData().getBaseNodeOld())
|
if (!targetActor.getRefData().getBaseNode() || !targetActor.getRefData().getBaseNode())
|
||||||
return false; // not in active cell
|
return false; // not in active cell
|
||||||
|
|
||||||
|
// TODO: move to PhysicsSystem
|
||||||
/*
|
/*
|
||||||
OEngine::Physic::PhysicActor* actor1 = mPhysEngine->getCharacter(actor.getRefData().getHandle());
|
OEngine::Physic::PhysicActor* actor1 = mPhysEngine->getCharacter(actor.getRefData().getHandle());
|
||||||
OEngine::Physic::PhysicActor* actor2 = mPhysEngine->getCharacter(targetActor.getRefData().getHandle());
|
OEngine::Physic::PhysicActor* actor2 = mPhysEngine->getCharacter(targetActor.getRefData().getHandle());
|
||||||
@ -2402,11 +2407,9 @@ namespace MWWorld
|
|||||||
|
|
||||||
void World::enableActorCollision(const MWWorld::Ptr& actor, bool enable)
|
void World::enableActorCollision(const MWWorld::Ptr& actor, bool enable)
|
||||||
{
|
{
|
||||||
/*
|
MWPhysics::Actor *physicActor = mPhysics->getActor(actor);
|
||||||
OEngine::Physic::PhysicActor *physicActor = 0;//mPhysEngine->getCharacter(actor.getRefData().getHandle());
|
|
||||||
if (physicActor)
|
if (physicActor)
|
||||||
physicActor->enableCollisionBody(enable);
|
physicActor->enableCollisionBody(enable);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::findInteriorPosition(const std::string &name, ESM::Position &pos)
|
bool World::findInteriorPosition(const std::string &name, ESM::Position &pos)
|
||||||
@ -3261,9 +3264,9 @@ namespace MWWorld
|
|||||||
{
|
{
|
||||||
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager();
|
||||||
if(!effect->mAreaSound.empty())
|
if(!effect->mAreaSound.empty())
|
||||||
sndMgr->playManualSound3D(origin, effect->mAreaSound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoTrack);
|
sndMgr->playManualSound3D(osg::Vec3f(origin.x, origin.y, origin.z), effect->mAreaSound, 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoTrack);
|
||||||
else
|
else
|
||||||
sndMgr->playManualSound3D(origin, schools[effect->mData.mSchool]+" area", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoTrack);
|
sndMgr->playManualSound3D(osg::Vec3f(origin.x, origin.y, origin.z), schools[effect->mData.mSchool]+" area", 1.0f, 1.0f, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoTrack);
|
||||||
}
|
}
|
||||||
// Get the actors in range of the effect
|
// Get the actors in range of the effect
|
||||||
std::vector<MWWorld::Ptr> objects;
|
std::vector<MWWorld::Ptr> objects;
|
||||||
@ -3348,12 +3351,9 @@ namespace MWWorld
|
|||||||
|
|
||||||
bool World::isWalkingOnWater(const Ptr &actor)
|
bool World::isWalkingOnWater(const Ptr &actor)
|
||||||
{
|
{
|
||||||
return false;
|
MWPhysics::Actor* physicActor = mPhysics->getActor(actor);
|
||||||
/*
|
|
||||||
OEngine::Physic::PhysicActor* physicActor = mPhysEngine->getCharacter(actor.getRefData().getHandle());
|
|
||||||
if (physicActor && physicActor->isWalkingOnWater())
|
if (physicActor && physicActor->isWalkingOnWater())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user