add the option to tie a SampleGroup to the listener position and orientation
This commit is contained in:
@@ -44,10 +44,9 @@ extern "C" int isinf (double);
|
||||
SGSampleGroup::SGSampleGroup () :
|
||||
_smgr(NULL),
|
||||
_active(false),
|
||||
_changed(true),
|
||||
_position_changed(true),
|
||||
_position(SGVec3d::zeros().data()),
|
||||
_orientation(SGVec3f::zeros().data())
|
||||
_orientation(SGVec3f::zeros().data()),
|
||||
_tied_to_listener(false)
|
||||
{
|
||||
_samples.clear();
|
||||
}
|
||||
@@ -55,10 +54,9 @@ SGSampleGroup::SGSampleGroup () :
|
||||
SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
|
||||
_smgr(smgr),
|
||||
_active(false),
|
||||
_changed(true),
|
||||
_position_changed(true),
|
||||
_position(SGVec3d::zeros().data()),
|
||||
_orientation(SGVec3f::zeros().data())
|
||||
_orientation(SGVec3f::zeros().data()),
|
||||
_tied_to_listener(false)
|
||||
{
|
||||
_smgr->add(this, refname);
|
||||
_active = _smgr->is_working();
|
||||
@@ -134,6 +132,12 @@ void SGSampleGroup::update( double dt ) {
|
||||
sample->set_buffer(buffer);
|
||||
}
|
||||
|
||||
if ( _tied_to_listener && _smgr->has_changed() ) {
|
||||
sample->set_base_position( _smgr->get_position_vec() );
|
||||
sample->set_orientation( _smgr->get_direction() );
|
||||
sample->set_velocity( _smgr->get_velocity() );
|
||||
}
|
||||
|
||||
// start playing the sample
|
||||
ALuint buffer = sample->get_buffer();
|
||||
ALuint source = _smgr->request_source();
|
||||
@@ -324,11 +328,13 @@ void SGSampleGroup::set_position( SGVec3d pos ) {
|
||||
return;
|
||||
}
|
||||
|
||||
sample_map_iterator sample_current = _samples.begin();
|
||||
sample_map_iterator sample_end = _samples.end();
|
||||
for ( ; sample_current != sample_end; ++sample_current ) {
|
||||
SGSoundSample *sample = sample_current->second;
|
||||
sample->set_base_position( pos );
|
||||
if ( !_tied_to_listener ) {
|
||||
sample_map_iterator sample_current = _samples.begin();
|
||||
sample_map_iterator sample_end = _samples.end();
|
||||
for ( ; sample_current != sample_end; ++sample_current ) {
|
||||
SGSoundSample *sample = sample_current->second;
|
||||
sample->set_base_position( pos );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -156,18 +156,18 @@ public:
|
||||
*/
|
||||
void load_file(SGSoundSample *sound);
|
||||
|
||||
inline void tie_to_listener() { _tied_to_listener = true; }
|
||||
|
||||
|
||||
protected:
|
||||
SGSoundMgr *_smgr;
|
||||
bool _active;
|
||||
|
||||
private:
|
||||
bool _changed;
|
||||
bool _position_changed;
|
||||
|
||||
float _volume;
|
||||
|
||||
SGVec3d _position;
|
||||
SGVec3f _orientation;
|
||||
bool _tied_to_listener;
|
||||
|
||||
sample_map _samples;
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ void SGSoundMgr::update( double dt )
|
||||
// run the audio scheduler
|
||||
void SGSoundMgr::update_late( double dt ) {
|
||||
if (_working) {
|
||||
// alcSuspendContext(_context);
|
||||
alcSuspendContext(_context);
|
||||
|
||||
sample_group_map_iterator sample_grp_current = _sample_groups.begin();
|
||||
sample_group_map_iterator sample_grp_end = _sample_groups.end();
|
||||
@@ -222,7 +222,7 @@ void SGSoundMgr::update_late( double dt ) {
|
||||
testForALError("update");
|
||||
_changed = false;
|
||||
}
|
||||
// alcProcessContext(_context);
|
||||
alcProcessContext(_context);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
// along with this program; if not, write to the Free Software Foundation,
|
||||
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
|
||||
@@ -124,9 +124,8 @@ public:
|
||||
_changed = true;
|
||||
}
|
||||
|
||||
inline double *get_position() {
|
||||
return _listener_pos.data();
|
||||
}
|
||||
inline double *get_position() { return _listener_pos.data(); }
|
||||
inline SGVec3d get_position_vec() { return _listener_pos; };
|
||||
|
||||
/**
|
||||
* set the velocity of the listener (in opengl coordinates)
|
||||
@@ -136,11 +135,17 @@ public:
|
||||
_changed = true;
|
||||
}
|
||||
|
||||
inline SGVec3f get_velocity() { return _listener_vel; }
|
||||
|
||||
/**
|
||||
* set the orientation of the listener (in opengl coordinates)
|
||||
*/
|
||||
void set_orientation( SGQuatd ori );
|
||||
|
||||
inline SGVec3f get_direction() {
|
||||
return SGVec3f(_listener_ori[0], _listener_ori[1], _listener_ori[2]);
|
||||
}
|
||||
|
||||
enum {
|
||||
NO_SOURCE = (unsigned int)-1,
|
||||
NO_BUFFER = (unsigned int)-1
|
||||
@@ -160,10 +165,17 @@ public:
|
||||
*/
|
||||
void release_source( unsigned int source );
|
||||
|
||||
|
||||
/**
|
||||
* returns true if the position has changed
|
||||
*/
|
||||
inline bool has_changed() { return _changed; }
|
||||
|
||||
static bool load(string &samplepath, void **data, int *format,
|
||||
unsigned int*size, int *freq );
|
||||
|
||||
|
||||
|
||||
private:
|
||||
static int _alut_init;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user