From ff172e0057dfd87fc6344386757eebfc068c46f4 Mon Sep 17 00:00:00 2001 From: Dale Stammen Date: Thu, 20 Nov 2014 09:00:22 -0800 Subject: [PATCH] fixed accelerometer for windows store apps device orientation --- cocos/platform/winrt/CCDevice.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cocos/platform/winrt/CCDevice.cpp b/cocos/platform/winrt/CCDevice.cpp index e3f7edbde5..71a6ff303a 100644 --- a/cocos/platform/winrt/CCDevice.cpp +++ b/cocos/platform/winrt/CCDevice.cpp @@ -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 event(new AccelerometerEvent(acc)); cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(event); });