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:
|
|
|
|
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
|
|
|
{
|
2013-09-29 15:09:53 +08:00
|
|
|
protected:
|
2013-10-09 17:53:12 +08:00
|
|
|
PhysicsTestScene* _scene;
|
2013-09-10 17:41:06 +08:00
|
|
|
|
|
|
|
public:
|
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-28 16:17:19 +08:00
|
|
|
Sprite* makeBall(float x, float y, float radius, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
Sprite* makeBox(float x, float y, Size size, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
|
|
|
Sprite* makeTriangle(float x, float y, Size size, PhysicsMaterial material = PHYSICSBODY_MATERIAL_DEFAULT);
|
2013-10-09 17:53:12 +08:00
|
|
|
|
2013-10-28 11:08:41 +08:00
|
|
|
bool onTouchBegan(Touch* touch, Event* event) override;
|
|
|
|
void onTouchMoved(Touch* touch, Event* event) override;
|
|
|
|
void onTouchEnded(Touch* touch, Event* event) override;
|
2013-10-23 17:28:23 +08:00
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
protected:
|
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-09-30 20:43:19 +08:00
|
|
|
void onEnter() override;
|
|
|
|
std::string subtitle() override;
|
2013-09-29 15:09:53 +08:00
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
|
|
|
void onAcceleration(Acceleration* acc, Event* event) override;
|
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-09-30 20:43:19 +08:00
|
|
|
void onEnter() override;
|
|
|
|
std::string title() override;
|
2013-10-09 17:53:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoPyramidStack : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void onEnter() override;
|
|
|
|
std::string title() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoPlink : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
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:
|
|
|
|
PhysicsDemoRayCast();
|
|
|
|
public:
|
|
|
|
void onEnter() override;
|
|
|
|
std::string title() override;
|
|
|
|
void update(float delta) override;
|
|
|
|
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event) override;
|
|
|
|
|
|
|
|
void changeModeCallback(Object* sender);
|
|
|
|
|
|
|
|
static bool anyRay(PhysicsWorld& world, PhysicsShape& shape, Point point, Point normal, float fraction, void* data);
|
|
|
|
|
|
|
|
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:
|
|
|
|
PhysicsDemoJoints();
|
|
|
|
|
2013-10-23 10:11:08 +08:00
|
|
|
public:
|
|
|
|
void onEnter() override;
|
|
|
|
std::string title() override;
|
2013-10-23 17:28:23 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
PhysicsShape* _touchesShape;
|
2013-10-23 10:11:08 +08:00
|
|
|
};
|
|
|
|
|
2013-09-10 17:41:06 +08:00
|
|
|
#endif
|