Use the triggers to test rumble for more fine grained vibration feedback

This commit is contained in:
Sam Lantinga 2020-02-07 11:45:32 -08:00
parent 8ba77b35a5
commit dd0ebfdf8b
1 changed files with 7 additions and 5 deletions

View File

@ -114,11 +114,6 @@ loop(void *arg)
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP: case SDL_CONTROLLERBUTTONUP:
SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released"); SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
/* First button triggers a 0.5 second full strength rumble */
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
event.cbutton.button == SDL_CONTROLLER_BUTTON_A) {
SDL_GameControllerRumble(gamecontroller, 0xFFFF, 0xFFFF, 500);
}
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (event.key.keysym.sym != SDLK_ESCAPE) { if (event.key.keysym.sym != SDLK_ESCAPE) {
@ -155,6 +150,13 @@ loop(void *arg)
} }
} }
/* Update rumble based on trigger state */
{
Uint16 low_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT) * 2;
Uint16 high_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) * 2;
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
}
SDL_RenderPresent(screen); SDL_RenderPresent(screen);
if (!SDL_GameControllerGetAttached(gamecontroller)) { if (!SDL_GameControllerGetAttached(gamecontroller)) {