- Timestamp:
- 01/11/07 18:15:04 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgmotionblur/osgmotionblur.cpp
r5381 r5968 12 12 #include <osgDB/ReadFile> 13 13 #include <osgUtil/Optimizer> 14 #include <osgProducer/Viewer> 14 #include <osgViewer/Viewer> 15 #include <iostream> 15 16 16 class MotionBlur DrawCallback: public osgProducer::OsgSceneHandler::Callback17 class MotionBlurOperation: public osg::GraphicsOperation 17 18 { 18 19 public: 19 MotionBlurDrawCallback(double persistence) 20 : cleared_(false), 20 MotionBlurOperation(double persistence): 21 osg::GraphicsOperation("MotionBlur",true), 22 cleared_(false), 21 23 persistence_(persistence) 22 24 { 23 25 } 24 26 25 virtual void operator ()(osgProducer::OsgSceneHandler &handler, Producer::Camera &camera)27 virtual void operator () (osg::GraphicsContext* gc) 26 28 { 27 double t = handler.getSceneView()->getFrameStamp()->getReferenceTime();29 double t = gc->getState()->getFrameStamp()->getReferenceTime(); 28 30 29 31 if (!cleared_) … … 38 40 double dt = fabs(t - t0_); 39 41 t0_ = t; 40 41 // call the scene handler's draw function42 handler.drawImplementation(camera);43 42 44 43 // compute the blur factor … … 73 72 74 73 // 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; 82 75 83 76 // if user request help write it out to cout. … … 91 84 arguments.read("-P", persistence) || arguments.read("--persistence", persistence); 92 85 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 108 86 // read the scene from the list of file specified commandline args. 109 87 osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); … … 116 94 } 117 95 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;130 96 131 97 // set the display settings we can to request, OsgCameraGroup will read this. 132 98 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());137 99 138 100 // pass the loaded scene graph to the viewer. … … 142 104 viewer.realize(); 143 105 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) 147 111 { 148 (*i )->setDrawCallback(new MotionBlurDrawCallback(persistence));112 (*itr)->add(new MotionBlurOperation(persistence)); 149 113 } 150 114 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(); 175 116 }
