Created
March 19, 2023 18:23
-
-
Save slouken/7c41d29a252d58778794311f555ebe8c to your computer and use it in GitHub Desktop.
Accumulating relative mouse motion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (SDL_PollEvent(&event) > 0) { | |
if (event.type == SDL_EVENT_MOUSE_MOTION) { | |
static float dx_frac, dy_frac; | |
float dx, dy; | |
/* Accumulate new motion with previous sub-pixel motion */ | |
dx = event.motion.xrel + dx_frac; | |
dy = event.motion.yrel + dy_frac; | |
/* Split the integral and fractional motion, dx and dy will contain whole pixel deltas */ | |
dx_frac = SDL_modff(dx, &dx); | |
dy_frac = SDL_modff(dy, &dy); | |
if (dx != 0.0f || dy != 0.0f) { | |
SDL_Log("Relative motion: %g,%g\n", dx, dy); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment