Changeset 8351 for code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h
r5781 r8351 18 18 19 19 20 /* 21 Overview: 22 23 btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc). 24 It is a fixed translation, 3 degree-of-freedom (DOF) rotational "joint". 25 It divides the 3 rotational DOFs into swing (movement within a cone) and twist. 26 Swing is divided into swing1 and swing2 which can have different limits, giving an elliptical shape. 27 (Note: the cone's base isn't flat, so this ellipse is "embedded" on the surface of a sphere.) 28 29 In the contraint's frame of reference: 30 twist is along the x-axis, 31 and swing 1 and 2 are along the z and y axes respectively. 32 */ 33 34 35 20 36 #ifndef CONETWISTCONSTRAINT_H 21 37 #define CONETWISTCONSTRAINT_H … … 27 43 class btRigidBody; 28 44 45 enum btConeTwistFlags 46 { 47 BT_CONETWIST_FLAGS_LIN_CFM = 1, 48 BT_CONETWIST_FLAGS_LIN_ERP = 2, 49 BT_CONETWIST_FLAGS_ANG_CFM = 4 50 }; 29 51 30 52 ///btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc) … … 84 106 btVector3 m_accMotorImpulse; 85 107 108 // parameters 109 int m_flags; 110 btScalar m_linCFM; 111 btScalar m_linERP; 112 btScalar m_angCFM; 113 114 protected: 115 116 void init(); 117 118 void computeConeLimitInfo(const btQuaternion& qCone, // in 119 btScalar& swingAngle, btVector3& vSwingAxis, btScalar& swingLimit); // all outs 120 121 void computeTwistLimitInfo(const btQuaternion& qTwist, // in 122 btScalar& twistAngle, btVector3& vTwistAxis); // all outs 123 124 void adjustSwingAxisToUseEllipseNormal(btVector3& vSwingAxis) const; 125 126 86 127 public: 87 128 … … 90 131 btConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame); 91 132 92 btConeTwistConstraint();93 94 133 virtual void buildJacobian(); 95 134 96 135 virtual void getInfo1 (btConstraintInfo1* info); 136 137 void getInfo1NonVirtual(btConstraintInfo1* info); 97 138 98 139 virtual void getInfo2 (btConstraintInfo2* info); 99 140 100 101 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep); 141 void getInfo2NonVirtual(btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB); 142 143 virtual void solveConstraintObsolete(btRigidBody& bodyA,btRigidBody& bodyB,btScalar timeStep); 102 144 103 145 void updateRHS(btScalar timeStep); … … 142 184 } 143 185 144 void setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan, btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) 186 // setLimit(), a few notes: 187 // _softness: 188 // 0->1, recommend ~0.8->1. 189 // describes % of limits where movement is free. 190 // beyond this softness %, the limit is gradually enforced until the "hard" (1.0) limit is reached. 191 // _biasFactor: 192 // 0->1?, recommend 0.3 +/-0.3 or so. 193 // strength with which constraint resists zeroth order (angular, not angular velocity) limit violation. 194 // __relaxationFactor: 195 // 0->1, recommend to stay near 1. 196 // the lower the value, the less the constraint will fight velocities which violate the angular limits. 197 void setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan, btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) 145 198 { 146 199 m_swingSpan1 = _swingSpan1; … … 172 225 173 226 void calcAngleInfo(); 174 void calcAngleInfo2( );227 void calcAngleInfo2(const btTransform& transA, const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB); 175 228 176 229 inline btScalar getSwingSpan1() … … 213 266 btVector3 GetPointForAngle(btScalar fAngleInRadians, btScalar fLength) const; 214 267 215 216 217 protected: 218 void init(); 219 220 void computeConeLimitInfo(const btQuaternion& qCone, // in 221 btScalar& swingAngle, btVector3& vSwingAxis, btScalar& swingLimit); // all outs 222 223 void computeTwistLimitInfo(const btQuaternion& qTwist, // in 224 btScalar& twistAngle, btVector3& vTwistAxis); // all outs 225 226 void adjustSwingAxisToUseEllipseNormal(btVector3& vSwingAxis) const; 268 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 269 ///If no axis is provided, it uses the default axis for this constraint. 270 virtual void setParam(int num, btScalar value, int axis = -1); 271 ///return the local value of parameter 272 virtual btScalar getParam(int num, int axis = -1) const; 273 274 virtual int calculateSerializeBufferSize() const; 275 276 ///fills the dataBuffer and returns the struct name (and 0 on failure) 277 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 278 227 279 }; 228 280 281 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 282 struct btConeTwistConstraintData 283 { 284 btTypedConstraintData m_typeConstraintData; 285 btTransformFloatData m_rbAFrame; 286 btTransformFloatData m_rbBFrame; 287 288 //limits 289 float m_swingSpan1; 290 float m_swingSpan2; 291 float m_twistSpan; 292 float m_limitSoftness; 293 float m_biasFactor; 294 float m_relaxationFactor; 295 296 float m_damping; 297 298 char m_pad[4]; 299 300 }; 301 302 303 304 SIMD_FORCE_INLINE int btConeTwistConstraint::calculateSerializeBufferSize() const 305 { 306 return sizeof(btConeTwistConstraintData); 307 308 } 309 310 311 ///fills the dataBuffer and returns the struct name (and 0 on failure) 312 SIMD_FORCE_INLINE const char* btConeTwistConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 313 { 314 btConeTwistConstraintData* cone = (btConeTwistConstraintData*) dataBuffer; 315 btTypedConstraint::serialize(&cone->m_typeConstraintData,serializer); 316 317 m_rbAFrame.serializeFloat(cone->m_rbAFrame); 318 m_rbBFrame.serializeFloat(cone->m_rbBFrame); 319 320 cone->m_swingSpan1 = float(m_swingSpan1); 321 cone->m_swingSpan2 = float(m_swingSpan2); 322 cone->m_twistSpan = float(m_twistSpan); 323 cone->m_limitSoftness = float(m_limitSoftness); 324 cone->m_biasFactor = float(m_biasFactor); 325 cone->m_relaxationFactor = float(m_relaxationFactor); 326 cone->m_damping = float(m_damping); 327 328 return "btConeTwistConstraintData"; 329 } 330 331 229 332 #endif //CONETWISTCONSTRAINT_H
Note: See TracChangeset
for help on using the changeset viewer.