axmol/tests/cpp-tests/Classes/PhysicsTest/PhysicsTest.h

242 lines
5.6 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:
PhysicsTestScene();
2013-11-18 03:43:32 +08:00
public:
virtual void runThisTest();
2013-10-09 17:53:12 +08:00
void toggleDebug();
private:
bool _debugDraw;
};
#if CC_USE_PHYSICS == 0
class PhysicsDemoDisabled : public BaseTest
{
public:
CREATE_FUNC(PhysicsDemoDisabled);
virtual void onEnter() override;
};
#else
2013-09-29 15:09:53 +08:00
class PhysicsDemo : public BaseTest
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemo);
2013-09-29 15:09:53 +08:00
PhysicsDemo();
virtual ~PhysicsDemo();
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void restartCallback(Ref* sender);
void nextCallback(Ref* sender);
void backCallback(Ref* sender);
void toggleDebugCallback(Ref* sender);
2013-10-09 17:53:12 +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
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-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;
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);
virtual ~PhysicsDemoClickAdd();
void onEnter() override;
virtual std::string subtitle() const 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:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemoLogoSmash);
void onEnter() override;
virtual std::string title() const override;
2013-10-09 17:53:12 +08:00
};
class PhysicsDemoPyramidStack : public PhysicsDemo
2013-10-09 17:53:12 +08:00
{
public:
CREATE_FUNC(PhysicsDemoPyramidStack);
2013-11-14 07:55:36 +08:00
2013-10-09 17:53:12 +08:00
void onEnter() override;
void updateOnce(float delta);
virtual std::string title() const override;
};
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;
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
void changeModeCallback(Ref* sender);
2013-10-22 18:00:24 +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;
};
class PhysicsDemoJoints : public PhysicsDemo
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemoJoints);
void onEnter() override;
virtual std::string title() const override;
};
class PhysicsDemoActions : public PhysicsDemo
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemoActions);
void onEnter() override;
virtual std::string title() const override;
};
class PhysicsDemoPump : public PhysicsDemo
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemoPump);
void onEnter() override;
void update(float delta) override;
virtual std::string title() const override;
virtual std::string subtitle() const 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:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemoOneWayPlatform);
2013-10-30 15:53:58 +08:00
void onEnter() override;
virtual std::string title() const override;
2014-01-28 14:59:34 +08:00
bool onContactBegin(PhysicsContact& contact);
2013-10-30 15:53:58 +08:00
};
class PhysicsDemoSlice : public PhysicsDemo
{
public:
2013-11-14 07:55:36 +08:00
CREATE_FUNC(PhysicsDemoSlice);
void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
bool slice(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data);
void clipPoly(PhysicsShapePolygon* shape, Vector2 normal, float distance);
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;
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;
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
};
class PhysicsPositionRotationTest : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsPositionRotationTest);
void onEnter() override;
virtual std::string title() const override;
};
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
#endif
#endif