|
昨天在家里试图扩展一下TrackballManipulator.由于我的问题使用eye,center,up来描述比较直观.所以我就打算将TrackballManipulator的矩阵先取出来 然后获取这三个参数,修改后再用TrackballManipulator的ComputePosition送回去.结果总是不对.在我无限简化我的代码后.发现一个很奇怪的现象:
在handle里面:当把eye,center,up取出来然后再送回去,场景就会消失.再取出来,送回去,场景就会出现.
下面是代码:- #include "StdAfx.h"
- #include "TrackballManipulatorEx.h"
- TrackballManipulatorEx::TrackballManipulatorEx(Viewer* view)
- {
- mMoveStep=1.0;
- mRotateStep=2.5;
- this->mView=view;
- }
- TrackballManipulatorEx::~TrackballManipulatorEx(void)
- {
- }
- void TrackballManipulatorEx::home(double currentTime)
- {
- TrackballManipulator::home(currentTime);
- }
- bool TrackballManipulatorEx::handleKeyDown(const GUIEventAdapter&ea,GUIActionAdapter& us)
- {
- bool handled=false;
- int keyCode=ea.getKey();
- unsigned int mode=ea.getModKeyMask();
- bool isCtrl=(GUIEventAdapter::MODKEY_CTRL&mode)!=0;
- switch(keyCode)
- {
- case GUIEventAdapter::KEY_F1:
- {
- if(isCtrl)
- {
- this->mRotateStep*=1.5;
- }else
- {
- this->mMoveStep*=1.5;
- }
- break;
- }
- case GUIEventAdapter::KEY_F2:
- {
- if(isCtrl)
- {
- this->mRotateStep/=1.5;
- }else
- {
- this->mMoveStep/=1.5;
- }
- break;
- }
- case GUIEventAdapter::KEY_Up:
- case GUIEventAdapter::KEY_KP_Up:
- {
- Matrixd mat=getMatrix();
- Vec3 eye,center,up;
- mat.getLookAt(eye,center,up,_distance);
- computePosition(eye,center,up);
- handled=true;
- break;
- }
- case GUIEventAdapter::KEY_Down:
- case GUIEventAdapter::KEY_KP_Down:
- {
- Matrixd mat=getMatrix();
- Vec3 eye,center,up;
- mat.getLookAt(eye,center,up,_distance);
- computePosition(eye,center,up);
- handled=true;
- break;
- }
-
- }
- return handled;
- }
- bool TrackballManipulatorEx::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
- {
- bool handled=TrackballManipulator::handle(ea,us);
- if(handled){
-
-
- }
- else{
- switch(ea.getEventType())
- {
- case GUIEventAdapter::KEYDOWN:
- {
- handled=handleKeyDown(ea,us);
- break;
- }
- }
- }
- return handled;
- }
复制代码 Stdafx中就是所有对osg头文件的引用.
另外该类public 派生于TrackballManipulator.
其中最诡异的就是:
handleKey中KEY_UP和KEY_DOWN的代码.其中KEY_UP会让场景消失,KEY_DOWN会让场景再次出现在原来的地方.
期待高人指点. |
|