fixed accelerometer for windows store apps device orientation

This commit is contained in:
Dale Stammen 2014-11-20 09:00:22 -08:00
parent 634fb98a5d
commit ff172e0057
1 changed files with 30 additions and 0 deletions

View File

@ -100,6 +100,7 @@ void Device::setAccelerometerEnabled(bool isEnabled)
auto orientation = GLViewImpl::sharedOpenGLView()->getDeviceOrientation();
#if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
switch (orientation)
{
case DisplayOrientations::Portrait:
@ -127,7 +128,36 @@ void Device::setAccelerometerEnabled(bool isEnabled)
acc.y = reading->AccelerationY;
break;
}
#else // Windows Store App
// from http://msdn.microsoft.com/en-us/library/windows/apps/dn440593
switch (orientation)
{
case DisplayOrientations::Portrait:
acc.x = reading->AccelerationY;
acc.y = -reading->AccelerationX;
break;
case DisplayOrientations::Landscape:
acc.x = reading->AccelerationX;
acc.y = reading->AccelerationY;
break;
case DisplayOrientations::PortraitFlipped:
acc.x = -reading->AccelerationY;
acc.y = reading->AccelerationX;
break;
case DisplayOrientations::LandscapeFlipped:
acc.x = -reading->AccelerationY;
acc.y = reading->AccelerationX;
break;
default:
acc.x = reading->AccelerationY;
acc.y = -reading->AccelerationX;
break;
}
#endif
std::shared_ptr<cocos2d::InputEvent> event(new AccelerometerEvent(acc));
cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(event);
});