|
TravelManipulator::TravelManipulator()
{
//初始化视点
m_vPosition=osg::Vec3(0,0,0);
//初始化朝向
m_vRotation=osg::Vec3(osg::PI_2,0,0);
m_vStep=1;//步长
m_vRotateStep=0;//这个是什么??
}
请问m_vRotation[0],m_vRotation[1],m_vRotation[2]都是什么意思???????????
bool TravelManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
{
switch(ea.getEventType())
{
case osgGA::GUIEventAdapter::KEYDOWN:
{
if((ea.getKey()=='w') || (ea.getKey()=='W') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Up))
{
//下边这句话中为何用m_vRotation[2]指的是什么呢?为何要加上pi_2呢,我看了视频,可是这块讲的有点快了,不理解
//为何要用osg::PI_2加上m_vRotation[2]呢?这块当时讲的一扫而过,不太理解,求解释,感谢!!
ChangePosition(osg::Vec3d(m_vStep*cosf(osg::PI_2 + m_vRotation[2]),m_vStep*::sinf(osg::PI_2+m_vRotation[2]),0));
return true;
}
else if((ea.getKey()=='s') || (ea.getKey()=='S') || (ea.getKey()==osgGA::GUIEventAdapter::KEY_Down))
{
ChangePosition(osg::Vec3d(-m_vStep*cosf(osg::PI_2 + m_vRotation[2]),-m_vStep*::sinf(osg::PI_2+m_vRotation[2]),0));
return true;
}
else if((ea.getKey()=='a') || (ea.getKey()=='A'))
{
ChangePosition(osg::Vec3d(-m_vStep*sinf(osg::PI_2 + m_vRotation[2]),m_vStep*::cosf(osg::PI_2+m_vRotation[2]),0));
return true;
}
else if((ea.getKey()=='d') || (ea.getKey()=='D'))
{
ChangePosition(osg::Vec3d(m_vStep*sinf(osg::PI_2 + m_vRotation[2]),-m_vStep*::cosf(osg::PI_2+m_vRotation[2]),0));
return true;
}
else if(ea.getKey()==osgGA::GUIEventAdapter::KEY_Left)
{
m_vRotation[2]+=0.2;
return true;
}
else if(ea.getKey()==osgGA::GUIEventAdapter::KEY_Right)
{
m_vRotation[2]-=0.2;
return true;
}
else if(ea.getKey()==osgGA::GUIEventAdapter::KEY_Home)
{
ChangePosition(osg::Vec3d(0,0,m_vStep));//向上,Z轴加正的m_vStep
return true;
}
else if(ea.getKey()==osgGA::GUIEventAdapter::KEY_End)
{
ChangePosition(osg::Vec3d(0,0,-m_vStep));//向下,Z轴加负的m_vStep
return true;
}
else
{
}
}
}
return false;
}
void TravelManipulator::ChangePosition(osg::Vec3d &delta)
{
m_vPosition+=delta;
} |
|