123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591 |
- #ifndef __PHYSICS_3D_CONSTRAINT_H__
- #define __PHYSICS_3D_CONSTRAINT_H__
- #include "math/CCMath.h"
- #include "base/CCRef.h"
- #include "base/ccConfig.h"
- #if CC_USE_3D_PHYSICS
- #if (CC_ENABLE_BULLET_INTEGRATION)
- class btTypedConstraint;
- NS_CC_BEGIN
- class Physics3DRigidBody;
- class CC_DLL Physics3DConstraint : public Ref
- {
- public:
- enum class ConstraintType
- {
- UNKNOWN,
- POINT_TO_POINT,
- HINGE,
- SLIDER,
- CONE_TWIST,
- SIX_DOF,
- };
-
- float getBreakingImpulse() const;
-
-
- void setBreakingImpulse(float impulse);
-
-
- bool isEnabled() const;
-
-
- void setEnabled(bool enabled);
-
-
- Physics3DRigidBody* getBodyA() const { return _bodyA; }
-
-
- Physics3DRigidBody* getBodyB() const { return _bodyB; }
-
-
- ConstraintType getConstraintType() const { return _type; }
-
-
- void setUserData(void* userData) { _userData = userData; }
-
-
- void* getUserData() const { return _userData; }
-
-
- int getOverrideNumSolverIterations() const;
-
-
- void setOverrideNumSolverIterations(int overrideNumIterations);
-
- #if (CC_ENABLE_BULLET_INTEGRATION)
- btTypedConstraint* getbtContraint() { return _constraint; }
- #endif
-
- protected:
-
- Physics3DConstraint();
- virtual ~Physics3DConstraint();
-
- btTypedConstraint* _constraint;
-
- Physics3DRigidBody* _bodyA;
- Physics3DRigidBody* _bodyB;
-
- ConstraintType _type;
- void* _userData;
- };
- class CC_DLL Physics3DPointToPointConstraint : public Physics3DConstraint
- {
- public:
-
- static Physics3DPointToPointConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotPointInA);
-
-
- static Physics3DPointToPointConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotPointInA, const cocos2d::Vec3& pivotPointInB);
-
-
- void setPivotPointInA(const cocos2d::Vec3& pivotA);
-
-
- void setPivotPointInB(const cocos2d::Vec3& pivotB);
-
-
- cocos2d::Vec3 getPivotPointInA() const;
-
-
- cocos2d::Vec3 getPivotPointInB() const;
-
- CC_CONSTRUCTOR_ACCESS:
- Physics3DPointToPointConstraint();
- virtual ~Physics3DPointToPointConstraint();
- bool init(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotPointInA);
- bool init(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotPointInA, const cocos2d::Vec3& pivotPointInB);
-
- };
- class CC_DLL Physics3DHingeConstraint : public Physics3DConstraint
- {
- public:
-
- static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Mat4& rbAFrame, bool useReferenceFrameA = false);
-
-
- static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Vec3& pivotInA, const cocos2d::Vec3& axisInA, bool useReferenceFrameA = false);
-
- static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Vec3& pivotInA,const cocos2d::Vec3& pivotInB, cocos2d::Vec3& axisInA, cocos2d::Vec3& axisInB, bool useReferenceFrameA = false);
-
-
- static Physics3DHingeConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& rbAFrame, const cocos2d::Mat4& rbBFrame, bool useReferenceFrameA = false);
-
-
- cocos2d::Mat4 getFrameOffsetA() const;
-
-
- cocos2d::Mat4 getFrameOffsetB() const;
-
-
- void setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
-
-
- void setAngularOnly(bool angularOnly);
-
-
- void enableAngularMotor(bool enableMotor, float targetVelocity, float maxMotorImpulse);
-
-
-
-
- void enableMotor(bool enableMotor);
-
- void setMaxMotorImpulse(float maxMotorImpulse);
-
- void setMotorTarget(const cocos2d::Quaternion& qAinB, float dt);
-
- void setMotorTarget(float targetAngle, float dt);
-
-
- void setLimit(float low, float high, float _softness = 0.9f, float _biasFactor = 0.3f, float _relaxationFactor = 1.0f);
-
- void setAxis(const cocos2d::Vec3& axisInA);
-
- float getLowerLimit() const;
-
- float getUpperLimit() const;
-
- float getHingeAngle() const;
-
- float getHingeAngle(const cocos2d::Mat4& transA, const cocos2d::Mat4& transB);
-
-
- cocos2d::Mat4 getAFrame() const;
-
- cocos2d::Mat4 getBFrame() const;
-
- bool getAngularOnly() const;
-
- bool getEnableAngularMotor() const;
-
- float getMotorTargetVelosity() const;
-
- float getMaxMotorImpulse() const;
-
-
- bool getUseFrameOffset() const;
-
- void setUseFrameOffset(bool frameOffsetOnOff);
-
- CC_CONSTRUCTOR_ACCESS:
- Physics3DHingeConstraint()
- {
- _type = ConstraintType::HINGE;
- }
- virtual ~Physics3DHingeConstraint(){}
- };
- class CC_DLL Physics3DSliderConstraint : public Physics3DConstraint
- {
- public:
-
- static Physics3DSliderConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInA, const cocos2d::Mat4& frameInB ,bool useLinearReferenceFrameA);
-
-
- cocos2d::Mat4 getFrameOffsetA() const;
-
- cocos2d::Mat4 getFrameOffsetB() const;
-
- float getLowerLinLimit() const;
-
- void setLowerLinLimit(float lowerLimit);
-
- float getUpperLinLimit() const;
-
- void setUpperLinLimit(float upperLimit);
-
- float getLowerAngLimit() const;
-
- void setLowerAngLimit(float lowerLimit);
-
- float getUpperAngLimit() const;
-
- void setUpperAngLimit(float upperLimit);
-
- bool getUseLinearReferenceFrameA() const;
-
- float getSoftnessDirLin() const;
- float getRestitutionDirLin() const;
- float getDampingDirLin() const;
- float getSoftnessDirAng() const;
- float getRestitutionDirAng() const;
- float getDampingDirAng() const;
- float getSoftnessLimLin() const;
- float getRestitutionLimLin() const;
- float getDampingLimLin() const;
- float getSoftnessLimAng() const;
- float getRestitutionLimAng() const;
- float getDampingLimAng() const;
- float getSoftnessOrthoLin() const;
- float getRestitutionOrthoLin() const;
- float getDampingOrthoLin() const;
- float getSoftnessOrthoAng() const;
- float getRestitutionOrthoAng() const;
- float getDampingOrthoAng() const;
- void setSoftnessDirLin(float softnessDirLin);
- void setRestitutionDirLin(float restitutionDirLin);
- void setDampingDirLin(float dampingDirLin);
- void setSoftnessDirAng(float softnessDirAng);
- void setRestitutionDirAng(float restitutionDirAng);
- void setDampingDirAng(float dampingDirAng);
- void setSoftnessLimLin(float softnessLimLin);
- void setRestitutionLimLin(float restitutionLimLin);
- void setDampingLimLin(float dampingLimLin);
- void setSoftnessLimAng(float softnessLimAng);
- void setRestitutionLimAng(float restitutionLimAng);
- void setDampingLimAng(float dampingLimAng);
- void setSoftnessOrthoLin(float softnessOrthoLin);
- void setRestitutionOrthoLin(float restitutionOrthoLin);
- void setDampingOrthoLin(float dampingOrthoLin);
- void setSoftnessOrthoAng(float softnessOrthoAng);
- void setRestitutionOrthoAng(float restitutionOrthoAng);
- void setDampingOrthoAng(float dampingOrthoAng);
- void setPoweredLinMotor(bool onOff);
- bool getPoweredLinMotor() const;
- void setTargetLinMotorVelocity(float targetLinMotorVelocity);
- float getTargetLinMotorVelocity() const;
- void setMaxLinMotorForce(float maxLinMotorForce);
- float getMaxLinMotorForce() const;
- void setPoweredAngMotor(bool onOff);
- bool getPoweredAngMotor() const;
- void setTargetAngMotorVelocity(float targetAngMotorVelocity);
- float getTargetAngMotorVelocity() const;
- void setMaxAngMotorForce(float maxAngMotorForce);
- float getMaxAngMotorForce() const;
-
- float getLinearPos() const;
- float getAngularPos() const;
-
-
- bool getUseFrameOffset() const;
-
- void setUseFrameOffset(bool frameOffsetOnOff);
-
-
- void setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
-
- CC_CONSTRUCTOR_ACCESS:
- Physics3DSliderConstraint()
- {
- _type = ConstraintType::SLIDER;
- }
- virtual ~Physics3DSliderConstraint(){}
- };
- class CC_DLL Physics3DConeTwistConstraint : public Physics3DConstraint
- {
- public:
-
- static Physics3DConeTwistConstraint* create(Physics3DRigidBody* rbA, const cocos2d::Mat4& frameA);
-
- static Physics3DConeTwistConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
-
-
- void setLimit(float swingSpan1,float swingSpan2,float twistSpan, float softness = 1.f, float biasFactor = 0.3f, float relaxationFactor = 1.0f);
-
-
- cocos2d::Mat4 getAFrame() const;
-
- cocos2d::Mat4 getBFrame() const;
-
-
- float getSwingSpan1() const;
-
- float getSwingSpan2() const;
-
- float getTwistSpan() const;
-
- float getTwistAngle() const;
-
-
- void setDamping(float damping);
-
-
- void enableMotor(bool b);
-
- void setMaxMotorImpulse(float maxMotorImpulse);
-
- void setMaxMotorImpulseNormalized(float maxMotorImpulse);
-
- float getFixThresh() const;
-
- void setFixThresh(float fixThresh);
-
-
- void setMotorTarget(const btQuaternion &q);
-
-
- void setMotorTargetInConstraintSpace(const btQuaternion &q);
-
-
- cocos2d::Vec3 GetPointForAngle(float fAngleInRadians, float fLength) const;
-
-
- virtual void setFrames(const cocos2d::Mat4& frameA, const cocos2d::Mat4& frameB);
-
-
- cocos2d::Mat4 getFrameOffsetA() const;
-
-
- cocos2d::Mat4 getFrameOffsetB() const;
-
- CC_CONSTRUCTOR_ACCESS:
- Physics3DConeTwistConstraint()
- {
- _type = ConstraintType::CONE_TWIST;
- }
- virtual ~Physics3DConeTwistConstraint(){}
- };
- class CC_DLL Physics3D6DofConstraint : public Physics3DConstraint
- {
- public:
-
- static Physics3D6DofConstraint* create(Physics3DRigidBody* rbA, Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInA, const cocos2d::Mat4& frameInB, bool useLinearReferenceFrameA);
-
-
- static Physics3D6DofConstraint* create(Physics3DRigidBody* rbB, const cocos2d::Mat4& frameInB, bool useLinearReferenceFrameB);
-
-
- void setLinearLowerLimit(const cocos2d::Vec3& linearLower);
-
-
- cocos2d::Vec3 getLinearLowerLimit() const;
-
-
- void setLinearUpperLimit(const cocos2d::Vec3& linearUpper);
-
-
- cocos2d::Vec3 getLinearUpperLimit() const;
-
-
- void setAngularLowerLimit(const cocos2d::Vec3& angularLower);
-
-
- cocos2d::Vec3 getAngularLowerLimit() const;
-
-
- void setAngularUpperLimit(const cocos2d::Vec3& angularUpper);
-
-
- cocos2d::Vec3 getAngularUpperLimit() const;
-
-
- bool isLimited(int limitIndex) const;
-
-
- bool getUseFrameOffset() const;
-
- void setUseFrameOffset(bool frameOffsetOnOff) const;
-
- CC_CONSTRUCTOR_ACCESS:
- Physics3D6DofConstraint()
- {
- _type = ConstraintType::SIX_DOF;
- }
- virtual ~Physics3D6DofConstraint(){}
- };
- NS_CC_END
- #endif
- #endif
- #endif
|