]> git.mxchange.org Git - flightgear.git/commitdiff
Fixes for win_ratio/aspect_ratio confusion. It was due to confusion in the
authorcurt <curt>
Wed, 24 Oct 2001 20:28:28 +0000 (20:28 +0000)
committercurt <curt>
Wed, 24 Oct 2001 20:28:28 +0000 (20:28 +0000)
meaning of "win_ratio".  I've removed win_ratio and added fov_ratio and
aspect_ratio, as it seems both are needed.

n.b. The multi-line changes in fgReshape comprise:
  extracting common code,
  removing an apparently arbitrary "+1" on the view height,
  changing "set_win_ratio" to "set_aspect_ratio".

src/Cockpit/hud.cxx
src/Cockpit/hud_ladr.cxx
src/GUI/gui.cxx
src/Main/fg_init.cxx
src/Main/fg_props.cxx
src/Main/main.cxx
src/Main/viewer.hxx

index 74c2d08fffd3fb3b7d9240d3e548d0bf3dd13e79..92183ba1855ec54280175f27e18c0f2deb76b6ea 100644 (file)
@@ -1033,8 +1033,8 @@ static void set_hud_color(float r, float g, float b) {
 void fgUpdateHUD( void ) {
        
     static const float normal_aspect = float(640) / float(480);
-    // note: win_ratio is Y/X
-    float current_aspect = 1.0f/globals->get_current_view()->get_win_ratio();
+    // note: aspect_ratio is Y/X
+    float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
     if( current_aspect > normal_aspect ) {
         float aspect_adjust = current_aspect / normal_aspect;
         float adjust = 320.0f*aspect_adjust - 320.0f;
index 09c0ee871054bc1117b2aaba19261b319bcd88b9..2ce6b2423b922ff8e36aea7312f79407ed8f9dd5 100644 (file)
@@ -251,12 +251,12 @@ void HudLadder :: draw( void )
        }
 
        xvvr = (((atan2(Vyy,Vxx)*SGD_RADIANS_TO_DEGREES)-psi)*
-               (factor/globals->get_current_view()->get_win_ratio()));
+               (factor/globals->get_current_view()->get_aspect_ratio()));
        drift = ((atan2(Vyy,Vxx)*SGD_RADIANS_TO_DEGREES)-psi);
        yvvr = ((actslope - pitch_value)*factor);
        vel_y = ((actslope -pitch_value) * cos(roll_value) + drift*sin(roll_value))*factor;
        vel_x = (-(actslope -pitch_value)*sin(roll_value) + drift*cos(roll_value))*
-               (factor/globals->get_current_view()->get_win_ratio());
+               (factor/globals->get_current_view()->get_aspect_ratio());
        //  printf("%f %f %f %f\n",vel_x,vel_y,drift,psi);
        //****************************************************************    
        // OBJECT MOVING RETICLE
index d3df0a87cb9b09f55681a305f82598e005165ca5..6d4e28168919a7e9ab611dd1f59ab4d1a0104fc5 100644 (file)
@@ -520,7 +520,7 @@ void fgHiResDump()
     glLoadIdentity();
     ssgSetCamera( (sgVec4 *)globals->get_current_view()->get_VIEW() );
     float fov = globals->get_current_view()->get_fov();
-    ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
+    ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
     // ssgSetNearFar( 10.0f, 120000.0f );
     ssgSetNearFar( 0.5f, 1200000.0f );
 
index 5419fcd040a421a6c6c44a009cee0d98375fe68e..17c2600b94713884e68bed66ccfc7d8ab708e662 100644 (file)
@@ -587,12 +587,14 @@ bool fgInitSubsystems( void ) {
     // Initialize the view manager subsystem.
     ////////////////////////////////////////////////////////////////////
 
+#if 0  /* As this wrongly does an integer division and gets x and y the wrong way around, I guess it's not needed.  JAF */
     // Initialize win_ratio parameters
     for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
        globals->get_viewmgr()->get_view(i)->
            set_win_ratio( fgGetInt("/sim/startup/xsize") /
                           fgGetInt("/sim/startup/ysize") );
     }
+#endif
 
     // Initialize pilot view
     FGViewerRPH *pilot_view =
index 1b00338f3a7e39290cac4e459e698d4b8c15c634..9dca63c5c1aac19ba161bcff1e21063501f70945 100644 (file)
@@ -952,7 +952,9 @@ getFOV ()
 static void
 setFOV (double fov)
 {
-  globals->get_current_view()->set_fov( fov );
+  if ( fov < 180 ) {
+      globals->get_current_view()->set_fov( fov );
+  }
 }
 
 static long
index 892aeb4d03f9ba2158c26332ca0e8efcbbc357f4..2a0802dda26c1153d9023ab0bf0e440859ca3b9d 100644 (file)
@@ -684,7 +684,7 @@ void fgRenderFrame( void ) {
        // glMatrixMode( GL_PROJECTION );
        // glLoadIdentity();
        float fov = globals->get_current_view()->get_fov();
-       ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
+       ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
 
        double agl = current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
            - scenery.cur_elev;
@@ -1391,36 +1391,28 @@ static void fgIdleFunction ( void ) {
 // options.cxx needs to see this for toggle_panel()
 // Handle new window size or exposure
 void fgReshape( int width, int height ) {
+    int view_h;
+
+    if ( fgPanelVisible() && idle_state == 1000 ) {
+       view_h = (int)(height * (current_panel->getViewHeight() -
+                                current_panel->getYOffset()) / 768.0);
+    } else {
+       view_h = height;
+    }
+
     // for all views
     for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) {
-       if ( ! fgPanelVisible() || idle_state != 1000 ) {
-           globals->get_viewmgr()->get_view(i)->
-               set_win_ratio( (float)height / (float)width );
-       } else {
-           int view_h =
-               int((current_panel->getViewHeight() -
-                    current_panel->getYOffset())
-                   * (height / 768.0)) + 1;
-           globals->get_viewmgr()->get_view(i)->
-               set_win_ratio( (float)view_h / (float)width );
-       }
+       globals->get_viewmgr()->get_view(i)->
+            set_aspect_ratio((float)view_h / (float)width);
     }
 
-    if ( ! fgPanelVisible() || idle_state != 1000 ) {
-       glViewport(0, 0 , (GLint)(width), (GLint)(height) );
-    } else {
-        int view_h =
-           int((current_panel->getViewHeight() - current_panel->getYOffset())
-               * (height / 768.0)) + 1;
-       glViewport(0, (GLint)(height - view_h),
-                  (GLint)(width), (GLint)(view_h) );
-    }
+    glViewport( 0, (GLint)(height - view_h), (GLint)(width), (GLint)(view_h) );
 
     fgSetInt("/sim/startup/xsize", width);
     fgSetInt("/sim/startup/ysize", height);
 
     float fov = globals->get_current_view()->get_fov();
-    ssgSetFOV(fov, fov * globals->get_current_view()->get_win_ratio());
+    ssgSetFOV(fov, fov * globals->get_current_view()->get_fov_ratio());
 
     fgHUDReshape();
 }
index 107401a373fa572b73e82251c09718a63caaa104..ccb51e5c0665900a639503dda26dc835457a0409 100644 (file)
@@ -62,8 +62,11 @@ protected:
     // the field of view in the x (width) direction
     double fov; 
 
-    // ratio of x and y fov's; fov(y) = fov(x) * win_ratio
-    double win_ratio;
+    // ratio of x and y fov's; fov(y) = fov(x) * fov_ratio
+    double fov_ratio;
+
+    // ratio of window width and height; height = width * aspect_ratio
+    double aspect_ratio;
 
     // the current view offset angle from forward (rotated about the
     // view_up vector)
@@ -130,7 +133,13 @@ public:
     // setter functions
     //////////////////////////////////////////////////////////////////////
     inline void set_fov( double amount ) { fov = amount; }
-    inline void set_win_ratio( double r ) { win_ratio = r; }
+    // Don't provide set_fov_ratio explicitely. Use set_aspect_ratio
+    // instead.
+    inline void set_aspect_ratio( double r ) {
+       aspect_ratio = r;
+       fov_ratio = atan(tan(fov/2 * SG_DEGREES_TO_RADIANS) * aspect_ratio) *
+           SG_RADIANS_TO_DEGREES / (fov/2);
+    }
     inline void set_view_offset( double a ) {
        set_dirty();
        view_offset = a;
@@ -176,7 +185,8 @@ public:
     inline int is_a( int t ) const { return get_type() == t ; }
     inline bool is_dirty() const { return dirty; }
     inline double get_fov() const { return fov; }
-    inline double get_win_ratio() const { return win_ratio; }
+    inline double get_aspect_ratio() const { return aspect_ratio; }
+    inline double get_fov_ratio() const { return fov_ratio; }
     inline double get_view_offset() const { return view_offset; }
     inline bool get_reverse_view_offset() const { return reverse_view_offset; }
     inline double get_goal_view_offset() const { return goal_view_offset; }