FGAircraftModel::~FGAircraftModel ()
{
- osg::Node* node = _aircraft->getSceneGraph();
- globals->get_scenery()->get_aircraft_branch()->removeChild(node);
-
- delete _aircraft;
+ deinit();
}
void
globals->get_scenery()->get_aircraft_branch()->addChild(node);
}
+void
+FGAircraftModel::reinit()
+{
+ deinit();
+ init();
+}
+
+void
+FGAircraftModel::deinit()
+{
+ if (!_aircraft) {
+ return;
+ }
+
+ osg::Node* node = _aircraft->getSceneGraph();
+ globals->get_scenery()->get_aircraft_branch()->removeChild(node);
+
+ delete _aircraft;
+ _aircraft = NULL;
+}
+
void
FGAircraftModel::bind ()
{
_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(),
+ SGQuatd orient = SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
_pitch->getDoubleValue(),
_roll->getDoubleValue());
_fx->set_orientation( orient );
- SGVec3d vel = SGVec3d( _speed_n->getFloatValue(),
- _speed_e->getFloatValue(),
- _speed_d->getFloatValue() );
- if ( vel[0] || vel[1] || vel[2] ) {
- SGQuatd hlOr = SGQuatd::fromLonLat( _aircraft->getPosition() );
- SGQuatd q(-0.5, -0.5, 0.5, 0.5);
- _velocity = toVec3f( (hlOr*q).backTransform( vel ) );
- }
- else
- _velocity = SGVec3f::zeros();
+ _velocity = SGVec3d( _speed_n->getDoubleValue(),
+ _speed_e->getDoubleValue(),
+ _speed_d->getDoubleValue() );
_fx->set_velocity( _velocity );
}