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