The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
android accelerometer
gerben


Joined: 12 Apr 2014
Posts: 1
Hey all, I've been toying around with porting an old game i wrote to sdl2 and android. Now I'm not sure about the java code in the sdl accelerometer, but it seems buggy. The code below

switch (mDisplay.getRotation()) {
case Surface.ROTATION_90:
x = -event.values[1];
y = event.values[0];
break;
case Surface.ROTATION_270:
x = event.values[1];
y = -event.values[0];
break;
case Surface.ROTATION_180:
x = -event.values[1]; // everything math seems to tell me this should [0]
y = -event.values[0]; // should be [1] ????
break;
default:
x = event.values[0];
y = event.values[1];
break;
}
SDLActivity.onNativeAccel(-x / SensorManager.GRAVITY_EARTH,
y / SensorManager.GRAVITY_EARTH,
event.values[2] / SensorManager.GRAVITY_EARTH - 1);
}

in the last line you subtract 1 from the z-axis. I figure you want to get rid of gravity. But under normal usage and the logic above the gravity axis is in the y direction. The way it now makes both the y-axis close to -1 and the z-axis. With the z-axis overflowing and thus flipping between -2^15 to +2^15 with small movements