Show
Ignore:
Timestamp:
12/21/06 17:56:20 (8 years ago)
Author:
robert
Message:

Moved rendering support into GraphisContext?, osgViewer::Viewer/View, and
added frame stamp updating and update traversal to osgViewer::Scene/Viewer.

Updated osgcamera example to use new Viewer API calls instead of using local
rendering calls.

Files:
1 modified

Legend:

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

    r5836 r5838  
    7272        return 1; 
    7373    } 
    74      
    75     // initialize the view to look at the center of the scene graph 
    76     const osg::BoundingSphere& bs = loadedModel->getBound(); 
    77     osg::Matrix viewMatrix; 
    78     viewMatrix.makeLookAt(bs.center()-osg::Vec3(0.0,2.0f*bs.radius(),0.0),bs.center(),osg::Vec3(0.0f,0.0f,1.0f)); 
    79  
    80     osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer; 
    81     viewer->setSceneData(loadedModel.get()); 
    82     viewer->setCameraManipulator(new osgGA::TrackballManipulator()); 
    83     viewer->setUpViewAcrossAllScreens(); 
    84     viewer->realize(); 
    85      
    86     viewer->getCamera()->setClearColor(osg::Vec4f(0.6f,0.6f,0.8f,1.0f)); 
    87      
    88     osg::ref_ptr<osg::FrameStamp> frameStamp = new osg::FrameStamp; 
    89  
    90     unsigned int frameNum = 0; 
    91  
    92     osgUtil::UpdateVisitor updateVisitor; 
    93     updateVisitor.setFrameStamp(frameStamp.get()); 
    94      
    95     setUpFrameStamp(viewer->getCamera(), frameStamp.get(), loadedModel.get()); 
    96     for(unsigned i=0; i<viewer->getNumSlaves(); ++i) 
    97     { 
    98         osg::View::Slave& slave = viewer->getSlave(i); 
    99         setUpFrameStamp(slave._camera.get(), frameStamp.get(), loadedModel.get()); 
    100     } 
    101  
    102     // record the timer tick at the start of rendering.     
    103     osg::Timer_t start_tick = osg::Timer::instance()->tick(); 
    104     osg::Timer_t previous_tick = start_tick; 
    105  
    106     while(true) 
    107     { 
    108         osg::Timer_t current_tick = osg::Timer::instance()->tick(); 
    109  
    110         frameStamp->setReferenceTime(osg::Timer::instance()->delta_s(start_tick,current_tick)); 
    111         frameStamp->setFrameNumber(frameNum++); 
    112          
    113         //std::cout<<"Frame rate "<<1.0/osg::Timer::instance()->delta_s(previous_tick,current_tick)<<std::endl; 
    114         previous_tick = current_tick; 
    115  
    116         // do the update traversal. 
    117         loadedModel->accept(updateVisitor); 
    118  
    119         viewer->frameAdvance(); 
    120         viewer->frameEventTraversal(); 
    121         viewer->frameUpdateTraversal(); 
    122  
    123         // viewer->getCamera()->setViewMatrix(viewMatrix); 
    124  
    125  
    126         if (viewer->getCamera() && viewer->getCamera()->getGraphicsContext()) renderCamera(viewer->getCamera()); 
    127          
    128         for(unsigned i=0; i<viewer->getNumSlaves(); ++i) 
    129         { 
    130             osg::View::Slave& slave = viewer->getSlave(i); 
    131             if (slave._camera.valid() && slave._camera->getGraphicsContext()) renderCamera(slave._camera.get()); 
    132         } 
    133          
    134     } 
     74 
     75    osgViewer::Viewer viewer; 
     76     
     77    viewer.setSceneData(loadedModel.get()); 
     78 
     79    viewer.setCameraManipulator(new osgGA::TrackballManipulator()); 
     80    viewer.getCamera()->setClearColor(osg::Vec4f(0.6f,0.6f,0.8f,1.0f)); 
     81 
     82    viewer.setUpViewAcrossAllScreens(); 
     83    viewer.realize(); 
     84 
     85    while(!viewer.done()) 
     86    { 
     87        viewer.frame(); 
     88    } 
     89 
    13590} 
    13691