]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/viewer.cxx
Fix line endings
[flightgear.git] / src / Main / viewer.cxx
index b39b1414451097894138aa7c5307a24f39fa32b9..c0fc51534bf599491b485e5440e38a61bbd70505 100644 (file)
@@ -23,6 +23,9 @@
 //
 // $Id$
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
 
 #include <simgear/compiler.h>
 
@@ -114,7 +117,7 @@ static void MakeVIEW_OFFSET( sgMat4 dst,
     mat3[0][1] = tmp * axis3[1] + s * axis3[2] ;
     mat3[0][2] = tmp * axis3[2] - s * axis3[1] ;
 
-    tmp = t * axis2[1];
+    tmp = t * axis3[1];
     mat3[1][0] = tmp * axis3[0] - s * axis3[2] ;
     mat3[1][1] = tmp * axis3[1] + c ;
     mat3[1][2] = tmp * axis3[2] + s * axis3[0] ;
@@ -176,7 +179,8 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
                     double damp_roll, double damp_pitch, double damp_heading,
                     double x_offset_m, double y_offset_m, double z_offset_m,
                     double heading_offset_deg, double pitch_offset_deg,
-                    double roll_offset_deg, double fov_deg,
+                    double roll_offset_deg,
+                    double fov_deg, double aspect_ratio_multiplier,
                     double target_x_offset_m, double target_y_offset_m,
                     double target_z_offset_m, double near_m, bool internal ):
     _dirty(true),
@@ -225,6 +229,7 @@ FGViewer::FGViewer( fgViewType Type, bool from_model, int from_model_index,
     } else {
       _fov_deg = 55;
     }
+    _aspect_ratio_multiplier = aspect_ratio_multiplier;
     _target_x_offset_m = target_x_offset_m;
     _target_y_offset_m = target_y_offset_m;
     _target_z_offset_m = target_z_offset_m;
@@ -529,25 +534,16 @@ FGViewer::getRelativeViewPos ()
   return _relative_view_pos;
 }
 
-float *
-FGViewer::getZeroElevViewPos () 
-{
-  if (_dirty)
-    recalc();
-  return _zero_elev_view_pos;
-}
-
 void
 FGViewer::updateFromModelLocation (SGLocation * location)
 {
-  sgCopyMat4(LOCAL, location->getCachedTransformMatrix());
+  sgCopyMat4(LOCAL, location->getTransformMatrix());
 }
 
 void
 FGViewer::updateAtModelLocation (SGLocation * location)
 {
-  sgCopyMat4(ATLOCAL, 
-             location->getCachedTransformMatrix());
+  sgCopyMat4(ATLOCAL, location->getTransformMatrix());
 }
 
 void
@@ -558,8 +554,7 @@ FGViewer::recalcOurOwnLocation (SGLocation * location, double lon_deg, double la
   dampEyeData(roll_deg, pitch_deg, heading_deg);
   location->setPosition( lon_deg, lat_deg, alt_ft );
   location->setOrientation( roll_deg, pitch_deg, heading_deg );
-  sgCopyMat4(LOCAL,
-             location->getTransformMatrix(globals->get_scenery()->get_center()));
+  sgCopyMat4(LOCAL, location->getTransformMatrix());
 }
 
 // recalc() is done every time one of the setters is called (making the 
@@ -668,11 +663,10 @@ FGViewer::recalcLookAt ()
           _target_roll_deg, _target_pitch_deg, _target_heading_deg );
   }
   // calculate the "at" target object positon relative to eye or view's tile center...
+  Point3D center = globals->get_scenery()->get_next_center();
   sgdVec3 dVec3;
-  sgdSetVec3(dVec3,  _location->get_tile_center()[0], _location->get_tile_center()[1], _location->get_tile_center()[2]);
-  sgdSubVec3(dVec3,
-             _target_location->get_absolute_view_pos(globals->get_scenery()->get_center()),
-             dVec3 );
+  sgdSetVec3(dVec3, center[0], center[1], center[2]);
+  sgdSubVec3(dVec3, _target_location->get_absolute_view_pos(), dVec3 );
   sgSetVec3(at_pos, dVec3[0], dVec3[1], dVec3[2]);
 
   // Update location data for eye...
@@ -685,7 +679,7 @@ FGViewer::recalcLookAt ()
           _roll_deg, _pitch_deg, _heading_deg );
   }
   // save the eye positon...
-  sgCopyVec3(eye_pos,  _location->get_view_pos());
+  sgCopyVec3(eye_pos,  _location->get_view_pos(center));
 
   // copy data from location class to local items...
   copyLocationData();
@@ -736,11 +730,10 @@ FGViewer::recalcLookAt ()
 void
 FGViewer::copyLocationData()
 {
+  Point3D center = globals->get_scenery()->get_center();
   // Get our friendly vectors from the eye location...
-  sgCopyVec3(_zero_elev_view_pos,  _location->get_zero_elev());
-  sgCopyVec3(_relative_view_pos, _location->get_view_pos());
-  sgdCopyVec3(_absolute_view_pos,
-              _location->get_absolute_view_pos(globals->get_scenery()->get_center()));
+  sgdCopyVec3(_absolute_view_pos, _location->get_absolute_view_pos());
+  sgCopyVec3(_relative_view_pos, _location->get_view_pos(center));
   sgCopyMat4(UP, _location->getCachedUpMatrix());
   sgCopyVec3(_world_up, _location->get_world_up());
   // these are the vectors that the sun and moon code like to get...
@@ -766,7 +759,8 @@ FGViewer::copyLocationData()
   }
 
   // copy coordinates to outputs for viewer...
-  sgCopyVec3(_zero_elev, _zero_elev_view_pos);
+  sgCopyVec3(_zero_elev, _relative_view_pos);
+  sgAddScaledVec3(_zero_elev, _world_up, -_alt_ft*SG_FEET_TO_METER);
   sgCopyVec3(_view_pos, _relative_view_pos);
 }
 
@@ -840,8 +834,10 @@ FGViewer::get_h_fov()
            return _fov_deg;
        } else {
            // v_fov == fov
-           return atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS) / _aspect_ratio) *
-               SG_RADIANS_TO_DEGREES * 2;
+           return
+                atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
+                     / (_aspect_ratio*_aspect_ratio_multiplier))
+                * SG_RADIANS_TO_DEGREES * 2;
        }
     default:
        assert(false);
@@ -856,13 +852,17 @@ FGViewer::get_v_fov()
 {
     switch (_scaling_type) {
     case FG_SCALING_WIDTH:  // h_fov == fov
-       return atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS) * _aspect_ratio) *
-           SG_RADIANS_TO_DEGREES * 2;
+       return 
+            atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
+                 * (_aspect_ratio*_aspect_ratio_multiplier))
+            * SG_RADIANS_TO_DEGREES * 2;
     case FG_SCALING_MAX:
        if (_aspect_ratio < 1.0) {
            // h_fov == fov
-           return atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS) * _aspect_ratio) *
-               SG_RADIANS_TO_DEGREES * 2;
+           return
+                atan(tan(_fov_deg/2 * SG_DEGREES_TO_RADIANS)
+                     * (_aspect_ratio*_aspect_ratio_multiplier))
+                * SG_RADIANS_TO_DEGREES * 2;
        } else {
            // v_fov == fov
            return _fov_deg;