diff --git a/project/jni/application/sc2/src/libs/input/sdl/vcontrol.c b/project/jni/application/sc2/src/libs/input/sdl/vcontrol.c index 0d38e1828..00b3993e0 100644 --- a/project/jni/application/sc2/src/libs/input/sdl/vcontrol.c +++ b/project/jni/application/sc2/src/libs/input/sdl/vcontrol.c @@ -399,9 +399,6 @@ event2gesture (SDL_Event *e, VCONTROL_GESTURE *g) g->gesture.axis.port = e->jaxis.which; g->gesture.axis.index = e->jaxis.axis; g->gesture.axis.polarity = (e->jaxis.value < 0) ? -1 : 1; -#ifdef ANDROID - g->gesture.axis.polarity = - g->gesture.axis.polarity; // Too lazy to swap it on SDL side -#endif break; case SDL_JOYHATMOTION: g->type = VCONTROL_JOYHAT; @@ -911,6 +908,11 @@ VControl_GetJoyAxis(int port, int axis) #endif /* HAVE_JOYSTICK */ }; +int VControl_GetJoysticksAmount() +{ + return joycount; +}; + void VControl_ResetInput (void) { diff --git a/project/jni/application/sc2/src/libs/input/sdl/vcontrol.h b/project/jni/application/sc2/src/libs/input/sdl/vcontrol.h index 6c9f35c2b..8f093e7a8 100644 --- a/project/jni/application/sc2/src/libs/input/sdl/vcontrol.h +++ b/project/jni/application/sc2/src/libs/input/sdl/vcontrol.h @@ -77,6 +77,7 @@ void VControl_ProcessJoyAxis (int port, int axis, int value); void VControl_ProcessJoyHat (int port, int which, Uint8 value); int VControl_GetJoyAxis(int port, int axis); +int VControl_GetJoysticksAmount(); /* Force the input into the blank state. For preventing "sticky" keys. */ void VControl_ResetInput (void); diff --git a/project/jni/application/sc2/src/uqm/gameinp.c b/project/jni/application/sc2/src/uqm/gameinp.c index 33f3de1f7..7b000852a 100644 --- a/project/jni/application/sc2/src/uqm/gameinp.c +++ b/project/jni/application/sc2/src/uqm/gameinp.c @@ -426,13 +426,14 @@ GetMenuSounds (MENU_SOUND_FLAGS *s0, MENU_SOUND_FLAGS *s1) *s1 = sound_1; } +// Fast arctan2, returns angle in radians as integer, with fractional part in lower 16 bits +// Stolen from http://www.dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization , precision is said to be 0.07 rads + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif enum { atan2i_coeff_1 = ((int)(M_PI*65536.0/4)), atan2i_coeff_2 = (3*atan2i_coeff_1), atan2i_PI = (int)(M_PI * 65536.0), SHIP_DIRECTIONS = 16 }; -// Fast arctan2, returns angle in radians as integer, with fractional part in lower 16 bits -// Stolen from http://www.dspguru.com/dsp/tricks/fixed-point-atan2-with-self-normalization , precision is said to be 0.07 rads inline int atan2i(int y, int x) { int angle; @@ -468,7 +469,7 @@ ControlInputToBattleInput (const int *keyState, int direction) if (keyState[KEY_DOWN]) InputState |= BATTLE_DOWN; - if(direction < 0) + if(direction < 0 || VControl_GetJoysticksAmount() == 0) { if (keyState[KEY_UP]) InputState |= BATTLE_THRUST; @@ -503,7 +504,7 @@ ControlInputToBattleInput (const int *keyState, int direction) if( diff > SHIP_DIRECTIONS / 2 ) InputState |= BATTLE_RIGHT; - if( axisX*axisX + axisY*axisY > 16384*16384 ) // Force of joystick tilt + if( axisX*axisX - 16384*16384 > axisY*axisY ) // Force of joystick tilt, equation is clumsy because (axisX*axisX + axisY*axisY) may overflow int32 InputState |= BATTLE_THRUST; } }