Skip to content

Commit

Permalink
Also send raw accelerometer events, in addition to gravity vector
Browse files Browse the repository at this point in the history
  • Loading branch information
pelya committed Mar 19, 2013
1 parent 2393edc commit 014d8df
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion project/jni/application/openarena/AndroidAppSettings.cfg
Expand Up @@ -28,7 +28,7 @@ ForceRelativeMouseMode=n
AppNeedsArrowKeys=y AppNeedsArrowKeys=y
AppNeedsTextInput=y AppNeedsTextInput=y
AppUsesJoystick=y AppUsesJoystick=y
AppUsesAccelerometer=n AppUsesAccelerometer=y
AppUsesGyroscope=y AppUsesGyroscope=y
AppUsesMultitouch=y AppUsesMultitouch=y
AppRecordsAudio=y AppRecordsAudio=y
Expand Down
7 changes: 5 additions & 2 deletions project/jni/sdl-1.2/src/video/android/SDL_androidinput.c
Expand Up @@ -57,7 +57,7 @@ static inline SDL_scancode TranslateKey(int scancode)
static int isTrackballUsed = 0; static int isTrackballUsed = 0;
int SDL_ANDROID_isMouseUsed = 0; int SDL_ANDROID_isMouseUsed = 0;


#define NORMALIZE_FLOAT_32767(X) (fminf(32767.0f, fmax(-32767.0f, (X) * 32767.0f))) #define NORMALIZE_FLOAT_32767(X) (fminf(32767.0f, fmaxf(-32767.0f, (X) * 32767.0f)))


enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2, enum { RIGHT_CLICK_NONE = 0, RIGHT_CLICK_WITH_MULTITOUCH = 1, RIGHT_CLICK_WITH_PRESSURE = 2,
RIGHT_CLICK_WITH_KEY = 3, RIGHT_CLICK_WITH_TIMEOUT = 4 }; RIGHT_CLICK_WITH_KEY = 3, RIGHT_CLICK_WITH_TIMEOUT = 4 };
Expand Down Expand Up @@ -826,6 +826,9 @@ JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobjec
normal = 0.00001f; normal = 0.00001f;


updateOrientation (accPosX/normal, accPosY/normal, 0.0f); updateOrientation (accPosX/normal, accPosY/normal, 0.0f);
SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 5, fminf(32767.0f, fmaxf(-32767.0f, accPosX*1000.0f))); // Do not consider wraparound case
SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 6, fminf(32767.0f, fmaxf(-32767.0f, accPosY*1000.0f)));
SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 7, fminf(32767.0f, fmaxf(-32767.0f, accPosZ*1000.0f)));
} }




Expand Down Expand Up @@ -1417,7 +1420,7 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
} }
if( joystick->index == JOY_ACCELGYRO ) if( joystick->index == JOY_ACCELGYRO )
{ {
joystick->naxes = 5; // Accelerometer = axes 0-1, gyroscope = axes 2-4 joystick->naxes = 8; // Normalized accelerometer = axes 0-1, gyroscope = axes 2-4, raw accelerometer = axes 5-7
SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1); SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1);
} }
if( joystick->index >= JOY_GAMEPAD1 || joystick->index <= JOY_GAMEPAD4 ) if( joystick->index >= JOY_GAMEPAD1 || joystick->index <= JOY_GAMEPAD4 )
Expand Down

0 comments on commit 014d8df

Please sign in to comment.