]> git.mxchange.org Git - flightgear.git/blobdiff - src/Model/acmodel.cxx
Expose a radio function (receiveBeacon) to the Nasal subsystem
[flightgear.git] / src / Model / acmodel.cxx
index 3b5ccfb138fa0a041f44fda6395176f91fff32fa..3b0658b0a7173f82051da959778c729358c30a89 100644 (file)
@@ -1,4 +1,4 @@
-// model.cxx - manage a 3D aircraft model.
+// acmodel.cxx - manage a 3D aircraft model.
 // Written by David Megginson, started 2002.
 //
 // This file is in the Public Domain, and comes with no warranty.
@@ -55,10 +55,7 @@ FGAircraftModel::FGAircraftModel ()
 
 FGAircraftModel::~FGAircraftModel ()
 {
-  osg::Node* node = _aircraft->getSceneGraph();
-  globals->get_scenery()->get_aircraft_branch()->removeChild(node);
-
-  delete _aircraft;
+  deinit();
 }
 
 void 
@@ -83,6 +80,31 @@ FGAircraftModel::init ()
   globals->get_scenery()->get_aircraft_branch()->addChild(node);
 }
 
+void
+FGAircraftModel::reinit()
+{
+  deinit();
+  _fx->reinit();
+  init();
+}
+
+void
+FGAircraftModel::deinit()
+{
+  // drop reference
+  _fx = 0;
+
+  if (!_aircraft) {
+    return;
+  }
+  
+  osg::Node* node = _aircraft->getSceneGraph();
+  globals->get_scenery()->get_aircraft_branch()->removeChild(node);
+
+  delete _aircraft;
+  _aircraft = NULL;
+}
+
 void
 FGAircraftModel::bind ()
 {
@@ -124,24 +146,17 @@ FGAircraftModel::update (double dt)
   _aircraft->update();
 
   // update model's audio sample values
-  _fx->set_position_geod( _aircraft->getPosition() );
+  SGGeod position = _aircraft->getPosition();
+  _fx->set_position_geod( position );
 
   SGQuatd orient = SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
                                                 _pitch->getDoubleValue(),
                                                 _roll->getDoubleValue());
   _fx->set_orientation( orient );
  
-#if 0
-  SGVec3d vel = SGVec3d( _speed_n->getFloatValue(),
-                         _speed_e->getFloatValue(),
-                         _speed_d->getFloatValue() );
-  if ( vel[0] || vel[1] || vel[2] ) {
-    SGQuatd q(-0.5, -0.5, 0.5, 0.5);
-    _velocity = toVec3f( q.backTransform( vel ) );
-  }
-  else
-      _velocity = SGVec3f::zeros();
-#endif
+  _velocity = SGVec3d( _speed_n->getDoubleValue(),
+                       _speed_e->getDoubleValue(),
+                       _speed_d->getDoubleValue() );
   _fx->set_velocity( _velocity );
 }