]> git.mxchange.org Git - flightgear.git/commitdiff
Push aspect-ratio handling into CameraGroup, so renderer doesn't need to resize viewp...
authorJames Turner <zakalawe@mac.com>
Mon, 19 Sep 2011 08:00:23 +0000 (09:00 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 21 Sep 2011 16:13:53 +0000 (17:13 +0100)
src/GUI/gui_funcs.cxx
src/Main/CameraGroup.cxx
src/Main/CameraGroup.hxx
src/Main/fg_os_osgviewer.cxx
src/Main/renderer.cxx
src/Main/renderer.hxx
src/Main/viewer.cxx
src/Main/viewer.hxx

index 9713b45c6fd84a570fecb9c34b0db7fdfecf1be0..538eb755d64941de7521631ad1fe5249937fcde4 100644 (file)
@@ -322,7 +322,7 @@ void fgHiResDump()
         int curColumn = trGet(tr, TR_CURRENT_COLUMN);
         // int curRow =  trGet(tr, TR_CURRENT_ROW);
 
-        renderer->update( false );
+        renderer->update();
         // OSGFIXME
 //         if ( do_hud )
 //             fgUpdateHUD( curColumn*hud_col_step,      curRow*hud_row_step,
index 78a27891b8bf781c42b894f133aa300905c280b0..3e70e9fe1c042f8461dedd08e89bbd7c3e304c4d 100644 (file)
@@ -263,6 +263,22 @@ void CameraGroup::setCameraParameters(float vfov, float aspectRatio)
                                                1.0f / aspectRatio,
                                                _zNear, _zFar);
 }
+    
+double CameraGroup::getMasterAspectRatio() const
+{
+    if (_cameras.empty())
+        return 0.0;
+    
+    const CameraInfo* info = _cameras.front();
+    
+    const osg::Viewport* viewport = info->camera->getViewport();
+    if (!viewport) {
+        return 0.0;
+    }
+    
+    return static_cast<double>(viewport->height()) / viewport->width();
+}
+    
 }
 
 namespace
index 1e18e28e1172702ebd12e8c7c2a826844cc23b1a..e0808ce47b03861ed6541b61ec21e5955c982bfa 100644 (file)
@@ -183,6 +183,11 @@ public:
 
     void buildDistortionCamera(const SGPropertyNode* psNode,
                                osg::Camera* camera);
+  
+    /**
+     * get aspect ratio of master camera's viewport
+     */
+    double getMasterAspectRatio() const;
 protected:
     CameraList _cameras;
     osg::ref_ptr<osgViewer::Viewer> _viewer;
index 764f90735cbd14772ebc9bd17156c8d6338b2c59..6952195f57d94fd8aece01c45e1787dddb3c5646 100644 (file)
@@ -281,7 +281,7 @@ int fgOSMainLoop()
         fgIdleHandler idleFunc = manipulator->getIdleHandler();
         if (idleFunc)
             (*idleFunc)();
-        globals->get_renderer()->update(true);
+        globals->get_renderer()->update();
         viewer->frame();
     }
     
index 6aa796d698a610302bf9f2f1d46c2f878d7ca67e..57980c785bf95f3f63aff32c986b6e61c2c1e33d 100644 (file)
@@ -597,7 +597,7 @@ FGRenderer::setupView( void )
 
 // Update all Visuals (redraws anything graphics related)
 void
-FGRenderer::update( bool refresh_camera_settings ) {
+FGRenderer::update( ) {
     if (!(_scenery_loaded->getBoolValue() || 
            _scenery_override->getBoolValue()))
     {
@@ -649,12 +649,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
     FGViewer *current__view = globals->get_current_view();
     // Force update of center dependent values ...
     current__view->set_dirty();
-
-    if ( refresh_camera_settings ) {
-        // update view port
-        resize( _xsize->getIntValue(),
-                _ysize->getIntValue() );
-    }
+  
     osg::Camera *camera = viewer->getCamera();
 
     bool skyblend = _skyblend->getBoolValue();
@@ -771,22 +766,9 @@ FGRenderer::update( bool refresh_camera_settings ) {
     CameraGroup::getDefault()->setCameraCullMasks(cullMask);
 }
 
-
-
-// options.cxx needs to see this for toggle_panel()
-// Handle new window size or exposure
 void
-FGRenderer::resize( int width, int height ) {
-
-// the following breaks aspect-ratio of the main 3D scenery window when 2D panels are moved
-// in y direction - causing issues for aircraft with 2D panels (/sim/virtual_cockpit=false).
-// Disabling for now. Seems this useful for the pre-OSG time only.
-//    if ( (!_virtual_cockpit->getBoolValue())
-//         && fgPanelVisible() && idle_state == 1000 ) {
-//        view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
-//                             globals->get_current_panel()->getYOffset()) / 768.0);
-//    }
-
+FGRenderer::resize( int width, int height )
+{
     int curWidth = _xsize->getIntValue(),
         curHeight = _ysize->getIntValue();
     if ((curHeight != height) || (curWidth != width)) {
@@ -794,18 +776,6 @@ FGRenderer::resize( int width, int height ) {
         _xsize->setIntValue(width);
         _ysize->setIntValue(height);
     }
-    
-    // must set view aspect ratio each frame, or initial values are wrong.
-    // should probably be fixed 'smarter' during view setup.
-    double aspect = height / (double) width;
-
-    // for all views
-    FGViewMgr *viewmgr = globals->get_viewmgr();
-    if (viewmgr) {
-        for ( int i = 0; i < viewmgr->size(); ++i ) {
-            viewmgr->get_view(i)->set_aspect_ratio(aspect);
-        }
-    }
 }
 
 bool
index 67b9ff9263cfee62ed7ae69f021c6a9957b32f34..84b03d87e06b1e1f29cc6e41f635271a7dfdb01a 100644 (file)
@@ -51,10 +51,7 @@ public:
 
     void resize(int width, int height );
 
-    // calling update( refresh_camera_settings = false ) will not
-    // touch window or camera settings.  This is useful for the tiled
-    // renderer which needs to set the view frustum itself.
-    void update( bool refresh_camera_settings);
+    void update();
   
     /** Just pick into the scene and return the pick callbacks on the way ...
      */
index 57e60f48110007c8eff18f06cd0f8fc05f2271b9..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;
@@ -539,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:
@@ -564,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
@@ -671,3 +672,8 @@ FGViewer::update (double dt)
     _cameraGroup->setCameraParameters(get_v_fov(), get_aspect_ratio());
   }
 }
+
+double FGViewer::get_aspect_ratio() const
+{
+    return _cameraGroup->getMasterAspectRatio();
+}
index 7cd58adae583058a48911b57a9d553581ebba261..ef5df5049d5201938185511a34b2a55e1961a4fd 100644 (file)
@@ -215,10 +215,7 @@ public:
     virtual double get_h_fov();    // Get horizontal fov, in degrees.
     virtual double get_v_fov();    // Get vertical fov, in degrees.
 
-    virtual void set_aspect_ratio( double r ) {
-       _aspect_ratio = r;
-    }
-    virtual double get_aspect_ratio() const { return _aspect_ratio; }
+    virtual double get_aspect_ratio() const;
 
     virtual void set_aspect_ratio_multiplier( double m ) {
        _aspect_ratio_multiplier = m;
@@ -305,11 +302,6 @@ private:
     // the nominal field of view (angle, in degrees)
     double _fov_deg;
 
-    // Ratio of window width and height; height = width *
-    // aspect_ratio.  This value is automatically calculated based on
-    // window dimentions.
-    double _aspect_ratio;
-
     // default = 1.0, this value is user configurable and is
     // multiplied into the aspect_ratio to get the actual vertical fov
     double _aspect_ratio_multiplier;