Changeset 2336
- Timestamp:
- 10/01/03 17:56:52
- Files:
-
- OpenSceneGraph/trunk/include/osg/DisplaySettings (modified) (2 diffs)
- OpenSceneGraph/trunk/include/osgUtil/SceneView (modified) (9 diffs)
- OpenSceneGraph/trunk/src/osg/DisplaySettings.cpp (modified) (5 diffs)
- OpenSceneGraph/trunk/src/osgUtil/SceneView.cpp (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/include/osg/DisplaySettings
r1979 r2336 65 65 void readCommandLine(ArgumentParser& arguments); 66 66 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 67 80 68 81 void setStereo(bool on) { _stereo = on; } … … 152 165 void copy(const DisplaySettings& vs); 153 166 167 DisplayType _displayType; 154 168 bool _stereo; 155 169 StereoMode _stereoMode; OpenSceneGraph/trunk/include/osgUtil/SceneView
r2323 r2336 131 131 132 132 /** 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); } 134 137 135 138 /** Set to a orthographic projection. See OpenGL glOrtho for documentation further details.*/ … … 153 156 154 157 /** Get the projection matrix.*/ 155 osg::Matrix & getProjectionMatrix() { return *_projectionMatrix; }158 osg::Matrixd& getProjectionMatrix() { return _projectionMatrix; } 156 159 157 160 /** Get the const projection matrix.*/ 158 const osg::Matrix & getProjectionMatrix() const { return *_projectionMatrix; }161 const osg::Matrixd& getProjectionMatrix() const { return _projectionMatrix; } 159 162 160 163 /** Get the othorgraphic settings of the orthographic projection matrix. … … 180 183 181 184 /** 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); } 183 189 184 190 /** Set to the position and orientation of view matrix, using the same convention as gluLookAt. */ … … 187 193 188 194 /** Get the view matrix. */ 189 osg::Matrix & getViewMatrix() { return *_viewMatrix; }195 osg::Matrixd& getViewMatrix() { return _viewMatrix; } 190 196 191 197 /** Get the const view matrix. */ 192 const osg::Matrix & getViewMatrix() const { return *_viewMatrix; }198 const osg::Matrixd& getViewMatrix() const { return _viewMatrix; } 193 199 194 200 /** Get to the position and orientation of a modelview matrix, using the same convention as gluLookAt. */ … … 345 351 346 352 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 347 399 /** Do init traversal of attached scene graph using Init NodeVisitor. 348 400 * The init traversal is called once for each SceneView, and should … … 356 408 /** Do app traversal of attached scene graph using App NodeVisitor.*/ 357 409 virtual void update(); 358 #ifdef USE_DEPREACTED_API359 virtual void app() { update(); }360 #endif361 410 362 411 /** Do cull traversal of attached scene graph using Cull NodeVisitor.*/ … … 371 420 372 421 /** 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); 374 423 375 424 const osg::Matrix computeMVPW() const; … … 381 430 osg::ref_ptr<osg::StateSet> _localStateSet; 382 431 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; 385 434 osg::ref_ptr<osg::DisplaySettings> _displaySettings; 386 435 osg::ref_ptr<osg::State> _state; … … 394 443 osg::ref_ptr<osgUtil::RenderStage> _renderStage; 395 444 445 osg::ref_ptr<ComputeStereoMatricesCallback> _computeStereoMatricesCallback; 446 396 447 osg::Node::NodeMask _cullMaskLeft; 397 448 osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorLeft; OpenSceneGraph/trunk/src/osg/DisplaySettings.cpp
r1979 r2336 46 46 void DisplaySettings::copy(const DisplaySettings& vs) 47 47 { 48 _displayType = vs._displayType; 48 49 _stereoMode = vs._stereoMode; 49 50 _eyeSeparation = vs._eyeSeparation; … … 84 85 void DisplaySettings::setDefaults() 85 86 { 87 _displayType = MONITOR; 88 86 89 _stereo = false; 87 90 _stereoMode = ANAGLYPHIC; … … 107 110 } 108 111 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."); 112 static ApplicationUsageProxy DisplaySetting_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_DISPLAY_TYPE <type>","MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY"); 113 static ApplicationUsageProxy DisplaySetting_e1(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_STEREO_MODE <mode>","QUAD_BUFFER | ANAGLYPHIC | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE"); 114 static ApplicationUsageProxy DisplaySetting_e2(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_STEREO <mode>","OFF | ON"); 115 static ApplicationUsageProxy DisplaySetting_e3(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_EYE_SEPARATION <float>","physical distance between eyes"); 116 static ApplicationUsageProxy DisplaySetting_e4(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN_DISTANCE <float>","physical distance between eyes and screen"); 117 static ApplicationUsageProxy DisplaySetting_e5(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SCREEN_HEIGHT <float>","physical screen height"); 118 static ApplicationUsageProxy DisplaySetting_e6(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_EYE_MAPPING <mode>","LEFT_EYE_LEFT_VIEWPORT | LEFT_EYE_RIGHT_VIEWPORT"); 119 static ApplicationUsageProxy DisplaySetting_e7(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_HORIZONTAL_SEPARATION <float>","number of pixels between viewports"); 120 static ApplicationUsageProxy DisplaySetting_e8(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_EYE_MAPPING <mode>","LEFT_EYE_TOP_VIEWPORT | LEFT_EYE_BOTTOM_VIEWPORT"); 121 static 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."); 122 static ApplicationUsageProxy DisplaySetting_e10(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_SPLIT_STEREO_VERTICAL_SEPARATION <float>","number of pixels between viewports"); 123 static ApplicationUsageProxy DisplaySetting_e11(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_NUMBER_OF_GRAPHICS_CONTEXTS <int>","maximum number of graphics contexts to be used with applications."); 120 124 121 125 void DisplaySettings::readEnvironmentalVariables() 122 126 { 123 127 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 124 152 if( (ptr = getenv("OSG_STEREO_MODE")) != 0) 125 153 { … … 245 273 if (arguments.getApplicationUsage()) 246 274 { 275 arguments.getApplicationUsage()->addCommandLineOption("--display <type>","MONITOR | POWERWALL | REALITY_CENTER | HEAD_MOUNTED_DISPLAY"); 247 276 arguments.getApplicationUsage()->addCommandLineOption("--stereo","Use default stereo mode which is ANAGLYPHIC if not overriden by environmental variable"); 248 277 arguments.getApplicationUsage()->addCommandLineOption("--stereo <mode>","ANAGLYPHIC | QUAD_BUFFER | HORIZONTAL_SPLIT | VERTICAL_SPLIT | LEFT_EYE | RIGHT_EYE | ON | OFF "); … … 251 280 } 252 281 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 } 253 290 254 291 int pos; OpenSceneGraph/trunk/src/osgUtil/SceneView.cpp
r2323 r2336 68 68 void SceneView::setDefaults() 69 69 { 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(); 79 72 80 73 _globalStateSet = new osg::StateSet; … … 194 187 } 195 188 189 osg::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 241 osg::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 265 osg::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 317 osg::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 196 341 void SceneView::cull() 197 342 { … … 218 363 219 364 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 226 365 if (!_cullVisitor) 227 366 { … … 243 382 { 244 383 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 260 384 if (_displaySettings->getStereoMode()==osg::DisplaySettings::LEFT_EYE) 261 385 { 262 386 // 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 276 387 _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()); 278 389 279 390 } … … 281 392 { 282 393 // 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 295 394 _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()); 299 396 } 300 397 else … … 310 407 311 408 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 349 409 _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()); 351 411 352 412 353 413 // 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 369 414 _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()); 371 416 372 417 } … … 377 422 378 423 _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 431 void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::RenderGraph* rendergraph, osgUtil::RenderStage* renderStage) 387 432 { 388 433 … … 392 437 393 438 439 osg::ref_ptr<RefMatrix> proj = new osg::RefMatrix(projection); 440 osg::ref_ptr<RefMatrix> mv = new osg::RefMatrix(modelview); 394 441 395 442 // collect any occluder in the view frustum. … … 409 456 410 457 cov.pushViewport(_viewport.get()); 411 cov.pushProjectionMatrix(proj ection);412 cov.pushModelViewMatrix(m odelview);458 cov.pushProjectionMatrix(proj.get()); 459 cov.pushModelViewMatrix(mv.get()); 413 460 414 461 // traverse the scene graph to search for occluder in there new positions. … … 474 521 break; 475 522 case(SKY_LIGHT): 476 if (_light.valid()) renderStage->addPositionedAttribute(m odelview,_light.get());523 if (_light.valid()) renderStage->addPositionedAttribute(mv.get(),_light.get()); 477 524 else osg::notify(osg::WARN)<<"Warning: no osg::Light attached to ogUtil::SceneView to provide sky light.*/"<<std::endl; 478 525 break; … … 486 533 487 534 cullVisitor->pushViewport(_viewport.get()); 488 cullVisitor->pushProjectionMatrix(proj ection);489 cullVisitor->pushModelViewMatrix(m odelview);535 cullVisitor->pushProjectionMatrix(proj.get()); 536 cullVisitor->pushModelViewMatrix(mv.get()); 490 537 491 538 … … 554 601 //std::cout<<"time to flush rendering objects"<<timer.delta_m(tstart,tend)<<std::endl; 555 602 556 if (_viewMatrix.valid()) _state->setInitialViewMatrix(_viewMatrix.get());603 _state->setInitialViewMatrix(new osg::RefMatrix(_viewMatrix)); 557 604 558 605 RenderLeaf* previous = NULL; … … 863 910 const osg::Matrix SceneView::computeMVPW() const 864 911 { 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); 872 913 873 914 if (_viewport.valid()) … … 894 935 } 895 936 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 903 937 void SceneView::setProjectionMatrixAsOrtho(double left, double right, 904 938 double bottom, double top, 905 939 double zNear, double zFar) 906 940 { 907 setProjectionMatrix(osg::Matrix ::ortho(left, right,941 setProjectionMatrix(osg::Matrixd::ortho(left, right, 908 942 bottom, top, 909 943 zNear, zFar)); … … 913 947 double bottom, double top) 914 948 { 915 setProjectionMatrix(osg::Matrix ::ortho2D(left, right,949 setProjectionMatrix(osg::Matrixd::ortho2D(left, right, 916 950 bottom, top)); 917 951 } … … 921 955 double zNear, double zFar) 922 956 { 923 setProjectionMatrix(osg::Matrix ::frustum(left, right,957 setProjectionMatrix(osg::Matrixd::frustum(left, right, 924 958 bottom, top, 925 959 zNear, zFar)); … … 929 963 double zNear, double zFar) 930 964 { 931 setProjectionMatrix(osg::Matrix ::perspective(fovy,aspectRatio,965 setProjectionMatrix(osg::Matrixd::perspective(fovy,aspectRatio, 932 966 zNear, zFar)); 933 967 } … … 937 971 double& zNear, double& zFar) 938 972 { 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); 946 976 } 947 977 … … 950 980 double& zNear, double& zFar) 951 981 { 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); 959 985 } 960 986 … … 962 988 double& zNear, double& zFar) 963 989 { 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); 969 991 } 970 992 971 void SceneView::setViewMatrix(const osg::Matrix& matrix)972 {973 if (!_viewMatrix) _viewMatrix = new osg::RefMatrix(matrix);974 else _viewMatrix->set(matrix);975 }976 977 993 void SceneView::setViewMatrixAsLookAt(const Vec3& eye,const Vec3& center,const Vec3& up) 978 994 { 979 setViewMatrix(osg::Matrix ::lookAt(eye,center,up));995 setViewMatrix(osg::Matrixd::lookAt(eye,center,up)); 980 996 } 981 997 982 998 void SceneView::getViewMatrixAsLookAt(Vec3& eye,Vec3& center,Vec3& up,float lookDistance) 983 999 { 984 if (_viewMatrix.valid()) 985 { 986 _viewMatrix->getLookAt(eye,center,up,lookDistance); 987 } 988 } 1000 _viewMatrix.getLookAt(eye,center,up,lookDistance); 1001 }
