Hi Alfonso, Use the osg::FrameStamp object that used by the OSG to record the time of a frame, this object is maintained by the Viewer, and is passed into the callback via the NodeVisitor. So do:
nv->getFrameStamp()->getSimulationTime(); Robert. On Wed, Jan 21, 2009 at 9:52 AM, Alfonso Callejo Goena <[email protected]> wrote: > Hello: > > I am trying to move a vehicle on scene by means of an update callback. It > should be a realistic simulation, and I want the vehicle to move, for > instance, at a constant velocity of 5 m/s. > The callback function I have written has the following aspect: > > osg::Matrix mT, dmT; // global variables containing the current and > differential translations of the vehicle > > > class myUpdateCallback : public osg::NodeCallback { > public: > myUpdateCallback() { > vehSpeed=5/3.6; // 5 km/h in m/s > tLast=0.; > } > virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ) { > osg::MatrixTransform* mTransf = dynamic_cast<osg::MatrixTransform*>( > node ); > > double t = osg::Timer::instance()->time_m()/1000; > double dt=t-tLast; > dmT.makeTranslate( vehSpeed*dt, 0., 0. ); > mT=mT*dmT; > tLast=t; > > mTransf->setMatrix( mT ); > traverse( node, nv ); > } > protected: > double tLast; > double vehSpeed; > }; > > The thing is that the resulting movement is not smooth, it has > discontinuities like little "jumps". I think this can be related with the > frequency the program performs the callback (around 62 Hz), but I don't know > how to solve it. > Thank you in advance for your help. > Fusu > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

