From 9178206c950226ea6c4814443e29e52112c72846 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Fri, 8 Mar 2019 19:56:17 +0100 Subject: [PATCH] add 10% dead zone to analog sticks --- core/input/gamepad_device.cpp | 21 +++++++++++++++++++-- core/input/gamepad_device.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/input/gamepad_device.cpp b/core/input/gamepad_device.cpp index 996159c4d..29cb1436a 100644 --- a/core/input/gamepad_device.cpp +++ b/core/input/gamepad_device.cpp @@ -117,12 +117,29 @@ bool GamepadDevice::gamepad_axis_input(u32 code, int value) else if (((int)key >> 16) == 2) // Analog axes { //printf("AXIS %d Mapped to %d -> %d\n", key, value, v); + s8 *this_axis; + s8 *other_axis; if (key == DC_AXIS_X) - joyx[_maple_port] = (s8)v; + { + this_axis = &joyx[_maple_port]; + other_axis = &joyy[_maple_port]; + } else if (key == DC_AXIS_Y) - joyy[_maple_port] = (s8)v; + { + this_axis = &joyy[_maple_port]; + other_axis = &joyx[_maple_port]; + } else return false; + // Radial dead zone + // FIXME compute both axes at the same time + if ((float)(v * v + *other_axis * *other_axis) < _dead_zone * _dead_zone * 128.f * 128.f * 2.f) + { + *this_axis = 0; + *other_axis = 0; + } + else + *this_axis = (s8)v; } else return false; diff --git a/core/input/gamepad_device.h b/core/input/gamepad_device.h index b8f7e269d..e11c5e90d 100644 --- a/core/input/gamepad_device.h +++ b/core/input/gamepad_device.h @@ -106,6 +106,7 @@ private: bool _detecting_button = false; input_detected_cb _input_detected; bool _remappable; + float _dead_zone = 0.1f; static std::vector> _gamepads; static std::mutex _gamepads_mutex;