Input: fix xinput deadzones

This commit is contained in:
Megamouse 2020-05-04 16:31:08 +02:00
parent f95bf01c78
commit 5c4b8e8dee
6 changed files with 7 additions and 11 deletions

View File

@ -174,12 +174,12 @@ u16 PadHandlerBase::NormalizeStickInput(u16 raw_value, int threshold, int multip
// return is new x and y values in 0-255 range
std::tuple<u16, u16> PadHandlerBase::NormalizeStickDeadzone(s32 inX, s32 inY, u32 deadzone)
{
const float dzRange = deadzone / static_cast<float>((std::abs(thumb_max) + std::abs(thumb_min)));
const float dz_range = deadzone / static_cast<float>(std::abs(thumb_max)); // NOTE: thumb_max should be positive anyway
float X = inX / 255.0f;
float Y = inY / 255.0f;
if (dzRange > 0.f)
if (dz_range > 0.f)
{
const float mag = std::min(sqrtf(X * X + Y * Y), 1.f);
@ -188,16 +188,16 @@ std::tuple<u16, u16> PadHandlerBase::NormalizeStickDeadzone(s32 inX, s32 inY, u3
return std::tuple<u16, u16>(ConvertAxis(X), ConvertAxis(Y));
}
if (mag > dzRange)
if (mag > dz_range)
{
const float pos = std::lerp(0.13f, 1.f, (mag - dzRange) / (1 - dzRange));
const float pos = std::lerp(0.13f, 1.f, (mag - dz_range) / (1 - dz_range));
const float scale = pos / mag;
X = X * scale;
Y = Y * scale;
}
else
{
const float pos = std::lerp(0.f, 0.13f, mag / dzRange);
const float pos = std::lerp(0.f, 0.13f, mag / dz_range);
const float scale = pos / mag;
X = X * scale;
Y = Y * scale;

View File

@ -123,8 +123,8 @@ protected:
static std::tuple<u16, u16> ConvertToSquirclePoint(u16 inX, u16 inY, int squircle_factor);
public:
s32 thumb_min = 0;
s32 thumb_max = 255;
// s32 thumb_min = 0; // Unused. Make sure all handlers report 0+ values for sticks in get_button_values.
s32 thumb_max = 255; // NOTE: Better keep this positive
s32 trigger_min = 0;
s32 trigger_max = 255;
s32 vibration_min = 0;

View File

@ -114,7 +114,6 @@ ds4_pad_handler::ds4_pad_handler() : PadHandlerBase(pad_handler::ds4)
init_configs();
// Define border values
thumb_min = 0;
thumb_max = 255;
trigger_min = 0;
trigger_max = 255;

View File

@ -25,7 +25,6 @@ evdev_joystick_handler::evdev_joystick_handler()
init_configs();
// Define border values
thumb_min = 0;
thumb_max = 255;
trigger_min = 0;
trigger_max = 255;

View File

@ -9,7 +9,6 @@ mm_joystick_handler::mm_joystick_handler() : PadHandlerBase(pad_handler::mm)
init_configs();
// Define border values
thumb_min = 0;
thumb_max = 255;
trigger_min = 0;
trigger_max = 255;

View File

@ -49,7 +49,6 @@ xinput_pad_handler::xinput_pad_handler() : PadHandlerBase(pad_handler::xinput)
init_configs();
// Define border values
thumb_min = -32768;
thumb_max = 32767;
trigger_min = 0;
trigger_max = 255;