I have a requirement to put code in to toggle the sensitivity of the mouse - increase or decrease the speed of my Camera’s walk speed in the scene. Currently, I have an eventhandler wired up to intercept keyboard commands, and process them accordingly. What is missing is the right code to slow/increase speed by selected amount. I have the enum below to depict the acceptable increase/decrease values.
enum CameraSpeed {_WALK = 10, _BRISK_WALK = 17, _JOG = 23, _RUN = 31, _RUN_FAST = 34, _FLY=60};
CameraSpeed _current_camera_speed;
I tried overwriting the CameraManipulator’s base class’s bool performMovement() method like so, but on careful examination, this does not seem to be the code I need to override or use for this purpose. I would appreciate some help in not only getting to the right method but also modifying it so I can control sensitivity even more.
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;
}