- Timestamp:
- 01/11/07 12:47:01 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgstereoimage/osgstereoimage.cpp
r5636 r5959 12 12 */ 13 13 14 #include <osg Producer/Viewer>14 #include <osgViewer/Viewer> 15 15 #include <osgDB/ReadFile> 16 16 #include <osgDB/WriteFile> … … 23 23 #include <osg/TexMat> 24 24 #include <osg/Texture2D> 25 26 #include <iostream> 25 27 26 28 typedef std::vector<std::string> FileList; … … 387 389 int main( int argc, char **argv ) 388 390 { 389 390 391 // use an ArgumentParser object to manage the program arguments. 391 392 osg::ArgumentParser arguments(&argc,argv); … … 402 403 403 404 // construct the viewer. 404 osgProducer::Viewer viewer(arguments); 405 406 // set up the value with sensible default event handlers. 407 viewer.setUpViewer(osgProducer::Viewer::ESCAPE_SETS_DONE); 405 osgViewer::Viewer viewer; 408 406 409 407 // register the handler to add keyboard and mosue handling. 410 408 SlideEventHandler* seh = new SlideEventHandler(); 411 viewer.getEventHandlerList().push_front(seh); 412 413 414 // get details on keyboard and mouse bindings used by the viewer. 415 viewer.getUsage(*arguments.getApplicationUsage()); 409 viewer.addEventHandler(seh); 416 410 417 411 // read any time delay argument. … … 463 457 } 464 458 465 // set up the use of stereo by default.466 osg::DisplaySettings* ds = viewer.getDisplaySettings();467 if (!ds) ds = osg::DisplaySettings::instance();468 if (ds) ds->setStereo(true);469 470 // create the windows and run the threads.471 viewer.realize();472 473 459 // now the windows have been realized we switch off the cursor to prevent it 474 460 // distracting the people seeing the stereo images. 475 float fovy = 1.0f; 476 for( unsigned int i = 0; i < viewer.getNumberOfCameras(); i++ ) 477 { 478 Producer::Camera* cam = viewer.getCamera(i); 479 Producer::RenderSurface* rs = cam->getRenderSurface(); 480 rs->useCursor(false); 481 fovy = osg::DegreesToRadians(cam->getLensVerticalFov()); 482 } 461 double fovy, aspectRatio, zNear, zFar; 462 viewer.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); 483 463 484 464 float radius = 1.0f; 485 float height = 2*radius*tan( fovy*0.5f);465 float height = 2*radius*tan(osg::DegreesToRadians(fovy)*0.5f); 486 466 float length = osg::PI*radius; // half a cylinder. 487 467 … … 499 479 viewer.setSceneData(rootNode.get()); 500 480 501 502 viewer.getCullSettings().setCullMask(0xffffffff); 503 viewer.getCullSettings().setCullMaskLeft(0x00000001); 504 viewer.getCullSettings().setCullMaskRight(0x00000002); 505 481 viewer.getCamera()->setCullMask(0xffffffff); 482 viewer.getCamera()->setCullMaskLeft(0x00000001); 483 viewer.getCamera()->setCullMaskRight(0x00000002); 484 485 // set up the use of stereo by default. 486 osg::DisplaySettings::instance()->setStereo(true); 487 488 // create the windows and run the threads. 489 viewer.realize(); 490 491 492 // switch off the cursor 493 osgViewer::Viewer::Windows windows; 494 viewer.getWindows(windows); 495 for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); 496 itr != windows.end(); 497 ++itr) 498 { 499 (*itr)->useCursor(false); 500 } 501 502 #if 0 506 503 // set all the sceneview's up so that their left and right add cull masks are set up. 507 504 for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); … … 512 509 sceneview->setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE,radius); 513 510 } 514 511 #endif 515 512 516 513 // set up the SlideEventHandler. 517 514 seh->set(rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,timeDelayBetweenSlides,autoSteppingActive); 518 519 515 520 516 osg::Matrix homePosition; … … 523 519 while( !viewer.done() ) 524 520 { 525 // wait for all cull and draw threads to complete. 526 viewer.sync(); 527 528 // update the scene by traversing it with the the update visitor which will 529 // call all node update callbacks and animations. 530 viewer.update(); 531 532 viewer.setView(homePosition); 521 viewer.getCamera()->setViewMatrix(homePosition); 533 522 534 523 // fire off the cull and draw traversals of the scene. … … 537 526 } 538 527 539 // wait for all cull and draw threads to complete.540 viewer.sync();541 542 // run a clean up frame to delete all OpenGL objects.543 viewer.cleanup_frame();544 545 // wait for all the clean up frame to complete.546 viewer.sync();547 548 528 return 0; 549 529 }
