2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +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
|
|
|
|
2018-01-29 16:25:32 +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
|
|
|
|
2018-01-29 16:25:32 +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-10 17:41:06 +08:00
|
|
|
|
2013-09-29 15:09:53 +08:00
|
|
|
#include "../BaseTest.h"
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
#if AX_USE_PHYSICS
|
2013-10-28 11:08:41 +08:00
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
DEFINE_TEST_SUITE(PhysicsTests);
|
2013-11-21 10:48:21 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
class PhysicsDemo : public TestCase
|
2013-09-10 17:41:06 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-29 15:09:53 +08:00
|
|
|
PhysicsDemo();
|
|
|
|
virtual ~PhysicsDemo();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
virtual bool init() override;
|
2013-09-30 20:43:19 +08:00
|
|
|
virtual void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void toggleDebugCallback(axis::Ref* sender);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +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,
|
2022-07-11 17:50:21 +08:00
|
|
|
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,
|
2022-07-11 17:50:21 +08:00
|
|
|
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,
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::PhysicsMaterial material = axis::PHYSICSBODY_MATERIAL_DEFAULT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +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
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
void toggleDebug();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-10-22 18:00:24 +08:00
|
|
|
protected:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Texture2D* _spriteTexture;
|
|
|
|
axis::SpriteBatchNode* _ball;
|
|
|
|
std::unordered_map<int, axis::Node*> _mouses;
|
2015-04-03 14:31:03 +08:00
|
|
|
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
|
|
|
|
2013-11-11 10:23:05 +08:00
|
|
|
virtual ~PhysicsDemoClickAdd();
|
2013-09-30 20:43:19 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string subtitle() const override;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +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
|
|
|
};
|
2013-09-10 17:41:06 +08:00
|
|
|
|
2013-11-08 14:25:03 +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;
|
2014-02-26 10:53:41 +08:00
|
|
|
void updateOnce(float delta);
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-09-10 17:41:06 +08:00
|
|
|
};
|
|
|
|
|
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;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-22 18:00:24 +08:00
|
|
|
void update(float delta) override;
|
2022-07-11 17:50:21 +08:00
|
|
|
void onTouchesEnded(const std::vector<axis::Touch*>& touches, axis::Event* event);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void changeModeCallback(axis::Ref* sender);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +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;
|
2022-07-11 17:50:21 +08:00
|
|
|
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
|
2013-10-23 10:11:08 +08:00
|
|
|
{
|
2013-10-23 17:28:23 +08:00
|
|
|
public:
|
2015-09-08 09:54:01 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoActions);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-10-29 17:31:35 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-29 17:31:35 +08:00
|
|
|
};
|
|
|
|
|
2015-09-08 09:54:01 +08:00
|
|
|
class PhysicsDemoJoints : public PhysicsDemo
|
2013-10-29 17:31:35 +08:00
|
|
|
{
|
2013-10-23 10:11:08 +08:00
|
|
|
public:
|
2015-09-08 09:54:01 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoJoints);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-10-23 10:11:08 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2013-10-29 17:31:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsDemoPump : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoPump);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-10-29 17:31:35 +08:00
|
|
|
void onEnter() override;
|
|
|
|
void update(float delta) override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +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
|
|
|
|
2013-10-23 17:28:23 +08:00
|
|
|
private:
|
2013-10-29 17:31:35 +08:00
|
|
|
float _distance;
|
|
|
|
float _rotationV;
|
2013-10-23 10:11:08 +08:00
|
|
|
};
|
|
|
|
|
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;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool onContactBegin(axis::PhysicsContact& contact);
|
2013-10-30 15:53:58 +08:00
|
|
|
};
|
|
|
|
|
2013-11-05 15:54:33 +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
|
|
|
|
2013-11-05 15:54:33 +08:00
|
|
|
void onEnter() override;
|
2013-12-19 05:52:10 +08:00
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-11 17:50:21 +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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void onTouchEnded(axis::Touch* touch, axis::Event* event);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2013-11-05 15:54:33 +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;
|
2014-02-27 13:35:37 +08:00
|
|
|
void resetTest();
|
2022-07-11 17:50:21 +08:00
|
|
|
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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void onDecrease(axis::Ref* sender);
|
|
|
|
void onIncrease(axis::Ref* sender);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-02-27 13:35:37 +08:00
|
|
|
private:
|
|
|
|
int _yellowBoxNum;
|
|
|
|
int _blueBoxNum;
|
|
|
|
int _yellowTriangleNum;
|
|
|
|
int _blueTriangleNum;
|
2014-02-25 15:28:13 +08:00
|
|
|
};
|
|
|
|
|
2014-02-28 15:47:49 +08:00
|
|
|
class PhysicsPositionRotationTest : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsPositionRotationTest);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-02-28 15:47:49 +08:00
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
};
|
|
|
|
|
2014-03-18 16:17:43 +08:00
|
|
|
class PhysicsSetGravityEnableTest : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
2014-05-02 07:55:28 +08:00
|
|
|
CREATE_FUNC(PhysicsSetGravityEnableTest);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-03-18 16:17:43 +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
|
2014-06-04 11:59:15 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-09-08 09:54:01 +08:00
|
|
|
CREATE_FUNC(PhysicsDemoBug5482);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-04 11:59:15 +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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
void changeBodyCallback(axis::Ref* sender);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-04 11:59:15 +08:00
|
|
|
private:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Sprite* _nodeA;
|
|
|
|
axis::Sprite* _nodeB;
|
|
|
|
axis::PhysicsBody* _body;
|
|
|
|
axis::MenuItemFont* _button;
|
2014-06-04 11:59:15 +08:00
|
|
|
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
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
bool onTouchBegan(axis::Touch* touch, axis::Event* event);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-04-10 15:39:39 +08:00
|
|
|
private:
|
2022-07-11 17:50:21 +08:00
|
|
|
axis::Sprite* _parentSprite;
|
|
|
|
axis::Layer* _rootLayer;
|
2014-06-27 17:30:50 +08:00
|
|
|
};
|
2015-01-28 10:20:30 +08:00
|
|
|
|
|
|
|
class PhysicsIssue9959 : public PhysicsDemo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CREATE_FUNC(PhysicsIssue9959);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2015-01-28 10:20:30 +08:00
|
|
|
void onEnter() override;
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
};
|
|
|
|
|
2016-06-23 05:12:27 +08:00
|
|
|
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
|