mirror of
https://github.com/modelec/GameController.git
synced 2026-03-18 21:40:43 +01:00
map that handle double
This commit is contained in:
@@ -41,21 +41,21 @@ public:
|
||||
if (tokens[1] == "all" || tokens[1] == "gc") {
|
||||
if (tokens[2] == "stop proximity") {
|
||||
std::vector<std::string> args = Utils::split(tokens[3], ",");
|
||||
int distance = stoi(args[0]);
|
||||
double distance = stod(args[0]);
|
||||
Uint16 strength;
|
||||
|
||||
if (distance <= 200) {
|
||||
if (distance <= 100) {
|
||||
strength = 0xFFFF;
|
||||
} else if (distance <= 500) {
|
||||
double factor = 1.0 - static_cast<double>(distance - 200) / (500 - 200);
|
||||
double factor = 1 - Utils::mapValue(distance, 100.0, 500.0, 0.0, 1.0);
|
||||
strength = static_cast<Uint16>(factor * 0xFFFF);
|
||||
} else {
|
||||
strength = 0;
|
||||
}
|
||||
|
||||
// if (SDL_GameControllerRumble(controller, strength, strength, 1000) != 0) {
|
||||
// std::cerr << "Erreur lors de l'activation de la vibration : " << SDL_GetError() << std::endl;
|
||||
// }
|
||||
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") {
|
||||
|
||||
5
utils.h
5
utils.h
@@ -37,4 +37,9 @@ namespace Utils {
|
||||
} while (pos < str.length() && prev < str.length());
|
||||
return tokens;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T mapValue(T v, T v_min, T v_max, T v_min_prime, T v_max_prime) {
|
||||
return v_min_prime + (((v - v_min) * (v_max_prime - v_min_prime)) / (v_max - v_min));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user