]> git.mxchange.org Git - flightgear.git/commitdiff
Correct (and verrified) position, orientation and velocity vector. Todo: proper sound...
authorehofman <ehofman>
Sun, 11 Oct 2009 13:40:12 +0000 (13:40 +0000)
committerTim Moore <timoore@redhat.com>
Mon, 12 Oct 2009 05:58:11 +0000 (07:58 +0200)
src/Main/viewmgr.cxx
src/Main/viewmgr.hxx
src/Model/acmodel.cxx
src/Model/acmodel.hxx
src/Sound/fg_fx.cxx

index d429c219cdda8c286236c718fa59c844d071356d..18b16a6a29ec243cb50c8553fd09c83483c75d30 100644 (file)
@@ -248,7 +248,6 @@ FGViewMgr::update (double dt)
   FGViewer *loop_view = (FGViewer *)get_view(current);
   SGPropertyNode *n = config_list[current];
   double lon_deg, lat_deg, alt_ft, roll_deg, pitch_deg, heading_deg;
-  SGVec3f velocity = SGVec3f(0,0,0);
 
   // Set up view location and orientation
 
@@ -265,10 +264,6 @@ FGViewMgr::update (double dt)
   } else {
     // force recalc in viewer
     loop_view->set_dirty();
-
-    // get the model velocity for the in-cockpit view
-    FGAircraftModel *aircraft = globals->get_aircraft_model();
-    velocity = aircraft->getVelocity();
   }
 
   // if lookat (type 1) then get target data...
@@ -303,8 +298,15 @@ FGViewMgr::update (double dt)
 
   // update audio listener values
   // set the viewer posotion in Cartesian coordinates in meters
-  smgr->set_position(abs_viewer_position);
+  smgr->set_position(-abs_viewer_position);
   smgr->set_orientation(loop_view->getViewOrientation());
+
+  // get the model velocity for the in-cockpit view
+  SGVec3f velocity = SGVec3f(0,0,0);
+  if ( !stationary() ) {
+    FGAircraftModel *aircraft = globals->get_aircraft_model();
+    velocity = aircraft->getVelocity();
+  }
   smgr->set_velocity(velocity);
 }
 
@@ -575,6 +577,20 @@ FGViewMgr::setViewZOffset_m (double z)
   }
 }
 
+bool
+FGViewMgr::stationary () const
+{
+  const FGViewer * view = get_current_view();
+  if (view != 0) {
+    if (((FGViewer *)view)->getXOffset_m() == 0.0 &&
+        ((FGViewer *)view)->getYOffset_m() == 0.0 &&
+        ((FGViewer *)view)->getZOffset_m() == 0.0)
+      return true;
+  }
+
+  return false;
+}
+
 double
 FGViewMgr::getViewTargetXOffset_m () const
 {
index 76ede702eb7ae2420aa4f1117992a594ac3d8f69..2c0feb428fdd1c778dd28996222ca12c4e261034 100644 (file)
@@ -116,6 +116,7 @@ private:
     void setViewAxisLat (double axis);
     int getView () const;
     void setView (int newview);
+    bool stationary () const;
 
     SGPropertyNode_ptr view_number;
     vector<SGPropertyNode_ptr> config_list;
index 0541a1159b273446b9f584d12fa9a9dcb7e2acdf..ff2c81aa076f1bc1bd9234c6e03d496f475717ec 100644 (file)
@@ -44,8 +44,7 @@ FGAircraftModel::FGAircraftModel ()
     _pitch(0),
     _roll(0),
     _heading(0),
-    _speed(0),
-    _speed_up(0)
+    _speed(0)
 {
     SGSoundMgr *smgr;
     smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
@@ -92,8 +91,7 @@ FGAircraftModel::bind ()
    _pitch = fgGetNode("orientation/pitch-deg", true);
    _roll = fgGetNode("orientation/roll-deg", true);
    _heading = fgGetNode("orientation/heading-deg", true);
-   _speed = fgGetNode("velocities/true-airspeed-kt", true);
-   _speed_up = fgGetNode("velocities/vertical-speed-fps", true);
+   _speed = fgGetNode("velocities/groundspeed-kt", true);
 }
 
 void
@@ -125,21 +123,19 @@ FGAircraftModel::update (double dt)
   // update model's audio sample values
   // Get the Cartesian coordinates in meters
   SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
-  _fx->set_position( pos );
+  _fx->set_position( -pos );
 
   SGQuatd orient_m = SGQuatd::fromLonLat(_aircraft->getPosition());
   orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
                                            _pitch->getDoubleValue(),
                                            _roll->getDoubleValue());
   SGVec3d orient = -orient_m.rotate(SGVec3d::e1());
-  _fx->set_orientation( toVec3f(orient) );
+  _fx->set_orientation( toVec3f( orient ) );
  
   // For now assume the aircraft speed is always along the longitudinal
   // axis, so sideslipping is not taken into account. This should be fine
   // for audio.
-  _velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_FPS);
-  // _velocity[2] = _speed_up->getFloatValue();
-  _velocity *= SG_FEET_TO_METER;
+  _velocity = toVec3f(orient * _speed->getDoubleValue() * SG_KT_TO_MPS);
   _fx->set_velocity( _velocity );
 }
 
index 5a0b31a0e763b14e1c4d5af08486bb5b6a7684ee..dd6e3b01f705bbcc74fd1f45e94cbcf71b435a6d 100644 (file)
@@ -54,7 +54,6 @@ private:
   SGPropertyNode * _roll;
   SGPropertyNode * _heading;
   SGPropertyNode * _speed;
-  SGPropertyNode * _speed_up;
 
 };
 
index 6e06fa403830ef91b14ff2d93e903bff41a76400..934ec5c1aa49baa21580d1a1205369423003c4b8 100644 (file)
@@ -45,6 +45,7 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
     _volume( fgGetNode("/sim/sound/volume") )
 {
     SGSampleGroup::_smgr = smgr;
+    SGSampleGroup::_refname = refname;
     SGSampleGroup::_smgr->add(this, refname);
     SGSampleGroup::_active = _smgr->is_working();
 }