Hi,
I have another problem with animationPath. I want to move object from -10,0,0
to 10,0,0 using 'w' button and bring it back to initial possition using 'q'
button. Everything work fine except the problem that I have 10 seconds delay
after I release keyboard button and object starts to move.
Could anybody help?
I implented to the following class:
class MoveObjectForward : public osg::AnimationPathCallback {
public:
MoveObjectForward::MoveObjectForward()
{
osg::ref_ptr<osg::AnimationPath> rPath = new osg::AnimationPath;
rPath->setLoopMode( osg::AnimationPath::NO_LOOPING);
osg::AnimationPath::ControlPoint c0(osg::Vec3(-10,0,0));
osg::AnimationPath::ControlPoint c1(osg::Vec3(10,0,0));
rPath->insert(16.0f , c0 );
rPath->insert( 20.0f, c1 );
this->setAnimationPath(rPath.get());
}
};
after it I implented recursive function
osg::Node* findNamedNode(const std::string& searchName, osg::Node* currNode);
which returns node according to its name.
Then I implement Keyboard event which sets appropriate callBack according to
key.
bool myKeyboardEventHandler::handle(const osgGA::GUIEventAdapter&
ea,osgGA::GUIActionAdapter& aa)
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
osg::Node* scene = viewer->getSceneData();
osg::PositionAttitudeTransform* tankXform = new
osg::PositionAttitudeTransform();
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYUP):
{
switch(ea.getKey())
{
case 'w':
tankXform =
dynamic_cast<osg::PositionAttitudeTransform*>(findNamedNode("myNode",scene));
tankXform->setUpdateCallback(new
MoveObjectForward());
return false;
break;
case 'q':
tankXform =
dynamic_cast<osg::PositionAttitudeTransform*>(findNamedNode("myNode",scene));
tankXform>setUpdateCallback(new MoveObjectBack());
return false;
break;
default:
return false;
}
}
default:
return false;
}
}
Thank you!
Cheers,
Danny
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=16853#16853
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org