From e3f70b712545bc42a43175a2a88174dacce9ce73 Mon Sep 17 00:00:00 2001 From: ehofman Date: Thu, 12 Nov 2009 20:41:19 +0000 Subject: [PATCH] temporarily remove listener (viewer) and source offsets. they mess things up --- simgear/sound/sample_group.cxx | 20 +++++--------------- simgear/sound/sample_openal.cxx | 7 ++++--- simgear/sound/sample_openal.hxx | 4 ++-- simgear/sound/soundmgr_openal.cxx | 12 ++++++++++++ simgear/sound/soundmgr_openal.hxx | 8 +++++++- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index f76d98b9..e56d37e5 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -318,38 +318,28 @@ void SGSampleGroup::set_volume( float vol ) _volume = vol; if (_volume < 0.0) _volume = 0.0; if (_volume > 1.0) _volume = 1.0; - - 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_master_volume( _volume ); - } } // set the source position and orientation of all managed sounds void SGSampleGroup::update_pos_and_orientation() { - static const SGQuatd q(-0.5, -0.5, 0.5, 0.5); - SGVec3d position = SGVec3d::fromGeod(_base_pos) - _smgr->get_position(); - - SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos); - SGQuatd ec2gl = hlOr*_orientation*q; + SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos) * _orientation; SGVec3f velocity = SGVec3f::zeros(); if ( _velocity[0] || _velocity[1] || _velocity[2] ) { - velocity = toVec3f( (hlOr*q).backTransform(_velocity) ); + velocity = toVec3f( hlOr.backTransform(_velocity*SG_FEET_TO_METER) ); } 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_master_volume( _volume ); + sample->set_orientation( _orientation ); + sample->set_rotation( hlOr ); sample->set_position( position ); sample->set_velocity( velocity ); - sample->set_orientation( _orientation ); - sample->set_rotation( ec2gl ); } } diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 2c87ec22..21e7cf71 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -198,15 +198,16 @@ SGSoundSample::~SGSoundSample() { void SGSoundSample::update_pos_and_orientation() { _absolute_pos = _base_pos; +#if 0 if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) { _absolute_pos += _rotation.backTransform( _relative_pos ); } +#endif + _orivec = SGVec3f::zeros(); if ( _direction[0] || _direction[1] || _direction[2] ) { - _orivec = toVec3f( _rotation.rotate(_direction) ); + _orivec = toVec3f( _rotation.rotate( _direction ) ); } - else - _orivec = SGVec3f::zeros(); } string SGSoundSample::random_string() { diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index f8516018..b1d0cf99 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -337,8 +337,8 @@ public: _orientation = ori; _changed = true; } - inline void set_rotation( const SGQuatd& ori ) { - _rotation = ori; _changed = true; + inline void set_rotation( const SGQuatd& hlOr ) { + _rotation = hlOr; _changed = true; } /** diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 1cb6c409..4cf3a63c 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -64,6 +64,8 @@ SGSoundMgr::SGSoundMgr() : _device(NULL), _context(NULL), _absolute_pos(SGVec3d::zeros()), + _offset_pos(SGVec3d::zeros()), + _base_pos(SGVec3d::zeros()), _velocity(SGVec3d::zeros()), _orientation(SGQuatd::zeros()), _devname(NULL) @@ -244,6 +246,10 @@ void SGSoundMgr::unbind () // run the audio scheduler void SGSoundMgr::update( double dt ) { if (_active) { + if (_changed) { + update_pos_and_orientation(); + } + sample_group_map_iterator sample_grp_current = _sample_groups.begin(); sample_group_map_iterator sample_grp_end = _sample_groups.end(); for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { @@ -469,6 +475,7 @@ void SGSoundMgr::update_pos_and_orientation() { * one or more vectors have zero length, implementation behavior * is undefined. If the two vectors are linearly dependent, * behavior is undefined. + * * This is in the same coordinate system as OpenGL; y=up, z=back, x=right. */ SGVec3d sgv_at = _orientation.backTransform(-SGVec3d::e3()); @@ -479,6 +486,11 @@ void SGSoundMgr::update_pos_and_orientation() { _at_up_vec[3] = sgv_up[0]; _at_up_vec[4] = sgv_up[1]; _at_up_vec[5] = sgv_up[2]; + + // static const SGQuatd q(-0.5, -0.5, 0.5, 0.5); + // SGQuatd hlOr = SGQuatd::fromLonLat(SGGeod::fromCart(_base_pos)); + // SGQuatd ec2body = hlOr*_orientation; + _absolute_pos = _base_pos; // + ec2body.backTransform( _offset_pos ); } bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt, diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index 6a4df530..ecfd2637 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -157,7 +157,11 @@ public: * @param pos OpenAL listener position */ void set_position( const SGVec3d& pos ) { - _absolute_pos = pos; _changed = true; + _base_pos = pos; _changed = true; + } + + void set_position_offset( const SGVec3d& pos ) { + _offset_pos = pos; _changed = true; } /** @@ -281,6 +285,8 @@ private: // Position of the listener. SGVec3d _absolute_pos; + SGVec3d _offset_pos; + SGVec3d _base_pos; // Velocity of the listener. SGVec3f _velocity; -- 2.39.5