|
各位大侠,我用下面这段代码写了一个类:
class MyEventHandler:public osgGA::GUIEventHandler
{
public:
virtual bool handler(const osgGA::GUIEventAdapter &ea,osgGA::GUIActionAdapter &aa)
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
if(!viewer) return false;
switch(ea.getEventType())
{
case osgGA::GUIEventAdapter::KEYDOWN:
{
if(ea.getKey() == 0xFF51)
{
viewer->getSceneData()->asGroup()->getChild(0)->setNodeMask(1);
}
if(ea.getKey() == 0xFF53)
{
viewer->getSceneData()->asGroup()->getChild(0)->setNodeMask(0);
}
}
break;
default:
break;
}
return false;
}
};
然后在main函数中:
void _tmain()
{
...
osgViewer::Viewer viewer;
....
viewer.addEventHandler(new MyEventHandler);
viewer.setSceneData(root);
viewer.realize();
viewer.run();
}
为什么运行的时候按相应的键没反应呢,调试也证明不会进去,是哪里有问题呢? |
|