]> git.mxchange.org Git - flightgear.git/commitdiff
First implementation of sound effects for AI models.
authorErik Hofman <erik@ehofman.com>
Sun, 20 Nov 2011 14:05:37 +0000 (15:05 +0100)
committerErik Hofman <erik@ehofman.com>
Sun, 20 Nov 2011 14:05:37 +0000 (15:05 +0100)
src/AIModel/.AIBase.cxx.swp [new file with mode: 0644]
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx

diff --git a/src/AIModel/.AIBase.cxx.swp b/src/AIModel/.AIBase.cxx.swp
new file mode 100644 (file)
index 0000000..29e590c
Binary files /dev/null and b/src/AIModel/.AIBase.cxx.swp differ
index 69442229cd6c53f900aae92471a4ea6624bd7d1e..d8c87f90fe2202f46433ff032ccf5265f57faaab 100644 (file)
@@ -42,6 +42,7 @@
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scripting/NasalSys.hxx>
+#include <Sound/fg_fx.hxx>
 
 #include "AIBase.hxx"
 #include "AIManager.hxx"
@@ -70,7 +71,8 @@ FGAIBase::FGAIBase(object_type ot, bool enableHot) :
     _impact_speed(0),
     _refID( _newAIModelID() ),
     _otype(ot),
-    _initialized(false)
+    _initialized(false),
+    _fx(0)
 
 {
     tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
@@ -137,6 +139,9 @@ FGAIBase::~FGAIBase() {
         if (parent)
             model_removed->setStringValue(props->getPath());
     }
+    delete _fx;
+    _fx = 0;
+
     delete fp;
     fp = 0;
 }
@@ -198,6 +203,19 @@ void FGAIBase::update(double dt) {
 
     ft_per_deg_lat = 366468.96 - 3717.12 * cos(pos.getLatitudeRad());
     ft_per_deg_lon = 365228.16 * cos(pos.getLatitudeRad());
+
+    if ( _fx )
+    {
+        // update model's audio sample values
+        _fx->set_position_geod( pos );
+
+        SGQuatd orient = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
+        _fx->set_orientation( orient );
+
+        SGVec3d velocity;
+        velocity = SGVec3d( speed_north_deg_sec, speed_east_deg_sec, pitch*speed );
+        _fx->set_velocity( velocity );
+    }
 }
 
 /** update LOD properties of the model */
@@ -293,6 +311,20 @@ bool FGAIBase::init(bool search_in_AI_path) {
         aip.setVisible(true);
         invisible = false;
         globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
+
+        // Get the sound-path tag from the configuration file and store it
+        // in the property tree.
+        string fxpath = props->getStringValue("/sim/sound/path");
+        if ( !fxpath.empty() )
+        {
+            props->setStringValue("sim/sound/path", fxpath.c_str());
+
+            // initialize the sound configuration
+            SGSoundMgr *smgr = globals->get_soundmgr();
+            _fx = new FGFX(smgr, "aifx:"+f, props);
+            _fx->init();
+        }
+
         _initialized = true;
 
     } else if (!model_path.empty()) {
@@ -400,7 +432,12 @@ void FGAIBase::bind() {
     props->setDoubleValue("controls/flight/target-alt", altitude_ft);
     props->setDoubleValue("controls/flight/target-pitch", pitch);
 
-   props->setDoubleValue("controls/flight/target-spd", speed);
+    props->setDoubleValue("controls/flight/target-spd", speed);
+
+    props->setBoolValue("sim/sound/avionics/enabled", false);
+    props->setDoubleValue("sim/sound/avionics/volume", 0.0);
+    props->setBoolValue("sim/sound/avionics/external-view", false);
+    props->setBoolValue("sim/current-view/internal", false);
 
 }
 
index fb845bd4158bb811bb87a7032742f4c6c7702f6f..726ce303bef95d5d008609686c5d2757b84b7cd5 100644 (file)
@@ -43,6 +43,7 @@ using std::list;
 class SGMaterial;
 class FGAIManager;
 class FGAIFlightPlan;
+class FGFX;
 
 class FGAIBase : public SGReferenced {
 
@@ -225,6 +226,7 @@ private:
     object_type _otype;
     bool _initialized;
     osg::ref_ptr<osg::LOD> _model; //The 3D model LOD object
+    SGSharedPtr<FGFX>  _fx;
 
 public:
     object_type getType();