]> git.mxchange.org Git - flightgear.git/commitdiff
(try to) properly align model and viewer
authorehofman <ehofman>
Tue, 6 Oct 2009 12:09:50 +0000 (12:09 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 7 Oct 2009 06:23:41 +0000 (08:23 +0200)
src/Main/viewmgr.cxx
src/Model/acmodel.cxx
src/Model/acmodel.hxx

index 20db9476ba6b0660cd263a75cd2f629e594e5ae7..d429c219cdda8c286236c718fa59c844d071356d 100644 (file)
@@ -248,6 +248,7 @@ 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
 
@@ -264,6 +265,10 @@ 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...
@@ -300,7 +305,7 @@ FGViewMgr::update (double dt)
   // set the viewer posotion in Cartesian coordinates in meters
   smgr->set_position(abs_viewer_position);
   smgr->set_orientation(loop_view->getViewOrientation());
-  smgr->set_velocity(SGVec3f(0,0,0)); // TODO: in meters per second
+  smgr->set_velocity(velocity);
 }
 
 void
index f54e4721ecdaa50046d1c705d1328cdff055cb95..0541a1159b273446b9f584d12fa9a9dcb7e2acdf 100644 (file)
@@ -36,6 +36,7 @@
 
 FGAircraftModel::FGAircraftModel ()
   : _aircraft(0),
+    _velocity(SGVec3f::zeros()),
     _fx(0),
     _lon(0),
     _lat(0),
@@ -43,8 +44,7 @@ FGAircraftModel::FGAircraftModel ()
     _pitch(0),
     _roll(0),
     _heading(0),
-    _speed_north(0),
-    _speed_east(0),
+    _speed(0),
     _speed_up(0)
 {
     SGSoundMgr *smgr;
@@ -92,9 +92,8 @@ FGAircraftModel::bind ()
    _pitch = fgGetNode("orientation/pitch-deg", true);
    _roll = fgGetNode("orientation/roll-deg", true);
    _heading = fgGetNode("orientation/heading-deg", true);
-   _speed_north = fgGetNode("/velocities/speed-north-fps", true);
-   _speed_east = fgGetNode("/velocities/speed-east-fps", true);
-   _speed_up = fgGetNode("/velocities/vertical-speed-fps", true);
+   _speed = fgGetNode("velocities/true-airspeed-kt", true);
+   _speed_up = fgGetNode("velocities/vertical-speed-fps", true);
 }
 
 void
@@ -123,7 +122,7 @@ FGAircraftModel::update (double dt)
                            _heading->getDoubleValue());
   _aircraft->update();
 
-  // update model's sample group values
+  // update model's audio sample values
   // Get the Cartesian coordinates in meters
   SGVec3d pos = SGVec3d::fromGeod(_aircraft->getPosition());
   _fx->set_position( pos );
@@ -132,15 +131,16 @@ FGAircraftModel::update (double dt)
   orient_m *= SGQuatd::fromYawPitchRollDeg(_heading->getDoubleValue(),
                                            _pitch->getDoubleValue(),
                                            _roll->getDoubleValue());
-  SGVec3d orient = orient_m.rotateBack(SGVec3d::e1());
+  SGVec3d orient = -orient_m.rotate(SGVec3d::e1());
   _fx->set_orientation( toVec3f(orient) );
  
-  SGVec3f vel = SGVec3f( _speed_north->getFloatValue(),
-                         _speed_east->getFloatValue(),
-                         _speed_up->getFloatValue());
-// TODO: rotate to properly align with the model orientation
-
-  _fx->set_velocity( vel*SG_FEET_TO_METER );
+  // 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;
+  _fx->set_velocity( _velocity );
 }
 
 
index da728fcf658204aa9c4dcdb45b82dfc0c0d5220d..5a0b31a0e763b14e1c4d5af08486bb5b6a7684ee 100644 (file)
@@ -39,10 +39,12 @@ public:
   virtual void unbind ();
   virtual void update (double dt);
   virtual SGModelPlacement * get3DModel() { return _aircraft; }
+  virtual SGVec3f getVelocity() { return _velocity; }
 
 private:
 
   SGModelPlacement * _aircraft;
+  SGVec3f _velocity;
   FGFX * _fx;
 
   SGPropertyNode * _lon;
@@ -51,8 +53,7 @@ private:
   SGPropertyNode * _pitch;
   SGPropertyNode * _roll;
   SGPropertyNode * _heading;
-  SGPropertyNode * _speed_north;
-  SGPropertyNode * _speed_east;
+  SGPropertyNode * _speed;
   SGPropertyNode * _speed_up;
 
 };