Gyroscope support

This commit is contained in:
pelya
2013-02-01 19:16:25 +02:00
parent 45128c67b4
commit a12c6ada8d
12 changed files with 86 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ CompatibilityHacksStaticInit=n
CompatibilityHacksTextInputEmulatesHwKeyboard=n
CompatibilityHacksPreventAudioChopping=n
CompatibilityHacksAppIgnoresAudioBufferSize=n
CompatibilityHacksAdditionalPreloadedSharedLibraries=""
AppUsesMouse=y
AppNeedsTwoButtonMouse=y
ShowMouseCursor=n
@@ -26,6 +27,7 @@ AppNeedsArrowKeys=y
AppNeedsTextInput=y
AppUsesJoystick=y
AppUsesAccelerometer=y
AppUsesGyroscope=y
AppUsesMultitouch=y
NonBlockingSwapBuffers=n
RedefinedKeys="SPACE RETURN NO_REMAP NO_REMAP SPACE ESCAPE"
@@ -45,7 +47,9 @@ CompiledLibraries="sdl_mixer sdl_image"
CustomBuildScript=n
AppCflags='-O2 -finline-functions'
AppLdflags=''
AppOverlapsSystemHeaders=
AppSubdirsBuild=''
AppBuildExclude=''
AppCmdline=''
ReadmeText='^Readme text'
MinimumScreenSize=s

View File

@@ -437,7 +437,7 @@ int main(int argc, char* argv[])
// some random colors
int colors[MAX_POINTERS] = { 0xaaaaaa, 0xffffff, 0x888888, 0xcccccc, 0x666666, 0x999999, 0xdddddd, 0xeeeeee, 0xaaaaaa, 0xffffff, 0x888888, 0xcccccc, 0x666666, 0x999999, 0xdddddd, 0xeeeeee };
struct TouchPointer_t { int x; int y; int pressure; int pressed; } touchPointers[MAX_POINTERS];
int accel[2], screenjoy[4], gamepads[4][8];
int accel[5], screenjoy[4], gamepads[4][8];
SDL_Surface *mouse[4];
int screenKeyboardShown = 0;
@@ -601,6 +601,7 @@ int main(int argc, char* argv[])
}
int joyInput[][3] = {
{accel[0], accel[1], 10},
{accel[2], accel[3], 10 + abs(accel[4]) * 100 / 32767},
{screenjoy[0], screenjoy[1], 10},
{screenjoy[2], screenjoy[3], 10},
{gamepads[0][0], gamepads[0][1], 10 + gamepads[0][4] * 100 / 32767},
@@ -674,7 +675,7 @@ int main(int argc, char* argv[])
}
if(evt.jaxis.which == 1)
{
accel[evt.jaxis.axis] = evt.jaxis.value;
accel[evt.jaxis.axis] = evt.jaxis.value; // accelerometer and gyroscope
}
if(evt.jaxis.which >= 2)
{

View File

@@ -1,3 +1,3 @@
#!/bin/sh
adb shell rm /sdcard/Android/data/ws.openarena.sdl/files/libsdl-DownloadFinished-10.flag
adb shell rm -r /sdcard/Android/data/ws.openarena.sdl/files/.openarena
[ -n "$1" ] && adb shell rm -r /sdcard/Android/data/ws.openarena.sdl/files/.openarena

View File

@@ -864,14 +864,27 @@ JAVA_EXPORT_NAME(AccelerometerReader_nativeAccelerometer) ( JNIEnv* env, jobjec
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(AccelerometerReader_nativeOrientation) ( JNIEnv* env, jobject thiz, jfloat accX, jfloat accY, jfloat accZ )
JAVA_EXPORT_NAME(AccelerometerReader_nativeGyroscope) ( JNIEnv* env, jobject thiz, jfloat X, jfloat Y, jfloat Z )
{
#if SDL_VERSION_ATLEAST(1,3,0)
#else
if( !SDL_CurrentVideoSurface )
return;
#endif
updateOrientation (accX, accY, accZ); // TODO: make values in range 0.0:1.0
while ( X != 0.0f || Y != 0.0f || Z != 0.0f )
{
float dx = ( X >= 1.0f ? 1.0f : ( X <= -1.0f ? -1.0f : X ) );
float dy = ( Y >= 1.0f ? 1.0f : ( Y <= -1.0f ? -1.0f : Y ) );
float dz = ( Z >= 1.0f ? 1.0f : ( Z <= -1.0f ? -1.0f : Z ) );
X -= dx;
Y -= dy;
Z -= dz;
SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 2, NORMALIZE_FLOAT_32767(dx));
SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 3, NORMALIZE_FLOAT_32767(dy));
SDL_ANDROID_MainThreadPushJoystickAxis(JOY_ACCELGYRO, 4, NORMALIZE_FLOAT_32767(dz));
}
}
JNIEXPORT void JNICALL
@@ -1434,7 +1447,8 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
}
if( joystick->index == JOY_ACCELGYRO )
{
joystick->naxes = 2; // Accelerometer/gyroscope angles
joystick->naxes = 5; // Accelerometer = axes 0-1, gyroscope = axes 2-4
SDL_ANDROID_CallJavaStartAccelerometerGyroscope(1);
}
if( joystick->index >= JOY_GAMEPAD1 || joystick->index <= JOY_GAMEPAD4 )
{
@@ -1453,6 +1467,8 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
{
SDL_ANDROID_CurrentJoysticks[joystick->index] = NULL;
if( joystick->index == JOY_ACCELGYRO )
SDL_ANDROID_CallJavaStartAccelerometerGyroscope(0);
return;
}

View File

@@ -65,6 +65,7 @@ static jmethodID JavaShowScreenKeyboard = NULL;
static jmethodID JavaToggleScreenKeyboardWithoutTextInput = NULL;
static jmethodID JavaHideScreenKeyboard = NULL;
static jmethodID JavaIsScreenKeyboardShown = NULL;
static jmethodID JavaStartAccelerometerGyroscope = NULL;
static jmethodID JavaGetAdvertisementParams = NULL;
static jmethodID JavaSetAdvertisementVisible = NULL;
static jmethodID JavaSetAdvertisementPosition = NULL;
@@ -297,6 +298,11 @@ int SDL_ANDROID_IsScreenKeyboardShown()
return SDL_ANDROID_IsScreenKeyboardShownFlag;
}
void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start)
{
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaStartAccelerometerGyroscope, (jint) start );
}
JNIEXPORT void JNICALL
JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject thiz )
{
@@ -309,7 +315,8 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t
JavaToggleScreenKeyboardWithoutTextInput = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "showScreenKeyboardWithoutTextInputField", "()V");
JavaHideScreenKeyboard = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "hideScreenKeyboard", "()V");
JavaIsScreenKeyboardShown = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "isScreenKeyboardShown", "()I");
// TODO: implement it
JavaStartAccelerometerGyroscope = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "startAccelerometerGyroscope", "(I)V");
JavaGetAdvertisementParams = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "getAdvertisementParams", "([I)V");
JavaSetAdvertisementVisible = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setAdvertisementVisible", "(I)V");
JavaSetAdvertisementPosition = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setAdvertisementPosition", "(II)V");

View File

@@ -72,7 +72,7 @@ extern void SDL_ANDROID_WarpMouse(int x, int y);
extern void SDL_ANDROID_DrawMouseCursor(int x, int y, int size, int alpha);
extern void SDL_ANDROID_DrawMouseCursorIfNeeded();
extern void SDL_ANDROID_CallJavaTogglePlainAndroidSoftKeyboardInput();
extern void SDL_ANDROID_CallJavaStartAccelerometerGyroscope(int start);
#if SDL_VERSION_ATLEAST(1,3,0)
extern SDL_Window * ANDROID_CurrentWindow;