Controller: Round floating point axis values instead of flooring

This commit is contained in:
Connor McLaughlin 2021-07-17 20:38:21 +10:00
parent b01d49fa52
commit 3cf12e8f0d
3 changed files with 3 additions and 3 deletions

View file

@ -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<u8>(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
const u8 u8_value = static_cast<u8>(std::clamp(std::round(((scaled_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f));
SetAxisState(static_cast<Axis>(axis_code), u8_value);
}

View file

@ -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<u8>(std::clamp(((scaled_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
const u8 u8_value = static_cast<u8>(std::clamp(std::round(((scaled_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f));
SetAxisState(static_cast<Axis>(axis_code), u8_value);
}

View file

@ -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<u8>(std::clamp(((float_value + 1.0f) / 2.0f) * 255.0f, 0.0f, 255.0f));
const u8 u8_value = static_cast<u8>(std::clamp(std::round(((float_value + 1.0f) / 2.0f) * 255.0f), 0.0f, 255.0f));
SetAxisState(static_cast<Axis>(axis_code), u8_value);