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

270 lines
6.9 KiB
C
Raw Normal View History

2015-09-08 09:54:01 +08:00
#pragma once
#include <map>
2013-09-29 15:09:53 +08:00
#include "../BaseTest.h"
2015-09-08 09:54:01 +08:00
#if CC_USE_PHYSICS
2015-09-08 09:54:01 +08:00
DEFINE_TEST_SUITE(PhysicsTests);
class PhysicsDemo : public TestCase
{
public:
2013-09-29 15:09:53 +08:00
PhysicsDemo();
virtual ~PhysicsDemo();
virtual bool init() override;
virtual void onEnter() override;
virtual std::string title() const override;
void toggleDebugCallback(cocos2d::Ref* sender);
2013-10-09 17:53:12 +08:00
cocos2d::Sprite* addGrossiniAtPosition(cocos2d::Vec2 p, float scale = 1.0);
cocos2d::Sprite* makeBall(cocos2d::Vec2 point, float radius, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
cocos2d::Sprite* makeBox(cocos2d::Vec2 point, cocos2d::Size size, int color = 0, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
cocos2d::Sprite* makeTriangle(cocos2d::Vec2 point, cocos2d::Size size, int color = 0, cocos2d::PhysicsMaterial material = cocos2d::PHYSICSBODY_MATERIAL_DEFAULT);
2013-10-09 17:53:12 +08:00
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
2015-09-08 09:54:01 +08:00
void toggleDebug();
2015-09-08 09:54:01 +08:00
2013-10-22 18:00:24 +08:00
protected:
2015-09-08 09:54:01 +08:00
cocos2d::Texture2D* _spriteTexture;
cocos2d::SpriteBatchNode* _ball;
std::unordered_map<int, cocos2d::Node*> _mouses;
bool _debugDraw;
2013-09-29 15:09:53 +08:00
};
2015-09-08 09:54:01 +08:00
class PhysicsDemoLogoSmash : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsDemoLogoSmash);
void onEnter() override;
virtual std::string title() const override;
};
2013-09-29 15:09:53 +08:00
class PhysicsDemoClickAdd : public PhysicsDemo
{
public:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoClickAdd);
2015-09-08 09:54:01 +08:00
virtual ~PhysicsDemoClickAdd();
void onEnter() override;
virtual std::string subtitle() const override;
2013-09-29 15:09:53 +08:00
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
void onAcceleration(cocos2d::Acceleration* acc, cocos2d::Event* event);
2013-09-29 15:09:53 +08:00
};
class PhysicsDemoPyramidStack : public PhysicsDemo
2013-10-09 17:53:12 +08:00
{
public:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoPyramidStack);
2015-09-08 09:54:01 +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:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoRayCast);
2015-09-08 09:54:01 +08:00
2013-10-22 18:00:24 +08:00
PhysicsDemoRayCast();
2015-09-08 09:54:01 +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;
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
2013-10-22 18:00:24 +08:00
void changeModeCallback(cocos2d::Ref* sender);
2013-10-22 18:00:24 +08:00
bool anyRay(cocos2d::PhysicsWorld& world, const cocos2d::PhysicsRayCastInfo& info, void* data);
2013-10-22 18:00:24 +08:00
private:
float _angle;
cocos2d::DrawNode* _node;
2013-10-22 18:00:24 +08:00
int _mode;
};
2015-09-08 09:54:01 +08:00
class PhysicsDemoActions : public PhysicsDemo
{
public:
2015-09-08 09:54:01 +08:00
CREATE_FUNC(PhysicsDemoActions);
void onEnter() override;
virtual std::string title() const override;
};
2015-09-08 09:54:01 +08:00
class PhysicsDemoJoints : public PhysicsDemo
{
public:
2015-09-08 09:54:01 +08:00
CREATE_FUNC(PhysicsDemoJoints);
void onEnter() override;
virtual std::string title() const override;
};
class PhysicsDemoPump : public PhysicsDemo
{
public:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoPump);
2015-09-08 09:54:01 +08:00
void onEnter() override;
void update(float delta) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
private:
float _distance;
float _rotationV;
};
2013-10-30 15:53:58 +08:00
class PhysicsDemoOneWayPlatform : public PhysicsDemo
{
public:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoOneWayPlatform);
2015-09-08 09:54:01 +08:00
2013-10-30 15:53:58 +08:00
void onEnter() override;
virtual std::string title() const override;
bool onContactBegin(cocos2d::PhysicsContact& contact);
2013-10-30 15:53:58 +08:00
};
class PhysicsDemoSlice : public PhysicsDemo
{
public:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoSlice);
2015-09-08 09:54:01 +08:00
void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
bool slice(cocos2d::PhysicsWorld& world, const cocos2d::PhysicsRayCastInfo& info, void* data);
void clipPoly(cocos2d::PhysicsShapePolygon* shape, cocos2d::Vec2 normal, float distance);
void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
private:
int _sliceTag;
};
2014-02-12 15:57:02 +08:00
class PhysicsDemoBug3988 : public PhysicsDemo
{
public:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsDemoBug3988);
2015-09-08 09:54:01 +08:00
2014-02-12 15:57:02 +08:00
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:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsContactTest);
2014-02-25 15:28:13 +08:00
void onEnter() override;
void resetTest();
bool onContactBegin(cocos2d::PhysicsContact& contact);
2014-02-25 15:28:13 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
void onDecrease(cocos2d::Ref* sender);
void onIncrease(cocos2d::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:
2014-05-02 07:55:28 +08:00
CREATE_FUNC(PhysicsSetGravityEnableTest);
void onEnter() override;
void onScheduleOnce(float delta);
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
2015-09-08 09:54:01 +08:00
class PhysicsDemoBug5482 : public PhysicsDemo
{
public:
2015-09-08 09:54:01 +08:00
CREATE_FUNC(PhysicsDemoBug5482);
void onEnter() override;
void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
void changeBodyCallback(cocos2d::Ref* sender);
private:
cocos2d::Sprite* _nodeA;
cocos2d::Sprite* _nodeB;
cocos2d::PhysicsBody* _body;
cocos2d::MenuItemFont* _button;
bool _bodyInA;
};
2014-06-12 12:57:29 +08:00
class PhysicsFixedUpdate : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsFixedUpdate);
void onEnter() override;
void updateStart(float delta);
void addBall();
virtual void update(float delta) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
2014-06-27 17:30:50 +08:00
class PhysicsTransformTest : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsTransformTest);
void onEnter() override;
virtual std::string title() const override;
bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
2014-06-27 17:30:50 +08:00
private:
cocos2d::Sprite* _parentSprite;
cocos2d::Layer* _rootLayer;
2014-06-27 17:30:50 +08:00
};
class PhysicsIssue9959 : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsIssue9959);
void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
2015-09-08 09:54:01 +08:00
#endif // #if CC_USE_PHYSICS