|
我做了一个事件回调,代码基本上是从书上扒下来的
class myEventCallback:public osg::NodeCallback
{
public:
virtual void operator()(osg::Node*node,osg::NodeVisitor*nv)
{
if(nv->getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
{
osg::ref_ptr<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)
{
osg::ref_ptr<osgViewer::Viewer> viewer= dynamic_cast<osgViewer::Viewer*>(&aa);
osg::ref_ptr<osg::Group> root = dynamic_cast<osg::Group*>(viewer->getSceneData());
osg::ref_ptr<osg::Switch> swit0000 = dynamic_cast<osg::Switch*>(root->getChild(0));
osg::ref_ptr<osg::Group> daba = dynamic_cast<osg::Group*>(swit0000->getChild(0));
osg::ref_ptr<osg::Switch> swit[9];
swit[0] = dynamic_cast<osg::Switch*>(daba->getChild(0));
swit[1] = dynamic_cast<osg::Switch*>(daba->getChild(1));
swit[2] = dynamic_cast<osg::Switch*>(daba->getChild(2));
swit[3] = dynamic_cast<osg::Switch*>(daba->getChild(3));
swit[4] = dynamic_cast<osg::Switch*>(daba->getChild(4));
swit[5] = dynamic_cast<osg::Switch*>(daba->getChild(5));
swit[6] = dynamic_cast<osg::Switch*>(daba->getChild(6));
swit[7] = dynamic_cast<osg::Switch*>(daba->getChild(7));
swit[8] = dynamic_cast<osg::Switch*>(daba->getChild(8));
osg::ref_ptr<month> mon = dynamic_cast<month*>(daba->getChild(9));
const int monMx[17][9][27]=0;
switch(ea.getEventType())
{
case(osgGA::GUIEventAdapter::KEYDOWN):
{
if(ea.getKey()==osgGA::GUIEventAdapter::KEY_Up)
{
if ( mon->m >= 0 && mon-> m < 16)
mon->m++;
}
if(ea.getKey()==osgGA::GUIEventAdapter::KEY_Down)
{
if( mon->m > 0 && mon-> m <= 16)
mon->m--;
}
for(int j=0;j<9;j++)
for(int k=0 ; k<27 ; k++)
{
bool sx;
if(monMx[mon->m][j][k]==0)
sx=false;
else if(monMx[mon->m][j][k]==1)
sx=true;
swit[j]->setValue(k,sx);
}
break;
}
default:
break;
}
return false;
}
};
通过up键down键控制mon->m的值来实现大量节点的switch控制,
现在我一兄弟用mfc做了一个框架包括按钮和进度条来控制一个变量
这个怎么整合的一起啊 |
|