我需要输入代码来切换鼠标的灵敏度 - 增加或减少我的相机在场景中的行走速度。目前,我有一个连接事件处理程序来拦截键盘命令,并相应地处理它们。缺少的是按选定数量减慢/提高速度的正确代码。我有下面的枚举来描述可接受的增加/减少值。
enum CameraSpeed {_WALK = 10, _BRISK_WALK = 17, _JOG = 23, _RUN = 31, _RUN_FAST = 34, _FLY=60};
CameraSpeed _current_camera_speed;
我尝试像这样覆盖 CameraManipulator 的基类的 bool performMovement() 方法,但仔细检查后,这似乎不是我需要覆盖或用于此目的的代码。我会很感激一些帮助,不仅可以找到正确的方法,还可以修改它,以便我可以更好地控制灵敏度。
bool WalkingCameraManipulator::performMovement()
{
// return if less then two events have been added
if( _ga_t0.get() == NULL || _ga_t1.get() == NULL )
return false;
// get delta time
double eventTimeDelta = _ga_t0->getTime() - _ga_t1->getTime();
if( eventTimeDelta < 0. )
{
OSG_WARN << "Manipulator warning: eventTimeDelta = " << eventTimeDelta << std::endl;
eventTimeDelta = 0.;
}
// get deltaX and deltaY
float dx = (_ga_t0->getXnormalized() - _ga_t1->getXnormalized()/_current_camera_speed);
float dy = (_ga_t0->getYnormalized() - _ga_t1->getYnormalized())/_current_camera_speed;
// return if there is no movement.
if( dx == 0. && dy == 0. )
return false;
// call appropriate methods
unsigned int buttonMask = _ga_t1->getButtonMask();
if( buttonMask == GUIEventAdapter::LEFT_MOUSE_BUTTON )
{
return performMovementLeftMouseButton( eventTimeDelta, dx, dy );
}
else if( buttonMask == GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
buttonMask == (GUIEventAdapter::LEFT_MOUSE_BUTTON | GUIEventAdapter::RIGHT_MOUSE_BUTTON) )
{
return performMovementMiddleMouseButton( eventTimeDelta, dx, dy );
}
else if( buttonMask == GUIEventAdapter::RIGHT_MOUSE_BUTTON )
{
return performMovementRightMouseButton( eventTimeDelta, dx, dy );
}
return false;
}