fixed #643, swap accelerometer input x/y according to the orientation (on ios devices)

This commit is contained in:
Walzer 2011-08-17 20:11:33 +08:00
parent a8835649fe
commit 4244fdb62b
1 changed files with 23 additions and 0 deletions

View File

@ -84,6 +84,29 @@ static AccelerometerDispatcher* s_pAccelerometerDispatcher;
accelerationCpp.z = acceleration.z;
accelerationCpp.timestamp = acceleration.timestamp;
double tmp = accelerationCpp.x;
switch ([[UIApplication sharedApplication] statusBarOrientation])
{
case UIInterfaceOrientationLandscapeRight:
accelerationCpp.x = -acceleration.y;
accelerationCpp.y = tmp;
break;
case UIInterfaceOrientationLandscapeLeft:
accelerationCpp.x = acceleration.y;
accelerationCpp.y = -tmp;
break;
case UIInterfaceOrientationPortraitUpsideDown:
accelerationCpp.x = -accelerationCpp.y;
accelerationCpp.y = -tmp;
break;
case UIInterfaceOrientationPortrait:
break;
}
for (AccelerometerDelegateWrapper *wrapper in delegateWrappers) {
[wrapper didAccelerate: &accelerationCpp];
}