]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/viewmgr.cxx
- implement progress information (enabled by default; can be turned off via
[flightgear.git] / src / Main / viewmgr.cxx
index 9b14bcd906109a361def2e75e32f0afe28fb2fbb..33fe8f7cb529dfff32d2cca298ff2d587e5a96d3 100644 (file)
@@ -3,7 +3,7 @@
 // Written by Curtis Olson, started October 2000.
 //   partially rewritten by Jim Wilson March 2002
 //
-// Copyright (C) 2000  Curtis L. Olson  - curt@flightgear.org
+// Copyright (C) 2000  Curtis L. Olson  - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 #include <string.h>            // strcmp
 
 #include <plib/sg.h>
+#include <plib/ssg.h>
+
+#include <simgear/compiler.h>
+
+#include <Model/acmodel.hxx>
 
 #include "viewmgr.hxx"
 #include "fg_props.hxx"
@@ -51,11 +56,16 @@ FGViewMgr::init ()
   bool at_model = false;
   int from_model_index = 0;
   int at_model_index = 0;
-  double at_model_damping = 0.0;
+  // double damp_alt;
+  double damp_roll = 0.0, damp_pitch = 0.0, damp_heading = 0.0;
   double x_offset_m, y_offset_m, z_offset_m, fov_deg;
   double heading_offset_deg, pitch_offset_deg, roll_offset_deg;
   double target_x_offset_m, target_y_offset_m, target_z_offset_m;
   double near_m;
+  bool internal;
+
+  double aspect_ratio_multiplier
+      = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
 
   for (int i = 0; i < fgGetInt("/sim/number-views"); i++) {
     viewpath = "/sim/view";
@@ -67,6 +77,12 @@ FGViewMgr::init ()
     nodepath += "/type";
     strdata = fgGetString(nodepath.c_str());
 
+    // find out if this is an internal view (e.g. in cockpit, low near plane)
+    internal = false; // default
+    nodepath = viewpath;
+    nodepath += "/internal";
+    internal = fgGetBool(nodepath.c_str());
+
     // FIXME:
     // this is assumed to be an aircraft model...we will need to read
     // model-from-type as well.
@@ -95,10 +111,14 @@ FGViewMgr::init ()
         at_model_index = fgGetInt(nodepath.c_str());
 
         nodepath = viewpath;
-        nodepath += "/config/at-model-damping";
-        at_model_damping = 1 - 1.0 / pow(10, fgGetDouble(nodepath.c_str()));
-        if (at_model_damping < 0.0)
-          at_model_damping = 0.0;
+        nodepath += "/config/at-model-roll-damping";
+        damp_roll = fgGetDouble(nodepath.c_str(), 0.0);
+        nodepath = viewpath;
+        nodepath += "/config/at-model-pitch-damping";
+        damp_pitch = fgGetDouble(nodepath.c_str(), 0.0);
+        nodepath = viewpath;
+        nodepath += "/config/at-model-heading-damping";
+        damp_heading = fgGetDouble(nodepath.c_str(), 0.0);
       }
     }
 
@@ -145,17 +165,20 @@ FGViewMgr::init ()
     // supporting two types now "lookat" = 1 and "lookfrom" = 0
     if ( strcmp("lookat",strdata.c_str()) == 0 )
       add_view(new FGViewer ( FG_LOOKAT, from_model, from_model_index,
-                              at_model, at_model_index, at_model_damping,
+                              at_model, at_model_index,
+                              damp_roll, damp_pitch, damp_heading,
                               x_offset_m, y_offset_m,z_offset_m,
                               heading_offset_deg, pitch_offset_deg,
-                              roll_offset_deg, fov_deg,
+                              roll_offset_deg, fov_deg, aspect_ratio_multiplier,
                               target_x_offset_m, target_y_offset_m,
-                              target_z_offset_m, near_m ));
+                              target_z_offset_m, near_m, internal ));
     else
-      add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index, false,
-                              0, 0.0, x_offset_m, y_offset_m, z_offset_m,
+      add_view(new FGViewer ( FG_LOOKFROM, from_model, from_model_index,
+                              false, 0, 0.0, 0.0, 0.0,
+                              x_offset_m, y_offset_m, z_offset_m,
                               heading_offset_deg, pitch_offset_deg,
-                              roll_offset_deg, fov_deg, 0, 0, 0, near_m ));
+                              roll_offset_deg, fov_deg, aspect_ratio_multiplier,
+                              0, 0, 0, near_m, internal ));
   }
 
   copyToCurrent();
@@ -257,6 +280,14 @@ FGViewMgr::bind ()
        &FGViewMgr::getGoalViewPitchOffset_deg,
         &FGViewMgr::setGoalViewPitchOffset_deg);
   fgSetArchivable("/sim/current-view/goal-pitch-offset-deg");
+  fgTie("/sim/current-view/roll-offset-deg", this,
+       &FGViewMgr::getViewRollOffset_deg,
+        &FGViewMgr::setViewRollOffset_deg);
+  fgSetArchivable("/sim/current-view/roll-offset-deg");
+  fgTie("/sim/current-view/goal-roll-offset-deg", this,
+       &FGViewMgr::getGoalViewRollOffset_deg,
+        &FGViewMgr::setGoalViewRollOffset_deg);
+  fgSetArchivable("/sim/current-view/goal-roll-offset-deg");
 
   fgTie("/sim/current-view/view-number", this, 
                       &FGViewMgr::getView, &FGViewMgr::setView);
@@ -274,6 +305,10 @@ FGViewMgr::bind ()
        &FGViewMgr::getFOV_deg, &FGViewMgr::setFOV_deg);
   fgSetArchivable("/sim/current-view/field-of-view");
 
+  fgTie("/sim/current-view/aspect-ratio-multiplier", this,
+       &FGViewMgr::getARM_deg, &FGViewMgr::setARM_deg);
+  fgSetArchivable("/sim/current-view/field-of-view");
+
   fgTie("/sim/current-view/ground-level-nearplane-m", this,
        &FGViewMgr::getNear_m, &FGViewMgr::setNear_m);
   fgSetArchivable("/sim/current-view/ground-level-nearplane-m");
@@ -289,7 +324,8 @@ FGViewMgr::unbind ()
   fgUntie("/sim/current-view/goal-heading-offset-deg");
   fgUntie("/sim/current-view/pitch-offset-deg");
   fgUntie("/sim/current-view/goal-pitch-offset-deg");
-  fgUntie("/sim/field-of-view");
+  fgUntie("/sim/current-view/field-of-view");
+  fgUntie("/sim/current-view/aspect-ratio-multiplier");
   fgUntie("/sim/current-view/view-number");
   fgUntie("/sim/current-view/axes/long");
   fgUntie("/sim/current-view/axes/lat");
@@ -368,8 +404,8 @@ FGViewMgr::update (double dt)
       nodepath = viewpath;
       nodepath += "/config/target-heading-deg-path";
       heading_deg = fgGetDouble(fgGetString(nodepath.c_str()));
-  
-      loop_view ->setTargetPosition(lon_deg, lat_deg, alt_ft);
+
+      loop_view->setTargetPosition(lon_deg, lat_deg, alt_ft);
       loop_view->setTargetOrientation(roll_deg, pitch_deg, heading_deg);
     } else {
       loop_view->set_dirty();
@@ -421,6 +457,12 @@ FGViewMgr::copyToCurrent()
     fgSetDouble("/sim/current-view/config/default-field-of-view-deg",
                 fgGetDouble(nodepath.c_str()));
 
+    nodepath = viewpath;
+    nodepath += "/config/from-model";
+    fgSetBool("/sim/current-view/config/from-model",
+                fgGetBool(nodepath.c_str()));
+
+
     // copy view data
     fgSetDouble("/sim/current-view/x-offset-m", getViewXOffset_m());
     fgSetDouble("/sim/current-view/y-offset-m", getViewYOffset_m());
@@ -443,6 +485,10 @@ FGViewMgr::copyToCurrent()
                 get_current_view()->getTargetYOffset_m());
     fgSetDouble("/sim/current-view/target-z-offset-m",
                 get_current_view()->getTargetZOffset_m());
+
+    fgSetBool("/sim/current-view/internal",
+                get_current_view()->getInternal());
+
 }
 
 
@@ -510,6 +556,38 @@ FGViewMgr::setGoalViewPitchOffset_deg (double tilt)
     view->setGoalPitchOffset_deg(tilt);
 }
 
+double
+FGViewMgr::getViewRollOffset_deg () const
+{
+  const FGViewer * view = get_current_view();
+  return (view == 0 ? 0 : view->getRollOffset_deg());
+}
+
+void
+FGViewMgr::setViewRollOffset_deg (double tilt)
+{
+  FGViewer * view = get_current_view();
+  if (view != 0) {
+    view->setGoalRollOffset_deg(tilt);
+    view->setRollOffset_deg(tilt);
+  }
+}
+
+double
+FGViewMgr::getGoalViewRollOffset_deg () const
+{
+  const FGViewer * view = get_current_view();
+  return (view == 0 ? 0 : view->getGoalRollOffset_deg());
+}
+
+void
+FGViewMgr::setGoalViewRollOffset_deg (double tilt)
+{
+  FGViewer * view = get_current_view();
+  if (view != 0)
+    view->setGoalRollOffset_deg(tilt);
+}
+
 double
 FGViewMgr::getViewXOffset_m () const
 {
@@ -651,6 +729,12 @@ FGViewMgr::setView (int newview )
   set_view( newview );
   // copy in view data
   copyToCurrent ();
+
+  // Copy the fdm's position into the SGLocation which is shared with
+  // some views ...
+  globals->get_aircraft_model()->update(0);
+  // Do the update ...
+  update(0);
 }
 
 
@@ -669,6 +753,21 @@ FGViewMgr::setFOV_deg (double fov)
     view->set_fov(fov);
 }
 
+double
+FGViewMgr::getARM_deg () const
+{
+  const FGViewer * view = get_current_view();
+  return (view == 0 ? 0 : view->get_aspect_ratio_multiplier());
+}
+
+void
+FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
+{
+  FGViewer * view = get_current_view();
+  if (view != 0)
+    view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
+}
+
 double
 FGViewMgr::getNear_m () const
 {