Hi, this is the code that i'm using: #include <osg/Node> #include <osg/MatrixTransform> #include <osg/Group> #include <osg/Timer> #include <osgGA/TrackBallManipulator> #include <osgDB/ReadFile> #include <osgDB/WriteFile> #include <osgViewer/Viewer> #include <iostream> #include <osgViewer/ViewerEventHandlers> #include <osgAnimation/BasicAnimationManager> using namespace std;
static osg::Timer_t old_tick,new_tick; int bandera=0; static double delta; class tankControll: public osgGA::GUIEventHandler{ public: tankControll(){ acc=0; }; virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa){ if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='q' || ea.getKey()=='Q')){ bandera=0; bandera=1; return true; }else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='w' || ea.getKey()=='W')){ bandera=0; bandera=2; return true; }else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='e' || ea.getKey()=='E')){ bandera=0; bandera=3; return true; }else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='a' || ea.getKey()=='A')){ bandera=0; bandera=4; return true; }else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='s' || ea.getKey()=='S')){ bandera=0; bandera=5; return true; }else if(ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN && (ea.getKey()=='d' || ea.getKey()=='D')){ bandera=0; bandera=6; return true; }else{ return false; } } private: int acc; }; struct AnimationManagerFinder : public osg::NodeVisitor { osg::ref_ptr<osgAnimation::BasicAnimationManager> _am; AnimationManagerFinder() {setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN); } void apply(osg::Node& node) { if (_am.valid()) return; if (node.getUpdateCallback()) { _am = dynamic_cast<osgAnimation::BasicAnimationManager*>(node.getUpdateCallback()); return; } traverse(node); } }; int main() { osg::ref_ptr<osg::Node> escena = osgDB::readNodeFile("Lerpz.osgb"); if (!escena){ cout<<"I´m not reading"<<endl; //exit(0); } AnimationManagerFinder finder; escena->accept(finder); const osgAnimation::AnimationList& animations = finder._am->getAnimationList(); tankControll *eh=new tankControll(); osgViewer::Viewer visor; visor.setSceneData(escena); visor.addEventHandler(eh); /*if(bandera==1) finder._am->playAnimation( animations[1].get() ); else if(bandera==2) finder._am->playAnimation( animations[2].get() ); else if(bandera==3) finder._am->playAnimation( animations[3].get() );*/ visor.setCameraManipulator(new osgGA::TrackballManipulator); visor.realize(); while ( !visor.done()){ //while (bandera!=6){ if (bandera==1) finder._am->playAnimation( animations[1].get() ); else if (bandera==2) finder._am->playAnimation( animations[2].get() ); else if (bandera==3) finder._am->playAnimation( animations[3].get() ); else printf("%i",bandera); visor.frame(); } return visor.run(); } the problem is the follow: when i press the w after the q, or e, it seems that animations are one over the other, why it happens? ... Thank you! Cheers, Josue ------------------ Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=38406#38406 _______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org