Changeset View
Changeset View
Standalone View
Standalone View
extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h
| Show All 35 Lines | |||||
| #endif //BT_USE_DOUBLE_PRECISION | #endif //BT_USE_DOUBLE_PRECISION | ||||
| enum btHingeFlags | enum btHingeFlags | ||||
| { | { | ||||
| BT_HINGE_FLAGS_CFM_STOP = 1, | BT_HINGE_FLAGS_CFM_STOP = 1, | ||||
| BT_HINGE_FLAGS_ERP_STOP = 2, | BT_HINGE_FLAGS_ERP_STOP = 2, | ||||
| BT_HINGE_FLAGS_CFM_NORM = 4 | BT_HINGE_FLAGS_CFM_NORM = 4, | ||||
| BT_HINGE_FLAGS_ERP_NORM = 8 | |||||
| }; | }; | ||||
| /// hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space | /// hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space | ||||
| /// axis defines the orientation of the hinge axis | /// axis defines the orientation of the hinge axis | ||||
| ATTRIBUTE_ALIGNED16(class) btHingeConstraint : public btTypedConstraint | ATTRIBUTE_ALIGNED16(class) btHingeConstraint : public btTypedConstraint | ||||
| { | { | ||||
| #ifdef IN_PARALLELL_SOLVER | #ifdef IN_PARALLELL_SOLVER | ||||
| Show All 36 Lines | #endif | ||||
| bool m_useSolveConstraintObsolete; | bool m_useSolveConstraintObsolete; | ||||
| bool m_useOffsetForConstraintFrame; | bool m_useOffsetForConstraintFrame; | ||||
| bool m_useReferenceFrameA; | bool m_useReferenceFrameA; | ||||
| btScalar m_accMotorImpulse; | btScalar m_accMotorImpulse; | ||||
| int m_flags; | int m_flags; | ||||
| btScalar m_normalCFM; | btScalar m_normalCFM; | ||||
| btScalar m_normalERP; | |||||
| btScalar m_stopCFM; | btScalar m_stopCFM; | ||||
| btScalar m_stopERP; | btScalar m_stopERP; | ||||
| public: | public: | ||||
| BT_DECLARE_ALIGNED_ALLOCATOR(); | BT_DECLARE_ALIGNED_ALLOCATOR(); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | void enableAngularMotor(bool enableMotor,btScalar targetVelocity,btScalar maxMotorImpulse) | ||||
| m_maxMotorImpulse = maxMotorImpulse; | m_maxMotorImpulse = maxMotorImpulse; | ||||
| } | } | ||||
| // extra motor API, including ability to set a target rotation (as opposed to angular velocity) | // extra motor API, including ability to set a target rotation (as opposed to angular velocity) | ||||
| // note: setMotorTarget sets angular velocity under the hood, so you must call it every tick to | // note: setMotorTarget sets angular velocity under the hood, so you must call it every tick to | ||||
| // maintain a given angular target. | // maintain a given angular target. | ||||
| void enableMotor(bool enableMotor) { m_enableAngularMotor = enableMotor; } | void enableMotor(bool enableMotor) { m_enableAngularMotor = enableMotor; } | ||||
| void setMaxMotorImpulse(btScalar maxMotorImpulse) { m_maxMotorImpulse = maxMotorImpulse; } | void setMaxMotorImpulse(btScalar maxMotorImpulse) { m_maxMotorImpulse = maxMotorImpulse; } | ||||
| void setMotorTargetVelocity(btScalar motorTargetVelocity) { m_motorTargetVelocity = motorTargetVelocity; } | |||||
| void setMotorTarget(const btQuaternion& qAinB, btScalar dt); // qAinB is rotation of body A wrt body B. | void setMotorTarget(const btQuaternion& qAinB, btScalar dt); // qAinB is rotation of body A wrt body B. | ||||
| void setMotorTarget(btScalar targetAngle, btScalar dt); | void setMotorTarget(btScalar targetAngle, btScalar dt); | ||||
| void setLimit(btScalar low,btScalar high,btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) | void setLimit(btScalar low,btScalar high,btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) | ||||
| { | { | ||||
| #ifdef _BT_USE_CENTER_LIMIT_ | #ifdef _BT_USE_CENTER_LIMIT_ | ||||
| m_limit.set(low, high, _softness, _biasFactor, _relaxationFactor); | m_limit.set(low, high, _softness, _biasFactor, _relaxationFactor); | ||||
| #else | #else | ||||
| m_lowerLimit = btNormalizeAngle(low); | m_lowerLimit = btNormalizeAngle(low); | ||||
| m_upperLimit = btNormalizeAngle(high); | m_upperLimit = btNormalizeAngle(high); | ||||
| m_limitSoftness = _softness; | m_limitSoftness = _softness; | ||||
| m_biasFactor = _biasFactor; | m_biasFactor = _biasFactor; | ||||
| m_relaxationFactor = _relaxationFactor; | m_relaxationFactor = _relaxationFactor; | ||||
| #endif | #endif | ||||
| } | } | ||||
| btScalar getLimitSoftness() const | |||||
| { | |||||
| #ifdef _BT_USE_CENTER_LIMIT_ | |||||
| return m_limit.getSoftness(); | |||||
| #else | |||||
| return m_limitSoftness; | |||||
| #endif | |||||
| } | |||||
| btScalar getLimitBiasFactor() const | |||||
| { | |||||
| #ifdef _BT_USE_CENTER_LIMIT_ | |||||
| return m_limit.getBiasFactor(); | |||||
| #else | |||||
| return m_biasFactor; | |||||
| #endif | |||||
| } | |||||
| btScalar getLimitRelaxationFactor() const | |||||
| { | |||||
| #ifdef _BT_USE_CENTER_LIMIT_ | |||||
| return m_limit.getRelaxationFactor(); | |||||
| #else | |||||
| return m_relaxationFactor; | |||||
| #endif | |||||
| } | |||||
| void setAxis(btVector3& axisInA) | void setAxis(btVector3& axisInA) | ||||
| { | { | ||||
| btVector3 rbAxisA1, rbAxisA2; | btVector3 rbAxisA1, rbAxisA2; | ||||
| btPlaneSpace1(axisInA, rbAxisA1, rbAxisA2); | btPlaneSpace1(axisInA, rbAxisA1, rbAxisA2); | ||||
| btVector3 pivotInA = m_rbAFrame.getOrigin(); | btVector3 pivotInA = m_rbAFrame.getOrigin(); | ||||
| // m_rbAFrame.getOrigin() = pivotInA; | // m_rbAFrame.getOrigin() = pivotInA; | ||||
| m_rbAFrame.getBasis().setValue( rbAxisA1.getX(),rbAxisA2.getX(),axisInA.getX(), | m_rbAFrame.getBasis().setValue( rbAxisA1.getX(),rbAxisA2.getX(),axisInA.getX(), | ||||
| rbAxisA1.getY(),rbAxisA2.getY(),axisInA.getY(), | rbAxisA1.getY(),rbAxisA2.getY(),axisInA.getY(), | ||||
| Show All 9 Lines | // m_rbAFrame.getOrigin() = pivotInA; | ||||
| m_rbBFrame.getBasis().setValue( rbAxisB1.getX(),rbAxisB2.getX(),axisInB.getX(), | m_rbBFrame.getBasis().setValue( rbAxisB1.getX(),rbAxisB2.getX(),axisInB.getX(), | ||||
| rbAxisB1.getY(),rbAxisB2.getY(),axisInB.getY(), | rbAxisB1.getY(),rbAxisB2.getY(),axisInB.getY(), | ||||
| rbAxisB1.getZ(),rbAxisB2.getZ(),axisInB.getZ() ); | rbAxisB1.getZ(),rbAxisB2.getZ(),axisInB.getZ() ); | ||||
| m_rbBFrame.getBasis() = m_rbB.getCenterOfMassTransform().getBasis().inverse() * m_rbBFrame.getBasis(); | m_rbBFrame.getBasis() = m_rbB.getCenterOfMassTransform().getBasis().inverse() * m_rbBFrame.getBasis(); | ||||
| } | } | ||||
| bool hasLimit() const { | |||||
| #ifdef _BT_USE_CENTER_LIMIT_ | |||||
| return m_limit.getHalfRange() > 0; | |||||
| #else | |||||
| return m_lowerLimit <= m_upperLimit; | |||||
| #endif | |||||
| } | |||||
| btScalar getLowerLimit() const | btScalar getLowerLimit() const | ||||
| { | { | ||||
| #ifdef _BT_USE_CENTER_LIMIT_ | #ifdef _BT_USE_CENTER_LIMIT_ | ||||
| return m_limit.getLow(); | return m_limit.getLow(); | ||||
| #else | #else | ||||
| return m_lowerLimit; | return m_lowerLimit; | ||||
| #endif | #endif | ||||
| } | } | ||||
| btScalar getUpperLimit() const | btScalar getUpperLimit() const | ||||
| { | { | ||||
| #ifdef _BT_USE_CENTER_LIMIT_ | #ifdef _BT_USE_CENTER_LIMIT_ | ||||
| return m_limit.getHigh(); | return m_limit.getHigh(); | ||||
| #else | #else | ||||
| return m_upperLimit; | return m_upperLimit; | ||||
| #endif | #endif | ||||
| } | } | ||||
| ///The getHingeAngle gives the hinge angle in range [-PI,PI] | |||||
| btScalar getHingeAngle(); | btScalar getHingeAngle(); | ||||
| btScalar getHingeAngle(const btTransform& transA,const btTransform& transB); | btScalar getHingeAngle(const btTransform& transA,const btTransform& transB); | ||||
| void testLimit(const btTransform& transA,const btTransform& transB); | void testLimit(const btTransform& transA,const btTransform& transB); | ||||
| const btTransform& getAFrame() const { return m_rbAFrame; }; | const btTransform& getAFrame() const { return m_rbAFrame; }; | ||||
| Show All 34 Lines | #endif | ||||
| } | } | ||||
| inline btScalar getMaxMotorImpulse() | inline btScalar getMaxMotorImpulse() | ||||
| { | { | ||||
| return m_maxMotorImpulse; | return m_maxMotorImpulse; | ||||
| } | } | ||||
| // access for UseFrameOffset | // access for UseFrameOffset | ||||
| bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; } | bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; } | ||||
| void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; } | void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; } | ||||
| // access for UseReferenceFrameA | |||||
| bool getUseReferenceFrameA() const { return m_useReferenceFrameA; } | |||||
| void setUseReferenceFrameA(bool useReferenceFrameA) { m_useReferenceFrameA = useReferenceFrameA; } | |||||
| ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). | ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). | ||||
| ///If no axis is provided, it uses the default axis for this constraint. | ///If no axis is provided, it uses the default axis for this constraint. | ||||
| virtual void setParam(int num, btScalar value, int axis = -1); | virtual void setParam(int num, btScalar value, int axis = -1); | ||||
| ///return the local value of parameter | ///return the local value of parameter | ||||
| virtual btScalar getParam(int num, int axis = -1) const; | virtual btScalar getParam(int num, int axis = -1) const; | ||||
| virtual int getFlags() const | |||||
| { | |||||
| return m_flags; | |||||
| } | |||||
| virtual int calculateSerializeBufferSize() const; | virtual int calculateSerializeBufferSize() const; | ||||
| ///fills the dataBuffer and returns the struct name (and 0 on failure) | ///fills the dataBuffer and returns the struct name (and 0 on failure) | ||||
| virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; | virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; | ||||
| }; | }; | ||||
| Show All 16 Lines | struct btHingeConstraintDoubleData | ||||
| float m_upperLimit; | float m_upperLimit; | ||||
| float m_limitSoftness; | float m_limitSoftness; | ||||
| float m_biasFactor; | float m_biasFactor; | ||||
| float m_relaxationFactor; | float m_relaxationFactor; | ||||
| }; | }; | ||||
| #endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION | #endif //BT_BACKWARDS_COMPATIBLE_SERIALIZATION | ||||
| ///The getAccumulatedHingeAngle returns the accumulated hinge angle, taking rotation across the -PI/PI boundary into account | |||||
| ATTRIBUTE_ALIGNED16(class) btHingeAccumulatedAngleConstraint : public btHingeConstraint | |||||
| { | |||||
| protected: | |||||
| btScalar m_accumulatedAngle; | |||||
| public: | |||||
| BT_DECLARE_ALIGNED_ALLOCATOR(); | |||||
| btHingeAccumulatedAngleConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, const btVector3& axisInA,const btVector3& axisInB, bool useReferenceFrameA = false) | |||||
| :btHingeConstraint(rbA,rbB,pivotInA,pivotInB, axisInA,axisInB, useReferenceFrameA ) | |||||
| { | |||||
| m_accumulatedAngle=getHingeAngle(); | |||||
| } | |||||
| btHingeAccumulatedAngleConstraint(btRigidBody& rbA,const btVector3& pivotInA,const btVector3& axisInA, bool useReferenceFrameA = false) | |||||
| :btHingeConstraint(rbA,pivotInA,axisInA, useReferenceFrameA) | |||||
| { | |||||
| m_accumulatedAngle=getHingeAngle(); | |||||
| } | |||||
| btHingeAccumulatedAngleConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA = false) | |||||
| :btHingeConstraint(rbA,rbB, rbAFrame, rbBFrame, useReferenceFrameA ) | |||||
| { | |||||
| m_accumulatedAngle=getHingeAngle(); | |||||
| } | |||||
| btHingeAccumulatedAngleConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA = false) | |||||
| :btHingeConstraint(rbA,rbAFrame, useReferenceFrameA ) | |||||
| { | |||||
| m_accumulatedAngle=getHingeAngle(); | |||||
| } | |||||
| btScalar getAccumulatedHingeAngle(); | |||||
| void setAccumulatedHingeAngle(btScalar accAngle); | |||||
| virtual void getInfo1 (btConstraintInfo1* info); | |||||
| }; | |||||
| struct btHingeConstraintFloatData | struct btHingeConstraintFloatData | ||||
| { | { | ||||
| btTypedConstraintData m_typeConstraintData; | btTypedConstraintData m_typeConstraintData; | ||||
| btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis. | btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis. | ||||
| btTransformFloatData m_rbBFrame; | btTransformFloatData m_rbBFrame; | ||||
| int m_useReferenceFrameA; | int m_useReferenceFrameA; | ||||
| int m_angularOnly; | int m_angularOnly; | ||||
| ▲ Show 20 Lines • Show All 76 Lines • Show Last 20 Lines | |||||