|
楼主 |
发表于 2009-11-20 14:24:10
|
显示全部楼层
本帖最后由 lxlbgd1 于 2009-11-20 14:26 编辑
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIEventHandler>
#include <osgGA/EventVisitor>
#include "TrInterfaceVedio.h"
//继承自osg::NodeCallback类,写一个事件回调类
class TrInterfaceVedioStateCallback : public osg::NodeCallback
{
public:
TrInterfaceVedioStateCallback(TrInterfaceVedio* vedio)
{
_vedio = NULL;
_vedio = vedio;
}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv )
{
//判断访问器类型
if (nv->getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
{ //创建一个事件访问器并初始化
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev)
{
//得到执行动作
osgGA::GUIActionAdapter* aa = ev->getActionAdapter();
//得到事件队列
osgGA::EventQueue::Events& events = ev->getEvents();
for(osgGA::EventQueue::Events::iterator itr=events.begin();
itr!=events.end(); ++itr)
{
//处理事件
handle(*(*itr),*(aa));
}
}
}
}
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
//得到场景数据
/*osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);*/
//osg::MatrixTransform* mt = dynamic_cast<osg::MatrixTransform*>(viewer->getSceneData());
/*osg::Camera* camera = dynamic_cast<osg::Camera*> (viewer->getCamera());*/
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
{
if (ea.getKey()=='p')
{
{
if( _vedio != NULL)
{
if(_playToggle)
{
_playToggle = !_playToggle ;
_vedio->pauseVedio();
// playing, so pause
std::cout<<"Pause"<<std::endl;
}
else
{
_playToggle = !_playToggle ;
_vedio->playVedio();
// playing, so pause
std::cout<<"bofang"<<std::endl;
}
}
else
break;
}
return true;
}
else if (ea.getKey()=='b')
{
//std::cout<<"Restart"<<std::endl;
if(_vedio!=NULL)
{
_vedio->playVedio();
// playing, so pause
std::cout<<"bofang"<<std::endl;
}
return true;
}
// else if (ea.getKey()=='y')
// {
////std::cout<<"yanshi"<<std::endl;
//if(_text!=NULL)
//{
// _text->autoHideText();
// /*_text->delay(1);
// _text->setCamera();*/
//
// // playing, so pause
// std::cout<<"yanshi"<<std::endl;
//}
//return true;
// }
//else if (ea.getKey()=='x')
//{
// //std::cout<<"yanshi"<<std::endl;
// if(_text!=NULL)
// {
//
// //_text->autoHideText();
//
// _text->delay(1);
//
// _text->setCamera();
// // playing, so pause
// std::cout<<"xianshi"<<std::endl;
// }
// return true;
//}
}
default:
return false;
}
return false;
}
private:
TrInterfaceVedio* _vedio;
// gif播放标志
bool _playToggle;
};
然后进行 节点时间回调,回调有时能触发事件,但按几次键后,就出现我上面提到的错误。 |
|