|
初学OSG,对其中很多还不懂.关于键盘响应问题,近几日一直解决不了,请各位帮忙看一下代码错在哪里?
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
using namespace std;
class PickHandler : public osgGA::GUIEventHandler
{
bool handle( 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::KEY_Down):
{
if (ea.getKey() == 'q')
{
//do something
int a;
cin>>a;
return false;
}
}
default:
return false;
}
return false;
}
};
int main()
{
osgViewer::Viewer viewer;
osg::Group* root = new osg::Group;
viewer.addEventHandler(new PickHandler());
//改变背景演色
osg::ClearNode* clearNode = new osg::ClearNode;
clearNode->setClearColor(osg::Vec4(0.3f,0.4f,0.5f,1.0f));
root->addChild(clearNode);
//加载T72
osg::Node* T72 = osgDB::readNodeFile( "models//t72.ive" );
root->addChild(T72);
osg::Node* cessnaNode = NULL;
cessnaNode = osgDB::readNodeFile("models//cessna.osg");
root->addChild(cessnaNode);
viewer.setSceneData( root);
osg::notify(osg::INFO) << "hello world" << std::endl;
return viewer.run();
}
以上代码可运行,但在键盘上按下键时,代码没有任何响应,也就是PickHandler中的代码没有用,why?
另外,
osg::notify(osg::INFO) << "hello world" << std::endl;
这一句也没有输出.头大. |
|