issue #2771: fix some code style

This commit is contained in:
boyu0 2013-11-01 16:26:03 +08:00
parent b2951b70ff
commit 2f67ceb495
12 changed files with 152 additions and 121 deletions

View File

@ -1389,12 +1389,12 @@ void Node::setPhysicsBody(PhysicsBody* body)
{ {
if (_physicsBody != nullptr) if (_physicsBody != nullptr)
{ {
_physicsBody->_owner = nullptr; _physicsBody->_node = nullptr;
_physicsBody->release(); _physicsBody->release();
} }
_physicsBody = body; _physicsBody = body;
_physicsBody->_owner = this; _physicsBody->_node = this;
_physicsBody->retain(); _physicsBody->retain();
_physicsBody->setPosition(getPosition()); _physicsBody->setPosition(getPosition());
_physicsBody->setRotation(getRotation()); _physicsBody->setRotation(getRotation());

View File

@ -60,7 +60,7 @@ namespace
} }
PhysicsBody::PhysicsBody() PhysicsBody::PhysicsBody()
: _owner(nullptr) : _node(nullptr)
, _shapes(nullptr) , _shapes(nullptr)
, _world(nullptr) , _world(nullptr)
, _info(nullptr) , _info(nullptr)
@ -570,7 +570,7 @@ void PhysicsBody::setMoment(float moment)
} }
} }
PhysicsShape* PhysicsBody::getShapeByTag(int tag) PhysicsShape* PhysicsBody::getShapeByTag(int tag) const
{ {
for (auto child : *_shapes) for (auto child : *_shapes)
{ {
@ -666,7 +666,7 @@ void PhysicsBody::setEnable(bool enable)
} }
} }
bool PhysicsBody::isResting() bool PhysicsBody::isResting() const
{ {
return cpBodyIsSleeping(_info->body) == cpTrue; return cpBodyIsSleeping(_info->body) == cpTrue;
} }

View File

@ -122,12 +122,12 @@ public:
/* /*
* @brief get the body shapes. * @brief get the body shapes.
*/ */
inline Array* getShapes() { return _shapes; } inline Array* getShapes() const { return _shapes; }
/* /*
* @brief get the first body shapes. * @brief get the first body shapes.
*/ */
inline PhysicsShape* getShape() { return _shapes->count() >= 1 ? dynamic_cast<PhysicsShape*>(_shapes->getObjectAtIndex(0)) : nullptr; } inline PhysicsShape* getShape() const { return _shapes->count() >= 1 ? dynamic_cast<PhysicsShape*>(_shapes->getObjectAtIndex(0)) : nullptr; }
PhysicsShape* getShapeByTag(int tag); PhysicsShape* getShapeByTag(int tag) const;
/* /*
* @brief remove a shape from body * @brief remove a shape from body
*/ */
@ -152,7 +152,7 @@ public:
/* /*
* @brief get the sprite the body set to. * @brief get the sprite the body set to.
*/ */
inline Node* getOwner() const { return _owner; } inline Node* getNode() const { return _node; }
void setCategoryBitmask(int bitmask); void setCategoryBitmask(int bitmask);
void setContactTestBitmask(int bitmask); void setContactTestBitmask(int bitmask);
@ -162,7 +162,7 @@ public:
inline int getCollisionBitmask() const { return _collisionBitmask; } inline int getCollisionBitmask() const { return _collisionBitmask; }
void setGroup(int group); void setGroup(int group);
inline int getGroup() { return _group; } inline int getGroup() const { return _group; }
/* /*
* @brief get the body position. * @brief get the body position.
@ -177,7 +177,7 @@ public:
* @brief test the body is dynamic or not. * @brief test the body is dynamic or not.
* a dynamic body will effect with gravity. * a dynamic body will effect with gravity.
*/ */
inline bool isDynamic() { return _dynamic; } inline bool isDynamic() const { return _dynamic; }
/* /*
* @brief set dynamic to body. * @brief set dynamic to body.
* a dynamic body will effect with gravity. * a dynamic body will effect with gravity.
@ -192,7 +192,7 @@ public:
/* /*
* @brief get the body mass. * @brief get the body mass.
*/ */
inline float getMass() { return _mass; } inline float getMass() const { return _mass; }
/* /*
* @brief add mass to body. * @brief add mass to body.
* if _mass(mass of the body) == PHYSICS_INFINITY, it remains. * if _mass(mass of the body) == PHYSICS_INFINITY, it remains.
@ -211,7 +211,7 @@ public:
/* /*
* @brief get the body moment of inertia. * @brief get the body moment of inertia.
*/ */
inline float getMoment(float moment) { return _moment; } inline float getMoment(float moment) const { return _moment; }
/* /*
* @brief add moment of inertia to body. * @brief add moment of inertia to body.
* if _moment(moment of the body) == PHYSICS_INFINITY, it remains. * if _moment(moment of the body) == PHYSICS_INFINITY, it remains.
@ -228,25 +228,25 @@ public:
/* /*
* @brief get angular damping. * @brief get angular damping.
*/ */
inline float getLinearDamping() { return _linearDamping; } inline float getLinearDamping() const { return _linearDamping; }
inline void setLinearDamping(float damping) { _linearDamping = damping; } inline void setLinearDamping(float damping) { _linearDamping = damping; }
inline float getAngularDamping() { return _angularDamping; } inline float getAngularDamping() const { return _angularDamping; }
inline void setAngularDamping(float damping) { _angularDamping = damping; } inline void setAngularDamping(float damping) { _angularDamping = damping; }
//virtual Clonable* clone() const override; //virtual Clonable* clone() const override;
bool isResting(); bool isResting() const;
inline bool isEnable() { return _enable; } inline bool isEnable() const { return _enable; }
void setEnable(bool enable); void setEnable(bool enable);
inline bool isRotationEnable() { return _rotationEnable; } inline bool isRotationEnable() const { return _rotationEnable; }
void setRotationEnable(bool enable); void setRotationEnable(bool enable);
inline bool isGravityEnable() { return _gravityEnable; } inline bool isGravityEnable() const { return _gravityEnable; }
void setGravityEnable(bool enable); void setGravityEnable(bool enable);
inline int getTag() { return _tag; } inline int getTag() const { return _tag; }
inline void setTag(int tag) { _tag = tag; } inline void setTag(int tag) { _tag = tag; }
Point world2Local(const Point& point); Point world2Local(const Point& point);
@ -266,7 +266,7 @@ protected:
virtual ~PhysicsBody(); virtual ~PhysicsBody();
protected: protected:
Node* _owner; Node* _node;
std::vector<PhysicsJoint*> _joints; std::vector<PhysicsJoint*> _joints;
Array* _shapes; Array* _shapes;
PhysicsWorld* _world; PhysicsWorld* _world;

View File

@ -41,6 +41,8 @@
NS_CC_BEGIN NS_CC_BEGIN
const char* PHYSICSCONTACT_EVENT_NAME = "PhysicsContactEvent";
PhysicsContact::PhysicsContact() PhysicsContact::PhysicsContact()
: Event(Event::Type::CUSTOM) : Event(Event::Type::CUSTOM)
, _world(nullptr) , _world(nullptr)
@ -100,7 +102,7 @@ void PhysicsContact::generateContactData()
return; return;
} }
cpArbiter* arb = (cpArbiter*)_contactInfo; cpArbiter* arb = static_cast<cpArbiter*>(_contactInfo);
_contactData = new PhysicsContactData(); _contactData = new PhysicsContactData();
_contactData->count = cpArbiterGetCount(arb); _contactData->count = cpArbiterGetCount(arb);
for (int i=0; i<_contactData->count; ++i) for (int i=0; i<_contactData->count; ++i)
@ -118,34 +120,34 @@ PhysicsContactPreSolve::PhysicsContactPreSolve(PhysicsContactData* data, void* c
{ {
} }
float PhysicsContactPreSolve::getElasticity() float PhysicsContactPreSolve::getElasticity() const
{ {
return ((cpArbiter*)_contactInfo)->e; return static_cast<cpArbiter*>(_contactInfo)->e;
} }
float PhysicsContactPreSolve::getFriciton() float PhysicsContactPreSolve::getFriciton() const
{ {
return ((cpArbiter*)_contactInfo)->u; return static_cast<cpArbiter*>(_contactInfo)->u;
} }
Point PhysicsContactPreSolve::getSurfaceVelocity() Point PhysicsContactPreSolve::getSurfaceVelocity() const
{ {
return PhysicsHelper::cpv2point(((cpArbiter*)_contactInfo)->surface_vr); return PhysicsHelper::cpv2point(static_cast<cpArbiter*>(_contactInfo)->surface_vr);
} }
void PhysicsContactPreSolve::setElasticity(float elasticity) void PhysicsContactPreSolve::setElasticity(float elasticity)
{ {
((cpArbiter*)_contactInfo)->e = elasticity; static_cast<cpArbiter*>(_contactInfo)->e = elasticity;
} }
void PhysicsContactPreSolve::setFriction(float friction) void PhysicsContactPreSolve::setFriction(float friction)
{ {
((cpArbiter*)_contactInfo)->u = friction; static_cast<cpArbiter*>(_contactInfo)->u = friction;
} }
void PhysicsContactPreSolve::setSurfaceVelocity(Point surfaceVelocity) void PhysicsContactPreSolve::setSurfaceVelocity(Point surfaceVelocity)
{ {
((cpArbiter*)_contactInfo)->surface_vr = PhysicsHelper::point2cpv(surfaceVelocity); static_cast<cpArbiter*>(_contactInfo)->surface_vr = PhysicsHelper::point2cpv(surfaceVelocity);
} }
PhysicsContactPreSolve::~PhysicsContactPreSolve() PhysicsContactPreSolve::~PhysicsContactPreSolve()
@ -165,19 +167,19 @@ PhysicsContactPostSolve::~PhysicsContactPostSolve()
} }
float PhysicsContactPostSolve::getElasticity() float PhysicsContactPostSolve::getElasticity() const
{ {
return ((cpArbiter*)_contactInfo)->e; return static_cast<cpArbiter*>(_contactInfo)->e;
} }
float PhysicsContactPostSolve::getFriciton() float PhysicsContactPostSolve::getFriciton() const
{ {
return ((cpArbiter*)_contactInfo)->u; return static_cast<cpArbiter*>(_contactInfo)->u;
} }
Point PhysicsContactPostSolve::getSurfaceVelocity() Point PhysicsContactPostSolve::getSurfaceVelocity() const
{ {
return PhysicsHelper::cpv2point(((cpArbiter*)_contactInfo)->surface_vr); return PhysicsHelper::cpv2point(static_cast<cpArbiter*>(_contactInfo)->surface_vr);
} }
EventListenerPhysicsContact::EventListenerPhysicsContact() EventListenerPhysicsContact::EventListenerPhysicsContact()

View File

@ -81,22 +81,22 @@ public:
/* /*
* @brief get data. * @brief get data.
*/ */
inline void* getData() { return _data; } inline void* getData() const { return _data; }
/* /*
* @brief set data to contact. you must manage the memory yourself, Generally you can set data at contact begin, and distory it at contact end. * @brief set data to contact. you must manage the memory yourself, Generally you can set data at contact begin, and distory it at contact end.
*/ */
inline void setData(void* data) { _data = data; } inline void setData(void* data) { _data = data; }
EventCode getEventCode() { return _eventCode; }; EventCode getEventCode() const { return _eventCode; };
private: private:
static PhysicsContact* create(PhysicsShape* a, PhysicsShape* b); static PhysicsContact* create(PhysicsShape* a, PhysicsShape* b);
bool init(PhysicsShape* a, PhysicsShape* b); bool init(PhysicsShape* a, PhysicsShape* b);
void setEventCode(EventCode eventCode) { _eventCode = eventCode; }; void setEventCode(EventCode eventCode) { _eventCode = eventCode; };
inline bool getNotify() { return _notify; } inline bool getNotify() const { return _notify; }
inline void setNotify(bool notify) { _notify = notify; } inline void setNotify(bool notify) { _notify = notify; }
inline PhysicsWorld* getWorld() { return _world; } inline PhysicsWorld* getWorld() const { return _world; }
inline void setWorld(PhysicsWorld* world) { _world = world; } inline void setWorld(PhysicsWorld* world) { _world = world; }
inline void setResult(bool result) { _result = result; } inline void setResult(bool result) { _result = result; }
inline bool resetResult() { bool ret = _result; _result = true; return ret; } inline bool resetResult() { bool ret = _result; _result = true; return ret; }
@ -133,9 +133,9 @@ class PhysicsContactPreSolve
{ {
public: public:
// getter/setter // getter/setter
float getElasticity(); float getElasticity() const;
float getFriciton(); float getFriciton() const;
Point getSurfaceVelocity(); Point getSurfaceVelocity() const;
void setElasticity(float elasticity); void setElasticity(float elasticity);
void setFriction(float friction); void setFriction(float friction);
void setSurfaceVelocity(Point surfaceVelocity); void setSurfaceVelocity(Point surfaceVelocity);
@ -161,9 +161,9 @@ class PhysicsContactPostSolve
{ {
public: public:
// getter // getter
float getElasticity(); float getElasticity() const;
float getFriciton(); float getFriciton() const;
Point getSurfaceVelocity(); Point getSurfaceVelocity() const;
private: private:
PhysicsContactPostSolve(void* contactInfo); PhysicsContactPostSolve(void* contactInfo);
@ -175,8 +175,6 @@ private:
friend class EventListenerPhysicsContact; friend class EventListenerPhysicsContact;
}; };
static const char* PHYSICSCONTACT_EVENT_NAME = "PhysicsContactEvent";
/* /*
* @brief contact listener. * @brief contact listener.
*/ */
@ -222,7 +220,7 @@ class EventListenerPhysicsContactWithBodies : public EventListenerPhysicsContact
public: public:
static EventListenerPhysicsContactWithBodies* create(PhysicsBody* bodyA, PhysicsBody* bodyB); static EventListenerPhysicsContactWithBodies* create(PhysicsBody* bodyA, PhysicsBody* bodyB);
virtual bool test(PhysicsShape* shapeA, PhysicsShape* shapeB); virtual bool test(PhysicsShape* shapeA, PhysicsShape* shapeB) override;
virtual EventListenerPhysicsContactWithBodies* clone() override; virtual EventListenerPhysicsContactWithBodies* clone() override;
protected: protected:
@ -239,7 +237,7 @@ class EventListenerPhysicsContactWithShapes : public EventListenerPhysicsContact
public: public:
static EventListenerPhysicsContactWithShapes* create(PhysicsShape* shapeA, PhysicsShape* shapeB); static EventListenerPhysicsContactWithShapes* create(PhysicsShape* shapeA, PhysicsShape* shapeB);
virtual bool test(PhysicsShape* shapeA, PhysicsShape* shapeB); virtual bool test(PhysicsShape* shapeA, PhysicsShape* shapeB) override;
virtual EventListenerPhysicsContactWithShapes* clone() override; virtual EventListenerPhysicsContactWithShapes* clone() override;
protected: protected:
@ -256,7 +254,7 @@ class EventListenerPhysicsContactWithGroup : public EventListenerPhysicsContact
public: public:
static EventListenerPhysicsContactWithGroup* create(int group); static EventListenerPhysicsContactWithGroup* create(int group);
virtual bool test(PhysicsShape* shapeA, PhysicsShape* shapeB); virtual bool test(PhysicsShape* shapeA, PhysicsShape* shapeB) override;
virtual EventListenerPhysicsContactWithGroup* clone() override; virtual EventListenerPhysicsContactWithGroup* clone() override;
protected: protected:

View File

@ -155,14 +155,14 @@ PhysicsJointDistance::~PhysicsJointDistance()
} }
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
PhysicsBodyInfo* PhysicsJoint::bodyInfo(PhysicsBody* body) const PhysicsBodyInfo* PhysicsJoint::getBodyInfo(PhysicsBody* body) const
{ {
return body->_info; return body->_info;
} }
Node* PhysicsJoint::bodyOwner(PhysicsBody* body) const Node* PhysicsJoint::getBodyNode(PhysicsBody* body) const
{ {
return body->_owner; return body->_node;
} }
@ -198,17 +198,17 @@ bool PhysicsJointFixed::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr)
{ {
CC_BREAK_IF(!PhysicsJoint::init(a, b)); CC_BREAK_IF(!PhysicsJoint::init(a, b));
bodyOwner(a)->setPosition(anchr); getBodyNode(a)->setPosition(anchr);
bodyOwner(b)->setPosition(anchr); getBodyNode(b)->setPosition(anchr);
// add a pivot joint to fixed two body together // add a pivot joint to fixed two body together
cpConstraint* joint = cpPivotJointNew(bodyInfo(a)->body, bodyInfo(b)->body, cpConstraint* joint = cpPivotJointNew(getBodyInfo(a)->body, getBodyInfo(b)->body,
PhysicsHelper::point2cpv(anchr)); PhysicsHelper::point2cpv(anchr));
CC_BREAK_IF(joint == nullptr); CC_BREAK_IF(joint == nullptr);
_info->add(joint); _info->add(joint);
// add a gear joint to make two body have the same rotation. // add a gear joint to make two body have the same rotation.
joint = cpGearJointNew(bodyInfo(a)->body, bodyInfo(b)->body, 0, 1); joint = cpGearJointNew(getBodyInfo(a)->body, getBodyInfo(b)->body, 0, 1);
CC_BREAK_IF(joint == nullptr); CC_BREAK_IF(joint == nullptr);
_info->add(joint); _info->add(joint);
@ -238,7 +238,7 @@ bool PhysicsJointPin::init(PhysicsBody *a, PhysicsBody *b, const Point& anchr)
do do
{ {
CC_BREAK_IF(!PhysicsJoint::init(a, b)); CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpPivotJointNew(bodyInfo(a)->body, bodyInfo(b)->body, cpConstraint* joint = cpPivotJointNew(getBodyInfo(a)->body, getBodyInfo(b)->body,
PhysicsHelper::point2cpv(anchr)); PhysicsHelper::point2cpv(anchr));
CC_BREAK_IF(joint == nullptr); CC_BREAK_IF(joint == nullptr);
@ -258,7 +258,7 @@ void PhysicsJointPin::setMaxForce(float force)
_info->joints.front()->maxForce = PhysicsHelper::float2cpfloat(force); _info->joints.front()->maxForce = PhysicsHelper::float2cpfloat(force);
} }
float PhysicsJointPin::getMaxForce() float PhysicsJointPin::getMaxForce() const
{ {
return PhysicsHelper::cpfloat2float(_info->joints.front()->maxForce); return PhysicsHelper::cpfloat2float(_info->joints.front()->maxForce);
} }
@ -282,7 +282,7 @@ bool PhysicsJointSliding::init(PhysicsBody* a, PhysicsBody* b, const Point& groo
{ {
CC_BREAK_IF(!PhysicsJoint::init(a, b)); CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpGrooveJointNew(bodyInfo(a)->body, bodyInfo(b)->body, cpConstraint* joint = cpGrooveJointNew(getBodyInfo(a)->body, getBodyInfo(b)->body,
PhysicsHelper::point2cpv(grooveA), PhysicsHelper::point2cpv(grooveA),
PhysicsHelper::point2cpv(grooveB), PhysicsHelper::point2cpv(grooveB),
PhysicsHelper::point2cpv(anchr)); PhysicsHelper::point2cpv(anchr));
@ -317,7 +317,7 @@ bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1
{ {
CC_BREAK_IF(!PhysicsJoint::init(a, b)); CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpSlideJointNew(bodyInfo(a)->body, bodyInfo(b)->body, cpConstraint* joint = cpSlideJointNew(getBodyInfo(a)->body, getBodyInfo(b)->body,
PhysicsHelper::point2cpv(anchr1), PhysicsHelper::point2cpv(anchr1),
PhysicsHelper::point2cpv(anchr2), PhysicsHelper::point2cpv(anchr2),
0, 0,
@ -333,7 +333,7 @@ bool PhysicsJointLimit::init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1
return false; return false;
} }
float PhysicsJointLimit::getMin() float PhysicsJointLimit::getMin() const
{ {
return PhysicsHelper::cpfloat2float(cpSlideJointGetMin(_info->joints.front())); return PhysicsHelper::cpfloat2float(cpSlideJointGetMin(_info->joints.front()));
} }
@ -343,7 +343,7 @@ void PhysicsJointLimit::setMin(float min)
cpSlideJointSetMin(_info->joints.front(), PhysicsHelper::float2cpfloat(min)); cpSlideJointSetMin(_info->joints.front(), PhysicsHelper::float2cpfloat(min));
} }
float PhysicsJointLimit::getMax() float PhysicsJointLimit::getMax() const
{ {
return PhysicsHelper::cpfloat2float(cpSlideJointGetMax(_info->joints.front())); return PhysicsHelper::cpfloat2float(cpSlideJointGetMax(_info->joints.front()));
} }
@ -372,8 +372,8 @@ bool PhysicsJointDistance::init(PhysicsBody* a, PhysicsBody* b, const Point& anc
{ {
CC_BREAK_IF(!PhysicsJoint::init(a, b)); CC_BREAK_IF(!PhysicsJoint::init(a, b));
cpConstraint* joint = cpPinJointNew(bodyInfo(a)->body, cpConstraint* joint = cpPinJointNew(getBodyInfo(a)->body,
bodyInfo(b)->body, getBodyInfo(b)->body,
PhysicsHelper::point2cpv(anchr1), PhysicsHelper::point2cpv(anchr2)); PhysicsHelper::point2cpv(anchr1), PhysicsHelper::point2cpv(anchr2));
CC_BREAK_IF(joint == nullptr); CC_BREAK_IF(joint == nullptr);

View File

@ -47,13 +47,13 @@ protected:
virtual ~PhysicsJoint() = 0; virtual ~PhysicsJoint() = 0;
public: public:
PhysicsBody* getBodyA() { return _bodyA; } PhysicsBody* getBodyA() const { return _bodyA; }
PhysicsBody* getBodyB() { return _bodyB; } PhysicsBody* getBodyB() const { return _bodyB; }
inline int getTag() { return _tag; } inline int getTag() const { return _tag; }
inline void setTag(int tag) { _tag = tag; } inline void setTag(int tag) { _tag = tag; }
inline bool isEnable() { return _enable; } inline bool isEnable() const { return _enable; }
void setEnable(bool enable); void setEnable(bool enable);
inline bool isCollisionEnable() { return _collisionEnable; } inline bool isCollisionEnable() const { return _collisionEnable; }
void setCollisionEnable(bool enable); void setCollisionEnable(bool enable);
protected: protected:
@ -62,8 +62,8 @@ protected:
/** /**
* PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody. * PhysicsShape is PhysicsBody's friend class, but all the subclasses isn't. so this method is use for subclasses to catch the bodyInfo from PhysicsBody.
*/ */
PhysicsBodyInfo* bodyInfo(PhysicsBody* body) const; PhysicsBodyInfo* getBodyInfo(PhysicsBody* body) const;
Node* bodyOwner(PhysicsBody* body) const; Node* getBodyNode(PhysicsBody* body) const;
protected: protected:
PhysicsBody* _bodyA; PhysicsBody* _bodyA;
@ -133,9 +133,9 @@ class PhysicsJointLimit : public PhysicsJoint
public: public:
PhysicsJointLimit* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2); PhysicsJointLimit* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
float getMin(); float getMin() const;
void setMin(float min); void setMin(float min);
float getMax(); float getMax() const;
void setMax(float max); void setMax(float max);
protected: protected:
@ -155,7 +155,7 @@ public:
static PhysicsJointPin* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr); static PhysicsJointPin* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
void setMaxForce(float force); void setMaxForce(float force);
float getMaxForce(); float getMaxForce() const;
protected: protected:
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr); bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr);

View File

@ -353,7 +353,7 @@ float PhysicsShapeCircle::calculateDefaultMoment()
cpCircleShapeGetOffset(shape))); cpCircleShapeGetOffset(shape)));
} }
float PhysicsShapeCircle::getRadius() float PhysicsShapeCircle::getRadius() const
{ {
return PhysicsHelper::cpfloat2float(cpCircleShapeGetRadius(_info->shapes.front())); return PhysicsHelper::cpfloat2float(cpCircleShapeGetRadius(_info->shapes.front()));
} }
@ -405,12 +405,12 @@ bool PhysicsShapeEdgeSegment::init(Point a, Point b, PhysicsMaterial material/*
return false; return false;
} }
Point PhysicsShapeEdgeSegment::getPointA() Point PhysicsShapeEdgeSegment::getPointA() const
{ {
return PhysicsHelper::cpv2point(((cpSegmentShape*)(_info->shapes.front()))->ta); return PhysicsHelper::cpv2point(((cpSegmentShape*)(_info->shapes.front()))->ta);
} }
Point PhysicsShapeEdgeSegment::getPointB() Point PhysicsShapeEdgeSegment::getPointB() const
{ {
return PhysicsHelper::cpv2point(((cpSegmentShape*)(_info->shapes.front()))->tb); return PhysicsHelper::cpv2point(((cpSegmentShape*)(_info->shapes.front()))->tb);
} }
@ -503,7 +503,7 @@ float PhysicsShapeBox::calculateDefaultMoment()
: PhysicsHelper::cpfloat2float(cpMomentForPoly(_mass, ((cpPolyShape*)shape)->numVerts, ((cpPolyShape*)shape)->verts, cpvzero)); : PhysicsHelper::cpfloat2float(cpMomentForPoly(_mass, ((cpPolyShape*)shape)->numVerts, ((cpPolyShape*)shape)->verts, cpvzero));
} }
Point* PhysicsShapeBox::getPoints(Point* points) Point* PhysicsShapeBox::getPoints(Point* points) const
{ {
cpShape* shape = _info->shapes.front(); cpShape* shape = _info->shapes.front();
return PhysicsHelper::cpvs2points(((cpPolyShape*)shape)->verts, points, ((cpPolyShape*)shape)->numVerts); return PhysicsHelper::cpvs2points(((cpPolyShape*)shape)->verts, points, ((cpPolyShape*)shape)->numVerts);
@ -511,7 +511,7 @@ Point* PhysicsShapeBox::getPoints(Point* points)
return points; return points;
} }
Size PhysicsShapeBox::getSize() Size PhysicsShapeBox::getSize() const
{ {
cpShape* shape = _info->shapes.front(); cpShape* shape = _info->shapes.front();
return PhysicsHelper::cpv2size(cpv(cpvdist(cpPolyShapeGetVert(shape, 0), cpPolyShapeGetVert(shape, 1)), return PhysicsHelper::cpv2size(cpv(cpvdist(cpPolyShapeGetVert(shape, 0), cpPolyShapeGetVert(shape, 1)),
@ -594,13 +594,13 @@ float PhysicsShapePolygon::calculateDefaultMoment()
: PhysicsHelper::cpfloat2float(cpMomentForPoly(_mass, ((cpPolyShape*)shape)->numVerts, ((cpPolyShape*)shape)->verts, cpvzero)); : PhysicsHelper::cpfloat2float(cpMomentForPoly(_mass, ((cpPolyShape*)shape)->numVerts, ((cpPolyShape*)shape)->verts, cpvzero));
} }
Point* PhysicsShapePolygon::getPoints(Point* points) Point* PhysicsShapePolygon::getPoints(Point* points) const
{ {
cpShape* shape = _info->shapes.front(); cpShape* shape = _info->shapes.front();
return PhysicsHelper::cpvs2points(((cpPolyShape*)shape)->verts, points, ((cpPolyShape*)shape)->numVerts); return PhysicsHelper::cpvs2points(((cpPolyShape*)shape)->verts, points, ((cpPolyShape*)shape)->numVerts);
} }
int PhysicsShapePolygon::getPointsCount() int PhysicsShapePolygon::getPointsCount() const
{ {
return ((cpPolyShape*)_info->shapes.front())->numVerts; return ((cpPolyShape*)_info->shapes.front())->numVerts;
} }
@ -715,7 +715,7 @@ Point PhysicsShapeEdgePolygon::getCenter()
return _center; return _center;
} }
int PhysicsShapeEdgePolygon::getPointsCount() int PhysicsShapeEdgePolygon::getPointsCount() const
{ {
return _info->shapes.size() + 1; return _info->shapes.size() + 1;
} }
@ -776,7 +776,7 @@ Point PhysicsShapeEdgeChain::getCenter()
return _center; return _center;
} }
int PhysicsShapeEdgeChain::getPointsCount() int PhysicsShapeEdgeChain::getPointsCount() const
{ {
return _info->shapes.size() + 1; return _info->shapes.size() + 1;
} }

View File

@ -156,8 +156,8 @@ public:
float calculateDefaultArea() override; float calculateDefaultArea() override;
float calculateDefaultMoment() override; float calculateDefaultMoment() override;
float getRadius(); float getRadius() const;
Point getOffset(); Point getOffset() override;
protected: protected:
bool init(float radius, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, Point offset = Point(0, 0)); bool init(float radius, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, Point offset = Point(0, 0));
@ -177,8 +177,8 @@ public:
float calculateDefaultArea() override; float calculateDefaultArea() override;
float calculateDefaultMoment() override; float calculateDefaultMoment() override;
Point* getPoints(Point* points); Point* getPoints(Point* points) const;
Size getSize(); Size getSize() const;
Point getOffset() override { return _offset; } Point getOffset() override { return _offset; }
protected: protected:
@ -203,8 +203,8 @@ public:
float calculateDefaultArea() override; float calculateDefaultArea() override;
float calculateDefaultMoment() override; float calculateDefaultMoment() override;
Point* getPoints(Point* points); Point* getPoints(Point* points) const;
int getPointsCount(); int getPointsCount() const;
Point getCenter() override; Point getCenter() override;
protected: protected:
bool init(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, Point offset = Point(0, 0)); bool init(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, Point offset = Point(0, 0));
@ -223,8 +223,8 @@ class PhysicsShapeEdgeSegment : public PhysicsShape
public: public:
static PhysicsShapeEdgeSegment* create(Point a, Point b, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); static PhysicsShapeEdgeSegment* create(Point a, Point b, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
Point getPointA(); Point getPointA() const;
Point getPointB(); Point getPointB() const;
Point getCenter() override; Point getCenter() override;
protected: protected:
@ -246,8 +246,8 @@ class PhysicsShapeEdgeBox : public PhysicsShape
public: public:
static PhysicsShapeEdgeBox* create(Size size, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 0, Point offset = Point(0, 0)); static PhysicsShapeEdgeBox* create(Size size, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 0, Point offset = Point(0, 0));
Point getOffset() override { return _offset; } Point getOffset() override { return _offset; }
Point* getPoints(Point* points); Point* getPoints(Point* points) const;
int getPointsCount(); int getPointsCount() const;
protected: protected:
bool init(Size size, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1, Point offset = Point(0, 0)); bool init(Size size, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1, Point offset = Point(0, 0));
@ -268,8 +268,8 @@ class PhysicsShapeEdgePolygon : public PhysicsShape
public: public:
static PhysicsShapeEdgePolygon* create(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); static PhysicsShapeEdgePolygon* create(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
Point getCenter() override; Point getCenter() override;
Point* getPoints(Point* points); Point* getPoints(Point* points) const;
int getPointsCount(); int getPointsCount() const;
protected: protected:
bool init(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); bool init(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
@ -290,8 +290,8 @@ class PhysicsShapeEdgeChain : public PhysicsShape
public: public:
static PhysicsShapeEdgeChain* create(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); static PhysicsShapeEdgeChain* create(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
Point getCenter() override; Point getCenter() override;
Point* getPoints(Point* points); Point* getPoints(Point* points) const;
int getPointsCount(); int getPointsCount() const;
protected: protected:
bool init(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1); bool init(Point* points, int count, PhysicsMaterial material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);

View File

@ -60,6 +60,8 @@
NS_CC_BEGIN NS_CC_BEGIN
extern const char* PHYSICSCONTACT_EVENT_NAME;
#if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK) #if (CC_PHYSICS_ENGINE == CC_PHYSICS_CHIPMUNK)
const float PHYSICS_INFINITY = INFINITY; const float PHYSICS_INFINITY = INFINITY;
@ -269,7 +271,8 @@ PhysicsShape* PhysicsWorld::addShape(PhysicsShape* shape)
if (cpBodyIsStatic(shape->getBody()->_info->body)) if (cpBodyIsStatic(shape->getBody()->_info->body))
{ {
cpSpaceAddStaticShape(_info->space, cps); cpSpaceAddStaticShape(_info->space, cps);
}else }
else
{ {
cpSpaceAddShape(_info->space, cps); cpSpaceAddShape(_info->space, cps);
} }
@ -473,7 +476,8 @@ void PhysicsWorld::drawWithJoint(DrawNode* node, PhysicsJoint* joint)
cpBody *body_b = constraint->b; cpBody *body_b = constraint->b;
const cpConstraintClass *klass = constraint->klass_private; const cpConstraintClass *klass = constraint->klass_private;
if(klass == cpPinJointGetClass()){ if(klass == cpPinJointGetClass())
{
cpPinJoint *joint = (cpPinJoint *)constraint; cpPinJoint *joint = (cpPinJoint *)constraint;
cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot));
@ -482,7 +486,9 @@ void PhysicsWorld::drawWithJoint(DrawNode* node, PhysicsJoint* joint)
node->drawSegment(PhysicsHelper::cpv2point(a), PhysicsHelper::cpv2point(b), 1, Color4F(0.0f, 0.0f, 1.0f, 1.0f)); node->drawSegment(PhysicsHelper::cpv2point(a), PhysicsHelper::cpv2point(b), 1, Color4F(0.0f, 0.0f, 1.0f, 1.0f));
node->drawDot(PhysicsHelper::cpv2point(a), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(a), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
node->drawDot(PhysicsHelper::cpv2point(b), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(b), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
} else if(klass == cpSlideJointGetClass()){ }
else if(klass == cpSlideJointGetClass())
{
cpSlideJoint *joint = (cpSlideJoint *)constraint; cpSlideJoint *joint = (cpSlideJoint *)constraint;
cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot));
@ -491,7 +497,9 @@ void PhysicsWorld::drawWithJoint(DrawNode* node, PhysicsJoint* joint)
node->drawSegment(PhysicsHelper::cpv2point(a), PhysicsHelper::cpv2point(b), 1, Color4F(0.0f, 0.0f, 1.0f, 1.0f)); node->drawSegment(PhysicsHelper::cpv2point(a), PhysicsHelper::cpv2point(b), 1, Color4F(0.0f, 0.0f, 1.0f, 1.0f));
node->drawDot(PhysicsHelper::cpv2point(a), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(a), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
node->drawDot(PhysicsHelper::cpv2point(b), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(b), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
} else if(klass == cpPivotJointGetClass()){ }
else if(klass == cpPivotJointGetClass())
{
cpPivotJoint *joint = (cpPivotJoint *)constraint; cpPivotJoint *joint = (cpPivotJoint *)constraint;
cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot)); cpVect a = cpvadd(body_a->p, cpvrotate(joint->anchr1, body_a->rot));
@ -499,7 +507,9 @@ void PhysicsWorld::drawWithJoint(DrawNode* node, PhysicsJoint* joint)
node->drawDot(PhysicsHelper::cpv2point(a), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(a), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
node->drawDot(PhysicsHelper::cpv2point(b), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(b), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
} else if(klass == cpGrooveJointGetClass()){ }
else if(klass == cpGrooveJointGetClass())
{
cpGrooveJoint *joint = (cpGrooveJoint *)constraint; cpGrooveJoint *joint = (cpGrooveJoint *)constraint;
cpVect a = cpvadd(body_a->p, cpvrotate(joint->grv_a, body_a->rot)); cpVect a = cpvadd(body_a->p, cpvrotate(joint->grv_a, body_a->rot));
@ -508,7 +518,9 @@ void PhysicsWorld::drawWithJoint(DrawNode* node, PhysicsJoint* joint)
node->drawSegment(PhysicsHelper::cpv2point(a), PhysicsHelper::cpv2point(b), 1, Color4F(0.0f, 0.0f, 1.0f, 1.0f)); node->drawSegment(PhysicsHelper::cpv2point(a), PhysicsHelper::cpv2point(b), 1, Color4F(0.0f, 0.0f, 1.0f, 1.0f));
node->drawDot(PhysicsHelper::cpv2point(c), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f)); node->drawDot(PhysicsHelper::cpv2point(c), 2, Color4F(0.0f, 1.0f, 0.0f, 1.0f));
} else if(klass == cpDampedSpringGetClass()){ }
else if(klass == cpDampedSpringGetClass())
{
} }
} }
@ -607,7 +619,8 @@ int PhysicsWorld::collisionBeginCallback(PhysicsContact& contact)
if (shapeA->getGroup() != 0 && shapeA->getGroup() == shapeB->getGroup()) if (shapeA->getGroup() != 0 && shapeA->getGroup() == shapeB->getGroup())
{ {
ret = shapeA->getGroup() > 0; ret = shapeA->getGroup() > 0;
}else }
else
{ {
if ((shapeA->getCategoryBitmask() & shapeB->getCollisionBitmask()) == 0 if ((shapeA->getCategoryBitmask() & shapeB->getCollisionBitmask()) == 0
|| (shapeB->getCategoryBitmask() & shapeA->getCollisionBitmask()) == 0) || (shapeB->getCategoryBitmask() & shapeA->getCollisionBitmask()) == 0)
@ -627,6 +640,11 @@ int PhysicsWorld::collisionBeginCallback(PhysicsContact& contact)
int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact) int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact)
{ {
if (!contact.getNotify())
{
return true;
}
contact.setEventCode(PhysicsContact::EventCode::PRESOLVE); contact.setEventCode(PhysicsContact::EventCode::PRESOLVE);
contact.setWorld(this); contact.setWorld(this);
EventCustom event(PHYSICSCONTACT_EVENT_NAME); EventCustom event(PHYSICSCONTACT_EVENT_NAME);
@ -638,6 +656,11 @@ int PhysicsWorld::collisionPreSolveCallback(PhysicsContact& contact)
void PhysicsWorld::collisionPostSolveCallback(PhysicsContact& contact) void PhysicsWorld::collisionPostSolveCallback(PhysicsContact& contact)
{ {
if (!contact.getNotify())
{
return;
}
contact.setEventCode(PhysicsContact::EventCode::POSTSOLVE); contact.setEventCode(PhysicsContact::EventCode::POSTSOLVE);
contact.setWorld(this); contact.setWorld(this);
EventCustom event(PHYSICSCONTACT_EVENT_NAME); EventCustom event(PHYSICSCONTACT_EVENT_NAME);
@ -647,6 +670,11 @@ void PhysicsWorld::collisionPostSolveCallback(PhysicsContact& contact)
void PhysicsWorld::collisionSeparateCallback(PhysicsContact& contact) void PhysicsWorld::collisionSeparateCallback(PhysicsContact& contact)
{ {
if (!contact.getNotify())
{
return;
}
contact.setEventCode(PhysicsContact::EventCode::SEPERATE); contact.setEventCode(PhysicsContact::EventCode::SEPERATE);
contact.setWorld(this); contact.setWorld(this);
EventCustom event(PHYSICSCONTACT_EVENT_NAME); EventCustom event(PHYSICSCONTACT_EVENT_NAME);
@ -680,7 +708,7 @@ void PhysicsWorld::rayCast(PhysicsRayCastCallback& callback, Point point1, Point
{ {
if (callback.report != nullptr) if (callback.report != nullptr)
{ {
RayCastCallbackInfo info = {this, &callback, point1, point2, data}; RayCastCallbackInfo info = { this, &callback, point1, point2, data };
PhysicsWorldCallback::continues = true; PhysicsWorldCallback::continues = true;
cpSpaceSegmentQuery(this->_info->space, cpSpaceSegmentQuery(this->_info->space,
@ -710,7 +738,7 @@ void PhysicsWorld::rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void
} }
} }
Array* PhysicsWorld::getShapesAtPoint(Point point) Array* PhysicsWorld::getShapesAtPoint(Point point) const
{ {
Array* arr = Array::create(); Array* arr = Array::create();
cpSpaceNearestPointQuery(this->_info->space, cpSpaceNearestPointQuery(this->_info->space,
@ -724,7 +752,7 @@ Array* PhysicsWorld::getShapesAtPoint(Point point)
return arr; return arr;
} }
PhysicsShape* PhysicsWorld::getShapeAtPoint(Point point) PhysicsShape* PhysicsWorld::getShapeAtPoint(Point point) const
{ {
cpShape* shape = cpSpaceNearestPointQueryNearest(this->_info->space, cpShape* shape = cpSpaceNearestPointQueryNearest(this->_info->space,
PhysicsHelper::point2cpv(point), PhysicsHelper::point2cpv(point),
@ -741,7 +769,7 @@ Array* PhysicsWorld::getAllBodies() const
return _bodies; return _bodies;
} }
PhysicsBody* PhysicsWorld::getBodyByTag(int tag) PhysicsBody* PhysicsWorld::getBodyByTag(int tag) const
{ {
for (auto body : *_bodies) for (auto body : *_bodies)
{ {

View File

@ -94,24 +94,24 @@ public:
void rayCast(PhysicsRayCastCallback& callback, Point point1, Point point2, void* data); void rayCast(PhysicsRayCastCallback& callback, Point point1, Point point2, void* data);
void rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void* data); void rectQuery(PhysicsRectQueryCallback& callback, Rect rect, void* data);
Array* getShapesAtPoint(Point point); Array* getShapesAtPoint(Point point) const;
PhysicsShape* getShapeAtPoint(Point point); PhysicsShape* getShapeAtPoint(Point point) const;
Array* getAllBodies() const; Array* getAllBodies() const;
PhysicsBody* getBodyByTag(int tag); PhysicsBody* getBodyByTag(int tag) const;
/** Register a listener to receive contact callbacks*/ /** Register a listener to receive contact callbacks*/
//inline void registerContactListener(EventListenerPhysicsContact* delegate) { _listener = delegate; } //inline void registerContactListener(EventListenerPhysicsContact* delegate) { _listener = delegate; }
/** Unregister a listener. */ /** Unregister a listener. */
//inline void unregisterContactListener() { _listener = nullptr; } //inline void unregisterContactListener() { _listener = nullptr; }
inline Scene& getScene() { return *_scene; } inline Scene& getScene() const { return *_scene; }
/** get the gravity value */ /** get the gravity value */
inline Point getGravity() { return _gravity; } inline Point getGravity() const { return _gravity; }
/** set the gravity value */ /** set the gravity value */
void setGravity(Point gravity); void setGravity(Point gravity);
/** test the debug draw is enabled */ /** test the debug draw is enabled */
inline bool isDebugDraw() { return _debugDraw; } inline bool isDebugDraw() const { return _debugDraw; }
/** set the debug draw */ /** set the debug draw */
inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; } inline void setDebugDraw(bool debugDraw) { _debugDraw = debugDraw; }

View File

@ -13,6 +13,7 @@ namespace
CL(PhysicsDemoJoints), CL(PhysicsDemoJoints),
CL(PhysicsDemoActions), CL(PhysicsDemoActions),
CL(PhysicsDemoPump), CL(PhysicsDemoPump),
CL(PhysicsDemoOneWayPlatform),
}; };
static int sceneIdx=-1; static int sceneIdx=-1;
@ -974,7 +975,7 @@ void PhysicsDemoPump::update(float delta)
PhysicsBody* body = dynamic_cast<PhysicsBody*>(obj); PhysicsBody* body = dynamic_cast<PhysicsBody*>(obj);
if (body->getTag() == DRAG_BODYS_TAG && body->getPosition().y < 0.0f) if (body->getTag() == DRAG_BODYS_TAG && body->getPosition().y < 0.0f)
{ {
body->getOwner()->setPosition(VisibleRect::leftTop() + Point(75 + CCRANDOM_0_1() * 90, 0)); body->getNode()->setPosition(VisibleRect::leftTop() + Point(75 + CCRANDOM_0_1() * 90, 0));
body->setVelocity(Point(0, 0)); body->setVelocity(Point(0, 0));
} }
} }
@ -992,7 +993,7 @@ void PhysicsDemoPump::update(float delta)
} }
gear->setAngularVelocity(_rotationV); gear->setAngularVelocity(_rotationV);
_rotationV *= 0.995; _rotationV *= 0.995f;
} }
} }
@ -1039,11 +1040,13 @@ void PhysicsDemoOneWayPlatform::onEnter()
this->addChild(ground); this->addChild(ground);
auto platform = Node::create(); auto platform = Node::create();
platform->setPhysicsBody(PhysicsBody::createEdgeBox(Size(200, 50))); platform->setPhysicsBody(PhysicsBody::createBox(Size(200, 50)));
platform->getPhysicsBody()->setDynamic(false);
platform->setPosition(VisibleRect::center()); platform->setPosition(VisibleRect::center());
this->addChild(platform); this->addChild(platform);
auto ball = makeBall(VisibleRect::center() + Point(0, 50), 5); auto ball = makeBall(VisibleRect::center() - Point(0, 50), 5);
ball->getPhysicsBody()->setVelocity(Point(0, 200));
this->addChild(ball); this->addChild(ball);
auto contactListener = EventListenerPhysicsContactWithBodies::create(platform->getPhysicsBody(), ball->getPhysicsBody()); auto contactListener = EventListenerPhysicsContactWithBodies::create(platform->getPhysicsBody(), ball->getPhysicsBody());