From bb46d91bc617be168074f5575581564ae50c0246 Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 16 Nov 2009 13:32:34 +0000 Subject: [PATCH] What do you know, the real problem turned out to be the distance attenuation function.. --- simgear/sound/sample_group.cxx | 6 +++--- simgear/sound/sample_openal.cxx | 9 +++------ simgear/sound/sample_openal.hxx | 4 ++-- simgear/sound/soundmgr_openal.cxx | 3 ++- simgear/sound/xmlsound.cxx | 12 ++++++------ 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index e56d37e5..dfe8d756 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -324,11 +324,11 @@ void SGSampleGroup::set_volume( float vol ) void SGSampleGroup::update_pos_and_orientation() { SGVec3d position = SGVec3d::fromGeod(_base_pos) - _smgr->get_position(); - SGQuatd hlOr = SGQuatd::fromLonLat(_base_pos) * _orientation; + SGQuatd ec2body= SGQuatd::fromLonLat(_base_pos) * _orientation; SGVec3f velocity = SGVec3f::zeros(); if ( _velocity[0] || _velocity[1] || _velocity[2] ) { - velocity = toVec3f( hlOr.backTransform(_velocity*SG_FEET_TO_METER) ); + velocity = toVec3f( ec2body.backTransform(_velocity*SG_FEET_TO_METER) ); } sample_map_iterator sample_current = _samples.begin(); @@ -337,7 +337,7 @@ void SGSampleGroup::update_pos_and_orientation() { SGSoundSample *sample = sample_current->second; sample->set_master_volume( _volume ); sample->set_orientation( _orientation ); - sample->set_rotation( hlOr ); + sample->set_rotation( ec2body ); sample->set_position( position ); sample->set_velocity( velocity ); } diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 21e7cf71..08eec611 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -197,12 +197,9 @@ 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 + // position is in basic view, no need to rotate + // (proper alignment is set in xmlsound) + _absolute_pos = _base_pos + _relative_pos; _orivec = SGVec3f::zeros(); if ( _direction[0] || _direction[1] || _direction[2] ) { diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index b1d0cf99..a4091d29 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& hlOr ) { - _rotation = hlOr; _changed = true; + inline void set_rotation( const SGQuatd& ec2body ) { + _rotation = ec2body; _changed = true; } /** diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index 4cf3a63c..ef4a8f15 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -133,11 +133,13 @@ void SGSoundMgr::init() { alDopplerFactor(1.0); alDopplerVelocity(340.3); // speed of sound in meters per second. +#if 0 if ( alIsExtensionPresent((const ALchar*)"EXT_exponent_distance") ) { alDistanceModel(AL_EXPONENT_DISTANCE); } else { alDistanceModel(AL_INVERSE_DISTANCE); } +#endif testForALError("listener initialization"); @@ -263,7 +265,6 @@ if (isNaN(_at_up_vec)) printf("NaN in listener orientation\n"); if (isNaN(toVec3f(_absolute_pos).data())) printf("NaN in listener position\n"); if (isNaN(_velocity.data())) printf("NaN in listener velocity\n"); #endif - update_pos_and_orientation(); alListenerf( AL_GAIN, _volume ); alListenerfv( AL_ORIENTATION, _at_up_vec ); // alListenerfv( AL_POSITION, toVec3f(_absolute_pos).data() ); diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 88bef765..79a57c7f 100644 --- a/simgear/sound/xmlsound.cxx +++ b/simgear/sound/xmlsound.cxx @@ -235,9 +235,9 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, SGVec3f offset_pos = SGVec3f::zeros(); SGPropertyNode_ptr prop = node->getChild("position"); if ( prop != NULL ) { - offset_pos[0] = prop->getDoubleValue("z", 0.0); - offset_pos[1] = prop->getDoubleValue("y", 0.0); - offset_pos[2] = prop->getDoubleValue("x", 0.0); + offset_pos[0] = -prop->getDoubleValue("x", 0.0); + offset_pos[1] = -prop->getDoubleValue("y", 0.0); + offset_pos[2] = -prop->getDoubleValue("z", 0.0); } // @@ -249,9 +249,9 @@ SGXmlSound::init(SGPropertyNode *root, SGPropertyNode *node, float outer_gain = 0.0; prop = node->getChild("orientation"); if ( prop != NULL ) { - dir = SGVec3f(prop->getFloatValue("z", 0.0), - prop->getFloatValue("y", 0.0), - prop->getFloatValue("x", 0.0)); + dir = SGVec3f(-prop->getFloatValue("x", 0.0), + -prop->getFloatValue("y", 0.0), + -prop->getFloatValue("z", 0.0)); inner = prop->getFloatValue("inner-angle", 360.0); outer = prop->getFloatValue("outer-angle", 360.0); outer_gain = prop->getFloatValue("outer-gain", 0.0); -- 2.39.5