我需要输入代码来切换鼠标的灵敏度 - 增加或减少相机在场景中的行走速度。目前,我有一个事件处理程序连接到拦截键盘命令,并相应地处理它们。缺少的是使用选定数量减慢/提高速度的正确代码。 我在下面的枚举中描述了可接受的增加/减少值。
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;
}