Skip to content

Commit 42a6ee2

Browse files
author
minggo
committed
Merge pull request cocos2d#3996 from boyu0/iss2771_physical
issue cocos2d#2771: physical
2 parents 920410e + f19b40b commit 42a6ee2

File tree

11 files changed

+545
-96
lines changed

11 files changed

+545
-96
lines changed

cocos/physics/CCPhysicsBody.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ PhysicsBody::PhysicsBody()
7777
, _linearDamping(0.0f)
7878
, _angularDamping(0.0f)
7979
, _tag(0)
80+
, _categoryBitmask(UINT_MAX)
81+
, _collisionBitmask(UINT_MAX)
82+
, _contactTestBitmask(0)
8083
{
8184
}
8285

@@ -109,11 +112,6 @@ PhysicsBody* PhysicsBody::create()
109112
return nullptr;
110113
}
111114

112-
void update(float delta)
113-
{
114-
115-
}
116-
117115
PhysicsBody* PhysicsBody::createCircle(float radius, PhysicsMaterial material)
118116
{
119117
PhysicsBody* body = new PhysicsBody();

cocos/physics/CCPhysicsBody.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ class PhysicsBody : public Object//, public Clonable
276276
int _tag;
277277

278278
int _categoryBitmask;
279-
int _contactTestBitmask;
280279
int _collisionBitmask;
280+
int _contactTestBitmask;
281281

282282
friend class PhysicsWorld;
283283
friend class PhysicsShape;

cocos/physics/CCPhysicsContact.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class PhysicsContact
8080
bool _notify;
8181

8282
friend class PhysicsWorld;
83+
friend class PhysicsWorldCallback;
8384
};
8485

8586
/*
@@ -94,7 +95,7 @@ class PhysicsContactPreSolve
9495
static PhysicsContactPreSolve* create();
9596
bool init();
9697

97-
friend class PhysicsWorld;
98+
friend class PhysicsWorldCallback;
9899
};
99100

100101
/*
@@ -109,7 +110,7 @@ class PhysicsContactPostSolve
109110
static PhysicsContactPostSolve* create();
110111
bool init();
111112

112-
friend class PhysicsWorld;
113+
friend class PhysicsWorldCallback;
113114
};
114115

115116
/*
@@ -125,20 +126,20 @@ class PhysicsContactListener
125126
/*
126127
* @brief it will called at two shapes start to contact, and only call it once.
127128
*/
128-
std::function<bool(const PhysicsContact& contact)> onContactBegin;
129+
std::function<bool(PhysicsWorld& world, const PhysicsContact& contact)> onContactBegin;
129130
/*
130131
* @brief Two shapes are touching during this step. Return false from the callback to make world ignore the collision this step or true to process it normally. Additionally, you may override collision values, elasticity, or surface velocity values.
131132
*/
132-
std::function<bool(const PhysicsContact& contact, const PhysicsContactPreSolve& solve)> onContactPreSolve;
133+
std::function<bool(PhysicsWorld& world, const PhysicsContact& contact, const PhysicsContactPreSolve& solve)> onContactPreSolve;
133134
/*
134135
* @brief Two shapes are touching and their collision response has been processed. You can retrieve the collision impulse or kinetic energy at this time if you want to use it to calculate sound volumes or damage amounts. See cpArbiter for more info
135136
*/
136-
std::function<void(const PhysicsContact& contact, const PhysicsContactPostSolve& solve)> onContactPostSolve;
137+
std::function<void(PhysicsWorld& world, const PhysicsContact& contact, const PhysicsContactPostSolve& solve)> onContactPostSolve;
137138
/*
138139
* @brief it will called at two shapes separated, and only call it once.
139140
* onContactBegin and onContactEnd will called in pairs.
140141
*/
141-
std::function<void(const PhysicsContact& contact)> onContactEnd;
142+
std::function<void(PhysicsWorld& world, const PhysicsContact& contact)> onContactEnd;
142143
};
143144

144145
NS_CC_END

cocos/physics/CCPhysicsJoint.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ void PhysicsJoint::setEnable(bool enable)
103103
}
104104
}
105105

106-
//PhysicsJointPin::PhysicsJointPin()
107-
//{
108-
//
109-
//}
110-
//
111-
//PhysicsJointPin::~PhysicsJointPin()
112-
//{
113-
//
114-
//}
106+
PhysicsJointPin::PhysicsJointPin()
107+
{
108+
109+
}
110+
111+
PhysicsJointPin::~PhysicsJointPin()
112+
{
113+
114+
}
115115

116116
PhysicsJointFixed::PhysicsJointFixed()
117117
{

cocos/physics/CCPhysicsShape.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,11 @@ typedef struct PhysicsMaterial
4444
float restitution;
4545
float friction;
4646

47-
PhysicsMaterial()
48-
: density(0.0f)
49-
, restitution(0.0f)
50-
, friction(0.0f){}
51-
52-
PhysicsMaterial(float density, float restitution, float friction)
53-
: density(density)
54-
, restitution(restitution)
55-
, friction(friction){}
47+
static PhysicsMaterial make(float density, float restitution, float friction)
48+
{
49+
PhysicsMaterial var = {density, restitution, friction};
50+
return var;
51+
}
5652
}PhysicsMaterial;
5753

5854
const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT = {0.0f, 1.0f, 1.0f};
@@ -97,7 +93,7 @@ class PhysicsShape : public Object
9793
virtual Point getOffset() { return Point::ZERO; }
9894
virtual Point getCenter() { return getOffset(); }
9995

100-
static Point* recenterPoints(Point* points, int count, Point center);
96+
static Point* recenterPoints(Point* points, int count, Point center = Point::ZERO);
10197
static Point getPolyonCenter(Point* points, int count);
10298

10399
protected:

0 commit comments

Comments
 (0)