Improve handling of mouse movement for the first person camera, especially at low framerates

This commit is contained in:
Flakebi 2015-03-08 15:14:31 +01:00
parent 33feb60d7a
commit b21f6f4782
3 changed files with 5 additions and 10 deletions

View File

@ -489,6 +489,7 @@ void Camera::update(float dt)
// - the kart should not be visible, but it works)
m_camera->setNearValue(27.0);
}
// Update the first person camera
else if (UserConfigParams::m_camera_debug == 3)
{
core::vector3df direction(m_camera->getTarget() - m_camera->getPosition());

View File

@ -67,8 +67,7 @@ using GUIEngine::EVENT_BLOCK;
/** Initialise input
*/
InputManager::InputManager() : m_mode(BOOTSTRAP),
m_mouse_val_x(-1), m_mouse_val_y(-1),
m_mouse_reset(0)
m_mouse_val_x(-1), m_mouse_val_y(-1)
{
m_device_manager = new DeviceManager();
m_device_manager->initialize();
@ -977,11 +976,13 @@ EventPropagation InputManager::input(const SEvent& event)
UserConfigParams::m_fpscam_direction_speed;
float mouse_y = ((float) diff_y) *
-UserConfigParams::m_fpscam_direction_speed;
// No movement the first time it's used
// At the moment there's also a hard limit because the mouse
// gets reset to the middle of the screen and sometimes there
// are more events fired than expected.
if (m_mouse_val_x != -1 && m_mouse_reset <= 0)
if (m_mouse_val_x != -1 &&
(diff_x + diff_y) < 100 && (diff_x + diff_y) > -100)
{
// Rotate camera
core::vector3df up(cam->getUpVector());
@ -1016,8 +1017,6 @@ EventPropagation InputManager::input(const SEvent& event)
irr_driver->getDevice()->getCursorControl()->setPosition(mid_x, mid_y);
m_mouse_val_x = mid_x;
m_mouse_val_y = mid_y;
// Ignore the next 2 movements
m_mouse_reset = 2;
}
else
{
@ -1029,7 +1028,6 @@ EventPropagation InputManager::input(const SEvent& event)
{
m_mouse_val_x = event.MouseInput.X;
m_mouse_val_y = event.MouseInput.Y;
--m_mouse_reset;
}
return EVENT_BLOCK;
}

View File

@ -67,10 +67,6 @@ private:
* makes the mouse behave like an analog axis on a gamepad/joystick.
*/
int m_mouse_val_x, m_mouse_val_y;
/** To detect mouse events that are not caused by the user but by resetting
the mouse position to the center of the screen.
If it's not 0, the movement is ignored and the value is decreased. */
int m_mouse_reset;
void dispatchInput(Input::InputType, int deviceID, int btnID,
Input::AxisDirection direction, int value);