Skip to content

Commit

Permalink
Improve the "Physics part" (#379)
Browse files Browse the repository at this point in the history
* 1. Add "initial" Chipmunk - TestBed

More demos comes later.

* 2. Removed unused source

* Update CMakeLists.txt

* Some fixes #1

* workaround #1

* workaround #1
  • Loading branch information
aismann authored Jun 16, 2021
1 parent eff5d17 commit a491997
Show file tree
Hide file tree
Showing 9 changed files with 451 additions and 72 deletions.
21 changes: 0 additions & 21 deletions extensions/physics-nodes/CCPhysicsSpriteBox2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ NS_CC_EXT_BEGIN

PhysicsSpriteBox2D::PhysicsSpriteBox2D()
: _ignoreBodyRotation(false)
, _CPBody(nullptr)
, _pB2Body(nullptr)
, _PTMRatio(0.0f)
, _syncTransform(nullptr)
Expand Down Expand Up @@ -194,24 +193,6 @@ Vec3 PhysicsSpriteBox2D::getPosition3D() const
return Vec3(pos.x, pos.y, 0);
}

//
// Chipmunk only
//



cpBody* PhysicsSpriteBox2D::getCPBody() const
{

CCASSERT(false, "Can't call chipmunk methods when Chipmunk is disabled");
return nullptr;
}

void PhysicsSpriteBox2D::setCPBody(cpBody *pBody)
{
_CPBody = pBody;
}

b2Body* PhysicsSpriteBox2D::getB2Body() const
{
return _pB2Body;
Expand Down Expand Up @@ -250,8 +231,6 @@ const Vec2& PhysicsSpriteBox2D::getPosFromPhysics() const

void PhysicsSpriteBox2D::setPosition(float x, float y)
{


float angle = _pB2Body->GetAngle();
_pB2Body->SetTransform(b2Vec2(x / _PTMRatio, y / _PTMRatio), angle);

Expand Down
11 changes: 0 additions & 11 deletions extensions/physics-nodes/CCPhysicsSpriteBox2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "base/CCEventListenerCustom.h"


struct cpBody;
class b2Body;

NS_CC_EXT_BEGIN
Expand Down Expand Up @@ -91,13 +90,6 @@ NS_CC_EXT_BEGIN
bool isIgnoreBodyRotation() const;
void setIgnoreBodyRotation(bool bIgnoreBodyRotation);

//
// Chipmunk specific
//
/** Body accessor when using regular Chipmunk */
cpBody* getCPBody() const;
void setCPBody(cpBody* pBody);

//
// Box2d specific
//
Expand Down Expand Up @@ -133,9 +125,6 @@ NS_CC_EXT_BEGIN
protected:
bool _ignoreBodyRotation;

// chipmunk specific
cpBody* _CPBody;

// box2d specific
b2Body* _pB2Body;
float _PTMRatio;
Expand Down
28 changes: 0 additions & 28 deletions extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ NS_CC_EXT_BEGIN
PhysicsSpriteChipmunk2D::PhysicsSpriteChipmunk2D()
: _ignoreBodyRotation(false)
, _CPBody(nullptr)
, _pB2Body(nullptr)
, _PTMRatio(0.0f)
, _syncTransform(nullptr)
{}

Expand Down Expand Up @@ -198,8 +196,6 @@ Vec3 PhysicsSpriteChipmunk2D::getPosition3D() const
// Chipmunk only
//



cpBody* PhysicsSpriteChipmunk2D::getCPBody() const
{
return _CPBody;
Expand All @@ -210,30 +206,6 @@ void PhysicsSpriteChipmunk2D::setCPBody(cpBody *pBody)
_CPBody = pBody;
}

b2Body* PhysicsSpriteChipmunk2D::getB2Body() const
{
CCASSERT(false, "Can't call box2d methods when Box2d is disabled");
return nullptr;
}

void PhysicsSpriteChipmunk2D::setB2Body(b2Body *pBody)
{
CC_UNUSED_PARAM(pBody);
CCASSERT(false, "Can't call box2d methods when Box2d is disabled");
}

float PhysicsSpriteChipmunk2D::getPTMRatio() const
{
CCASSERT(false, "Can't call box2d methods when Box2d is disabled");
return 0;
}

void PhysicsSpriteChipmunk2D::setPTMRatio(float fRatio)
{
CC_UNUSED_PARAM(fRatio);
CCASSERT(false, "Can't call box2d methods when Box2d is disabled");
}

//
// Common to Box2d and Chipmunk
//
Expand Down
12 changes: 0 additions & 12 deletions extensions/physics-nodes/CCPhysicsSpriteChipmunk2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "base/CCEventListenerCustom.h"

struct cpBody;
class b2Body;

NS_CC_EXT_BEGIN

Expand Down Expand Up @@ -97,13 +96,6 @@ class CC_EX_DLL PhysicsSpriteChipmunk2D : public Sprite
cpBody* getCPBody() const;
void setCPBody(cpBody *pBody);

//
// Box2d specific
//
/** Body accessor when using box2d */
b2Body* getB2Body() const;
void setB2Body(b2Body *pBody);

float getPTMRatio() const;
void setPTMRatio(float fPTMRatio);
virtual void syncPhysicsTransform() const;
Expand Down Expand Up @@ -134,10 +126,6 @@ class CC_EX_DLL PhysicsSpriteChipmunk2D : public Sprite

// chipmunk specific
cpBody *_CPBody;

// box2d specific
b2Body *_pB2Body;
float _PTMRatio;

// Event for update synchronise physic transform
cocos2d::EventListenerCustom* _syncTransform;
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp-tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,12 @@ list(APPEND GAME_SOURCE
list(APPEND GAME_HEADER
Classes/PhysicsTest/PhysicsTest.h
Classes/ChipmunkTest/ChipmunkTest.h
Classes/ChipmunkTestBed/ChipmunkTestBed.h
)
list(APPEND GAME_SOURCE
Classes/PhysicsTest/PhysicsTest.cpp
Classes/ChipmunkTest/ChipmunkTest.cpp
Classes/ChipmunkTestBed/ChipmunkTestBed.cpp
)

if(NOT LINUX)
Expand Down
Loading

0 comments on commit a491997

Please sign in to comment.