Changeset 8351 for code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btTypedConstraint.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/btTypedConstraint.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-20 06Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/ 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "LinearMath/btScalar.h" 21 21 #include "btSolverConstraint.h" 22 struct btSolverBody; 23 24 25 22 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" 23 24 class btSerializer; 26 25 27 26 enum btTypedConstraintType 28 27 { 29 POINT2POINT_CONSTRAINT_TYPE ,28 POINT2POINT_CONSTRAINT_TYPE=MAX_CONTACT_MANIFOLD_TYPE+1, 30 29 HINGE_CONSTRAINT_TYPE, 31 30 CONETWIST_CONSTRAINT_TYPE, 32 31 D6_CONSTRAINT_TYPE, 33 SLIDER_CONSTRAINT_TYPE 32 SLIDER_CONSTRAINT_TYPE, 33 CONTACT_CONSTRAINT_TYPE 34 34 }; 35 35 36 37 enum btConstraintParams 38 { 39 BT_CONSTRAINT_ERP=1, 40 BT_CONSTRAINT_STOP_ERP, 41 BT_CONSTRAINT_CFM, 42 BT_CONSTRAINT_STOP_CFM 43 }; 44 45 #if 1 46 #define btAssertConstrParams(_par) btAssert(_par) 47 #else 48 #define btAssertConstrParams(_par) 49 #endif 50 51 36 52 ///TypedConstraint is the baseclass for Bullet constraints and vehicles 37 class btTypedConstraint 53 class btTypedConstraint : public btTypedObject 38 54 { 39 55 int m_userConstraintType; 40 int m_userConstraintId; 41 42 btTypedConstraintType m_constraintType; 56 57 union 58 { 59 int m_userConstraintId; 60 void* m_userConstraintPtr; 61 }; 62 63 bool m_needsFeedback; 43 64 44 65 btTypedConstraint& operator=(btTypedConstraint& other) … … 55 76 btScalar m_dbgDrawSize; 56 77 78 ///internal method used by the constraint solver, don't use them directly 79 btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact); 80 81 static btRigidBody& getFixedBody(); 57 82 58 83 public: 59 84 60 btTypedConstraint(btTypedConstraintType type);61 85 virtual ~btTypedConstraint() {}; 62 86 btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA); … … 94 118 // the constraint. 95 119 int *findex; 120 // number of solver iterations 121 int m_numIterations; 122 123 //damping of the velocity 124 btScalar m_damping; 96 125 }; 97 126 98 99 virtual void buildJacobian() = 0; 100 127 ///internal method used by the constraint solver, don't use them directly 128 virtual void buildJacobian() {}; 129 130 ///internal method used by the constraint solver, don't use them directly 101 131 virtual void setupSolverConstraint(btConstraintArray& ca, int solverBodyA,int solverBodyB, btScalar timeStep) 102 132 { 103 } 133 (void)ca; 134 (void)solverBodyA; 135 (void)solverBodyB; 136 (void)timeStep; 137 } 138 139 ///internal method used by the constraint solver, don't use them directly 104 140 virtual void getInfo1 (btConstraintInfo1* info)=0; 105 141 142 ///internal method used by the constraint solver, don't use them directly 106 143 virtual void getInfo2 (btConstraintInfo2* info)=0; 107 144 108 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) = 0; 109 110 btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact); 145 ///internal method used by the constraint solver, don't use them directly 146 void internalSetAppliedImpulse(btScalar appliedImpulse) 147 { 148 m_appliedImpulse = appliedImpulse; 149 } 150 ///internal method used by the constraint solver, don't use them directly 151 btScalar internalGetAppliedImpulse() 152 { 153 return m_appliedImpulse; 154 } 155 156 ///internal method used by the constraint solver, don't use them directly 157 virtual void solveConstraintObsolete(btRigidBody& /*bodyA*/,btRigidBody& /*bodyB*/,btScalar /*timeStep*/) {}; 158 111 159 112 160 const btRigidBody& getRigidBodyA() const … … 148 196 } 149 197 198 void setUserConstraintPtr(void* ptr) 199 { 200 m_userConstraintPtr = ptr; 201 } 202 203 void* getUserConstraintPtr() 204 { 205 return m_userConstraintPtr; 206 } 207 150 208 int getUid() const 151 209 { … … 153 211 } 154 212 213 bool needsFeedback() const 214 { 215 return m_needsFeedback; 216 } 217 218 ///enableFeedback will allow to read the applied linear and angular impulse 219 ///use getAppliedImpulse, getAppliedLinearImpulse and getAppliedAngularImpulse to read feedback information 220 void enableFeedback(bool needsFeedback) 221 { 222 m_needsFeedback = needsFeedback; 223 } 224 225 ///getAppliedImpulse is an estimated total applied impulse. 226 ///This feedback could be used to determine breaking constraints or playing sounds. 155 227 btScalar getAppliedImpulse() const 156 228 { 229 btAssert(m_needsFeedback); 157 230 return m_appliedImpulse; 158 231 } … … 160 233 btTypedConstraintType getConstraintType () const 161 234 { 162 return m_constraintType;235 return btTypedConstraintType(m_objectType); 163 236 } 164 237 … … 171 244 return m_dbgDrawSize; 172 245 } 173 246 247 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 248 ///If no axis is provided, it uses the default axis for this constraint. 249 virtual void setParam(int num, btScalar value, int axis = -1) = 0; 250 251 ///return the local value of parameter 252 virtual btScalar getParam(int num, int axis = -1) const = 0; 253 254 virtual int calculateSerializeBufferSize() const; 255 256 ///fills the dataBuffer and returns the struct name (and 0 on failure) 257 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 258 174 259 }; 175 260 261 // returns angle in range [-SIMD_2_PI, SIMD_2_PI], closest to one of the limits 262 // all arguments should be normalized angles (i.e. in range [-SIMD_PI, SIMD_PI]) 263 SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians) 264 { 265 if(angleLowerLimitInRadians >= angleUpperLimitInRadians) 266 { 267 return angleInRadians; 268 } 269 else if(angleInRadians < angleLowerLimitInRadians) 270 { 271 btScalar diffLo = btFabs(btNormalizeAngle(angleLowerLimitInRadians - angleInRadians)); 272 btScalar diffHi = btFabs(btNormalizeAngle(angleUpperLimitInRadians - angleInRadians)); 273 return (diffLo < diffHi) ? angleInRadians : (angleInRadians + SIMD_2_PI); 274 } 275 else if(angleInRadians > angleUpperLimitInRadians) 276 { 277 btScalar diffHi = btFabs(btNormalizeAngle(angleInRadians - angleUpperLimitInRadians)); 278 btScalar diffLo = btFabs(btNormalizeAngle(angleInRadians - angleLowerLimitInRadians)); 279 return (diffLo < diffHi) ? (angleInRadians - SIMD_2_PI) : angleInRadians; 280 } 281 else 282 { 283 return angleInRadians; 284 } 285 } 286 287 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 288 struct btTypedConstraintData 289 { 290 btRigidBodyData *m_rbA; 291 btRigidBodyData *m_rbB; 292 char *m_name; 293 294 int m_objectType; 295 int m_userConstraintType; 296 int m_userConstraintId; 297 int m_needsFeedback; 298 299 float m_appliedImpulse; 300 float m_dbgDrawSize; 301 302 int m_disableCollisionsBetweenLinkedBodies; 303 char m_pad4[4]; 304 305 }; 306 307 SIMD_FORCE_INLINE int btTypedConstraint::calculateSerializeBufferSize() const 308 { 309 return sizeof(btTypedConstraintData); 310 } 311 312 313 314 176 315 #endif //TYPED_CONSTRAINT_H
Note: See TracChangeset
for help on using the changeset viewer.