From 5bfd306a480f0bb2582d882f93f9986c4c34976a Mon Sep 17 00:00:00 2001 From: ackimixs Date: Wed, 15 May 2024 15:55:47 +0200 Subject: [PATCH] rumble --- GameControllerHandler.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/GameControllerHandler.h b/GameControllerHandler.h index cbce1d7..48abd63 100644 --- a/GameControllerHandler.h +++ b/GameControllerHandler.h @@ -40,9 +40,16 @@ public: if (tokens[1] == "all" || tokens[1] == "gc") { if (tokens[2] == "stop proximity") { - // if (SDL_GameControllerRumble(controller, 0xFFFF, 0xFFFF, 1000) != 0) { - // std::cerr << "Erreur lors de l'activation de la vibration : " << SDL_GetError() << std::endl; - // } + std::vector args = Utils::split(tokens[3], ","); + int distance = stoi(args[0]); + Uint16 strength = 0xFFFF; + if (distance < 200) { + strength = static_cast((200 - distance) * 0xFFFF / 200); + } + + if (SDL_GameControllerRumble(controller, strength, strength, 1000) != 0) { + std::cerr << "Erreur lors de l'activation de la vibration : " << SDL_GetError() << std::endl; + } } if (tokens[2] == "ready") {