|
楼主 |
发表于 2012-10-11 10:23:00
|
显示全部楼层
bool CMyCamera::handleKeyDown( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us )
{
if (ea.getKey() == 0x20)//' '空格
{
us.requestRedraw();
us.requestContinuousUpdate(false);
return true;
}
if (ea.getKey() == 0x2B)//+
{ return true; }
if (ea.getKey() == 0x2D)//-
{
return true;
}
if (ea.getKey() == 0xFF52)//up 应该旋转但是不旋转 是不是不是这么做啊 新人求教啊哥哥姐姐们
{
m_rotation = osg:uat(osg:egreesToRadians(1.0), osg::Vec3(0,1,0))*m_rotation;
return true;
}
if (ea.getKey() == 0xFF54)//down
{
m_rotation = osg::Quat(osg::DegreesToRadians(-1.0), osg::Vec3(0,1,0))*m_rotation;
return true;
}
if (ea.getKey() == 0xFF53)//Right
{
m_rotation = osg::Quat(osg::DegreesToRadians(1.0), osg::Vec3(1,0,0))*m_rotation;
return true;
}
if (ea.getKey()== 0xFF51)//Left
{
m_rotation = osg::Quat(osg::DegreesToRadians(-1.0), osg::Vec3(1,0,0))*m_rotation;
return true;
}
if (ea.getKey () == 0x4A || ea.getKey () == 0x6A )//j
{
m_rotation = osg::Quat(osg::DegreesToRadians(1.0), osg::Vec3(0,0,1))*m_rotation;
return true;
}
if (ea.getKey () == 0x4B || ea.getKey () == 0x6B )//k
{
m_rotation = osg::Quat(osg::DegreesToRadians(-1.0), osg::Vec3(0,0,1))*m_rotation;
return true;
}
if (ea.getKey () == 0x41||ea.getKey () == 0x61) //a
{
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate( m_rotation );
osg::Vec3d dv( 100, 0, 0 );
m_vPosition += dv * rotation_matrix;
return true;
}
if (ea.getKey () == 0x44||ea.getKey () == 0x64)//d
{
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate( m_rotation );
osg::Vec3d dv( -100, 0, 0 );
m_vPosition += dv * rotation_matrix;
return true;
}
if (ea.getKey () == 0x57 || ea.getKey () == 0x77 )//w
{
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate( m_rotation );
osg::Vec3d dv( 0, 0, 100 );
m_vPosition += dv * rotation_matrix;
return true;
}
if (ea.getKey () == 0x53 || ea.getKey () == 0x73 )//s
{
osg::Matrix rotation_matrix;
rotation_matrix.makeRotate( m_rotation );
osg::Vec3d dv( 0, 0, -100 );
m_vPosition += dv * rotation_matrix;
return true;
}
if (ea.getKey() == 0xFF50)//home
{
m_vPosition += osg::Vec3(0,-100,0);
return true;
}
if (ea.getKey() == 0xFF57) //end
{
m_vPosition += osg::Vec3(0,100,0);
return true;
}
if (ea.getKey() == 0x46 || ea.getKey() == 0x66)//F
{
return true ;
}
if (ea.getKey() == 0x47 || ea.getKey() == 0x67)//G
{
//m_vPosition += osg::Vec3(0,1500,0);
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&us);
osg::Vec3 centerPos = viewer->getSceneData()->getBound().center();
m_vPosition;
osg::Vec3 fangxiang = m_vPosition - centerPos;
m_vPosition += fangxiang*0.1;
return true ;
}
if (ea.getKey() == 0x5A || ea.getKey () == 0x7A) //z 测试
{
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&us);
osg::Vec3 centerPos = viewer->getSceneData()->getBound().center();
m_vPosition;
osg::Vec3 fangxiang = m_vPosition - centerPos;
m_vPosition += (-fangxiang)*0.1;
return true;
}
if (ea.getKey() == 0x58 || ea.getKey () == 0x78) //x 测试
{
return true;
}
if (ea.getKey() == 0x43 || ea.getKey () == 0x63) //c 测试
{
return true;
}
return false;
} |
|