axmol/samples/Cpp/TestCpp/Classes/PhysicsTest/PhysicsTest.h

159 lines
3.7 KiB
C
Raw Normal View History

#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"
#include <map>
2013-09-29 15:09:53 +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-29 15:09:53 +08:00
class PhysicsDemo : public BaseTest
{
2013-09-29 15:09:53 +08:00
protected:
2013-10-09 17:53:12 +08:00
PhysicsTestScene* _scene;
public:
2013-09-29 15:09:53 +08:00
PhysicsDemo();
virtual ~PhysicsDemo();
virtual void onEnter() override;
virtual std::string title() override;
virtual std::string subtitle() override;
2013-09-29 15:09:53 +08:00
void restartCallback(Object* sender);
void nextCallback(Object* sender);
void backCallback(Object* sender);
void toggleDebugCallback(Object* sender);
2013-10-09 17:53:12 +08:00
Sprite* addGrossiniAtPosition(Point p, float scale = 1.0);
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
bool onTouchBegan(Touch* touch, Event* event);
void onTouchMoved(Touch* touch, Event* event);
void onTouchEnded(Touch* touch, Event* event);
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;
std::map<int, Node*> _mouses;
2013-09-29 15:09:53 +08:00
};
class PhysicsDemoClickAdd : public PhysicsDemo
{
public:
void onEnter() override;
std::string subtitle() override;
2013-09-29 15:09:53 +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
};
class PhysicsDemoLogoSmash : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
2013-10-09 17:53:12 +08:00
};
class PhysicsDemoPlink : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
};
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;
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);
bool anyRay(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data);
2013-10-22 18:00:24 +08:00
private:
float _angle;
DrawNode* _node;
int _mode;
};
class PhysicsDemoJoints : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
};
class PhysicsDemoActions : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
};
class PhysicsDemoPump : public PhysicsDemo
{
public:
void onEnter() override;
void update(float delta) override;
std::string title() override;
std::string subtitle() override;
bool onTouchBegan(Touch* touch, Event* event);
void onTouchMoved(Touch* touch, Event* event);
void onTouchEnded(Touch* touch, Event* event);
private:
float _distance;
float _rotationV;
};
2013-10-30 15:53:58 +08:00
class PhysicsDemoOneWayPlatform : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
bool onContactBegin(EventCustom* event, const PhysicsContact& contact);
2013-10-30 15:53:58 +08:00
};
class PhysicsDemoSlice : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
std::string subtitle() override;
bool slice(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data);
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;
};
#endif