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

311 lines
8.3 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-28 16:06:23 +08:00
https://axis-project.github.io/
2021-12-28 16:06:23 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-28 16:06:23 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-28 16:06:23 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2015-09-08 09:54:01 +08:00
#pragma once
#include <map>
2013-09-29 15:09:53 +08:00
#include "../BaseTest.h"
2022-07-15 19:17:01 +08:00
#if AX_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();
2021-12-28 16:06:23 +08:00
virtual bool init() override;
virtual void onEnter() override;
virtual std::string title() const override;
2021-12-28 16:06:23 +08:00
void toggleDebugCallback(axis::Ref* sender);
2021-12-28 16:06:23 +08:00
axis::Sprite* addGrossiniAtPosition(axis::Vec2 p, float scale = 1.0);
axis::Sprite* makeBall(axis::Vec2 point,
2021-12-28 16:06:23 +08:00
float radius,
axis::PhysicsMaterial material = axis::PHYSICSBODY_MATERIAL_DEFAULT);
axis::Sprite* makeBox(axis::Vec2 point,
axis::Size size,
2021-12-28 16:06:23 +08:00
int color = 0,
axis::PhysicsMaterial material = axis::PHYSICSBODY_MATERIAL_DEFAULT);
axis::Sprite* makeTriangle(axis::Vec2 point,
axis::Size size,
2021-12-28 16:06:23 +08:00
int color = 0,
axis::PhysicsMaterial material = axis::PHYSICSBODY_MATERIAL_DEFAULT);
2021-12-28 16:06:23 +08:00
bool onTouchBegan(axis::Touch* touch, axis::Event* event);
void onTouchMoved(axis::Touch* touch, axis::Event* event);
void onTouchEnded(axis::Touch* touch, axis::Event* event);
2021-12-28 16:06:23 +08:00
void toggleDebug();
2021-12-28 16:06:23 +08:00
2013-10-22 18:00:24 +08:00
protected:
axis::Texture2D* _spriteTexture;
axis::SpriteBatchNode* _ball;
std::unordered_map<int, axis::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);
2021-12-28 16:06:23 +08:00
2015-09-08 09:54:01 +08:00
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);
2021-12-28 16:06:23 +08:00
virtual ~PhysicsDemoClickAdd();
void onEnter() override;
virtual std::string subtitle() const override;
2021-12-28 16:06:23 +08:00
void onTouchesEnded(const std::vector<axis::Touch*>& touches, axis::Event* event);
void onAcceleration(axis::Acceleration* acc, axis::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);
2021-12-28 16:06:23 +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);
2021-12-28 16:06:23 +08:00
2013-10-22 18:00:24 +08:00
PhysicsDemoRayCast();
2021-12-28 16:06:23 +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<axis::Touch*>& touches, axis::Event* event);
2021-12-28 16:06:23 +08:00
void changeModeCallback(axis::Ref* sender);
2021-12-28 16:06:23 +08:00
bool anyRay(axis::PhysicsWorld& world, const axis::PhysicsRayCastInfo& info, void* data);
2021-12-28 16:06:23 +08:00
2013-10-22 18:00:24 +08:00
private:
float _angle;
axis::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);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +08:00
void onEnter() override;
void update(float delta) override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2021-12-28 16:06:23 +08:00
bool onTouchBegan(axis::Touch* touch, axis::Event* event);
void onTouchMoved(axis::Touch* touch, axis::Event* event);
void onTouchEnded(axis::Touch* touch, axis::Event* event);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +08:00
2013-10-30 15:53:58 +08:00
void onEnter() override;
virtual std::string title() const override;
2021-12-28 16:06:23 +08:00
bool onContactBegin(axis::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);
2021-12-28 16:06:23 +08:00
void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2021-12-28 16:06:23 +08:00
bool slice(axis::PhysicsWorld& world, const axis::PhysicsRayCastInfo& info, void* data);
void clipPoly(axis::PhysicsShapePolygon* shape, axis::Vec2 normal, float distance);
2021-12-28 16:06:23 +08:00
void onTouchEnded(axis::Touch* touch, axis::Event* event);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +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);
2021-12-28 16:06:23 +08:00
2014-02-25 15:28:13 +08:00
void onEnter() override;
void resetTest();
bool onContactBegin(axis::PhysicsContact& contact);
2014-02-25 15:28:13 +08:00
virtual std::string title() const override;
virtual std::string subtitle() const override;
2021-12-28 16:06:23 +08:00
void onDecrease(axis::Ref* sender);
void onIncrease(axis::Ref* sender);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +08:00
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);
2021-12-28 16:06:23 +08:00
void onEnter() override;
void onExit() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
2021-12-28 16:06:23 +08:00
void changeBodyCallback(axis::Ref* sender);
2021-12-28 16:06:23 +08:00
private:
axis::Sprite* _nodeA;
axis::Sprite* _nodeB;
axis::PhysicsBody* _body;
axis::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);
2021-12-28 16:06:23 +08:00
2014-06-27 17:30:50 +08:00
void onEnter() override;
virtual std::string title() const override;
2021-12-28 16:06:23 +08:00
bool onTouchBegan(axis::Touch* touch, axis::Event* event);
2021-12-28 16:06:23 +08:00
private:
axis::Sprite* _parentSprite;
axis::Layer* _rootLayer;
2014-06-27 17:30:50 +08:00
};
class PhysicsIssue9959 : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsIssue9959);
2021-12-28 16:06:23 +08:00
void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
class PhysicsIssue15932 : public PhysicsDemo
{
public:
CREATE_FUNC(PhysicsIssue15932);
void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
};
2022-07-15 19:17:01 +08:00
#endif // #if AX_USE_PHYSICS