mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-05 06:40:09 +00:00
Added convenience classes for connecting sound to Ogre
This commit is contained in:
parent
c7b179d654
commit
4692375491
@ -15,15 +15,15 @@ namespace Input {
|
||||
{
|
||||
Mangle::Input::Driver &driver;
|
||||
|
||||
ExitListener(Mangle::Input::Driver &drv)
|
||||
OgreInputCapture(Mangle::Input::Driver &drv)
|
||||
: driver(drv) {}
|
||||
|
||||
bool frameStarted(const FrameEvent &evt)
|
||||
bool frameStarted(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
driver.capture();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
69
sound/clients/ogre_listener_mover.hpp
Normal file
69
sound/clients/ogre_listener_mover.hpp
Normal file
@ -0,0 +1,69 @@
|
||||
#ifndef MANGLE_SOUND_OGRELISTENERMOVER_H
|
||||
#define MANGLE_SOUND_OGRELISTENERMOVER_H
|
||||
|
||||
#include <OgreCamera.h>
|
||||
#include <assert.h>
|
||||
#include "../output.hpp"
|
||||
|
||||
namespace Mangle {
|
||||
namespace Sound {
|
||||
|
||||
/** This class lets a sound listener (ie. the SoundFactory) track a
|
||||
given camera in Ogre3D. The poisition and orientation of the
|
||||
listener will be updated to match the camera whenever the camera
|
||||
is moved.
|
||||
*/
|
||||
struct OgreListenerMover : Ogre::Camera::Listener
|
||||
{
|
||||
OgreListenerMover(Mangle::Sound::SoundFactoryPtr snd)
|
||||
: soundFact(snd), camera(NULL)
|
||||
{}
|
||||
|
||||
/// Follow a camera. WARNING: This will OVERRIDE any other
|
||||
/// MovableObject::Listener you may have attached to the camera.
|
||||
void followCamera(Ogre::Camera *cam)
|
||||
{
|
||||
camera = cam;
|
||||
camera->addListener(this);
|
||||
}
|
||||
|
||||
private:
|
||||
Mangle::Sound::SoundFactoryPtr soundFact;
|
||||
Ogre::Camera *camera;
|
||||
Ogre::Vector3 pos, dir, up;
|
||||
|
||||
/// From Camera::Listener. This is called once per
|
||||
/// frame. Unfortunately, Ogre doesn't allow us to be notified
|
||||
/// only when the camera itself has moved, so we must poll every
|
||||
/// frame.
|
||||
void cameraPreRenderScene(Ogre::Camera *cam)
|
||||
{
|
||||
assert(cam == camera);
|
||||
|
||||
Ogre::Vector3 nPos, nDir, nUp;
|
||||
|
||||
nPos = camera->getPosition();
|
||||
nDir = camera->getDirection();
|
||||
nUp = camera->getUp();
|
||||
|
||||
// Don't bother the sound system needlessly
|
||||
if(nDir != dir || nPos != pos || nUp != up)
|
||||
{
|
||||
pos = nPos;
|
||||
dir = nDir;
|
||||
up = nUp;
|
||||
|
||||
soundFact->setListenerPos(pos.x, pos.y, pos.z,
|
||||
dir.x, dir.y, dir.z,
|
||||
up.x, up.y, up.z);
|
||||
}
|
||||
}
|
||||
|
||||
void cameraDestroyed(Ogre::Camera *cam)
|
||||
{
|
||||
assert(cam == camera);
|
||||
camera = NULL;
|
||||
}
|
||||
};
|
||||
}}
|
||||
#endif
|
31
sound/clients/ogre_output_updater.hpp
Normal file
31
sound/clients/ogre_output_updater.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MANGLE_SOUND_OGREUPDATER_H
|
||||
#define MANGLE_SOUND_OGREUPDATER_H
|
||||
|
||||
/*
|
||||
This Ogre FrameListener calls update on a SoundFactory
|
||||
*/
|
||||
|
||||
#include <OgreFrameListener.h>
|
||||
#include "../output.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Mangle {
|
||||
namespace Sound {
|
||||
|
||||
struct OgreOutputUpdater : Ogre::FrameListener
|
||||
{
|
||||
Mangle::Sound::SoundFactory &driver;
|
||||
|
||||
OgreOutputUpdater(Mangle::Sound::SoundFactory &drv)
|
||||
: driver(drv)
|
||||
{ assert(drv.needsUpdate); }
|
||||
|
||||
bool frameStarted(const Ogre::FrameEvent &evt)
|
||||
{
|
||||
driver.update();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user