mirror of https://github.com/axmolengine/axmol.git
Unify Accelerometer coordinate on IOS and Android.
This commit is contained in:
parent
ba47e666c1
commit
479355ee32
|
@ -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);
|
||||
|
||||
|
|
|
@ -67,13 +67,15 @@ void AccelerometerTest::onAcceleration(Acceleration* acc, Event* event)
|
|||
auto ballSize = _ball->getContentSize();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
|
|
@ -243,6 +243,7 @@
|
|||
</Filter>
|
||||
<Filter Include="Classes\PhysicsTest">
|
||||
<UniqueIdentifier>{a83cb042-e3d6-4d3b-a4f6-30a4b3fcb3e9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\ExtensionsTest\CocoStudioGUITest">
|
||||
<UniqueIdentifier>{9daecd38-37c6-4216-a999-86077af83beb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
|
@ -632,6 +633,7 @@
|
|||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\PhysicsTest\PhysicsTest.cpp">
|
||||
<Filter>Classes\PhysicsTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest\UIButtonTest.cpp">
|
||||
<Filter>Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1204,6 +1206,7 @@
|
|||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\PhysicsTest\PhysicsTest.h">
|
||||
<Filter>Classes\PhysicsTest</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest\UIButtonTest.h">
|
||||
<Filter>Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest</Filter>
|
||||
</ClInclude>
|
||||
|
|
Loading…
Reference in New Issue