Show
Ignore:
Timestamp:
01/11/07 18:15:04 (8 years ago)
Author:
robert
Message:

Ported osgmotionblurr across to osgViewer

Files:
1 modified

Legend:

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

    r5381 r5968  
    1212#include <osgDB/ReadFile> 
    1313#include <osgUtil/Optimizer> 
    14 #include <osgProducer/Viewer> 
     14#include <osgViewer/Viewer> 
     15#include <iostream> 
    1516 
    16 class MotionBlurDrawCallback: public osgProducer::OsgSceneHandler::Callback 
     17class MotionBlurOperation: public osg::GraphicsOperation 
    1718{ 
    1819public: 
    19     MotionBlurDrawCallback(double persistence) 
    20     :    cleared_(false), 
     20    MotionBlurOperation(double persistence): 
     21        osg::GraphicsOperation("MotionBlur",true), 
     22        cleared_(false), 
    2123        persistence_(persistence) 
    2224    { 
    2325    } 
    2426 
    25     virtual void operator()(osgProducer::OsgSceneHandler &handler, Producer::Camera &camera) 
     27    virtual void operator () (osg::GraphicsContext* gc) 
    2628    { 
    27         double t = handler.getSceneView()->getFrameStamp()->getReferenceTime(); 
     29        double t = gc->getState()->getFrameStamp()->getReferenceTime(); 
    2830 
    2931        if (!cleared_) 
     
    3840        double dt = fabs(t - t0_); 
    3941        t0_ = t; 
    40  
    41         // call the scene handler's draw function 
    42         handler.drawImplementation(camera);         
    4342 
    4443        // compute the blur factor 
     
    7372 
    7473    // construct the viewer. 
    75     osgProducer::Viewer viewer(arguments); 
    76  
    77     // set up the value with sensible default event handlers. 
    78     viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); 
    79  
    80     // get details on keyboard and mouse bindings used by the viewer. 
    81     viewer.getUsage(*arguments.getApplicationUsage()); 
     74    osgViewer::Viewer viewer; 
    8275 
    8376    // if user request help write it out to cout. 
     
    9184    arguments.read("-P", persistence) || arguments.read("--persistence", persistence); 
    9285 
    93     // report any errors if they have occured when parsing the program aguments. 
    94     if (arguments.errors()) 
    95     { 
    96         arguments.writeErrorMessages(std::cout); 
    97         return 1; 
    98     } 
    99      
    100     if (arguments.argc()<=1) 
    101     { 
    102         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    103         return 1; 
    104     } 
    105  
    106     osg::Timer_t start_tick = osg::Timer::instance()->tick(); 
    107  
    10886    // read the scene from the list of file specified commandline args. 
    10987    osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 
     
    11694    } 
    11795 
    118     // any option left unread are converted into errors to write out later. 
    119     arguments.reportRemainingOptionsAsUnrecognized(); 
    120  
    121     // report any errors if they have occured when parsing the program aguments. 
    122     if (arguments.errors()) 
    123     { 
    124         arguments.writeErrorMessages(std::cout); 
    125     } 
    126  
    127     osg::Timer_t end_tick = osg::Timer::instance()->tick(); 
    128  
    129     std::cout << "Time to load = "<<osg::Timer::instance()->delta_s(start_tick,end_tick)<<std::endl; 
    13096 
    13197    // set the display settings we can to request, OsgCameraGroup will read this. 
    13298    osg::DisplaySettings::instance()->setMinimumNumAccumBits(8,8,8,8); 
    133  
    134     // optimize the scene graph, remove rendundent nodes and state etc. 
    135     osgUtil::Optimizer optimizer; 
    136     optimizer.optimize(loadedModel.get()); 
    13799 
    138100    // pass the loaded scene graph to the viewer. 
     
    142104    viewer.realize(); 
    143105 
    144     // set our motion blur callback as the draw callback for each scene handler 
    145     osgProducer::Viewer::SceneHandlerList &shl = viewer.getSceneHandlerList(); 
    146     for (osgProducer::Viewer::SceneHandlerList::iterator i=shl.begin(); i!=shl.end(); ++i) 
     106    osgViewer::Viewer::Windows windows; 
     107    viewer.getWindows(windows); 
     108    for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); 
     109        itr != windows.end(); 
     110        ++itr) 
    147111    { 
    148         (*i)->setDrawCallback(new MotionBlurDrawCallback(persistence)); 
     112        (*itr)->add(new MotionBlurOperation(persistence)); 
    149113    } 
    150114 
    151     while( !viewer.done() ) 
    152     { 
    153         // wait for all cull and draw threads to complete. 
    154         viewer.sync(); 
    155  
    156         // update the scene by traversing it with the the update visitor which will 
    157         // call all node update callbacks and animations. 
    158         viewer.update(); 
    159           
    160         // fire off the cull and draw traversals of the scene. 
    161         viewer.frame(); 
    162          
    163     } 
    164      
    165     // wait for all cull and draw threads to complete. 
    166     viewer.sync(); 
    167  
    168     // run a clean up frame to delete all OpenGL objects. 
    169     viewer.cleanup_frame(); 
    170  
    171     // wait for all the clean up frame to complete. 
    172     viewer.sync(); 
    173  
    174     return 0; 
     115    return viewer.run(); 
    175116}