From: ehofman Date: Tue, 10 Nov 2009 14:28:28 +0000 (+0000) Subject: also recalculate the velocity in update_pos_and_orienation, so pass the north-east... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5b2af1f6b353078e0662453bb74bc7d80dc31a6b;p=simgear.git also recalculate the velocity in update_pos_and_orienation, so pass the north-east-down velocity directly and orientate position, orientation and velocity to OpenGL/OpenAL frames (x-right, y-up and z-back) --- diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index 539ab61b..f76d98b9 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -41,7 +41,6 @@ SGSampleGroup::SGSampleGroup () : _pause(false), _tied_to_listener(false), _velocity(SGVec3d::zeros()), - _base_pos(SGVec3d::zeros()), _orientation(SGQuatd::zeros()) { _samples.clear(); @@ -55,7 +54,6 @@ SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) : _pause(false), _tied_to_listener(false), _velocity(SGVec3d::zeros()), - _base_pos(SGVec3d::zeros()), _orientation(SGQuatd::zeros()) { _smgr->add(this, refname); @@ -315,25 +313,6 @@ bool SGSampleGroup::stop( const string& refname ) { return true; } -// set source velocity of all managed sounds -void SGSampleGroup::set_velocity( const SGVec3f &vel ) { - if ( isnan(vel[0]) || isnan(vel[1]) || isnan(vel[2]) ) - { - SG_LOG( SG_GENERAL, SG_ALERT, "NAN's found in SampleGroup velocity"); - return; - } - - if (_velocity != vel) { - 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_velocity( vel ); - } - _velocity = vel; - } -} - void SGSampleGroup::set_volume( float vol ) { _volume = vol; @@ -351,16 +330,26 @@ void SGSampleGroup::set_volume( float vol ) // set the source position and orientation of all managed sounds void SGSampleGroup::update_pos_and_orientation() { - SGVec3d position = _base_pos - _smgr->get_position(); - SGQuatd hlOr = SGQuatd::fromLonLat(_position_geod) * _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; + + SGVec3f velocity = SGVec3f::zeros(); + if ( _velocity[0] || _velocity[1] || _velocity[2] ) { + velocity = toVec3f( (hlOr*q).backTransform(_velocity) ); + } 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_position( position ); + sample->set_velocity( velocity ); sample->set_orientation( _orientation ); - sample->set_rotation( hlOr ); + sample->set_rotation( ec2gl ); } } diff --git a/simgear/sound/sample_group.hxx b/simgear/sound/sample_group.hxx index f4ae23d2..c0b0fdc6 100644 --- a/simgear/sound/sample_group.hxx +++ b/simgear/sound/sample_group.hxx @@ -189,7 +189,9 @@ public: * This is in the local frame coordinate system; x=north, y=east, z=down * @param vel Velocity vector */ - void set_velocity( const SGVec3f& vel ); + void set_velocity( const SGVec3d& vel ) { + _velocity = vel; _changed = true; + } /** * Set the position of this sample group. @@ -197,8 +199,7 @@ public: * @param pos Base position */ void set_position_geod( const SGGeod& pos ) { - _position_geod = pos; - _base_pos = SGVec3d::fromGeod( pos ); _changed = true; + _base_pos = pos; _changed = true; } /** @@ -225,9 +226,8 @@ private: float _volume; bool _tied_to_listener; - SGVec3f _velocity; - SGVec3d _base_pos; - SGGeod _position_geod; + SGVec3d _velocity; + SGGeod _base_pos; SGQuatd _orientation; sample_map _samples; diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index f716f4a1..2c87ec22 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -199,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 += _rotation.backTransform(_relative_pos); + _absolute_pos += _rotation.backTransform( _relative_pos ); } if ( _direction[0] || _direction[1] || _direction[2] ) { - _orivec = toVec3f(_rotation.rotate(_direction) ); + _orivec = toVec3f( _rotation.rotate(_direction) ); } else _orivec = SGVec3f::zeros(); diff --git a/simgear/sound/soundmgr_openal.hxx b/simgear/sound/soundmgr_openal.hxx index c24afc57..6a4df530 100644 --- a/simgear/sound/soundmgr_openal.hxx +++ b/simgear/sound/soundmgr_openal.hxx @@ -153,7 +153,7 @@ public: SGSampleGroup *find( const string& refname, bool create = false ); /** - * Set the Geodetic position of the sound manager. + * Set the Cartesian position of the sound manager. * @param pos OpenAL listener position */ void set_position( const SGVec3d& pos ) { diff --git a/simgear/sound/xmlsound.cxx b/simgear/sound/xmlsound.cxx index 7fa893d8..88bef765 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("x", 0.0); + offset_pos[0] = prop->getDoubleValue("z", 0.0); offset_pos[1] = prop->getDoubleValue("y", 0.0); - offset_pos[2] = -prop->getDoubleValue("z", 0.0); + offset_pos[2] = prop->getDoubleValue("x", 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("x", 0.0), + dir = SGVec3f(prop->getFloatValue("z", 0.0), prop->getFloatValue("y", 0.0), - -prop->getFloatValue("z", 0.0)); + prop->getFloatValue("x", 0.0)); inner = prop->getFloatValue("inner-angle", 360.0); outer = prop->getFloatValue("outer-angle", 360.0); outer_gain = prop->getFloatValue("outer-gain", 0.0);