From 8d551c266430b283da04e1a9e4fdf70e8f63362f Mon Sep 17 00:00:00 2001 From: ehofman Date: Tue, 3 Nov 2009 11:42:32 +0000 Subject: [PATCH] fix directional sound orientation --- simgear/sound/sample_group.cxx | 2 ++ simgear/sound/sample_group.hxx | 2 ++ simgear/sound/sample_openal.cxx | 8 ++++++-- simgear/sound/sample_openal.hxx | 6 ++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index 6cccf634..c10d2dce 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -352,6 +352,7 @@ void SGSampleGroup::set_volume( float vol ) void SGSampleGroup::update_pos_and_orientation() { SGVec3d position = _base_pos - _smgr->get_position(); + SGQuatd hlOr = SGQuatd::fromLonLat(_position_geod) * _orientation; sample_map_iterator sample_current = _samples.begin(); sample_map_iterator sample_end = _samples.end(); @@ -359,6 +360,7 @@ void SGSampleGroup::update_pos_and_orientation() { SGSoundSample *sample = sample_current->second; sample->set_position( position ); sample->set_orientation( _orientation ); + sample->set_rotation( hlOr ); } } diff --git a/simgear/sound/sample_group.hxx b/simgear/sound/sample_group.hxx index e6bb10e2..f4ae23d2 100644 --- a/simgear/sound/sample_group.hxx +++ b/simgear/sound/sample_group.hxx @@ -197,6 +197,7 @@ public: * @param pos Base position */ void set_position_geod( const SGGeod& pos ) { + _position_geod = pos; _base_pos = SGVec3d::fromGeod( pos ); _changed = true; } @@ -226,6 +227,7 @@ private: SGVec3f _velocity; SGVec3d _base_pos; + SGGeod _position_geod; SGQuatd _orientation; sample_map _samples; diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 4abbb7cb..f716f4a1 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -50,6 +50,7 @@ SGSoundSample::SGSoundSample() : _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGVec3d::zeros()), + _rotation(SGQuatd::zeros()), _refname(random_string()), _data(NULL), _format(AL_FORMAT_MONO8), @@ -84,6 +85,7 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGVec3d::zeros()), + _rotation(SGQuatd::zeros()), _refname(file), _data(NULL), _format(AL_FORMAT_MONO8), @@ -124,6 +126,7 @@ SGSoundSample::SGSoundSample( const unsigned char** data, _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGVec3d::zeros()), + _rotation(SGQuatd::zeros()), _refname(random_string()), _format(format), _size(len), @@ -159,6 +162,7 @@ SGSoundSample::SGSoundSample( void** data, int len, int freq, int format ) : _orientation(SGQuatd::zeros()), _orivec(SGVec3f::zeros()), _base_pos(SGVec3d::zeros()), + _rotation(SGQuatd::zeros()), _refname(random_string()), _format(format), _size(len), @@ -195,11 +199,11 @@ void SGSoundSample::update_pos_and_orientation() { _absolute_pos = _base_pos; if ( _relative_pos[0] || _relative_pos[1] || _relative_pos[2] ) { - _absolute_pos += _orientation.backTransform(_relative_pos); + _absolute_pos += _rotation.backTransform(_relative_pos); } if ( _direction[0] || _direction[1] || _direction[2] ) { - _orivec = toVec3f( _orientation.rotate(_direction) ); + _orivec = toVec3f(_rotation.rotate(_direction) ); } else _orivec = SGVec3f::zeros(); diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index d1965601..f8516018 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -337,6 +337,10 @@ public: _orientation = ori; _changed = true; } + inline void set_rotation( const SGQuatd& ori ) { + _rotation = ori; _changed = true; + } + /** * Set direction of this sound relative to the orientation. * This is in the same coordinate system as OpenGL; y=up, z=back, x=right @@ -454,6 +458,8 @@ private: SGVec3f _orivec; // orientation vector for OpenAL SGVec3d _base_pos; // base position + SGQuatd _rotation; + std::string _refname; // name or file path unsigned char* _data; -- 2.39.5