]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/viewer.cxx
Expose a radio function (receiveBeacon) to the Nasal subsystem
[flightgear.git] / src / Main / viewer.cxx
index 05816f8bc6c407434dfef501a1b519dbf835d854..49d77cf5b0c30c25249b2ac99a5ef4db18300bfa 100644 (file)
@@ -65,7 +65,6 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
     _pitch_deg(0),
     _heading_deg(0),
     _scaling_type(FG_SCALING_MAX),
-    _aspect_ratio(0),
     _cameraGroup(CameraGroup::getDefault())
 {
     _absolute_view_pos = SGVec3d(0, 0, 0);
@@ -102,7 +101,7 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
     } else {
       _fov_deg = 55;
     }
-    _aspect_ratio = 1;
+
     _aspect_ratio_multiplier = aspect_ratio_multiplier;
     _target_offset_m.x() = target_x_offset_m;
     _target_offset_m.y() = target_y_offset_m;
@@ -289,7 +288,14 @@ void
 FGViewer::setHeadingOffset_deg (double heading_offset_deg)
 {
   _dirty = true;
-  _heading_offset_deg = heading_offset_deg;
+  if (_at_model && (_offset_m.x() == 0.0)&&(_offset_m.z() == 0.0))
+  {
+      /* avoid optical effects (e.g. rotating sky) when "looking at" with
+       * heading offsets x==z==0 (view heading cannot change). */
+      _heading_offset_deg = 0.0;
+  }
+  else
+      _heading_offset_deg = heading_offset_deg;
 }
 
 void
@@ -317,6 +323,14 @@ void
 FGViewer::setGoalHeadingOffset_deg (double goal_heading_offset_deg)
 {
   _dirty = true;
+  if (_at_model && (_offset_m.x() == 0.0)&&(_offset_m.z() == 0.0))
+  {
+      /* avoid optical effects (e.g. rotating sky) when "looking at" with
+       * heading offsets x==z==0 (view heading cannot change). */
+      _goal_heading_offset_deg = 0.0;
+      return;
+  }
+  
   _goal_heading_offset_deg = goal_heading_offset_deg;
   while ( _goal_heading_offset_deg < 0.0 ) {
     _goal_heading_offset_deg += 360;
@@ -524,18 +538,19 @@ FGViewer::updateDampOutput(double dt)
 double
 FGViewer::get_h_fov()
 {
+    double aspectRatio = _cameraGroup->getMasterAspectRatio();
     switch (_scaling_type) {
     case FG_SCALING_WIDTH:  // h_fov == fov
        return _fov_deg;
     case FG_SCALING_MAX:
-       if (_aspect_ratio < 1.0) {
+       if (aspectRatio < 1.0) {
            // h_fov == fov
            return _fov_deg;
        } else {
            // v_fov == fov
            return
                 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
-                     / (_aspect_ratio*_aspect_ratio_multiplier))
+                     / (aspectRatio*_aspect_ratio_multiplier))
                 * SG_RADIANS_TO_DEGREES * 2;
        }
     default:
@@ -549,18 +564,19 @@ FGViewer::get_h_fov()
 double
 FGViewer::get_v_fov()
 {
+    double aspectRatio = _cameraGroup->getMasterAspectRatio();
     switch (_scaling_type) {
     case FG_SCALING_WIDTH:  // h_fov == fov
        return 
             atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
-                 * (_aspect_ratio*_aspect_ratio_multiplier))
+                 * (aspectRatio*_aspect_ratio_multiplier))
             * SG_RADIANS_TO_DEGREES * 2;
     case FG_SCALING_MAX:
-       if (_aspect_ratio < 1.0) {
+       if (aspectRatio < 1.0) {
            // h_fov == fov
            return
                 atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
-                     * (_aspect_ratio*_aspect_ratio_multiplier))
+                     * (aspectRatio*_aspect_ratio_multiplier))
                 * SG_RADIANS_TO_DEGREES * 2;
        } else {
            // v_fov == fov
@@ -656,3 +672,8 @@ FGViewer::update (double dt)
     _cameraGroup->setCameraParameters(get_v_fov(), get_aspect_ratio());
   }
 }
+
+double FGViewer::get_aspect_ratio() const
+{
+    return _cameraGroup->getMasterAspectRatio();
+}