mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-26 23:55:40 +00:00
Controller: Round floating point axis values instead of flooring
This commit is contained in:
parent
b01d49fa52
commit
3cf12e8f0d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue