summaryrefslogtreecommitdiff
path: root/test/testgamecontroller.c
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2020-11-11 18:57:37 -0800
committerSam Lantinga <slouken@libsdl.org>2020-11-11 18:57:37 -0800
commit0d678445809fdac349be10854bfec6d9c1f734f2 (patch)
tree3eb78897c5c69bcde1f1bacb75b1a29f0e360dff /test/testgamecontroller.c
parent0c3572e719bef564ef33f0ca61a370ea88e33aea (diff)
downloadsdl-0d678445809fdac349be10854bfec6d9c1f734f2.tar.gz
Added SDL_JoystickRumbleTriggers() and SDL_GameControllerRumbleTriggers()
Diffstat (limited to 'test/testgamecontroller.c')
-rw-r--r--test/testgamecontroller.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c
index 3d6a371b6..59419931e 100644
--- a/test/testgamecontroller.c
+++ b/test/testgamecontroller.c
@@ -114,6 +114,17 @@ UpdateWindowTitle()
}
}
+static Uint16 ConvertAxisToRumble(Sint16 axis)
+{
+ /* Only start rumbling if the axis is past the halfway point */
+ const int half_axis = (SDL_JOYSTICK_AXIS_MAX / 2);
+ if (axis > half_axis) {
+ return (Uint16)(axis - half_axis) * 4;
+ } else {
+ return 0;
+ }
+}
+
void
loop(void *arg)
{
@@ -227,6 +238,16 @@ loop(void *arg)
Uint16 high_frequency_rumble = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT) * 2;
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
}
+
+ /* Update trigger rumble based on thumbstick state */
+ {
+ Sint16 left_y = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
+ Sint16 right_y = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
+ Uint16 left_rumble = ConvertAxisToRumble(~left_y);
+ Uint16 right_rumble = ConvertAxisToRumble(~right_y);
+
+ SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250);
+ }
}
SDL_RenderPresent(screen);