mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-07 04:17:14 +00:00
Added SDL_modf() and SDL_modff()
This function is useful for accumulating relative mouse motion if you want to only handle whole pixel movement.
e.g.
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) {
...
}
This commit is contained in:
@@ -322,6 +322,28 @@ float SDL_log10f(float x)
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
SDL_modf(double x, double *y)
|
||||
{
|
||||
#if defined(HAVE_MODF)
|
||||
return modf(x, y);
|
||||
#else
|
||||
return SDL_uclibc_modf(x, y);
|
||||
#endif
|
||||
}
|
||||
|
||||
float SDL_modff(float x, float *y)
|
||||
{
|
||||
#if defined(HAVE_MODFF)
|
||||
return modff(x, y);
|
||||
#else
|
||||
double double_result, double_y;
|
||||
double_result = SDL_modf((double)x, &double_y);
|
||||
*y = (float)double_y;
|
||||
return (float)double_result;
|
||||
#endif
|
||||
}
|
||||
|
||||
double
|
||||
SDL_pow(double x, double y)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user