Merge pull request #710 from minggo/iss954_accerometer

correct accelerometer data when set orientation to portrait in tablet
This commit is contained in:
minggo 2012-02-06 18:23:15 -08:00
commit 3874450200
3 changed files with 24 additions and 6 deletions

View File

@ -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]);

View File

@ -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]);

View File

@ -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]);