Changeset 2336

Show
Ignore:
Timestamp:
10/01/03 17:56:52
Author:
robert
Message:

Introduced new DisplaySettings?::set/getDisplayType() and environemtal variables
to and command line arguments to set it.

Added support for using the DisplaySettings?::getDisplayType() to detect use
of a Head Mounted Display when doing stereo so that the asymtric frustum can
be switched off.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/include/osg/DisplaySettings

    r1979 r2336  
    6565        void readCommandLine(ArgumentParser& arguments); 
    6666         
     67         
     68        enum DisplayType 
     69        { 
     70            MONITOR, 
     71            POWERWALL, 
     72            REALITY_CENTER, 
     73            HEAD_MOUNTED_DISPLAY 
     74        }; 
     75 
     76        void setDisplayType(DisplayType type) { _displayType = type; } 
     77         
     78        DisplayType getDisplayType() const { return _displayType; } 
     79 
    6780 
    6881        void setStereo(bool on) { _stereo = on; } 
     
    152165        void copy(const DisplaySettings& vs); 
    153166 
     167        DisplayType                     _displayType; 
    154168        bool                            _stereo; 
    155169        StereoMode                      _stereoMode; 
  • OpenSceneGraph/trunk/include/osgUtil/SceneView

    r2323 r2336  
    131131 
    132132        /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ 
    133         void setProjectionMatrix(const osg::Matrix& matrix); 
     133        inline void setProjectionMatrix(const osg::Matrixf& matrix) { _projectionMatrix.set(matrix); } 
     134 
     135        /** Set the projection matrix. Can be thought of as setting the lens of a camera. */ 
     136        inline void setProjectionMatrix(const osg::Matrixd& matrix) { _projectionMatrix.set(matrix); } 
    134137 
    135138        /** Set to a orthographic projection. See OpenGL glOrtho for documentation further details.*/ 
     
    153156 
    154157        /** Get the projection matrix.*/ 
    155         osg::Matrix& getProjectionMatrix() { return *_projectionMatrix; } 
     158        osg::Matrixd& getProjectionMatrix() { return _projectionMatrix; } 
    156159 
    157160        /** Get the const projection matrix.*/ 
    158         const osg::Matrix& getProjectionMatrix() const { return *_projectionMatrix; } 
     161        const osg::Matrixd& getProjectionMatrix() const { return _projectionMatrix; } 
    159162 
    160163        /** Get the othorgraphic settings of the orthographic projection matrix.  
     
    180183 
    181184        /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ 
    182         void setViewMatrix(const osg::Matrix& matrix); 
     185        inline void setViewMatrix(const osg::Matrixf& matrix) { _viewMatrix.set(matrix); } 
     186         
     187        /** Set the view matrix. Can be thought of as setting the position of the world relative to the camera in camera coordinates. */ 
     188        inline void setViewMatrix(const osg::Matrixd& matrix) { _viewMatrix.set(matrix); } 
    183189 
    184190        /** Set to the position and orientation of view matrix, using the same convention as gluLookAt. */ 
     
    187193 
    188194        /** Get the view matrix. */ 
    189         osg::Matrix& getViewMatrix() { return *_viewMatrix; } 
     195        osg::Matrixd& getViewMatrix() { return _viewMatrix; } 
    190196 
    191197        /** Get the const view matrix. */ 
    192         const osg::Matrix& getViewMatrix() const { return *_viewMatrix; } 
     198        const osg::Matrixd& getViewMatrix() const { return _viewMatrix; } 
    193199 
    194200        /** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ 
     
    345351 
    346352 
     353 
     354        /** callback for overidding the default method for compute the offset projection and view matrices.*/ 
     355        struct ComputeStereoMatricesCallback : public osg::Referenced 
     356        { 
     357            virtual osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const = 0; 
     358            virtual osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const = 0; 
     359 
     360            virtual osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const = 0; 
     361            virtual osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const = 0; 
     362        }; 
     363         
     364        void setComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { _computeStereoMatricesCallback=callback; } 
     365        ComputeStereoMatricesCallback* getComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { return _computeStereoMatricesCallback.get(); } 
     366        const ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() const { return _computeStereoMatricesCallback.get(); } 
     367 
     368        inline osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection)  const 
     369        { 
     370            if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeProjection(projection); 
     371            else return computeLeftEyeProjectionImplementation(projection); 
     372        } 
     373 
     374        inline osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const 
     375        { 
     376            if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeLeftEyeView(view); 
     377            else return computeLeftEyeViewImplementation(view); 
     378        } 
     379         
     380        inline osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection)  const 
     381        { 
     382            if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeProjection(projection); 
     383            else return computeRightEyeProjectionImplementation(projection); 
     384        } 
     385 
     386        inline osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const 
     387        { 
     388            if (_computeStereoMatricesCallback.valid()) return _computeStereoMatricesCallback->computeRightEyeView(view); 
     389            else return computeRightEyeViewImplementation(view); 
     390        } 
     391 
     392        virtual osg::Matrixd computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const; 
     393        virtual osg::Matrixd computeLeftEyeViewImplementation(const osg::Matrixd& view) const; 
     394 
     395        virtual osg::Matrixd computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const; 
     396        virtual osg::Matrixd computeRightEyeViewImplementation(const osg::Matrixd& view) const; 
     397 
     398 
    347399        /** Do init traversal of attached scene graph using Init NodeVisitor. 
    348400          * The init traversal is called once for each SceneView, and should 
     
    356408        /** Do app traversal of attached scene graph using App NodeVisitor.*/ 
    357409        virtual void update(); 
    358 #ifdef USE_DEPREACTED_API 
    359         virtual void app() { update(); } 
    360 #endif        
    361410 
    362411        /** Do cull traversal of attached scene graph using Cull NodeVisitor.*/ 
     
    371420 
    372421        /** Do cull traversal of attached scene graph using Cull NodeVisitor.*/ 
    373         virtual void cullStage(osg::RefMatrix* projection,osg::RefMatrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage); 
     422        virtual void cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage); 
    374423 
    375424        const osg::Matrix computeMVPW() const; 
     
    381430        osg::ref_ptr<osg::StateSet>                 _localStateSet; 
    382431        osg::ref_ptr<osg::Light>                    _light; 
    383         osg::ref_ptr<osg::RefMatrix>                _projectionMatrix; 
    384         osg::ref_ptr<osg::RefMatrix>                _viewMatrix; 
     432        osg::Matrixd                                _projectionMatrix; 
     433        osg::Matrixd                                _viewMatrix; 
    385434        osg::ref_ptr<osg::DisplaySettings>          _displaySettings; 
    386435        osg::ref_ptr<osg::State>                    _state; 
     
    394443        osg::ref_ptr<osgUtil::RenderStage>          _renderStage; 
    395444 
     445        osg::ref_ptr<ComputeStereoMatricesCallback> _computeStereoMatricesCallback; 
     446 
    396447        osg::Node::NodeMask                          _cullMaskLeft; 
    397448        osg::ref_ptr<osgUtil::CullVisitor>          _cullVisitorLeft; 
  • OpenSceneGraph/trunk/src/osg/DisplaySettings.cpp

    r1979 r2336  
    4646void DisplaySettings::copy(const DisplaySettings& vs) 
    4747{ 
     48    _displayType = vs._displayType; 
    4849    _stereoMode = vs._stereoMode; 
    4950    _eyeSeparation = vs._eyeSeparation; 
     
    8485void DisplaySettings::setDefaults() 
    8586{ 
     87    _displayType = MONITOR; 
     88 
    8689    _stereo = false; 
    8790    _stereoMode = ANAGLYPHIC; 
     
    107110} 
    108111 
    109 static ApplicationUsageProxy DisplaySetting_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_STEREO_MODE <mode>","QUAD_BUFFER | ANAGLYPHIC | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE"); 
    110 static ApplicationUsageProxy DisplaySetting_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_STEREO <mode>","OFF | ON"); 
    111 static ApplicationUsageProxy DisplaySetting_e2(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_EYE_SEPARATION <float>","physical distance between eyes"); 
    112 static ApplicationUsageProxy DisplaySetting_e3(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN_DISTANCE <float>","physical distance between eyes and screen"); 
    113 static ApplicationUsageProxy DisplaySetting_e4(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN_HEIGHT <float>","physical screen height"); 
    114 static ApplicationUsageProxy DisplaySetting_e5(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING <mode>","LEFT_EYE_LEFT_VIEWPORT | LEFT_EYE_RIGHT_VIEWPORT"); 
    115 static ApplicationUsageProxy DisplaySetting_e8(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION <float>","number of pixels between viewports"); 
    116 static ApplicationUsageProxy DisplaySetting_e9(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING <mode>","LEFT_EYE_TOP_VIEWPORT | LEFT_EYE_BOTTOM_VIEWPORT"); 
    117 static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO <mode>","OFF | ON  Default to ON to compenstate for the compression of the aspect ratio when viewing in split screen stereo.  Note, if you are setting fovx and fovy explicityly OFF should be used."); 
    118 static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>","number of pixels between viewports"); 
    119 static ApplicationUsageProxy DisplaySetting_e12(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>","maximum number of graphics contexts to be used with applications."); 
     112static ApplicationUsageProxy DisplaySetting_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DISPLAY_TYPE <type>","MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY"); 
     113static ApplicationUsageProxy DisplaySetting_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_STEREO_MODE <mode>","QUAD_BUFFER | ANAGLYPHIC | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE"); 
     114static ApplicationUsageProxy DisplaySetting_e2(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_STEREO <mode>","OFF | ON"); 
     115static ApplicationUsageProxy DisplaySetting_e3(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_EYE_SEPARATION <float>","physical distance between eyes"); 
     116static ApplicationUsageProxy DisplaySetting_e4(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN_DISTANCE <float>","physical distance between eyes and screen"); 
     117static ApplicationUsageProxy DisplaySetting_e5(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN_HEIGHT <float>","physical screen height"); 
     118static ApplicationUsageProxy DisplaySetting_e6(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING <mode>","LEFT_EYE_LEFT_VIEWPORT | LEFT_EYE_RIGHT_VIEWPORT"); 
     119static ApplicationUsageProxy DisplaySetting_e7(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION <float>","number of pixels between viewports"); 
     120static ApplicationUsageProxy DisplaySetting_e8(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING <mode>","LEFT_EYE_TOP_VIEWPORT | LEFT_EYE_BOTTOM_VIEWPORT"); 
     121static ApplicationUsageProxy DisplaySetting_e9(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_AUTO_ADJUST_ASPECT_RATIO <mode>","OFF | ON  Default to ON to compenstate for the compression of the aspect ratio when viewing in split screen stereo.  Note, if you are setting fovx and fovy explicityly OFF should be used."); 
     122static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>","number of pixels between viewports"); 
     123static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>","maximum number of graphics contexts to be used with applications."); 
    120124 
    121125void DisplaySettings::readEnvironmentalVariables() 
    122126{ 
    123127    char *ptr; 
     128     
     129    if ((ptr = getenv("OSG_DISPLAY_TYPE")) != 0) 
     130    { 
     131        if (strcmp(ptr,"MONITOR")==0) 
     132        { 
     133            _displayType = MONITOR; 
     134        } 
     135        else 
     136        if (strcmp(ptr,"POWERWALL")==0) 
     137        { 
     138            _displayType = POWERWALL; 
     139        } 
     140        else 
     141        if (strcmp(ptr,"REALITY_CENTER")==0) 
     142        { 
     143            _displayType = REALITY_CENTER; 
     144        } 
     145        else 
     146        if (strcmp(ptr,"HEAD_MOUNTED_DISPLAY")==0) 
     147        { 
     148            _displayType = HEAD_MOUNTED_DISPLAY; 
     149        } 
     150    } 
     151     
    124152    if( (ptr = getenv("OSG_STEREO_MODE")) != 0) 
    125153    { 
     
    245273    if (arguments.getApplicationUsage()) 
    246274    { 
     275        arguments.getApplicationUsage()->addCommandLineOption("--display <type>","MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY"); 
    247276        arguments.getApplicationUsage()->addCommandLineOption("--stereo","Use default stereo mode which is ANAGLYPHIC if not overriden by environmental variable"); 
    248277        arguments.getApplicationUsage()->addCommandLineOption("--stereo <mode>","ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE | ON | OFF "); 
     
    251280    } 
    252281 
     282    std::string str; 
     283    while(arguments.read("--display",str)) 
     284    { 
     285        if (str=="MONITOR") _displayType = MONITOR; 
     286        else if (str=="POWERWALL") _displayType = POWERWALL; 
     287        else if (str=="REALITY_CENTER") _displayType = REALITY_CENTER; 
     288        else if (str=="HEAD_MOUNTED_DISPLAY") _displayType = HEAD_MOUNTED_DISPLAY; 
     289    } 
    253290 
    254291    int pos; 
  • OpenSceneGraph/trunk/src/osgUtil/SceneView.cpp

    r2323 r2336  
    6868void SceneView::setDefaults() 
    6969{ 
    70     if (!_projectionMatrix)  
    71     { 
    72         _projectionMatrix = new RefMatrix(); 
    73         _projectionMatrix->makePerspective(50.0f,1.4f,1.0f,10000.0f); 
    74     } 
    75     if (!_viewMatrix) 
    76     { 
    77         _viewMatrix = new RefMatrix(); 
    78     } 
     70    _projectionMatrix.makePerspective(50.0f,1.4f,1.0f,10000.0f); 
     71    _viewMatrix.makeIdentity(); 
    7972 
    8073    _globalStateSet = new osg::StateSet; 
     
    194187} 
    195188 
     189osg::Matrixd SceneView::computeLeftEyeProjectionImplementation(const osg::Matrixd& projection) const 
     190{ 
     191    double fusionDistance = _displaySettings->getScreenDistance(); 
     192    switch(_fusionDistanceMode) 
     193    { 
     194        case(USE_FUSION_DISTANCE_VALUE): 
     195            fusionDistance = _fusionDistanceValue; 
     196            break; 
     197        case(PROPORTIONAL_TO_SCREEN_DISTANCE): 
     198            fusionDistance *= _fusionDistanceValue; 
     199            break; 
     200    } 
     201 
     202    double iod = _displaySettings->getEyeSeparation(); 
     203    double sd = _displaySettings->getScreenDistance(); 
     204    double scale_x = 1.0; 
     205    double scale_y = 1.0; 
     206 
     207    if (_displaySettings->getSplitStereoAutoAjustAspectRatio()) 
     208    { 
     209        switch(_displaySettings->getStereoMode()) 
     210        { 
     211            case(osg::DisplaySettings::HORIZONTAL_SPLIT): 
     212                scale_x = 2.0; 
     213                break; 
     214            case(osg::DisplaySettings::VERTICAL_SPLIT): 
     215                scale_y = 2.0; 
     216                break; 
     217            default: 
     218                break; 
     219        } 
     220    } 
     221 
     222    if (_displaySettings->getDisplayType()==osg::DisplaySettings::HEAD_MOUNTED_DISPLAY) 
     223    { 
     224        // head mounted display has the same projection matrix for left and right eyes. 
     225        return osg::Matrixd::scale(scale_x,scale_y,1.0) * 
     226               projection; 
     227    } 
     228    else 
     229    { 
     230        // all other display types assume working like a projected power wall 
     231        // need to shjear projection matrix to account for asymetric frustum due to eye offset. 
     232        return osg::Matrixd(1.0,0.0,0.0,0.0, 
     233                           0.0,1.0,0.0,0.0, 
     234                           iod/(2.0*sd),0.0,1.0,0.0, 
     235                           0.0,0.0,0.0,1.0) * 
     236               osg::Matrixd::scale(scale_x,scale_y,1.0) * 
     237               projection; 
     238    } 
     239} 
     240 
     241osg::Matrixd SceneView::computeLeftEyeViewImplementation(const osg::Matrixd& view) const 
     242{ 
     243    double fusionDistance = _displaySettings->getScreenDistance(); 
     244    switch(_fusionDistanceMode) 
     245    { 
     246        case(USE_FUSION_DISTANCE_VALUE): 
     247            fusionDistance = _fusionDistanceValue; 
     248            break; 
     249        case(PROPORTIONAL_TO_SCREEN_DISTANCE): 
     250            fusionDistance *= _fusionDistanceValue; 
     251            break; 
     252    } 
     253 
     254    double iod = _displaySettings->getEyeSeparation(); 
     255    double sd = _displaySettings->getScreenDistance(); 
     256    double es = 0.5f*iod*(fusionDistance/sd); 
     257 
     258    return view * 
     259           osg::Matrixd(1.0,0.0,0.0,0.0, 
     260                       0.0,1.0,0.0,0.0, 
     261                       0.0,0.0,1.0,0.0, 
     262                       es,0.0,0.0,1.0); 
     263} 
     264 
     265osg::Matrixd SceneView::computeRightEyeProjectionImplementation(const osg::Matrixd& projection) const 
     266{ 
     267    double fusionDistance = _displaySettings->getScreenDistance(); 
     268    switch(_fusionDistanceMode) 
     269    { 
     270        case(USE_FUSION_DISTANCE_VALUE): 
     271            fusionDistance = _fusionDistanceValue; 
     272            break; 
     273        case(PROPORTIONAL_TO_SCREEN_DISTANCE): 
     274            fusionDistance *= _fusionDistanceValue; 
     275            break; 
     276    } 
     277 
     278    double iod = _displaySettings->getEyeSeparation(); 
     279    double sd = _displaySettings->getScreenDistance(); 
     280    double scale_x = 1.0; 
     281    double scale_y = 1.0; 
     282 
     283    if (_displaySettings->getSplitStereoAutoAjustAspectRatio()) 
     284    { 
     285        switch(_displaySettings->getStereoMode()) 
     286        { 
     287            case(osg::DisplaySettings::HORIZONTAL_SPLIT): 
     288                scale_x = 2.0; 
     289                break; 
     290            case(osg::DisplaySettings::VERTICAL_SPLIT): 
     291                scale_y = 2.0; 
     292                break; 
     293            default: 
     294                break; 
     295        } 
     296    } 
     297 
     298    if (_displaySettings->getDisplayType()==osg::DisplaySettings::HEAD_MOUNTED_DISPLAY) 
     299    { 
     300        // head mounted display has the same projection matrix for left and right eyes. 
     301        return osg::Matrixd::scale(scale_x,scale_y,1.0) * 
     302               projection; 
     303    } 
     304    else 
     305    { 
     306        // all other display types assume working like a projected power wall 
     307        // need to shjear projection matrix to account for asymetric frustum due to eye offset. 
     308        return osg::Matrixd(1.0,0.0,0.0,0.0, 
     309                           0.0,1.0,0.0,0.0, 
     310                           -iod/(2.0*sd),0.0,1.0,0.0, 
     311                           0.0,0.0,0.0,1.0) * 
     312               osg::Matrixd::scale(scale_x,scale_y,1.0) * 
     313               projection; 
     314    } 
     315} 
     316 
     317osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& view) const 
     318{ 
     319    float fusionDistance = _displaySettings->getScreenDistance(); 
     320    switch(_fusionDistanceMode) 
     321    { 
     322        case(USE_FUSION_DISTANCE_VALUE): 
     323            fusionDistance = _fusionDistanceValue; 
     324            break; 
     325        case(PROPORTIONAL_TO_SCREEN_DISTANCE): 
     326            fusionDistance *= _fusionDistanceValue; 
     327            break; 
     328    } 
     329 
     330    double iod = _displaySettings->getEyeSeparation(); 
     331    double sd = _displaySettings->getScreenDistance(); 
     332    double es = 0.5*iod*(fusionDistance/sd); 
     333 
     334    return view * 
     335           osg::Matrixd(1.0,0.0,0.0,0.0, 
     336                       0.0,1.0,0.0,0.0, 
     337                       0.0,0.0,1.0,0.0, 
     338                       -es,0.0,0.0,1.0); 
     339} 
     340 
    196341void SceneView::cull() 
    197342{ 
     
    218363 
    219364 
    220     osg::ref_ptr<osg::RefMatrix> projection = _projectionMatrix.get(); 
    221     osg::ref_ptr<osg::RefMatrix> modelview = _viewMatrix.get(); 
    222         
    223     if (!projection) projection = new osg::RefMatrix(); 
    224     if (!modelview)  modelview  = new osg::RefMatrix(); 
    225  
    226365    if (!_cullVisitor) 
    227366    { 
     
    243382    { 
    244383 
    245         float fusionDistance = _displaySettings->getScreenDistance(); 
    246         switch(_fusionDistanceMode) 
    247         { 
    248             case(USE_FUSION_DISTANCE_VALUE): 
    249                 fusionDistance = _fusionDistanceValue; 
    250                 break; 
    251             case(PROPORTIONAL_TO_SCREEN_DISTANCE): 
    252                 fusionDistance *= _fusionDistanceValue; 
    253                 break; 
    254         } 
    255  
    256         float iod = _displaySettings->getEyeSeparation(); 
    257         float sd = _displaySettings->getScreenDistance(); 
    258         float es = 0.5f*iod*(fusionDistance/sd); 
    259  
    260384        if (_displaySettings->getStereoMode()==osg::DisplaySettings::LEFT_EYE) 
    261385        { 
    262386            // set up the left eye. 
    263             osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    264                                                                                          0.0f,1.0f,0.0f,0.0f, 
    265                                                                                          iod/(2.0f*sd),0.0f,1.0f,0.0f, 
    266                                                                                          0.0f,0.0f,0.0f,1.0f)* 
    267                                                                              (*projection)); 
    268  
    269  
    270             osg::ref_ptr<osg::RefMatrix> modelviewLeft = new osg::RefMatrix( (*modelview) * 
    271                                                                              osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    272                                                                                          0.0f,1.0f,0.0f,0.0f, 
    273                                                                                          0.0f,0.0f,1.0f,0.0f, 
    274                                                                                          es,0.0f,0.0f,1.0f)); 
    275  
    276387            _cullVisitor->setTraversalMask(_cullMaskLeft); 
    277             cullStage(projectionLeft.get(),modelviewLeft.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); 
     388            cullStage(computeLeftEyeProjection(_projectionMatrix),computeLeftEyeView(_viewMatrix),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); 
    278389 
    279390        } 
     
    281392        { 
    282393            // set up the right eye. 
    283             osg::ref_ptr<osg::RefMatrix> projectionRight = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    284                                                                                           0.0f,1.0f,0.0f,0.0f, 
    285                                                                                           -iod/(2.0f*sd),0.0f,1.0f,0.0f, 
    286                                                                                           0.0f,0.0f,0.0f,1.0f)* 
    287                                                                               (*projection)); 
    288  
    289             osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) * 
    290                                                                               osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    291                                                                                           0.0f,1.0f,0.0f,0.0f, 
    292                                                                                           0.0f,0.0f,1.0f,0.0f, 
    293                                                                                           -es,0.0f,0.0f,1.0f)); 
    294  
    295394            _cullVisitor->setTraversalMask(_cullMaskRight); 
    296             cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); 
    297  
    298  
     395            cullStage(computeRightEyeProjection(_projectionMatrix),computeRightEyeView(_viewMatrix),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); 
    299396        } 
    300397        else 
     
    310407 
    311408 
    312  
    313  
    314             osg::Matrix projection_scale; 
    315              
    316              
    317             if (_displaySettings->getSplitStereoAutoAjustAspectRatio()) 
    318             { 
    319  
    320                 switch(_displaySettings->getStereoMode()) 
    321                 { 
    322                     case(osg::DisplaySettings::HORIZONTAL_SPLIT): 
    323                         projection_scale.makeScale(2.0f,1.0f,1.0f); 
    324                         break; 
    325                     case(osg::DisplaySettings::VERTICAL_SPLIT): 
    326                         projection_scale.makeScale(1.0f,2.0f,1.0f); 
    327                         break; 
    328                     default: 
    329                         break; 
    330                 } 
    331             } 
    332              
    333             // set up the left eye. 
    334             osg::ref_ptr<osg::RefMatrix> projectionLeft = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    335                                                                                          0.0f,1.0f,0.0f,0.0f, 
    336                                                                                          iod/(2.0f*sd),0.0f,1.0f,0.0f, 
    337                                                                                          0.0f,0.0f,0.0f,1.0f)* 
    338                                                                              projection_scale* 
    339                                                                              (*projection)); 
    340  
    341  
    342  
    343             osg::ref_ptr<osg::RefMatrix> modelviewLeft = new osg::RefMatrix( (*modelview) * 
    344                                                              osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    345                                                                          0.0f,1.0f,0.0f,0.0f, 
    346                                                                          0.0f,0.0f,1.0f,0.0f, 
    347                                                                          es,0.0f,0.0f,1.0f)); 
    348  
    349409            _cullVisitorLeft->setTraversalMask(_cullMaskLeft); 
    350             cullStage(projectionLeft.get(),modelviewLeft.get(),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); 
     410            cullStage(computeLeftEyeProjection(_projectionMatrix),computeLeftEyeView(_viewMatrix),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); 
    351411 
    352412 
    353413            // set up the right eye. 
    354             osg::ref_ptr<osg::RefMatrix> projectionRight = new osg::RefMatrix(osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    355                                                                                           0.0f,1.0f,0.0f,0.0f, 
    356                                                                                           -iod/(2.0f*sd),0.0f,1.0f,0.0f, 
    357                                                                                           0.0f,0.0f,0.0f,1.0f)* 
    358                                                                               projection_scale* 
    359                                                                               (*projection)); 
    360  
    361             osg::ref_ptr<osg::RefMatrix> modelviewRight = new osg::RefMatrix( (*modelview) * 
    362                                                                               osg::Matrix(1.0f,0.0f,0.0f,0.0f, 
    363                                                                                          0.0f,1.0f,0.0f,0.0f, 
    364                                                                                          0.0f,0.0f,1.0f,0.0f, 
    365                                                                                          -es,0.0f,0.0f,1.0f)); 
    366  
    367  
    368  
    369414            _cullVisitorRight->setTraversalMask(_cullMaskRight); 
    370             cullStage(projectionRight.get(),modelviewRight.get(),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); 
     415            cullStage(computeRightEyeProjection(_projectionMatrix),computeRightEyeView(_viewMatrix),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); 
    371416            
    372417        } 
     
    377422 
    378423        _cullVisitor->setTraversalMask(_cullMask); 
    379         cullStage(projection.get(),modelview.get(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); 
    380  
    381     } 
    382      
    383      
    384 } 
    385  
    386 void SceneView::cullStage(osg::RefMatrix* projection,osg::RefMatrix* modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage) 
     424        cullStage(_projectionMatrix,_viewMatrix,_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); 
     425 
     426    } 
     427     
     428     
     429} 
     430 
     431void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage) 
    387432{ 
    388433 
     
    392437 
    393438 
     439    osg::ref_ptr<RefMatrix> proj = new osg::RefMatrix(projection); 
     440    osg::ref_ptr<RefMatrix> mv = new osg::RefMatrix(modelview); 
    394441 
    395442    // collect any occluder in the view frustum. 
     
    409456 
    410457        cov.pushViewport(_viewport.get()); 
    411         cov.pushProjectionMatrix(projection); 
    412         cov.pushModelViewMatrix(modelview); 
     458        cov.pushProjectionMatrix(proj.get()); 
     459        cov.pushModelViewMatrix(mv.get()); 
    413460 
    414461        // traverse the scene graph to search for occluder in there new positions. 
     
    474521        break; 
    475522    case(SKY_LIGHT): 
    476         if (_light.valid()) renderStage->addPositionedAttribute(modelview,_light.get()); 
     523        if (_light.valid()) renderStage->addPositionedAttribute(mv.get(),_light.get()); 
    477524        else osg::notify(osg::WARN)<<"Warning: no osg::Light attached to ogUtil::SceneView to provide sky light.*/"<<std::endl; 
    478525        break; 
     
    486533 
    487534    cullVisitor->pushViewport(_viewport.get()); 
    488     cullVisitor->pushProjectionMatrix(projection); 
    489     cullVisitor->pushModelViewMatrix(modelview); 
     535    cullVisitor->pushProjectionMatrix(proj.get()); 
     536    cullVisitor->pushModelViewMatrix(mv.get()); 
    490537     
    491538 
     
    554601    //std::cout<<"time to flush rendering objects"<<timer.delta_m(tstart,tend)<<std::endl; 
    555602 
    556     if (_viewMatrix.valid()) _state->setInitialViewMatrix(_viewMatrix.get()); 
     603    _state->setInitialViewMatrix(new osg::RefMatrix(_viewMatrix)); 
    557604 
    558605    RenderLeaf* previous = NULL; 
     
    863910const osg::Matrix SceneView::computeMVPW() const 
    864911{ 
    865     osg::Matrix matrix; 
    866      
    867     if (_viewMatrix.valid()) 
    868         matrix = (*_viewMatrix); 
    869          
    870     if (_projectionMatrix.valid()) 
    871         matrix.postMult(*_projectionMatrix); 
     912    osg::Matrix matrix( _viewMatrix * _projectionMatrix); 
    872913         
    873914    if (_viewport.valid()) 
     
    894935} 
    895936 
    896 void SceneView::setProjectionMatrix(const osg::Matrix& matrix) 
    897 { 
    898     if (!_projectionMatrix) _projectionMatrix = new osg::RefMatrix(matrix); 
    899     else _projectionMatrix->set(matrix); 
    900 } 
    901  
    902  
    903937void SceneView::setProjectionMatrixAsOrtho(double left, double right, 
    904938                                           double bottom, double top, 
    905939                                           double zNear, double zFar) 
    906940{ 
    907     setProjectionMatrix(osg::Matrix::ortho(left, right, 
     941    setProjectionMatrix(osg::Matrixd::ortho(left, right, 
    908942                                           bottom, top, 
    909943                                           zNear, zFar)); 
     
    913947                                             double bottom, double top) 
    914948{ 
    915     setProjectionMatrix(osg::Matrix::ortho2D(left, right, 
     949    setProjectionMatrix(osg::Matrixd::ortho2D(left, right, 
    916950                                             bottom, top)); 
    917951} 
     
    921955                                             double zNear, double zFar) 
    922956{ 
    923     setProjectionMatrix(osg::Matrix::frustum(left, right, 
     957    setProjectionMatrix(osg::Matrixd::frustum(left, right, 
    924958                                             bottom, top, 
    925959                                             zNear, zFar)); 
     
    929963                                                 double zNear, double zFar) 
    930964{ 
    931     setProjectionMatrix(osg::Matrix::perspective(fovy,aspectRatio, 
     965    setProjectionMatrix(osg::Matrixd::perspective(fovy,aspectRatio, 
    932966                                                 zNear, zFar)); 
    933967}                                       
     
    937971                                           double& zNear, double& zFar) 
    938972{ 
    939     if (_projectionMatrix.valid())  
    940     { 
    941         return _projectionMatrix->getOrtho(left, right, 
    942                                            bottom, top, 
    943                                            zNear, zFar); 
    944     } 
    945     return false; 
     973    return _projectionMatrix.getOrtho(left, right, 
     974                                       bottom, top, 
     975                                       zNear, zFar); 
    946976} 
    947977 
     
    950980                                             double& zNear, double& zFar) 
    951981{ 
    952     if (_projectionMatrix.valid())  
    953     { 
    954         return _projectionMatrix->getFrustum(left, right, 
    955                                              bottom, top, 
    956                                              zNear, zFar); 
    957     } 
    958     return false; 
     982    return _projectionMatrix.getFrustum(left, right, 
     983                                         bottom, top, 
     984                                         zNear, zFar); 
    959985}                                   
    960986 
     
    962988                                                 double& zNear, double& zFar) 
    963989{ 
    964     if (_projectionMatrix.valid())  
    965     { 
    966         return _projectionMatrix->getPerspective(fovy, aspectRatio, zNear, zFar); 
    967     } 
    968     return false; 
     990    return _projectionMatrix.getPerspective(fovy, aspectRatio, zNear, zFar); 
    969991}                                                  
    970992 
    971 void SceneView::setViewMatrix(const osg::Matrix& matrix) 
    972 { 
    973     if (!_viewMatrix) _viewMatrix = new osg::RefMatrix(matrix); 
    974     else _viewMatrix->set(matrix); 
    975 } 
    976  
    977993void SceneView::setViewMatrixAsLookAt(const Vec3& eye,const Vec3& center,const Vec3& up) 
    978994{ 
    979     setViewMatrix(osg::Matrix::lookAt(eye,center,up)); 
     995    setViewMatrix(osg::Matrixd::lookAt(eye,center,up)); 
    980996} 
    981997 
    982998void SceneView::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance) 
    983999{ 
    984     if (_viewMatrix.valid()) 
    985     { 
    986         _viewMatrix->getLookAt(eye,center,up,lookDistance); 
    987     } 
    988 
     1000    _viewMatrix.getLookAt(eye,center,up,lookDistance); 
     1001