From 915b7d3726e2f44e9db995a6cd035011e2407cc7 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 17 Sep 2020 19:57:08 +1000 Subject: [PATCH] AnalogController: Use nonlinear mapping of vibration strength Curve from Pokopom: https://github.com/KrossX/Pokopom/blob/master/Pokopom/Input_XInput.cpp#L210 --- src/core/analog_controller.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index 0c5267dde..2ec8b9c6e 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -141,9 +141,13 @@ float AnalogController::GetVibrationMotorStrength(u32 motor) if (m_motor_state[motor] == 0) return 0.0f; - return static_cast( - std::min(static_cast(m_motor_state[motor]) + static_cast(m_rumble_bias), 255)) / - 255.0f; + // Curve from https://github.com/KrossX/Pokopom/blob/master/Pokopom/Input_XInput.cpp#L210 + const double x = + static_cast(std::min(static_cast(m_motor_state[motor]) + static_cast(m_rumble_bias), 255)); + const double strength = 0.006474549734772402 * std::pow(x, 3.0) - 1.258165252213538 * std::pow(x, 2.0) + + 156.82454281087692 * x + 3.637978807091713e-11; + + return static_cast(strength / 65535.0); } void AnalogController::ResetTransferState()