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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
|
|
|
@ -242,7 +242,8 @@
|
|||
<UniqueIdentifier>{0b414789-7971-4a4c-86e3-40cc00936684}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\PhysicsTest">
|
||||
<UniqueIdentifier>{a83cb042-e3d6-4d3b-a4f6-30a4b3fcb3e9}</UniqueIdentifier>
|
||||
<UniqueIdentifier>{a83cb042-e3d6-4d3b-a4f6-30a4b3fcb3e9}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Classes\ExtensionsTest\CocoStudioGUITest">
|
||||
<UniqueIdentifier>{9daecd38-37c6-4216-a999-86077af83beb}</UniqueIdentifier>
|
||||
</Filter>
|
||||
|
@ -631,7 +632,8 @@
|
|||
<Filter>Classes\NewEventDispatcherTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\PhysicsTest\PhysicsTest.cpp">
|
||||
<Filter>Classes\PhysicsTest</Filter>
|
||||
<Filter>Classes\PhysicsTest</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest\UIButtonTest.cpp">
|
||||
<Filter>Classes\ExtensionsTest\CocoStudioGUITest\UIButtonTest</Filter>
|
||||
</ClCompile>
|
||||
|
@ -1203,7 +1205,8 @@
|
|||
<Filter>Classes\NewEventDispatcherTest</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Classes\PhysicsTest\PhysicsTest.h">
|
||||
<Filter>Classes\PhysicsTest</Filter>
|
||||
<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