- Timestamp:
- 11/17/05 21:22:55 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgmotionblur/osgmotionblur.cpp
r4666 r4805 17 17 { 18 18 public: 19 MotionBlurDrawCallback(double persistence)20 :cleared_(false),21 persistence_(persistence)22 {23 }19 MotionBlurDrawCallback(double persistence) 20 : cleared_(false), 21 persistence_(persistence) 22 { 23 } 24 24 25 virtual void operator()(osgProducer::OsgSceneHandler &handler, Producer::Camera &camera)26 {27 double t = handler.getSceneView()->getFrameStamp()->getReferenceTime();25 virtual void operator()(osgProducer::OsgSceneHandler &handler, Producer::Camera &camera) 26 { 27 double t = handler.getSceneView()->getFrameStamp()->getReferenceTime(); 28 28 29 if (!cleared_)30 {31 // clear the accumulation buffer32 glClearColor(0, 0, 0, 0);33 glClear(GL_ACCUM_BUFFER_BIT);34 cleared_ = true;35 t0_ = t;36 }29 if (!cleared_) 30 { 31 // clear the accumulation buffer 32 glClearColor(0, 0, 0, 0); 33 glClear(GL_ACCUM_BUFFER_BIT); 34 cleared_ = true; 35 t0_ = t; 36 } 37 37 38 double dt = fabs(t - t0_);39 t0_ = t;38 double dt = fabs(t - t0_); 39 t0_ = t; 40 40 41 // call the scene handler's draw function42 handler.drawImplementation(camera); 41 // call the scene handler's draw function 42 handler.drawImplementation(camera); 43 43 44 // compute the blur factor45 double s = powf(0.2, dt / persistence_);44 // compute the blur factor 45 double s = powf(0.2, dt / persistence_); 46 46 47 // scale, accumulate and return48 glAccum(GL_MULT, s);49 glAccum(GL_ACCUM, 1 - s);50 glAccum(GL_RETURN, 1.0f);51 }47 // scale, accumulate and return 48 glAccum(GL_MULT, s); 49 glAccum(GL_ACCUM, 1 - s); 50 glAccum(GL_RETURN, 1.0f); 51 } 52 52 53 53 private: 54 bool cleared_;55 double t0_;56 double persistence_;54 bool cleared_; 55 double t0_; 56 double persistence_; 57 57 }; 58 58 … … 69 69 arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 70 70 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 71 arguments.getApplicationUsage()->addCommandLineOption("-P or --persistence","Set the motion blur persistence time");71 arguments.getApplicationUsage()->addCommandLineOption("-P or --persistence","Set the motion blur persistence time"); 72 72 73 73 … … 88 88 } 89 89 90 double persistence = 0.25;91 arguments.read("-P", persistence) || arguments.read("--persistence", persistence);90 double persistence = 0.25; 91 arguments.read("-P", persistence) || arguments.read("--persistence", persistence); 92 92 93 93 // report any errors if they have occured when parsing the program aguments. … … 142 142 viewer.realize(); 143 143 144 // set our motion blur callback as the draw callback for each scene handler145 osgProducer::Viewer::SceneHandlerList &shl = viewer.getSceneHandlerList();146 for (osgProducer::Viewer::SceneHandlerList::iterator i=shl.begin(); i!=shl.end(); ++i)147 {148 (*i)->setDrawCallback(new MotionBlurDrawCallback(persistence));149 }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) 147 { 148 (*i)->setDrawCallback(new MotionBlurDrawCallback(persistence)); 149 } 150 150 151 151 while( !viewer.done() )
