SDL_JoystickGetBall(3)

πŸ’– SDL_JoystickGetBall(3) πŸ’–

okay so bestie, we're in the SDL API Reference today and the vibe is trackballs. yes, those little rolling balls. they still exist. sit with me. πŸŽ€


✨ NAME ✨

SDL_JoystickGetBall β€” get that relative trackball motion, no cap πŸ¦‹


🌸 SYNOPSIS 🌸

#include "SDL.h"

int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);

πŸ’… DESCRIPTION πŸ’…

So like, this function gets you the ball axis change. that's it, that's the whole job. πŸ’β™€οΈ

Here's the tea though: trackballs can only return relative motion β€” meaning the movement since the last call to SDL_JoystickGetBall. these motion deltas get placed into dx and dy. so don't come in here expecting absolute coordinates, bestie, because you will not be getting them. it's giving deltas only. 🫢


πŸ”₯ RETURN VALUE πŸ”₯

Returns 0 on success or -1 on failure. iconic behaviour, honestly. ✨


🌈 EXAMPLES 🌈

int delta_x, delta_y;
SDL_Joystick *joy;
.
.
.
SDL_JoystickUpdate();
if(SDL_JoystickGetBall(joy, 0, &delta_x, &delta_y)==-1)
  printf("TrackBall Read Error!
");
printf("Trackball Delta- X:%d, Y:%d
", delta_x, delta_y);

look at that. SDL_JoystickUpdate() first (mandatory, don't skip it, she's the main character of this snippet), then vibe check the return value against -1, then print your deltas. πŸ’œ

the way those printf strings have a literal line break right in the middle of them? yeah. that's exactly how it's written in the original, and I am not touching it. copy it character for character, fr fr. πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

SDL_JoystickNumBalls β€” go count your balls, bestie πŸ‘‘


and that's a wrap on the SDL manual page, brought to you by SDL itself, dated Tue 11 Sep 2001, 23:00. yes, 2001. the trackball lore is ancient and we respect it. periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from