Fixed small joystick movement getting lost due to the set axes threshold.

This fixes issue #1329.
This commit is contained in:
Mario Liebisch 2017-12-28 09:55:57 +01:00 committed by Lukas Dürrenberger
parent 8b7a50a914
commit 49d611ee69
2 changed files with 15 additions and 5 deletions

View File

@ -86,7 +86,10 @@ m_joystickThreshold(0.1f)
// Get the initial joystick states // Get the initial joystick states
JoystickManager::getInstance().update(); JoystickManager::getInstance().update();
for (unsigned int i = 0; i < Joystick::Count; ++i) for (unsigned int i = 0; i < Joystick::Count; ++i)
{
m_joystickStates[i] = JoystickManager::getInstance().getState(i); m_joystickStates[i] = JoystickManager::getInstance().getState(i);
std::fill_n(m_previousAxes[i], static_cast<std::size_t>(Joystick::AxisCount), 0.f);
}
// Get the initial sensor states // Get the initial sensor states
for (unsigned int i = 0; i < Sensor::Count; ++i) for (unsigned int i = 0; i < Sensor::Count; ++i)
@ -176,6 +179,10 @@ void WindowImpl::processJoystickEvents()
event.type = connected ? Event::JoystickConnected : Event::JoystickDisconnected; event.type = connected ? Event::JoystickConnected : Event::JoystickDisconnected;
event.joystickButton.joystickId = i; event.joystickButton.joystickId = i;
pushEvent(event); pushEvent(event);
// Clear previous axes positions
if (connected)
std::fill_n(m_previousAxes[i], static_cast<std::size_t>(Joystick::AxisCount), 0.f);
} }
if (connected) if (connected)
@ -186,7 +193,7 @@ void WindowImpl::processJoystickEvents()
if (caps.axes[j]) if (caps.axes[j])
{ {
Joystick::Axis axis = static_cast<Joystick::Axis>(j); Joystick::Axis axis = static_cast<Joystick::Axis>(j);
float prevPos = previousState.axes[axis]; float prevPos = m_previousAxes[i][axis];
float currPos = m_joystickStates[i].axes[axis]; float currPos = m_joystickStates[i].axes[axis];
if (fabs(currPos - prevPos) >= m_joystickThreshold) if (fabs(currPos - prevPos) >= m_joystickThreshold)
{ {
@ -196,6 +203,8 @@ void WindowImpl::processJoystickEvents()
event.joystickMove.axis = axis; event.joystickMove.axis = axis;
event.joystickMove.position = currPos; event.joystickMove.position = currPos;
pushEvent(event); pushEvent(event);
m_previousAxes[i][axis] = currPos;
} }
} }
} }

View File

@ -270,10 +270,11 @@ private:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
std::queue<Event> m_events; ///< Queue of available events std::queue<Event> m_events; ///< Queue of available events
JoystickState m_joystickStates[Joystick::Count]; ///< Previous state of the joysticks JoystickState m_joystickStates[Joystick::Count]; ///< Previous state of the joysticks
Vector3f m_sensorValue[Sensor::Count]; ///< Previous value of the sensors Vector3f m_sensorValue[Sensor::Count]; ///< Previous value of the sensors
float m_joystickThreshold; ///< Joystick threshold (minimum motion for "move" event to be generated) float m_joystickThreshold; ///< Joystick threshold (minimum motion for "move" event to be generated)
float m_previousAxes[Joystick::Count][Joystick::AxisCount]; ///< Position of each axis last time a move event triggered, in range [-100, 100]
}; };
} // namespace priv } // namespace priv