diff --git a/src/Cockpit/hud.cxx b/src/Cockpit/hud.cxx index 74c2d08ff..92183ba18 100644 --- a/src/Cockpit/hud.cxx +++ b/src/Cockpit/hud.cxx @@ -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; diff --git a/src/Cockpit/hud_ladr.cxx b/src/Cockpit/hud_ladr.cxx index 09c0ee871..2ce6b2423 100644 --- a/src/Cockpit/hud_ladr.cxx +++ b/src/Cockpit/hud_ladr.cxx @@ -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 diff --git a/src/GUI/gui.cxx b/src/GUI/gui.cxx index d3df0a87c..6d4e28168 100644 --- a/src/GUI/gui.cxx +++ b/src/GUI/gui.cxx @@ -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 ); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 5419fcd04..17c2600b9 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -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 = diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index 1b00338f3..9dca63c5c 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -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 diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 892aeb4d0..2a0802dda 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -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 ) { - // 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 ); - } + int view_h; + + if ( fgPanelVisible() && idle_state == 1000 ) { + view_h = (int)(height * (current_panel->getViewHeight() - + current_panel->getYOffset()) / 768.0); + } else { + view_h = height; } - 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) ); + // for all views + for ( int i = 0; i < globals->get_viewmgr()->size(); ++i ) { + globals->get_viewmgr()->get_view(i)-> + set_aspect_ratio((float)view_h / (float)width); } + 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(); } diff --git a/src/Main/viewer.hxx b/src/Main/viewer.hxx index 107401a37..ccb51e5c0 100644 --- a/src/Main/viewer.hxx +++ b/src/Main/viewer.hxx @@ -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; }