mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-01-12 05:25:36 +00:00
Haptic: Explicitly avoid floating point arithmetic if it's not needed.
Thanks, Elias! Partially fixes Bugzilla #2686.
This commit is contained in:
parent
1db581b4ca
commit
a2622ce6e0
|
@ -658,7 +658,6 @@ static int
|
||||||
SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
||||||
{
|
{
|
||||||
Uint32 tmp;
|
Uint32 tmp;
|
||||||
float f; /* Ideally we'd use fixed point math instead of floats... */
|
|
||||||
|
|
||||||
switch (src->type) {
|
switch (src->type) {
|
||||||
case SDL_HAPTIC_POLAR:
|
case SDL_HAPTIC_POLAR:
|
||||||
|
@ -690,7 +689,12 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_HAPTIC_CARTESIAN:
|
case SDL_HAPTIC_CARTESIAN:
|
||||||
f = atan2(src->dir[1], src->dir[0]);
|
if (!src->dir[1])
|
||||||
|
*dest = (src->dir[0] >= 0 ? 0x4000 : 0xC000);
|
||||||
|
else if (!src->dir[0])
|
||||||
|
*dest = (src->dir[1] >= 0 ? 0x8000 : 0);
|
||||||
|
else {
|
||||||
|
float f = atan2(src->dir[1], src->dir[0]); /* Ideally we'd use fixed point math instead of floats... */
|
||||||
/*
|
/*
|
||||||
atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
|
atan2 takes the parameters: Y-axis-value and X-axis-value (in that order)
|
||||||
- Y-axis-value is the second coordinate (from center to SOUTH)
|
- Y-axis-value is the second coordinate (from center to SOUTH)
|
||||||
|
@ -704,6 +708,7 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
|
||||||
tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
|
tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
|
||||||
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
|
||||||
*dest = (Uint16) tmp;
|
*dest = (Uint16) tmp;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue