|
发表于 2011-9-9 15:48:26
|
显示全部楼层
回复 1# osg穷人
你好,我的问题解决了,其实很简单,你看看代码就能明白。- bool LOGO_ComboKey::handle(const osgGA::GUIEventAdapter &ea,osgGA::GUIActionAdapter &aa)
- {
- switch (ea.getEventType())
- {
- case(osgGA::GUIEventAdapter::KEYDOWN):
- {
- if (ea.getKey() == 0xFF52 || ea.getKey () == 0x57 || ea.getKey () == 0x77)//up
- {
- btnUP=true;
- return true;
- }
- if (ea.getKey() == 0xFF54 || ea.getKey () == 0x53 || ea.getKey () == 0x73 )//down
- {
- btnDOWN=true;
- return true;
- }
- if (ea.getKey () == 0x41||ea.getKey () == 0x61) //A
- {
- btnLEFT=true;
- return true;
- }
- if (ea.getKey () == 0x44||ea.getKey () == 0x64)//D
- {
- btnRIGHT=true;
- return true;
- }
- return false;
- case osgGA::GUIEventAdapter::KEYUP:
- if (ea.getKey() == 0xFF52 || ea.getKey () == 0x57 || ea.getKey () == 0x77)//up
- {
- btnUP=false;
- return true;
- }
- if (ea.getKey() == 0xFF54 || ea.getKey () == 0x53 || ea.getKey () == 0x73 )//down
- {
- btnDOWN=false;
- return true;
- }
- if (ea.getKey () == 0x41||ea.getKey () == 0x61) //A
- {
- btnLEFT=false;
- return true;
- }
- if (ea.getKey () == 0x44||ea.getKey () == 0x64)//D
- {
- btnRIGHT=false;
- return true;
- }
- }
- break;
- default:
- break;
- }
- if (btnUP)
- {
- m_vPosition += osg::Vec3 (0, m_fMoveSpeed * sinf(osg::PI_2+m_vRotation._v[2]), 0) ;
- m_vPosition += osg::Vec3 (m_fMoveSpeed * cosf(osg::PI_2+m_vRotation._v[2]), 0, 0);
- }
- if (btnDOWN)
- {
- m_vPosition += osg::Vec3 (0, -m_fMoveSpeed * sinf(osg::PI_2+m_vRotation._v[2]), 0) ;
- m_vPosition += osg::Vec3 (-m_fMoveSpeed * cosf(osg::PI_2+m_vRotation._v[2]), 0, 0);
- }
- if (btnLEFT) //A
- {
- m_vPosition += osg::Vec3 (0, m_fMoveSpeed * cosf(osg::PI_2+m_vRotation._v[2]), 0) ;
- m_vPosition += osg::Vec3 (-m_fMoveSpeed * sinf(osg::PI_2+m_vRotation._v[2]), 0, 0) ;
- }
- if (btnRIGHT)//D
- {
- m_vPosition += osg::Vec3 (0, -m_fMoveSpeed * cosf(osg::PI_2+m_vRotation._v[2]), 0) ;
- m_vPosition += osg::Vec3 (m_fMoveSpeed * sinf(osg::PI_2+m_vRotation._v[2]), 0, 0) ;
- }
- return false;
- }
复制代码 |
|