From 55600c40a9a72e6117ee0ae1536edd44247d6ad1 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 28 Jul 2022 10:47:42 +0200 Subject: [PATCH] sdl: use exp scale for rumble power Better sensitivity for low power values. Issue #707 --- core/sdl/sdl_gamepad.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/sdl/sdl_gamepad.h b/core/sdl/sdl_gamepad.h index 4b50b88a7..f7134d31f 100644 --- a/core/sdl/sdl_gamepad.h +++ b/core/sdl/sdl_gamepad.h @@ -189,6 +189,10 @@ public: return GamepadDevice::gamepad_axis_input(code, value); } + u16 getRumbleIntensity(float power) { + return (u16)std::min(power * 65535.f / std::pow(1.06f, 100.f - rumblePower), 65535.f); + } + void rumble(float power, float inclination, u32 duration_ms) override { if (rumbleEnabled) @@ -196,7 +200,7 @@ public: vib_inclination = inclination * power; vib_stop_time = os_GetSeconds() + duration_ms / 1000.0; - Uint16 intensity = (Uint16)std::min(power * rumblePower * 65535.f / 100.f, 65535.f); + u16 intensity = getRumbleIntensity(power); SDL_JoystickRumble(sdl_joystick, intensity, intensity, duration_ms); } } @@ -211,7 +215,7 @@ public: vib_inclination = 0; else { - Uint16 intensity = (Uint16)std::min(vib_inclination * rem_time * 65535.f * rumblePower / 100.f, 65535.f); + u16 intensity = getRumbleIntensity(vib_inclination * rem_time); SDL_JoystickRumble(sdl_joystick, intensity, intensity, rem_time); } }