From 09704ae2438c7e4bbc786d2306dd988bbb4797c0 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Thu, 12 Sep 2019 07:21:11 -0400 Subject: [PATCH] Fixed issue where GetAnalogActionData magnitude of joystick was always maximum. --- controller/gamepad.c | 4 ++++ dll/steam_controller.h | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/controller/gamepad.c b/controller/gamepad.c index d78c0916..f1e7893d 100644 --- a/controller/gamepad.c +++ b/controller/gamepad.c @@ -554,6 +554,10 @@ static void GamepadUpdateStick(GAMEPAD_AXIS* axis, float deadzone) { axis->nx = axis->x / axis->length; axis->ny = axis->y / axis->length; + //fix special case + if (axis->nx < -1.0) axis->nx = -1.0; + if (axis->ny < -1.0) axis->ny = -1.0; + // adjust length for deadzone and find normalized length axis->length -= deadzone; axis->length /= (32767.0f - deadzone); diff --git a/dll/steam_controller.h b/dll/steam_controller.h index b03dc572..7a31879c 100644 --- a/dll/steam_controller.h +++ b/dll/steam_controller.h @@ -495,9 +495,16 @@ ControllerAnalogActionData_t GetAnalogActionData( ControllerHandle_t controllerH if (a >= 10) { int joystick_id = a - 10; GamepadStickNormXY((GAMEPAD_DEVICE)(controllerHandle - 1), (GAMEPAD_STICK) joystick_id, &data.x, &data.y); + float length = GamepadStickLength((GAMEPAD_DEVICE)(controllerHandle - 1), (GAMEPAD_STICK) joystick_id); + data.x = data.x * length; + data.y = data.y * length; } else { data.x = GamepadTriggerLength((GAMEPAD_DEVICE)(controllerHandle - 1), (GAMEPAD_TRIGGER) a); } + + if (data.x || data.y) { + break; + } } return data;