From 3cf12e8f0d16726d0624519ff3efb031d9ba4df6 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 17 Jul 2021 20:38:21 +1000 Subject: [PATCH] Controller: Round floating point axis values instead of flooring --- src/core/analog_controller.cpp | 2 +- src/core/analog_joystick.cpp | 2 +- src/core/negcon.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 966f25b8b..5da66129e 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -123,7 +123,7 @@ void AnalogController::SetAxisState(s32 axis_code, float value) // -1..1 -> 0..255 const float scaled_value = std::clamp(value * m_axis_scale, -1.0f, 1.0f); - const u8 u8_value = static_cast(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); + const u8 u8_value = static_cast(std::clamp(std::round(((scaled_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); } diff --git a/src/core/analog_joystick.cpp b/src/core/analog_joystick.cpp index dceb52af0..e9feb6cc1 100644 --- a/src/core/analog_joystick.cpp +++ b/src/core/analog_joystick.cpp @@ -86,7 +86,7 @@ void AnalogJoystick::SetAxisState(s32 axis_code, float value) // -1..1 -> 0..255 const float scaled_value = std::clamp(value * m_axis_scale, -1.0f, 1.0f); - const u8 u8_value = static_cast(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); + const u8 u8_value = static_cast(std::clamp(std::round(((scaled_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value); } diff --git a/src/core/negcon.cpp b/src/core/negcon.cpp index ff8fd515d..8069e20dc 100644 --- a/src/core/negcon.cpp +++ b/src/core/negcon.cpp @@ -71,7 +71,7 @@ void NeGcon::SetAxisState(s32 axis_code, float value) (std::abs(value) < m_steering_deadzone) ? 0.0f : std::copysign((std::abs(value) - m_steering_deadzone) / (1.0f - m_steering_deadzone), value); - const u8 u8_value = static_cast(std::clamp(((float_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f)); + const u8 u8_value = static_cast(std::clamp(std::round(((float_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f)); SetAxisState(static_cast(axis_code), u8_value);