2015-09-08 09:54:01 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
#include "../BaseTest.h"
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
#if CC_USE_PHYSICS
|
2013-10-28 11:08:41 +08:00
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
DEFINE_TEST_SUITE(PhysicsTests);
|
2013-11-21 10:48:21 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
class PhysicsDemo : public TestCase
|
2013-09-10 17:41:06 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-29 15:09:53 +08:00
|
|
|
PhysicsDemo();
|
|
|
|
virtual ~PhysicsDemo();
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
virtual bool init() override;
|
2013-09-30 20:43:19 +08:00
|
|
|
virtual void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void toggleDebugCallback(cocos2d::Ref* sender);
|
2013-10-09 17:53:12 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Sprite* addGrossiniAtPosition(cocos2d::Vec2 p, float scale = 1.0);
|
|
|
|
cocos2d::Sprite* makeBall(cocos2d::Vec2 point, float radius, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
cocos2d::Sprite* makeBox(cocos2d::Vec2 point, cocos2d::Size size, int color = 0, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
cocos2d::Sprite* makeTriangle(cocos2d::Vec2 point, cocos2d::Size size, int color = 0, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
|
2013-10-09 17:53:12 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
|
|
|
|
void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
|
|
|
|
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
void toggleDebug();
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
protected:
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Texture2D* _spriteTexture;
|
|
|
|
cocos2d::SpriteBatchNode* _ball;
|
|
|
|
std::unordered_map<int, cocos2d::Node*> _mouses;
|
2015-04-03 14:31:03 +08:00
|
|
|
bool _debugDraw;
|
2013-09-29 15:09:53 +08:00
|
|
|
};
|
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
class PhysicsDemoLogoSmash : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsDemoLogoSmash);
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
};
|
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
class PhysicsDemoClickAdd : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoClickAdd);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-11-11 10:23:05 +08:00
|
|
|
virtual ~PhysicsDemoClickAdd();
|
2013-09-30 20:43:19 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string subtitle() const override;
|
2013-09-29 15:09:53 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
|
|
|
void onAcceleration(cocos2d::Acceleration* acc, cocos2d::Event* event);
|
2013-09-29 15:09:53 +08:00
|
|
|
};
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2013-11-08 14:25:03 +08:00
|
|
|
class PhysicsDemoPyramidStack : public PhysicsDemo
|
2013-10-09 17:53:12 +08:00
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoPyramidStack);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-10-09 17:53:12 +08:00
|
|
|
void onEnter() override;
|
2014-02-26 10:53:41 +08:00
|
|
|
void updateOnce(float delta);
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-09-10 17:41:06 +08:00
|
|
|
};
|
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
class PhysicsDemoRayCast : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoRayCast);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
PhysicsDemoRayCast();
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-22 18:00:24 +08:00
|
|
|
void update(float delta) override;
|
2015-04-09 08:37:30 +08:00
|
|
|
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
2013-10-22 18:00:24 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void changeModeCallback(cocos2d::Ref* sender);
|
2013-10-22 18:00:24 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
bool anyRay(cocos2d::PhysicsWorld& world, const cocos2d::PhysicsRayCastInfo& info, void* data);
|
2013-10-22 18:00:24 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
float _angle;
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::DrawNode* _node;
|
2013-10-22 18:00:24 +08:00
|
|
|
int _mode;
|
|
|
|
};
|
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
class PhysicsDemoActions : public PhysicsDemo
|
2013-10-23 10:11:08 +08:00
|
|
|
{
|
2013-10-23 17:28:23 +08:00
|
|
|
public:
|
2015-09-08 09:54:01 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoActions);
|
|
|
|
|
2013-10-29 17:31:35 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-29 17:31:35 +08:00
|
|
|
};
|
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
class PhysicsDemoJoints : public PhysicsDemo
|
2013-10-29 17:31:35 +08:00
|
|
|
{
|
2013-10-23 10:11:08 +08:00
|
|
|
public:
|
2015-09-08 09:54:01 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoJoints);
|
|
|
|
|
2013-10-23 10:11:08 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-29 17:31:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoPump : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoPump);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-10-29 17:31:35 +08:00
|
|
|
void onEnter() override;
|
|
|
|
void update(float delta) override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2013-10-29 17:31:35 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
|
|
|
|
void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
|
|
|
|
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
|
2013-10-23 17:28:23 +08:00
|
|
|
|
|
|
|
private:
|
2013-10-29 17:31:35 +08:00
|
|
|
float _distance;
|
|
|
|
float _rotationV;
|
2013-10-23 10:11:08 +08:00
|
|
|
};
|
|
|
|
|
2013-10-30 15:53:58 +08:00
|
|
|
class PhysicsDemoOneWayPlatform : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoOneWayPlatform);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-10-30 15:53:58 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-11-01 14:50:06 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
bool onContactBegin(cocos2d::PhysicsContact& contact);
|
2013-10-30 15:53:58 +08:00
|
|
|
};
|
|
|
|
|
2013-11-05 15:54:33 +08:00
|
|
|
class PhysicsDemoSlice : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoSlice);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2013-11-05 15:54:33 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2013-11-05 15:54:33 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
bool slice(cocos2d::PhysicsWorld& world, const cocos2d::PhysicsRayCastInfo& info, void* data);
|
|
|
|
void clipPoly(cocos2d::PhysicsShapePolygon* shape, cocos2d::Vec2 normal, float distance);
|
2013-11-05 15:54:33 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
|
2013-11-05 15:54:33 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
int _sliceTag;
|
|
|
|
};
|
|
|
|
|
2014-02-12 15:57:02 +08:00
|
|
|
class PhysicsDemoBug3988 : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoBug3988);
|
2015-09-08 09:54:01 +08:00
|
|
|
|
2014-02-12 15:57:02 +08:00
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2014-02-25 15:28:13 +08:00
|
|
|
class PhysicsContactTest : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsContactTest);
|
2014-02-25 15:28:13 +08:00
|
|
|
|
|
|
|
void onEnter() override;
|
2014-02-27 13:35:37 +08:00
|
|
|
void resetTest();
|
2015-04-09 08:37:30 +08:00
|
|
|
bool onContactBegin(cocos2d::PhysicsContact& contact);
|
2014-02-25 15:28:13 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2014-02-27 13:35:37 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void onDecrease(cocos2d::Ref* sender);
|
|
|
|
void onIncrease(cocos2d::Ref* sender);
|
2014-02-27 13:35:37 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
int _yellowBoxNum;
|
|
|
|
int _blueBoxNum;
|
|
|
|
int _yellowTriangleNum;
|
|
|
|
int _blueTriangleNum;
|
2014-02-25 15:28:13 +08:00
|
|
|
};
|
|
|
|
|
2014-02-28 15:47:49 +08:00
|
|
|
class PhysicsPositionRotationTest : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsPositionRotationTest);
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
};
|
|
|
|
|
2014-03-18 16:17:43 +08:00
|
|
|
class PhysicsSetGravityEnableTest : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsSetGravityEnableTest);
|
2014-03-18 16:17:43 +08:00
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
void onScheduleOnce(float delta);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
class PhysicsDemoBug5482 : public PhysicsDemo
|
2014-06-04 11:59:15 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-09-08 09:54:01 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoBug5482);
|
2014-06-04 11:59:15 +08:00
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
void onExit() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
void changeBodyCallback(cocos2d::Ref* sender);
|
2014-06-04 11:59:15 +08:00
|
|
|
private:
|
2015-04-09 08:37:30 +08:00
|
|
|
cocos2d::Sprite* _nodeA;
|
|
|
|
cocos2d::Sprite* _nodeB;
|
|
|
|
cocos2d::PhysicsBody* _body;
|
|
|
|
cocos2d::MenuItemFont* _button;
|
2014-06-04 11:59:15 +08:00
|
|
|
bool _bodyInA;
|
|
|
|
};
|
|
|
|
|
2014-06-12 12:57:29 +08:00
|
|
|
class PhysicsFixedUpdate : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsFixedUpdate);
|
|
|
|
void onEnter() override;
|
|
|
|
void updateStart(float delta);
|
|
|
|
void addBall();
|
|
|
|
virtual void update(float delta) override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2014-06-27 17:30:50 +08:00
|
|
|
class PhysicsTransformTest : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsTransformTest);
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
|
2014-06-27 17:30:50 +08:00
|
|
|
|
2015-04-10 15:39:39 +08:00
|
|
|
private:
|
|
|
|
cocos2d::Sprite* _parentSprite;
|
|
|
|
cocos2d::Layer* _rootLayer;
|
2014-06-27 17:30:50 +08:00
|
|
|
};
|
2015-01-28 10:20:30 +08:00
|
|
|
|
|
|
|
class PhysicsIssue9959 : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsIssue9959);
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
#endif // #if CC_USE_PHYSICS
|