🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

SDL2 Android accelerometer

Started by
0 comments, last by sergamer1 7 years, 7 months ago

Hi everyone,

So, I've been writing my own little SDL2/Open GL ES 2 engine/framework for a while now and making some good encouraging progress, particularly getting it to work on Android (via NDK) with touch support. However, accessing the accelerometer is proving to be a bit of a show-stopper so was hoping someone with similar experiences can help me out. The SDL2 'wishlist' suggests implementing official accelerometer support in the future leaving only workarounds and hacks for the moment it seems. I've looked around on google and there are two solutions :

1) Set the SDL_HINT_ACCELEROMETER_AS_JOYSTICK hint and then access Joystick number 0 as the x/y values of the accelerometer. Compiles but does nothing. The SDL2 wiki only directly mentions supporting this feature in iOS and NOT Android so perhaps it shouldn't even work?

2) Try to access the Accelerometer values directly using the Android_JNI_GetAccelerometerValues function. However, I can't get this to compile since it complains with repeated definitions (no compile guards??) when including the required header (SDL2/src/core/android/SDL_android.h). I tried hacking it myself but not to no avail.

Maybe there's something special/extra-hacky that needs to be done to get one of these to work, or perhaps someone knows a third 'better' way?? If you know one of these really should work and need me to post extra stuff (some compiler errors) then I can do so. Thanks in advance for your help.

Advertisement

ok, more than a 1000 views (apparently) and no replies so guess I'm out of luck! :-/

No worries, I'll maybe post on the SDL forum and hope someone can help me there (surely right? :-) ). But if someone reads this late and can help, I would still appreciate the advice.

Thanks anyway!

This topic is closed to new replies.

Advertisement