Show
Ignore:
Timestamp:
01/11/07 12:47:01 (8 years ago)
Author:
robert
Message:

Ported follow examples to osgViewer:

osgshape
osgsimplifier
osgsimulation
osgslice
osgspacewarp
osgspheresegment
osgspotlight
osgstereoimage

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgstereoimage/osgstereoimage.cpp

    r5636 r5959  
    1212*/ 
    1313 
    14 #include <osgProducer/Viewer> 
     14#include <osgViewer/Viewer> 
    1515#include <osgDB/ReadFile> 
    1616#include <osgDB/WriteFile> 
     
    2323#include <osg/TexMat> 
    2424#include <osg/Texture2D> 
     25 
     26#include <iostream> 
    2527 
    2628typedef std::vector<std::string> FileList; 
     
    387389int main( int argc, char **argv ) 
    388390{ 
    389  
    390391    // use an ArgumentParser object to manage the program arguments. 
    391392    osg::ArgumentParser arguments(&argc,argv); 
     
    402403 
    403404    // 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; 
    408406 
    409407    // register the handler to add keyboard and mosue handling. 
    410408    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); 
    416410 
    417411    // read any time delay argument. 
     
    463457    } 
    464458 
    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  
    473459    // now the windows have been realized we switch off the cursor to prevent it 
    474460    // 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); 
    483463 
    484464    float radius = 1.0f; 
    485     float height = 2*radius*tan(fovy*0.5f); 
     465    float height = 2*radius*tan(osg::DegreesToRadians(fovy)*0.5f); 
    486466    float length = osg::PI*radius;  // half a cylinder. 
    487467 
     
    499479    viewer.setSceneData(rootNode.get()); 
    500480 
    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 
    506503    // set all the sceneview's up so that their left and right add cull masks are set up. 
    507504    for(osgProducer::OsgCameraGroup::SceneHandlerList::iterator itr=viewer.getSceneHandlerList().begin(); 
     
    512509        sceneview->setFusionDistance(osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE,radius); 
    513510    } 
    514  
     511#endif 
    515512 
    516513    // set up the SlideEventHandler. 
    517514    seh->set(rootNode.get(),offsetX,offsetY,texmatLeft,texmatRight,timeDelayBetweenSlides,autoSteppingActive); 
    518      
    519515     
    520516    osg::Matrix homePosition; 
     
    523519    while( !viewer.done() ) 
    524520    { 
    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); 
    533522 
    534523        // fire off the cull and draw traversals of the scene. 
     
    537526    } 
    538527     
    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      
    548528    return 0; 
    549529}