From 9e1121fc4ccaa179baa8fe292d604bc2eaf7a62e Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sun, 20 Nov 2011 15:05:37 +0100 Subject: [PATCH] First implementation of sound effects for AI models. --- src/AIModel/.AIBase.cxx.swp | Bin 0 -> 16384 bytes src/AIModel/AIBase.cxx | 41 ++++++++++++++++++++++++++++++++++-- src/AIModel/AIBase.hxx | 2 ++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/AIModel/.AIBase.cxx.swp diff --git a/src/AIModel/.AIBase.cxx.swp b/src/AIModel/.AIBase.cxx.swp new file mode 100644 index 0000000000000000000000000000000000000000..29e590c57d7804a3e8feaa8ddfe70a780c654402 GIT binary patch literal 16384 zcmeI2TZ|-C8OIA2mW!Y$D*FKV(QB}W?dj^v&d%)2u+Y16>#)-^neN$TK~t&jI@Nuk zx=vAbdS-gLNMeE-P0$x1JQ`y}h%dw!O}r!~$b%AN)ToI@6C;Tx1|LYo3;xfks+sPY zU6%)aG1bYhyXsuN`p*A+b?Tf`-7cN0uhMj}V&HR&VZ3wrwZ=178^-H*8U_pbqbm7I zpA9>ZBD_*5!+1&=G^4O%x?MLiU5|HrvdipHr`77K!eO3StDm+bR_yHTT-jn)B2yq! z;N2^5vr(;-OGk5e(XAiYeD~F|l9>XT0+|At0+|At0+|At0+|At0{<5Z$l!Y89kc{X ze&ciCs)Tp&c^b!`PtN~^^8m*;p@1s$Pn=)C?-R-SKXCpK&VQDi{~hNSac;t}D*ral zU&il?$@$-Kp2PX(p*SCh*(XyVQy^0yQy^0yQy^0yQy^0yQy^0yQy^0yQ{aE3fbHnl z{>Hl60KofywFmI}`wZg+ume60E`Zy>2fXukSI8H^FbgZ@{bI74STG4oI*LJ__Et5q^P}!Asy-5P$}# zf(p1D90FH^*KRP3FN1Sn6U>7-a2ULKyfSJ_%g#Fn9<&2<`wsKWrFZ15blTKoi^tOmGCeeJyN(Z-Z}vuY(uCm%yh$00ejt zoCcGi0Imav!5^-{HNf}5SH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T+mi8)oQOr3yh{|3Y4)z1I` literal 0 HcmV?d00001 diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 69442229c..d8c87f90f 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -42,6 +42,7 @@ #include
#include #include +#include #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); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index fb845bd41..726ce303b 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -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 _model; //The 3D model LOD object + SGSharedPtr _fx; public: object_type getType();