|
楼主 |
发表于 2011-5-23 16:54:37
|
显示全部楼层
回复 4# wangjunchao
漫游器中按下键后执行的:
- bool CSouth::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us)
- {
- float mouseX=ea.getX();
- float mouseY=ea.getY();
- //判断事件类型
- switch (ea.getEventType())
- {
- case (osgGA::GUIEventAdapter::KEYDOWN) :
- {
- if (ea.getKey()==' ')//如果是空格 重绘
- {
- us.requestRedraw();
- us.requestContinuousUpdate(false);
- return true;
- }
- if (ea.getKey() == 0xFF50)//如果是home键,则视点向上移动
- {
- ChangePosition(Vec3(0, 0, m_fMoveSpeed));
- return true;
- }
- if (ea.getKey() == 0xFF57) //如果是end键,同视点向下移动
- {
- ChangePosition(Vec3(0, 0, -m_fMoveSpeed));
- return true;
- }
- //向前走,W键,或者UP键
- if (ea.getKey() == 0xFF52 || ea.getKey () == 'w' || ea.getKey () == 'W')
- {
- ChangePosition(Vec3(0, m_fMoveSpeed * sinf(PI_2+m_vRotation._v[2]), 0));
- ChangePosition(Vec3(m_fMoveSpeed * cosf(PI_2+m_vRotation._v[2]), 0, 0));
- return true;
- }
- //向后退,S键,或者DOWN键
- if (ea.getKey() == 0xFF54 || ea.getKey () == 's' || ea.getKey () == 'S')
- {
- ChangePosition(Vec3(0, -m_fMoveSpeed *sinf(PI_2+m_vRotation._v[2]), 0));
- ChangePosition(Vec3(-m_fMoveSpeed *cosf(PI_2+m_vRotation._v[2]), 0, 0));
- return true;
- }
- //A
- if (ea.getKey() == 'A' || ea.getKey () == 'a' )
- {
- ChangePosition(Vec3(0, m_fMoveSpeed *cosf(PI_2+m_vRotation._v[2]), 0));
- ChangePosition(Vec3(-m_fMoveSpeed *sinf(PI_2+m_vRotation._v[2]), 0, 0));
- return true;
- }
- //D
- if (ea.getKey() == 'D' || ea.getKey () == 'd' )
- {
- ChangePosition(Vec3(0, -m_fMoveSpeed * cosf(PI_2+m_vRotation._v[2]), 0));
- ChangePosition(Vec3(m_fMoveSpeed * sinf(PI_2+m_vRotation._v[2]), 0, 0));
- return true;
- }
- if (ea.getKey() == 0xFF53)//Right
- {
- m_vRotation._v[2] -= osg::DegreesToRadians(m_fAngle);
- }
- if (ea.getKey()== 0xFF51)//Left
- {
- m_vRotation._v[2] += osg::DegreesToRadians(m_fAngle);
- }
- return false;
- }
- //单击
- case (osgGA::GUIEventAdapter::PUSH):
- {
- if (ea.getButton() == 1)
- {
- m_fpushX = mouseX ;
- m_fpushY = mouseY ;
- m_bLeftButtonDown = true ;
- }
- return false;
- }
- //拖动
- case (osgGA::GUIEventAdapter::DRAG):
- {
- if ( m_bLeftButtonDown)
- {
- m_vRotation._v[2] -= osg::DegreesToRadians(m_fAngle * (mouseX-m_fpushX));
- m_vRotation._v[0] += osg::DegreesToRadians(1.0f*(mouseY-m_fpushY));
- //防止背过去
- if (m_vRotation._v [0] >= 3.14)
- m_vRotation._v [0] = 3.14 ;
- if (m_vRotation._v [0] <= 0)
- m_vRotation._v [0] = 0 ;
- }
- return false;
- }
- //键弹起
- case (osgGA::GUIEventAdapter ::RELEASE ):
- {
- if ( ea.getButton () == 1)
- {
- m_bLeftButtonDown = false ;
- }
- return false ;
- }
- default:
- return false;
- }//end switch
- }
复制代码 |
|