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-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsTestScene);
|
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
virtual bool initTest() override;
|
|
|
|
virtual void runThisTest();
|
2013-10-09 17:53:12 +08:00
|
|
|
|
|
|
|
void toggleDebug();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool _debugDraw;
|
2013-09-30 20:43:19 +08:00
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
virtual std::string title() override;
|
|
|
|
virtual std::string subtitle() override;
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
void restartCallback(Object* sender);
|
|
|
|
void nextCallback(Object* sender);
|
|
|
|
void backCallback(Object* sender);
|
2013-09-16 21:22:22 +08:00
|
|
|
void toggleDebugCallback(Object* sender);
|
2013-10-09 17:53:12 +08:00
|
|
|
|
2013-10-28 11:08:41 +08:00
|
|
|
Sprite* addGrossiniAtPosition(Point p, float scale = 1.0);
|
2013-10-29 17:31:35 +08:00
|
|
|
Sprite* makeBall(Point point, float radius, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
Sprite* makeBox(Point point, Size size, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
Sprite* makeTriangle(Point point, Size size, 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-14 07:55:36 +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-10-28 11:08:41 +08:00
|
|
|
std::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;
|
|
|
|
std::string subtitle() 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;
|
|
|
|
std::string title() override;
|
2013-10-09 17:53:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoPlink : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2013-11-14 07:55:36 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoPlink);
|
|
|
|
|
2013-10-09 17:53:12 +08:00
|
|
|
void onEnter() override;
|
|
|
|
std::string title() 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;
|
|
|
|
std::string title() override;
|
|
|
|
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
|
|
|
|
|
|
|
void changeModeCallback(Object* sender);
|
|
|
|
|
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;
|
|
|
|
std::string title() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
std::string title() 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-11-07 17:53:30 +08:00
|
|
|
std::string title() override;
|
|
|
|
std::string subtitle() 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;
|
|
|
|
std::string title() override;
|
2013-11-01 14:50:06 +08:00
|
|
|
|
2013-11-04 14:36:38 +08:00
|
|
|
bool onContactBegin(EventCustom* event, const 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;
|
|
|
|
std::string title() override;
|
|
|
|
std::string subtitle() override;
|
|
|
|
|
2013-11-07 16:23:50 +08:00
|
|
|
bool slice(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data);
|
2013-11-05 15:54:33 +08:00
|
|
|
void clipPoly(PhysicsShapePolygon* shape, Point normal, float distance);
|
|
|
|
|
|
|
|
bool onTouchBegan(Touch *touch, Event *event);
|
|
|
|
void onTouchMoved(Touch *touch, Event *event);
|
|
|
|
void onTouchEnded(Touch *touch, Event *event);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int _sliceTag;
|
|
|
|
};
|
|
|
|
|
2013-09-10 17:41:06 +08:00
|
|
|
#endif
|