From ea6edd54175424291ba8dae7fac03082b0220083 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Tue, 11 Feb 2014 17:10:27 +0800 Subject: [PATCH 1/3] closed #3988: fix bug Node::setRotation() moves opposite when node has a physics body. --- cocos/physics/CCPhysicsBody.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/physics/CCPhysicsBody.cpp b/cocos/physics/CCPhysicsBody.cpp index 240f9833ba..dc959f0600 100644 --- a/cocos/physics/CCPhysicsBody.cpp +++ b/cocos/physics/CCPhysicsBody.cpp @@ -345,7 +345,7 @@ void PhysicsBody::setPosition(Point position) void PhysicsBody::setRotation(float rotation) { - cpBodySetAngle(_info->getBody(), PhysicsHelper::float2cpfloat(rotation * M_PI / 180.0f)); + cpBodySetAngle(_info->getBody(), -PhysicsHelper::float2cpfloat(rotation * M_PI / 180.0f)); } Point PhysicsBody::getPosition() const From 4fda8a26355d52a9bbd44dadc01d2c14ad2cd697 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Wed, 12 Feb 2014 15:57:02 +0800 Subject: [PATCH 2/3] closed #3988: add bug test --- .../Classes/PhysicsTest/PhysicsTest.cpp | 28 +++++++++++++++++++ .../Classes/PhysicsTest/PhysicsTest.h | 11 ++++++++ 2 files changed, 39 insertions(+) diff --git a/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp b/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp index 3fc4732efc..cac660e581 100644 --- a/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -16,6 +16,7 @@ namespace CL(PhysicsDemoPump), CL(PhysicsDemoOneWayPlatform), CL(PhysicsDemoSlice), + CL(PhysicsDemoBug3988), #else CL(PhysicsDemoDisabled), #endif @@ -1219,4 +1220,31 @@ std::string PhysicsDemoSlice::subtitle() const return "click and drag to slice up the block"; } + +void PhysicsDemoBug3988::onEnter() +{ + PhysicsDemo::onEnter(); + _scene->toggleDebug(); + _scene->getPhysicsWorld()->setGravity(Vect::ZERO); + + auto ball = Sprite::create("Images/YellowSquare.png"); + ball->setPosition(VisibleRect::center() - Point(100, 0)); + ball->setRotation(30.0f); + this->addChild(ball); + + auto physicsBall = makeBox(VisibleRect::center() + Point(100, 0), Size(100, 100)); + physicsBall->setRotation(30.0f); + this->addChild(physicsBall); +} + +std::string PhysicsDemoBug3988::title() const +{ + return "Bug3988"; +} + +std::string PhysicsDemoBug3988::subtitle() const +{ + return "All the Rectangles should have same rotation angle"; +} + #endif // ifndef CC_USE_PHYSICS diff --git a/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.h b/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.h index 9e9e69f96e..31f3e6fbdb 100644 --- a/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.h +++ b/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.h @@ -184,5 +184,16 @@ private: int _sliceTag; }; +class PhysicsDemoBug3988 : public PhysicsDemo +{ +public: + CREATE_FUNC(PhysicsDemoBug3988); + + void onEnter() override; + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + + #endif #endif From e7c077bb1601d2ed6e2ba70f44cfad521e05d545 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Wed, 12 Feb 2014 16:21:26 +0800 Subject: [PATCH 3/3] closed #3988: fix indent. --- tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp b/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp index cac660e581..45392a3ce9 100644 --- a/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp +++ b/tests/test-cpp/Classes/PhysicsTest/PhysicsTest.cpp @@ -16,7 +16,7 @@ namespace CL(PhysicsDemoPump), CL(PhysicsDemoOneWayPlatform), CL(PhysicsDemoSlice), - CL(PhysicsDemoBug3988), + CL(PhysicsDemoBug3988), #else CL(PhysicsDemoDisabled), #endif