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

121 lines
2.8 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(float x, float y, float radius, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f));
Sprite* makeBox(float x, float y, Size size, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f));
Sprite* makeTriangle(float x, float y, Size size, PhysicsMaterial material = PhysicsMaterial(1.0f, 1.0f, 1.0f));
2013-10-09 17:53:12 +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-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) override;
void onAcceleration(Acceleration* acc, Event* event) override;
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 PhysicsDemoPyramidStack : public PhysicsDemo
{
public:
void onEnter() override;
std::string title() override;
};
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;
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;
};
class PhysicsDemoJoints : public PhysicsDemo
{
public:
PhysicsDemoJoints();
public:
void onEnter() override;
std::string title() override;
private:
PhysicsShape* _touchesShape;
};
#endif