diff --git a/Windows/XinputDevice.cpp b/Windows/XinputDevice.cpp index 72b3ada03f..befe6d4761 100644 --- a/Windows/XinputDevice.cpp +++ b/Windows/XinputDevice.cpp @@ -1,4 +1,4 @@ -#include +#include #include "Core/Config.h" #include "input/input_state.h" #include "XinputDevice.h" @@ -90,31 +90,35 @@ int XinputDevice::UpdateState(InputState &input_state) { } } -inline float Clampf(float val, float min, float max) { - if (val < min) return min; - if (val > max) return max; - return val; -} - -// We only filter the left stick since PSP has no analog triggers or right stick -// Doesn't currently do any real deadzoning. Maybe we don't need it. -static Stick NormalizedDeadzoneFilter(short x, short y) { - Stick s; - float magnitude = 32767.0f; - - s.x = (float)x / magnitude; - s.y = (float)y / magnitude; - - magnitude = s.x * s.x + s.y * s.y; - - if (magnitude > 1.0f) { - s.x *= 1.41421f; - s.y *= 1.41421f; - } - - s.x = Clampf(s.x, -1.0f, 1.0f); - s.y = Clampf(s.y, -1.0f, 1.0f); - return s; +inline float Clampf(float val, float min, float max) { + if (val < min) return min; + if (val > max) return max; + return val; +} + +// We only filter the left stick since PSP has no analog triggers or right stick +static Stick NormalizedDeadzoneFilter(short x, short y) { + static const float DEADZONE = (float)XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32767.0f; + Stick s; + + s.x = (float)x / 32767.0f; + s.y = (float)y / 32767.0f; + + float magnitude = sqrtf(s.x * s.x + s.y * s.y); + + if (magnitude > DEADZONE) { + if (magnitude > 1.0f) { + s.x *= 1.41421f; + s.y *= 1.41421f; + } + + s.x = Clampf(s.x, -1.0f, 1.0f); + s.y = Clampf(s.y, -1.0f, 1.0f); + } else { + s.x = 0.0f; + s.y = 0.0f; + } + return s; }