2013-09-10 17:41:06 +08:00
|
|
|
#ifndef _PHYSICS_TEST_H_
|
|
|
|
#define _PHYSICS_TEST_H_
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "../testBasic.h"
|
2013-09-29 15:09:53 +08:00
|
|
|
#include "../BaseTest.h"
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2013-10-28 11:08:41 +08:00
|
|
|
#include <map>
|
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
class PhysicsTestScene : public TestScene
|
|
|
|
{
|
|
|
|
public:
|
2013-11-21 10:48:21 +08:00
|
|
|
PhysicsTestScene();
|
2013-11-18 03:43:32 +08:00
|
|
|
|
|
|
|
public:
|
2013-09-30 20:43:19 +08:00
|
|
|
virtual void runThisTest();
|
2013-10-09 17:53:12 +08:00
|
|
|
|
|
|
|
void toggleDebug();
|
|
|
|
|
|
|
|
private:
|
2013-11-18 20:42:10 +08:00
|
|
|
bool _debugDraw;
|
2013-09-30 20:43:19 +08:00
|
|
|
};
|
|
|
|
|
2013-12-27 15:49:08 +08:00
|
|
|
#if CC_USE_PHYSICS == 0
|
2013-11-21 10:48:21 +08:00
|
|
|
class PhysicsDemoDisabled : public BaseTest
|
|
|
|
{
|
|
|
|
public:
|
2013-12-30 14:42:41 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoDisabled);
|
|
|
|
|
2013-11-21 10:48:21 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
class PhysicsDemo : public BaseTest
|
2013-09-10 17:41:06 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemo);
|
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
PhysicsDemo();
|
|
|
|
virtual ~PhysicsDemo();
|
|
|
|
|
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;
|
|
|
|
virtual std::string subtitle() const override;
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void restartCallback(Ref* sender);
|
|
|
|
void nextCallback(Ref* sender);
|
|
|
|
void backCallback(Ref* sender);
|
|
|
|
void toggleDebugCallback(Ref* sender);
|
2013-10-09 17:53:12 +08:00
|
|
|
|
2014-04-15 18:23:40 +08:00
|
|
|
Sprite* addGrossiniAtPosition(Vector2 p, float scale = 1.0);
|
|
|
|
Sprite* makeBall(Vector2 point, float radius, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
Sprite* makeBox(Vector2 point, Size size, int color = 0, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
Sprite* makeTriangle(Vector2 point, Size size, int color = 0, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
2013-10-09 17:53:12 +08:00
|
|
|
|
2013-10-30 17:27:09 +08:00
|
|
|
bool onTouchBegan(Touch* touch, Event* event);
|
|
|
|
void onTouchMoved(Touch* touch, Event* event);
|
|
|
|
void onTouchEnded(Touch* touch, Event* event);
|
2013-10-23 17:28:23 +08:00
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
protected:
|
2013-11-13 11:22:34 +08:00
|
|
|
PhysicsTestScene* _scene;
|
2013-10-09 17:53:12 +08:00
|
|
|
Texture2D* _spriteTexture; // weak ref
|
2013-10-22 18:00:24 +08:00
|
|
|
SpriteBatchNode* _ball;
|
2013-11-22 05:43:59 +08:00
|
|
|
std::unordered_map<int, Node*> _mouses;
|
2013-09-29 15:09:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoClickAdd : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoClickAdd);
|
|
|
|
|
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
|
|
|
|
2013-10-12 14:02:01 +08:00
|
|
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
|
|
|
void onAcceleration(Acceleration* acc, Event* event);
|
2013-09-29 15:09:53 +08:00
|
|
|
};
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
class PhysicsDemoLogoSmash : public PhysicsDemo
|
2013-09-10 17:41:06 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoLogoSmash);
|
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-09 17:53:12 +08:00
|
|
|
};
|
|
|
|
|
2013-11-08 14:25:03 +08:00
|
|
|
class PhysicsDemoPyramidStack : public PhysicsDemo
|
2013-10-09 17:53:12 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-11-19 03:07:15 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoPyramidStack);
|
2013-11-14 07:55:36 +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:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoRayCast);
|
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
PhysicsDemoRayCast();
|
2013-11-14 07:55:36 +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;
|
2013-10-24 17:46:13 +08:00
|
|
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
2013-10-22 18:00:24 +08:00
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void changeModeCallback(Ref* sender);
|
2013-10-22 18:00:24 +08:00
|
|
|
|
2013-11-07 16:23:50 +08:00
|
|
|
bool anyRay(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data);
|
2013-10-22 18:00:24 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
float _angle;
|
|
|
|
DrawNode* _node;
|
|
|
|
int _mode;
|
|
|
|
};
|
|
|
|
|
2013-10-23 10:11:08 +08:00
|
|
|
class PhysicsDemoJoints : public PhysicsDemo
|
|
|
|
{
|
2013-10-23 17:28:23 +08:00
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoJoints);
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoActions : public PhysicsDemo
|
|
|
|
{
|
2013-10-23 10:11:08 +08:00
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoActions);
|
|
|
|
|
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:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoPump);
|
|
|
|
|
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
|
|
|
|
2013-10-30 17:27:09 +08:00
|
|
|
bool onTouchBegan(Touch* touch, Event* event);
|
|
|
|
void onTouchMoved(Touch* touch, Event* event);
|
|
|
|
void onTouchEnded(Touch* touch, 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:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoOneWayPlatform);
|
|
|
|
|
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
|
|
|
|
2014-01-28 14:59:34 +08:00
|
|
|
bool onContactBegin(PhysicsContact& contact);
|
2013-10-30 15:53:58 +08:00
|
|
|
};
|
|
|
|
|
2013-11-05 15:54:33 +08:00
|
|
|
class PhysicsDemoSlice : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoSlice);
|
|
|
|
|
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
|
|
|
|
2013-11-07 16:23:50 +08:00
|
|
|
bool slice(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data);
|
2014-04-15 18:23:40 +08:00
|
|
|
void clipPoly(PhysicsShapePolygon* shape, Vector2 normal, float distance);
|
2013-11-05 15:54:33 +08:00
|
|
|
|
|
|
|
void onTouchEnded(Touch *touch, Event *event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int _sliceTag;
|
|
|
|
};
|
|
|
|
|
2014-02-12 15:57:02 +08:00
|
|
|
class PhysicsDemoBug3988 : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsDemoBug3988);
|
|
|
|
|
|
|
|
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:
|
|
|
|
CREATE_FUNC(PhysicsContactTest);
|
|
|
|
|
|
|
|
void onEnter() override;
|
2014-02-27 13:35:37 +08:00
|
|
|
void resetTest();
|
2014-02-25 15:28:13 +08:00
|
|
|
bool onContactBegin(PhysicsContact& contact);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2014-02-27 13:35:37 +08:00
|
|
|
|
|
|
|
void onDecrease(Ref* sender);
|
|
|
|
void onIncrease(Ref* sender);
|
|
|
|
|
|
|
|
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:
|
|
|
|
CREATE_FUNC(PhysicsSetGravityEnableTest);
|
|
|
|
|
|
|
|
void onEnter() override;
|
|
|
|
void onScheduleOnce(float delta);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2014-02-12 15:57:02 +08:00
|
|
|
|
2013-09-10 17:41:06 +08:00
|
|
|
#endif
|
2013-11-21 10:48:21 +08:00
|
|
|
#endif
|