2021-06-16 19:34:09 +08:00
|
|
|
/****************************************************************************
|
2021-06-24 15:54:02 +08:00
|
|
|
* Copyright (c) 2021 @aismann; Peter Eismann, Germany; dreifrankensoft
|
|
|
|
|
2021-06-16 19:34:09 +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-06-30 18:57:41 +08:00
|
|
|
|
2021-06-16 19:34:09 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-06-30 18:57:41 +08:00
|
|
|
|
2021-06-16 19:34:09 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
//
|
|
|
|
// cocos2d
|
|
|
|
//
|
2021-06-16 19:34:09 +08:00
|
|
|
#ifndef __CHIPMUNKTESTBED_H__
|
|
|
|
#define __CHIPMUNKTESTBED_H__
|
|
|
|
|
2022-10-12 00:15:09 +08:00
|
|
|
#include "axmol.h"
|
2021-06-16 19:34:09 +08:00
|
|
|
#include "chipmunk/chipmunk.h"
|
|
|
|
#include "../BaseTest.h"
|
2023-03-14 07:56:07 +08:00
|
|
|
#include "extensions/axmol-ext.h"
|
2021-06-18 15:47:48 +08:00
|
|
|
|
|
|
|
#include "demo/ChipmunkDemo.h"
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class ChipmunkTestBed : public TestCase
|
|
|
|
{
|
2021-06-16 19:34:09 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(ChipmunkTestBed);
|
2021-06-24 02:23:02 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
ChipmunkTestBed();
|
|
|
|
~ChipmunkTestBed();
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void onEnter() override;
|
|
|
|
void createResetButton();
|
2022-10-18 19:17:36 +08:00
|
|
|
void reset(ax::Ref* sender);
|
2021-06-23 14:25:44 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void update(float dt) override;
|
|
|
|
virtual void initPhysics();
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
void onMouseDown(ax::Event* event);
|
|
|
|
void onMouseUp(ax::Event* event);
|
|
|
|
void onMouseMove(ax::Event* event);
|
2021-12-28 16:06:23 +08:00
|
|
|
void DrawInfo();
|
|
|
|
void updateInit(ChipmunkDemo tt);
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
cpSpace* _space; // strong ref
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::extension::PhysicsDebugNodeChipmunk2D* _debugLayer; // weak ref
|
2021-12-28 16:06:23 +08:00
|
|
|
int keyPresses;
|
|
|
|
bool mousePresses = false;
|
2021-06-25 21:31:13 +08:00
|
|
|
|
2021-06-30 18:57:41 +08:00
|
|
|
private:
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::EventListenerMouse* _mouseListener;
|
|
|
|
ax::Node* _trackNode;
|
|
|
|
ax::DrawNode* draw;
|
|
|
|
ax::Label* drawInfo;
|
2021-06-17 14:22:52 +08:00
|
|
|
};
|
2021-06-16 19:34:09 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class LogoSmashDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-17 14:22:52 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(LogoSmashDemo);
|
|
|
|
std::string title() const override;
|
|
|
|
void onEnter() override;
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-17 14:22:52 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class PlinkDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-18 15:47:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(PlinkDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-18 15:47:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class TumbleDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-17 14:22:52 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(TumbleDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-18 15:47:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-16 19:34:09 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class PyramidStackDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-18 15:47:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(PyramidStackDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-18 15:47:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class PyramidToppleDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-17 14:22:52 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(PyramidToppleDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-17 14:22:52 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class ChainsDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-18 15:47:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(ChainsDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-18 15:47:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-18 15:47:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class OneWayDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-18 15:47:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(OneWayDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-18 15:47:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-18 15:47:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class PlanetDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 14:25:44 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(PlanetDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 14:25:44 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 14:25:44 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class TheoJansenDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 14:25:44 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(TheoJansenDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 14:25:44 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 14:25:44 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class TankDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 14:25:44 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(TankDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 14:25:44 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 14:25:44 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class BenchDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 14:25:44 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(BenchDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual std::string subtitle() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-30 18:57:41 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 14:25:44 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class SpringiesDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 14:25:44 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(SpringiesDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 14:25:44 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 14:25:44 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class StickyDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(StickyDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class ShatterDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(ShatterDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class CraneDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(CraneDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class JointsDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(JointsDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class ConvexDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(ConvexDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class PumpDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(PumpDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class PlatformerPlayerDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(PlatformerPlayerDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class QueryDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(QueryDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class ContactGraphDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(ContactGraphDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class BuoyancyDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(BuoyancyDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class SliceDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(SliceDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class UnicycleDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-23 23:09:48 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(UnicycleDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-23 23:09:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-23 23:09:48 +08:00
|
|
|
};
|
2021-06-18 15:47:48 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
class ExampleDemo : public ChipmunkTestBed
|
|
|
|
{
|
2021-06-17 14:22:52 +08:00
|
|
|
public:
|
2021-12-28 16:06:23 +08:00
|
|
|
CREATE_FUNC(ExampleDemo);
|
|
|
|
virtual std::string title() const override;
|
|
|
|
virtual void onEnter() override;
|
2021-06-17 14:22:52 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void initPhysics() override;
|
|
|
|
virtual void update(float dt) override;
|
2021-06-17 14:22:52 +08:00
|
|
|
};
|
2021-06-16 19:34:09 +08:00
|
|
|
DEFINE_TEST_SUITE(ChipmunkTestBedTests);
|
|
|
|
|
|
|
|
#endif /* __CHIPMUNKTESTBED_H__ */
|