2013-09-09 10:29:02 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-09-10 14:15:19 +08:00
|
|
|
#include "CCPhysicsSetting.h"
|
2013-09-10 17:36:49 +08:00
|
|
|
#ifdef CC_USE_PHYSICS
|
2013-09-10 14:15:19 +08:00
|
|
|
|
2013-09-09 10:29:02 +08:00
|
|
|
#ifndef __CCPHYSICS_JOINT_H__
|
|
|
|
#define __CCPHYSICS_JOINT_H__
|
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCObject.h"
|
|
|
|
#include "CCGeometry.h"
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class PhysicsBody;
|
2013-09-16 21:22:22 +08:00
|
|
|
class PhysicsJointInfo;
|
|
|
|
class PhysicsBodyInfo;
|
2013-09-09 10:29:02 +08:00
|
|
|
|
2013-09-17 16:27:43 +08:00
|
|
|
/*
|
|
|
|
* @brief An PhysicsJoint object connects two physics bodies together.
|
|
|
|
*/
|
2013-10-28 11:08:41 +08:00
|
|
|
class PhysicsJoint
|
2013-09-09 10:29:02 +08:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
PhysicsJoint();
|
2013-09-16 21:22:22 +08:00
|
|
|
virtual ~PhysicsJoint() = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PhysicsBody* getBodyA() { return _bodyA; }
|
|
|
|
PhysicsBody* getBodyB() { return _bodyB; }
|
2013-09-29 09:39:20 +08:00
|
|
|
inline int getTag() { return _tag; }
|
|
|
|
inline void setTag(int tag) { _tag = tag; }
|
|
|
|
inline bool isEnable() { return _enable; }
|
|
|
|
void setEnable(bool enable);
|
2013-10-18 15:34:13 +08:00
|
|
|
inline bool isCollisionEnable() { return _collisionEnable; }
|
|
|
|
void setCollisionEnable(bool enable);
|
2013-09-16 21:22:22 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool init(PhysicsBody* a, PhysicsBody* b);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2013-10-28 16:17:19 +08:00
|
|
|
Node* bodyOwner(PhysicsBody* body) const;
|
2013-09-09 10:29:02 +08:00
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
protected:
|
2013-09-09 10:29:02 +08:00
|
|
|
PhysicsBody* _bodyA;
|
|
|
|
PhysicsBody* _bodyB;
|
2013-09-16 21:22:22 +08:00
|
|
|
PhysicsJointInfo* _info;
|
2013-09-29 09:39:20 +08:00
|
|
|
bool _enable;
|
2013-10-18 15:34:13 +08:00
|
|
|
bool _collisionEnable;
|
2013-09-29 09:39:20 +08:00
|
|
|
int _tag;
|
2013-09-16 21:22:22 +08:00
|
|
|
|
|
|
|
friend class PhysicsBody;
|
2013-09-29 09:39:20 +08:00
|
|
|
friend class PhysicsWorld;
|
2013-09-09 10:29:02 +08:00
|
|
|
};
|
|
|
|
|
2013-09-17 16:27:43 +08:00
|
|
|
/*
|
|
|
|
* @brief A fixed joint fuses the two bodies together at a reference point. Fixed joints are useful for creating complex shapes that can be broken apart later.
|
|
|
|
*/
|
2013-09-09 10:29:02 +08:00
|
|
|
class PhysicsJointFixed : public PhysicsJoint
|
|
|
|
{
|
|
|
|
public:
|
2013-10-28 16:17:19 +08:00
|
|
|
static PhysicsJointFixed* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
2013-09-16 21:22:22 +08:00
|
|
|
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PhysicsJointFixed();
|
2013-09-16 21:22:22 +08:00
|
|
|
virtual ~PhysicsJointFixed();
|
2013-09-09 10:29:02 +08:00
|
|
|
};
|
|
|
|
|
2013-09-17 16:27:43 +08:00
|
|
|
/*
|
|
|
|
* @brief A sliding joint allows the two bodies to slide along a chosen axis.
|
|
|
|
*/
|
2013-09-09 10:29:02 +08:00
|
|
|
class PhysicsJointSliding : public PhysicsJoint
|
|
|
|
{
|
|
|
|
public:
|
2013-10-28 16:17:19 +08:00
|
|
|
static PhysicsJointSliding* create(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
2013-09-16 21:22:22 +08:00
|
|
|
bool init(PhysicsBody* a, PhysicsBody* b, const Point& grooveA, const Point& grooveB, const Point& anchr);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PhysicsJointSliding();
|
2013-09-16 21:22:22 +08:00
|
|
|
virtual ~PhysicsJointSliding();
|
2013-09-09 10:29:02 +08:00
|
|
|
};
|
|
|
|
|
2013-09-17 16:27:43 +08:00
|
|
|
/*
|
|
|
|
* @brief A spring joint connects the two bodies with a spring whose length is the initial distance between the two bodies.
|
|
|
|
*/
|
2013-09-09 10:29:02 +08:00
|
|
|
class PhysicsJointSpring : public PhysicsJoint
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PhysicsJointSpring* create();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PhysicsJointSpring();
|
2013-09-16 21:22:22 +08:00
|
|
|
virtual ~PhysicsJointSpring();
|
2013-09-09 10:29:02 +08:00
|
|
|
};
|
|
|
|
|
2013-09-17 16:27:43 +08:00
|
|
|
/*
|
|
|
|
* @brief A limit joint imposes a maximum distance between the two bodies, as if they were connected by a rope.
|
|
|
|
*/
|
2013-09-09 10:29:02 +08:00
|
|
|
class PhysicsJointLimit : public PhysicsJoint
|
|
|
|
{
|
|
|
|
public:
|
2013-10-18 15:34:13 +08:00
|
|
|
PhysicsJointLimit* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
|
|
|
|
|
|
|
float getMin();
|
|
|
|
void setMin(float min);
|
|
|
|
float getMax();
|
|
|
|
void setMax(float max);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
2013-10-18 15:34:13 +08:00
|
|
|
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr1, const Point& anchr2);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PhysicsJointLimit();
|
2013-09-16 21:22:22 +08:00
|
|
|
virtual ~PhysicsJointLimit();
|
2013-09-09 10:29:02 +08:00
|
|
|
};
|
|
|
|
|
2013-09-17 16:27:43 +08:00
|
|
|
/*
|
|
|
|
* @brief A pin joint allows the two bodies to independently rotate around the anchor point as if pinned together.
|
|
|
|
*/
|
2013-09-09 10:29:02 +08:00
|
|
|
class PhysicsJointPin : public PhysicsJoint
|
|
|
|
{
|
|
|
|
public:
|
2013-10-18 15:34:13 +08:00
|
|
|
static PhysicsJointPin* create(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
2013-10-28 16:17:19 +08:00
|
|
|
void setMaxForce(float force);
|
|
|
|
float getMaxForce();
|
|
|
|
|
2013-09-09 10:29:02 +08:00
|
|
|
protected:
|
2013-10-18 15:34:13 +08:00
|
|
|
bool init(PhysicsBody* a, PhysicsBody* b, const Point& anchr);
|
2013-09-09 10:29:02 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PhysicsJointPin();
|
2013-09-16 21:22:22 +08:00
|
|
|
virtual ~PhysicsJointPin();
|
2013-09-09 10:29:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2013-09-09 10:40:31 +08:00
|
|
|
#endif // __CCPHYSICS_JOINT_H__
|
2013-09-10 14:15:19 +08:00
|
|
|
|
2013-09-10 17:36:49 +08:00
|
|
|
#endif // CC_USE_PHYSICS
|