From 479355ee3282cd769ff4208412cad6c1bcbade09 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 19 Sep 2013 00:04:50 +0800 Subject: [PATCH] Unify Accelerometer coordinate on IOS and Android. --- cocos2dx/platform/android/nativeactivity.cpp | 12 ++++++------ .../AccelerometerTest/AccelerometerTest.cpp | 14 ++++++++------ .../Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters | 9 ++++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cocos2dx/platform/android/nativeactivity.cpp b/cocos2dx/platform/android/nativeactivity.cpp index da63f353de..63846f0ac3 100644 --- a/cocos2dx/platform/android/nativeactivity.cpp +++ b/cocos2dx/platform/android/nativeactivity.cpp @@ -598,9 +598,9 @@ void android_main(struct android_app* state) { // ACONFIGURATION_ORIENTATION_PORT // ACONFIGURATION_ORIENTATION_SQUARE cocos2d::Acceleration acc; - acc.x = event.acceleration.x; - acc.y = event.acceleration.y; - acc.z = event.acceleration.z; + acc.x = event.acceleration.x/10; + acc.y = -event.acceleration.y/10; + acc.z = event.acceleration.z/10; acc.timestamp = 0; cocos2d::AccelerationEvent accEvent(acc); @@ -609,9 +609,9 @@ void android_main(struct android_app* state) { // ACONFIGURATION_ORIENTATION_LAND // swap x and y parameters cocos2d::Acceleration acc; - acc.x = -event.acceleration.y; - acc.y = event.acceleration.x; - acc.z = event.acceleration.z; + acc.x = -event.acceleration.y/10; + acc.y = -event.acceleration.x/10; + acc.z = event.acceleration.z/10; acc.timestamp = 0; cocos2d::AccelerationEvent accEvent(acc); diff --git a/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.cpp b/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.cpp index 73f1854947..7fa2e58162 100644 --- a/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/AccelerometerTest/AccelerometerTest.cpp @@ -66,14 +66,16 @@ void AccelerometerTest::onAcceleration(Acceleration* acc, Event* event) auto ballSize = _ball->getContentSize(); - auto ptNow = _ball->getPosition(); + auto ptNow = _ball->getPosition(); + auto ptTemp = pDir->convertToUI(ptNow); - ptNow.x -= acc->x ; - ptNow.y -= acc->y ; + ptTemp.x -= acc->x * 9.81f; + ptTemp.y -= acc->y * 9.81f; - FIX_POS(ptNow.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0)); - FIX_POS(ptNow.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0)); - _ball->setPosition(ptNow); + auto ptNext = pDir->convertToGL(ptTemp); + FIX_POS(ptNext.x, (VisibleRect::left().x+ballSize.width / 2.0), (VisibleRect::right().x - ballSize.width / 2.0)); + FIX_POS(ptNext.y, (VisibleRect::bottom().y+ballSize.height / 2.0), (VisibleRect::top().y - ballSize.height / 2.0)); + _ball->setPosition(ptNext); } //------------------------------------------------------------------ diff --git a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters index d02707f9c4..2d24b00d42 100644 --- a/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters +++ b/samples/Cpp/TestCpp/proj.win32/TestCpp.vcxproj.filters @@ -242,7 +242,8 @@ {0b414789-7971-4a4c-86e3-40cc00936684} - {a83cb042-e3d6-4d3b-a4f6-30a4b3fcb3e9} + {a83cb042-e3d6-4d3b-a4f6-30a4b3fcb3e9} + {9daecd38-37c6-4216-a999-86077af83beb} @@ -631,7 +632,8 @@ Classes\NewEventDispatcherTest - Classes\PhysicsTest + Classes\PhysicsTest + Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest @@ -1203,7 +1205,8 @@ Classes\NewEventDispatcherTest - Classes\PhysicsTest + Classes\PhysicsTest + Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest