]> git.mxchange.org Git - simgear.git/blobdiff - simgear/sound/sample_group.cxx
small fixes
[simgear.git] / simgear / sound / sample_group.cxx
index 43235d8684b7e48e1bc1b7de6c619095671c6662..539ab61bfa233eb2fb67155ff64d93c7ce93cd81 100644 (file)
@@ -41,10 +41,8 @@ SGSampleGroup::SGSampleGroup () :
     _pause(false),
     _tied_to_listener(false),
     _velocity(SGVec3d::zeros()),
-    _orientation(SGQuatd::zeros()),
-    _position(SGVec3d::zeros()),
-    _pos_offs(SGVec3d::zeros()),
-    _position_geod(SGGeod())
+    _base_pos(SGVec3d::zeros()),
+    _orientation(SGQuatd::zeros())
 {
     _samples.clear();
 }
@@ -57,10 +55,8 @@ SGSampleGroup::SGSampleGroup ( SGSoundMgr *smgr, const string &refname ) :
     _pause(false),
     _tied_to_listener(false),
     _velocity(SGVec3d::zeros()),
-    _orientation(SGQuatd::zeros()),
-    _position(SGVec3d::zeros()),
-    _pos_offs(SGVec3d::zeros()),
-    _position_geod(SGGeod())
+    _base_pos(SGVec3d::zeros()),
+    _orientation(SGQuatd::zeros())
 {
     _smgr->add(this, refname);
     _samples.clear();
@@ -118,7 +114,7 @@ void SGSampleGroup::update( double dt ) {
     }
 
     // Update the position and orientation information for all samples.
-    if ( _changed ) {
+    if ( _changed || _smgr->has_changed() ) {
         update_pos_and_orientation();
         _changed = false;
     }
@@ -338,57 +334,33 @@ void SGSampleGroup::set_velocity( const SGVec3f &vel ) {
     }
 }
 
-// set the source position of all managed sounds
-void SGSampleGroup::update_pos_and_orientation() {
-
-    SGVec3d position = SGVec3d::fromGeod( _position_geod );
-    SGVec3d pos_offs = SGVec3d::fromGeod( _smgr->get_position_geod() );
-
-    if (_position != position || _pos_offs != pos_offs) {
-        _position = position;
-        _pos_offs = pos_offs;
-
-        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_position_offset( _pos_offs );
-        }
-    }
-
-    // The rotation rotating from the earth centerd frame to
-    // the horizontal local frame
-    SGQuatd hlOr = SGQuatd::fromLonLat(_position_geod);
-
-    // Rotate the x-forward, y-right, z-down coordinate system
-    // into the OpenGL camera system with x-right, y-up, z-back.
-    SGQuatd q(-0.5, -0.5, 0.5, 0.5);
-
-    // Compute the sounds orientation and position
-    // wrt the earth centered frame - that is global coorinates
-    SGQuatd sc2body = hlOr*_orientation*q;
+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_orientation( _orientation );
-        sample->set_rotation( sc2body );
+        sample->set_master_volume( _volume );
     }
 }
 
-void SGSampleGroup::set_volume( float vol )
-{
-    _volume = vol;
-    if (_volume < 0.0) _volume = 0.0;
-    if (_volume > 1.0) _volume = 1.0;
+// 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;
 
     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_position( position );
+        sample->set_orientation( _orientation );
+        sample->set_rotation( hlOr );
     }
 }
 
@@ -398,7 +370,7 @@ void SGSampleGroup::update_sample_config( SGSoundSample *sample ) {
 
     if ( _tied_to_listener ) {
         orientation = _smgr->get_direction();
-        position = _smgr->get_position();
+        position = SGVec3d::zeros();
         velocity = _smgr->get_velocity();
     } else {
         sample->update_pos_and_orientation();