]> git.mxchange.org Git - flightgear.git/blobdiff - src/Sound/soundmanager.cxx
Make the view-manager and sound-manager independent.
[flightgear.git] / src / Sound / soundmanager.cxx
index 16db632894620a25639eaf75f02ba8f5e6941d72..2a41ade13b61570f2a171514a04b9459fafc8877 100644 (file)
@@ -64,6 +64,15 @@ void FGSoundManager::init()
     _volume        = fgGetNode("/sim/sound/volume");
     _device_name   = fgGetNode("/sim/sound/device-name");
 
+    _currentView = fgGetNode("sim/current-view");
+    _viewPosLon    = fgGetNode("sim/current-view/viewer-lon-deg");
+    _viewPosLat    = fgGetNode("sim/current-view/viewer-lat-deg");
+    _viewPosElev   = fgGetNode("sim/current-view/viewer-elev-ft");
+  
+    _velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true);
+    _velocityEastFPS = fgGetNode("velocities/speed-east-fps", true);
+    _velocityDownFPS = fgGetNode("velocities/speed-down-fps", true);
+  
     reinit();
 }
 
@@ -113,6 +122,15 @@ void FGSoundManager::update_device_list()
     devices.clear();
 }
 
+bool FGSoundManager::stationary() const
+{
+  // this is an ugly hack to decide if the *viewer* is stationary,
+  // since we don't model the viewer velocity directly.
+  return (_currentView->getDoubleValue("x-offset-m") == 0.0) &&
+         (_currentView->getDoubleValue("y-offset-m") == 0.0) &&
+         (_currentView->getDoubleValue("z-offset-m") == 0.0);
+}
+
 // Update sound manager and propagate property values,
 // since the sound manager doesn't read any properties itself.
 // Actual sound update is triggered by the subsystem manager.
@@ -120,6 +138,29 @@ void FGSoundManager::update(double dt)
 {
     if (_is_initialized && _sound_working->getBoolValue() && _sound_enabled->getBoolValue())
     {
+        SGGeod viewPosGeod(SGGeod::fromDegFt(_viewPosLon->getDoubleValue(),
+                                             _viewPosLat->getDoubleValue(),
+                                             _viewPosElev->getDoubleValue()));
+        SGVec3d cartPos = SGVec3d::fromGeod(viewPosGeod);
+        
+        set_position(cartPos, viewPosGeod);
+        
+        SGQuatd viewOrientation;
+        for (int i=0; i<4; ++i) {
+          viewOrientation[i] = _currentView->getChild("raw-orientation", i, true)->getDoubleValue();
+        }
+        
+        set_orientation( viewOrientation );
+        
+        SGVec3d velocity(SGVec3d::zeros());
+        if (!stationary()) {
+          velocity = SGVec3d(_velocityNorthFPS->getDoubleValue(),
+                             _velocityEastFPS->getDoubleValue(),
+                             _velocityDownFPS->getDoubleValue() );
+        }
+        
+        set_velocity( velocity );
+      
         set_volume(_volume->getFloatValue());
         SGSoundMgr::update(dt);
     }