when to flip accelerometer axis

Anything libgdx related goes here!

when to flip accelerometer axis

Postby VBCoder68 » Sun Dec 25, 2011 5:43 pm

My game is in landscape mode. So, to make the accelerometer input work, I have to flip the axis (use x for y & y for x). This works for most cases. It works on my phone & tablet. But, I have a user that reports it doesn't work on his tablet. On his, the axis should not be flipped. How can I detect if I should flip the axis or not?

Thanks in advance,

Mike
VBCoder68
 
Posts: 17
Joined: Wed May 18, 2011 3:43 pm

Re: when to flip accelerometer axis

Postby Magnesus » Sun Dec 25, 2011 8:02 pm

I can only say that some games had inverted axis on Asus Transformer. Right now most is OK I think. I don't know if it was Transformer fault or Honeycomb issue or what. I would add an option to options so the user can invert it themselves just in case but probably someone knows a better way and will provide you a better answer soon. :)
Magnesus
 
Posts: 1124
Joined: Sun Sep 25, 2011 3:50 pm

Re: when to flip accelerometer axis

Postby mzechner » Mon Dec 26, 2011 7:50 pm

Libgdx will actually flip the axis automatically for you, see http://www.badlogicgames.com/wordpress/?p=2041
mzechner
Site Admin
 
Posts: 4721
Joined: Sat Jul 10, 2010 3:50 pm

Re: when to flip accelerometer axis

Postby Zwiebel » Mon Jan 16, 2012 3:42 pm

Hi!

In my opinion it is needed for the SuperJumper too. It is on every tablet Could you tell me please, how did you do it? Because there are some needed things to the method too. So, how I can return the angle in degrees with the getRotation() method, and how the getNativeOrientation() will return the native orientation? Thanks
Zwiebel
 
Posts: 71
Joined: Fri Aug 26, 2011 3:05 pm

Re: when to flip accelerometer axis

Postby robbycandra » Mon Apr 30, 2012 8:12 am

automatic flip axis - AccelerometerHandle For SuperJumper

public class AccelerometerHandler implements SensorEventListener {
private float accelX;
private float accelY;
private float accelZ;
private int deviceOrientation;
private Context mCtx;

public AccelerometerHandler(Context context) {
mCtx = context;
SensorManager manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
if (manager.getSensorList(Sensor.TYPE_ACCELEROMETER).size() != 0) {
Sensor accelerometer = manager.getSensorList(Sensor.TYPE_ACCELEROMETER).get(0);
manager.registerListener(this, accelerometer,SensorManager.SENSOR_DELAY_GAME);
}
deviceOrientation=(WindowManager)mCtx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getOrientation();
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// nothing to do here
}

@Override
public void onSensorChanged(SensorEvent event) {
boolean isLandscape = mCtx.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
if (isLandscape == false && deviceOrientation != Surface.ROTATION_0) {
accelX = event.values[1];
accelY = -event.values[0];
} else {
accelX = event.values[0];
accelY = event.values[1];
}
accelZ = event.values[2];
}

public float getAccelX() { return accelX; }
public float getAccelY() { return accelY; }
public float getAccelZ() { return accelZ; }
}
robbycandra
 
Posts: 7
Joined: Sun Apr 29, 2012 1:00 am


Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 9 guests