123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- #ifndef __CCPHYSICS_JOINT_H__
- #define __CCPHYSICS_JOINT_H__
- #include "base/ccConfig.h"
- #if CC_USE_PHYSICS
- #include "base/CCRef.h"
- #include "math/CCGeometry.h"
- struct cpConstraint;
- NS_CC_BEGIN
- class Node;
- class PhysicsBody;
- class PhysicsWorld;
- class CC_DLL PhysicsJoint
- {
- protected:
- PhysicsJoint();
- virtual ~PhysicsJoint() = 0;
- public:
-
- PhysicsBody* getBodyA() const { return _bodyA; }
-
-
- PhysicsBody* getBodyB() const { return _bodyB; }
-
- PhysicsWorld* getWorld() const { return _world; }
-
-
- int getTag() const { return _tag; }
-
-
- void setTag(int tag) { _tag = tag; }
-
-
- bool isEnabled() const { return _enable; }
-
- void setEnable(bool enable);
-
-
- bool isCollisionEnabled() const { return _collisionEnable; }
-
-
- void setCollisionEnable(bool enable);
-
-
- void removeFormWorld();
-
- void setMaxForce(float force);
-
-
- float getMaxForce() const { return _maxForce; }
- protected:
- bool init(PhysicsBody* a, PhysicsBody* b);
- bool initJoint();
-
-
- virtual bool createConstraints() { return false; }
- std::vector<cpConstraint*> _cpConstraints;
- PhysicsBody* _bodyA;
- PhysicsBody* _bodyB;
- PhysicsWorld* _world;
- bool _enable;
- bool _collisionEnable;
- bool _destroyMark;
- int _tag;
- float _maxForce;
- bool _initDirty;
- friend class PhysicsBody;
- friend class PhysicsWorld;
- friend class PhysicsDebugDraw;
- };
- class CC_DLL PhysicsJointFixed : public PhysicsJoint
- {
- public:
-
- static PhysicsJointFixed* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointFixed() {}
- virtual ~PhysicsJointFixed() {}
- Vec2 _anchr;
- };
- class CC_DLL PhysicsJointLimit : public PhysicsJoint
- {
- public:
-
- static PhysicsJointLimit* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2);
-
-
- static PhysicsJointLimit* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float min, float max);
-
- Vec2 getAnchr1() const;
-
-
- void setAnchr1(const Vec2& anchr1);
-
-
- Vec2 getAnchr2() const;
-
-
- void setAnchr2(const Vec2& anchr2);
-
-
- float getMin() const;
-
- void setMin(float min);
-
-
- float getMax() const;
-
- void setMax(float max);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointLimit() {}
- virtual ~PhysicsJointLimit() {}
- Vec2 _anchr1;
- Vec2 _anchr2;
- float _min;
- float _max;
- };
- class CC_DLL PhysicsJointPin : public PhysicsJoint
- {
- public:
-
- static PhysicsJointPin* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& pivot);
-
- static PhysicsJointPin* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointPin() {}
- virtual ~PhysicsJointPin() {}
- bool _useSpecificAnchr;
- Vec2 _anchr1;
- Vec2 _anchr2;
- };
- class CC_DLL PhysicsJointDistance : public PhysicsJoint
- {
- public:
-
- static PhysicsJointDistance* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2);
-
- float getDistance() const;
-
- void setDistance(float distance);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointDistance() {}
- virtual ~PhysicsJointDistance() {}
- Vec2 _anchr1;
- Vec2 _anchr2;
- };
- class CC_DLL PhysicsJointSpring : public PhysicsJoint
- {
- public:
-
- static PhysicsJointSpring* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& anchr1, const Vec2& anchr2, float stiffness, float damping);
-
- Vec2 getAnchr1() const;
-
- void setAnchr1(const Vec2& anchr1);
-
- Vec2 getAnchr2() const;
-
- void setAnchr2(const Vec2& anchr2);
-
-
- float getRestLength() const;
-
-
- void setRestLength(float restLength);
-
-
- float getStiffness() const;
-
-
- void setStiffness(float stiffness);
-
-
- float getDamping() const;
-
-
- void setDamping(float damping);
-
- virtual bool createConstraints() override;
- protected:
- PhysicsJointSpring() {}
- virtual ~PhysicsJointSpring() {}
- Vec2 _anchr1;
- Vec2 _anchr2;
- float _stiffness;
- float _damping;
- };
- class CC_DLL PhysicsJointGroove : public PhysicsJoint
- {
- public:
-
- static PhysicsJointGroove* construct(PhysicsBody* a, PhysicsBody* b, const Vec2& grooveA, const Vec2& grooveB, const Vec2& anchr2);
-
- Vec2 getGrooveA() const;
-
- void setGrooveA(const Vec2& grooveA);
-
-
- Vec2 getGrooveB() const;
-
-
- void setGrooveB(const Vec2& grooveB);
-
-
- Vec2 getAnchr2() const;
-
-
- void setAnchr2(const Vec2& anchr2);
-
- virtual bool createConstraints() override;
- protected:
- PhysicsJointGroove() {}
- virtual ~PhysicsJointGroove() {}
- Vec2 _grooveA;
- Vec2 _grooveB;
- Vec2 _anchr2;
- };
- class CC_DLL PhysicsJointRotarySpring : public PhysicsJoint
- {
- public:
-
- static PhysicsJointRotarySpring* construct(PhysicsBody* a, PhysicsBody* b, float stiffness, float damping);
-
- float getRestAngle() const;
-
- void setRestAngle(float restAngle);
-
- float getStiffness() const;
-
-
- void setStiffness(float stiffness);
-
-
- float getDamping() const;
-
- void setDamping(float damping);
-
- virtual bool createConstraints() override;
- protected:
- PhysicsJointRotarySpring() {}
- virtual ~PhysicsJointRotarySpring() {}
- float _stiffness;
- float _damping;
- };
- class CC_DLL PhysicsJointRotaryLimit : public PhysicsJoint
- {
- public:
-
- static PhysicsJointRotaryLimit* construct(PhysicsBody* a, PhysicsBody* b, float min, float max);
-
- static PhysicsJointRotaryLimit* construct(PhysicsBody* a, PhysicsBody* b);
-
- float getMin() const;
-
-
- void setMin(float min);
-
-
- float getMax() const;
-
-
- void setMax(float max);
-
- virtual bool createConstraints() override;
- protected:
- PhysicsJointRotaryLimit() {}
- virtual ~PhysicsJointRotaryLimit() {}
- float _min;
- float _max;
- };
- class CC_DLL PhysicsJointRatchet : public PhysicsJoint
- {
- public:
-
- static PhysicsJointRatchet* construct(PhysicsBody* a, PhysicsBody* b, float phase, float ratchet);
-
- float getAngle() const;
-
-
- void setAngle(float angle);
-
-
- float getPhase() const;
-
-
- void setPhase(float phase);
-
-
- float getRatchet() const;
-
- void setRatchet(float ratchet);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointRatchet() {}
- virtual ~PhysicsJointRatchet() {}
- float _phase;
- float _ratchet;
- };
- class CC_DLL PhysicsJointGear : public PhysicsJoint
- {
- public:
-
- static PhysicsJointGear* construct(PhysicsBody* a, PhysicsBody* b, float phase, float ratio);
-
- float getPhase() const;
-
-
- void setPhase(float phase);
-
-
- float getRatio() const;
-
-
- void setRatio(float ratchet);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointGear() {}
- virtual ~PhysicsJointGear() {}
- float _phase;
- float _ratio;
- };
- class CC_DLL PhysicsJointMotor : public PhysicsJoint
- {
- public:
-
- static PhysicsJointMotor* construct(PhysicsBody* a, PhysicsBody* b, float rate);
-
- float getRate() const;
-
-
- void setRate(float rate);
- virtual bool createConstraints() override;
- protected:
- PhysicsJointMotor() {}
- virtual ~PhysicsJointMotor() {}
- float _rate;
- };
- NS_CC_END
- #endif
- #endif
|