mirror of https://github.com/axmolengine/axmol.git
Merge pull request #710 from minggo/iss954_accerometer
correct accelerometer data when set orientation to portrait in tablet
This commit is contained in:
commit
3874450200
|
@ -79,8 +79,8 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, don't
|
||||
* need to translate coordinate.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, so should
|
||||
* consider this.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if ((orientation == Configuration.ORIENTATION_LANDSCAPE) && (mNaturalOrientation != Surface.ROTATION_0)){
|
||||
|
@ -88,6 +88,12 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
else if ((orientation == Configuration.ORIENTATION_PORTRAIT) && (mNaturalOrientation != Surface.ROTATION_0))
|
||||
{
|
||||
float tmp = x;
|
||||
x = y;
|
||||
y = -tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
|
|
|
@ -79,8 +79,8 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, don't
|
||||
* need to translate coordinate.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, so should
|
||||
* consider this.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if ((orientation == Configuration.ORIENTATION_LANDSCAPE) && (mNaturalOrientation != Surface.ROTATION_0)){
|
||||
|
@ -88,6 +88,12 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
else if ((orientation == Configuration.ORIENTATION_PORTRAIT) && (mNaturalOrientation != Surface.ROTATION_0))
|
||||
{
|
||||
float tmp = x;
|
||||
x = y;
|
||||
y = -tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
|
|
|
@ -79,8 +79,8 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
/*
|
||||
* Because the axes are not swapped when the device's screen orientation changes.
|
||||
* So we should swap it here.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, don't
|
||||
* need to translate coordinate.
|
||||
* In tablets such as Motorola Xoom, the default orientation is landscape, so should
|
||||
* consider this.
|
||||
*/
|
||||
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||
if ((orientation == Configuration.ORIENTATION_LANDSCAPE) && (mNaturalOrientation != Surface.ROTATION_0)){
|
||||
|
@ -88,6 +88,12 @@ public class Cocos2dxAccelerometer implements SensorEventListener {
|
|||
x = -y;
|
||||
y = tmp;
|
||||
}
|
||||
else if ((orientation == Configuration.ORIENTATION_PORTRAIT) && (mNaturalOrientation != Surface.ROTATION_0))
|
||||
{
|
||||
float tmp = x;
|
||||
x = y;
|
||||
y = -tmp;
|
||||
}
|
||||
|
||||
onSensorChanged(x, y, z, event.timestamp);
|
||||
// Log.d(TAG, "x = " + event.values[0] + " y = " + event.values[1] + " z = " + event.values[2]);
|
||||
|
|
Loading…
Reference in New Issue