00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef COLLISION_OBJECT_H
00017 #define COLLISION_OBJECT_H
00018
00019 #include "LinearMath/btTransform.h"
00020
00021
00022 #define ACTIVE_TAG 1
00023 #define ISLAND_SLEEPING 2
00024 #define WANTS_DEACTIVATION 3
00025 #define DISABLE_DEACTIVATION 4
00026 #define DISABLE_SIMULATION 5
00027
00028 struct btBroadphaseProxy;
00029 class btCollisionShape;
00030 struct btCollisionShapeData;
00031 #include "LinearMath/btMotionState.h"
00032 #include "LinearMath/btAlignedAllocator.h"
00033 #include "LinearMath/btAlignedObjectArray.h"
00034
00035 typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
00036
00037 #ifdef BT_USE_DOUBLE_PRECISION
00038 #define btCollisionObjectData btCollisionObjectDoubleData
00039 #define btCollisionObjectDataName "btCollisionObjectDoubleData"
00040 #else
00041 #define btCollisionObjectData btCollisionObjectFloatData
00042 #define btCollisionObjectDataName "btCollisionObjectFloatData"
00043 #endif
00044
00045
00049 ATTRIBUTE_ALIGNED16(class) btCollisionObject
00050 {
00051
00052 protected:
00053
00054 btTransform m_worldTransform;
00055
00058 btTransform m_interpolationWorldTransform;
00059
00060
00061 btVector3 m_interpolationLinearVelocity;
00062 btVector3 m_interpolationAngularVelocity;
00063
00064 btVector3 m_anisotropicFriction;
00065 int m_hasAnisotropicFriction;
00066 btScalar m_contactProcessingThreshold;
00067
00068 btBroadphaseProxy* m_broadphaseHandle;
00069 btCollisionShape* m_collisionShape;
00070
00074 btCollisionShape* m_rootCollisionShape;
00075
00076 int m_collisionFlags;
00077
00078 int m_islandTag1;
00079 int m_companionId;
00080
00081 int m_activationState1;
00082 btScalar m_deactivationTime;
00083
00084 btScalar m_friction;
00085 btScalar m_restitution;
00086
00089 int m_internalType;
00090
00092 void* m_userObjectPointer;
00093
00095 btScalar m_hitFraction;
00096
00098 btScalar m_ccdSweptSphereRadius;
00099
00101 btScalar m_ccdMotionThreshold;
00102
00104 int m_checkCollideWith;
00105
00106 virtual bool checkCollideWithOverride(btCollisionObject* )
00107 {
00108 return true;
00109 }
00110
00111 public:
00112
00113 BT_DECLARE_ALIGNED_ALLOCATOR();
00114
00115 enum CollisionFlags
00116 {
00117 CF_STATIC_OBJECT= 1,
00118 CF_KINEMATIC_OBJECT= 2,
00119 CF_NO_CONTACT_RESPONSE = 4,
00120 CF_CUSTOM_MATERIAL_CALLBACK = 8,
00121 CF_CHARACTER_OBJECT = 16,
00122 CF_DISABLE_VISUALIZE_OBJECT = 32,
00123 CF_DISABLE_SPU_COLLISION_PROCESSING = 64
00124 };
00125
00126 enum CollisionObjectTypes
00127 {
00128 CO_COLLISION_OBJECT =1,
00129 CO_RIGID_BODY,
00132 CO_GHOST_OBJECT,
00133 CO_SOFT_BODY,
00134 CO_HF_FLUID
00135 };
00136
00137 SIMD_FORCE_INLINE bool mergesSimulationIslands() const
00138 {
00140 return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
00141 }
00142
00143 const btVector3& getAnisotropicFriction() const
00144 {
00145 return m_anisotropicFriction;
00146 }
00147 void setAnisotropicFriction(const btVector3& anisotropicFriction)
00148 {
00149 m_anisotropicFriction = anisotropicFriction;
00150 m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
00151 }
00152 bool hasAnisotropicFriction() const
00153 {
00154 return m_hasAnisotropicFriction!=0;
00155 }
00156
00159 void setContactProcessingThreshold( btScalar contactProcessingThreshold)
00160 {
00161 m_contactProcessingThreshold = contactProcessingThreshold;
00162 }
00163 btScalar getContactProcessingThreshold() const
00164 {
00165 return m_contactProcessingThreshold;
00166 }
00167
00168 SIMD_FORCE_INLINE bool isStaticObject() const {
00169 return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
00170 }
00171
00172 SIMD_FORCE_INLINE bool isKinematicObject() const
00173 {
00174 return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
00175 }
00176
00177 SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
00178 {
00179 return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
00180 }
00181
00182 SIMD_FORCE_INLINE bool hasContactResponse() const {
00183 return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
00184 }
00185
00186
00187 btCollisionObject();
00188
00189 virtual ~btCollisionObject();
00190
00191 virtual void setCollisionShape(btCollisionShape* collisionShape)
00192 {
00193 m_collisionShape = collisionShape;
00194 m_rootCollisionShape = collisionShape;
00195 }
00196
00197 SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
00198 {
00199 return m_collisionShape;
00200 }
00201
00202 SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
00203 {
00204 return m_collisionShape;
00205 }
00206
00207 SIMD_FORCE_INLINE const btCollisionShape* getRootCollisionShape() const
00208 {
00209 return m_rootCollisionShape;
00210 }
00211
00212 SIMD_FORCE_INLINE btCollisionShape* getRootCollisionShape()
00213 {
00214 return m_rootCollisionShape;
00215 }
00216
00219 void internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
00220 {
00221 m_collisionShape = collisionShape;
00222 }
00223
00224 SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;}
00225
00226 void setActivationState(int newState);
00227
00228 void setDeactivationTime(btScalar time)
00229 {
00230 m_deactivationTime = time;
00231 }
00232 btScalar getDeactivationTime() const
00233 {
00234 return m_deactivationTime;
00235 }
00236
00237 void forceActivationState(int newState);
00238
00239 void activate(bool forceActivation = false);
00240
00241 SIMD_FORCE_INLINE bool isActive() const
00242 {
00243 return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
00244 }
00245
00246 void setRestitution(btScalar rest)
00247 {
00248 m_restitution = rest;
00249 }
00250 btScalar getRestitution() const
00251 {
00252 return m_restitution;
00253 }
00254 void setFriction(btScalar frict)
00255 {
00256 m_friction = frict;
00257 }
00258 btScalar getFriction() const
00259 {
00260 return m_friction;
00261 }
00262
00264 int getInternalType() const
00265 {
00266 return m_internalType;
00267 }
00268
00269 btTransform& getWorldTransform()
00270 {
00271 return m_worldTransform;
00272 }
00273
00274 const btTransform& getWorldTransform() const
00275 {
00276 return m_worldTransform;
00277 }
00278
00279 void setWorldTransform(const btTransform& worldTrans)
00280 {
00281 m_worldTransform = worldTrans;
00282 }
00283
00284
00285 SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle()
00286 {
00287 return m_broadphaseHandle;
00288 }
00289
00290 SIMD_FORCE_INLINE const btBroadphaseProxy* getBroadphaseHandle() const
00291 {
00292 return m_broadphaseHandle;
00293 }
00294
00295 void setBroadphaseHandle(btBroadphaseProxy* handle)
00296 {
00297 m_broadphaseHandle = handle;
00298 }
00299
00300
00301 const btTransform& getInterpolationWorldTransform() const
00302 {
00303 return m_interpolationWorldTransform;
00304 }
00305
00306 btTransform& getInterpolationWorldTransform()
00307 {
00308 return m_interpolationWorldTransform;
00309 }
00310
00311 void setInterpolationWorldTransform(const btTransform& trans)
00312 {
00313 m_interpolationWorldTransform = trans;
00314 }
00315
00316 void setInterpolationLinearVelocity(const btVector3& linvel)
00317 {
00318 m_interpolationLinearVelocity = linvel;
00319 }
00320
00321 void setInterpolationAngularVelocity(const btVector3& angvel)
00322 {
00323 m_interpolationAngularVelocity = angvel;
00324 }
00325
00326 const btVector3& getInterpolationLinearVelocity() const
00327 {
00328 return m_interpolationLinearVelocity;
00329 }
00330
00331 const btVector3& getInterpolationAngularVelocity() const
00332 {
00333 return m_interpolationAngularVelocity;
00334 }
00335
00336 SIMD_FORCE_INLINE int getIslandTag() const
00337 {
00338 return m_islandTag1;
00339 }
00340
00341 void setIslandTag(int tag)
00342 {
00343 m_islandTag1 = tag;
00344 }
00345
00346 SIMD_FORCE_INLINE int getCompanionId() const
00347 {
00348 return m_companionId;
00349 }
00350
00351 void setCompanionId(int id)
00352 {
00353 m_companionId = id;
00354 }
00355
00356 SIMD_FORCE_INLINE btScalar getHitFraction() const
00357 {
00358 return m_hitFraction;
00359 }
00360
00361 void setHitFraction(btScalar hitFraction)
00362 {
00363 m_hitFraction = hitFraction;
00364 }
00365
00366
00367 SIMD_FORCE_INLINE int getCollisionFlags() const
00368 {
00369 return m_collisionFlags;
00370 }
00371
00372 void setCollisionFlags(int flags)
00373 {
00374 m_collisionFlags = flags;
00375 }
00376
00378 btScalar getCcdSweptSphereRadius() const
00379 {
00380 return m_ccdSweptSphereRadius;
00381 }
00382
00384 void setCcdSweptSphereRadius(btScalar radius)
00385 {
00386 m_ccdSweptSphereRadius = radius;
00387 }
00388
00389 btScalar getCcdMotionThreshold() const
00390 {
00391 return m_ccdMotionThreshold;
00392 }
00393
00394 btScalar getCcdSquareMotionThreshold() const
00395 {
00396 return m_ccdMotionThreshold*m_ccdMotionThreshold;
00397 }
00398
00399
00400
00402 void setCcdMotionThreshold(btScalar ccdMotionThreshold)
00403 {
00404 m_ccdMotionThreshold = ccdMotionThreshold;
00405 }
00406
00408 void* getUserPointer() const
00409 {
00410 return m_userObjectPointer;
00411 }
00412
00414 void setUserPointer(void* userPointer)
00415 {
00416 m_userObjectPointer = userPointer;
00417 }
00418
00419
00420 inline bool checkCollideWith(btCollisionObject* co)
00421 {
00422 if (m_checkCollideWith)
00423 return checkCollideWithOverride(co);
00424
00425 return true;
00426 }
00427
00428 virtual int calculateSerializeBufferSize() const;
00429
00431 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
00432
00433 virtual void serializeSingleObject(class btSerializer* serializer) const;
00434
00435 };
00436
00438 struct btCollisionObjectDoubleData
00439 {
00440 void *m_broadphaseHandle;
00441 void *m_collisionShape;
00442 btCollisionShapeData *m_rootCollisionShape;
00443 char *m_name;
00444
00445 btTransformDoubleData m_worldTransform;
00446 btTransformDoubleData m_interpolationWorldTransform;
00447 btVector3DoubleData m_interpolationLinearVelocity;
00448 btVector3DoubleData m_interpolationAngularVelocity;
00449 btVector3DoubleData m_anisotropicFriction;
00450 double m_contactProcessingThreshold;
00451 double m_deactivationTime;
00452 double m_friction;
00453 double m_restitution;
00454 double m_hitFraction;
00455 double m_ccdSweptSphereRadius;
00456 double m_ccdMotionThreshold;
00457
00458 int m_hasAnisotropicFriction;
00459 int m_collisionFlags;
00460 int m_islandTag1;
00461 int m_companionId;
00462 int m_activationState1;
00463 int m_internalType;
00464 int m_checkCollideWith;
00465
00466 char m_padding[4];
00467 };
00468
00470 struct btCollisionObjectFloatData
00471 {
00472 void *m_broadphaseHandle;
00473 void *m_collisionShape;
00474 btCollisionShapeData *m_rootCollisionShape;
00475 char *m_name;
00476
00477 btTransformFloatData m_worldTransform;
00478 btTransformFloatData m_interpolationWorldTransform;
00479 btVector3FloatData m_interpolationLinearVelocity;
00480 btVector3FloatData m_interpolationAngularVelocity;
00481 btVector3FloatData m_anisotropicFriction;
00482 float m_contactProcessingThreshold;
00483 float m_deactivationTime;
00484 float m_friction;
00485 float m_restitution;
00486 float m_hitFraction;
00487 float m_ccdSweptSphereRadius;
00488 float m_ccdMotionThreshold;
00489
00490 int m_hasAnisotropicFriction;
00491 int m_collisionFlags;
00492 int m_islandTag1;
00493 int m_companionId;
00494 int m_activationState1;
00495 int m_internalType;
00496 int m_checkCollideWith;
00497 };
00498
00499
00500
00501 SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const
00502 {
00503 return sizeof(btCollisionObjectData);
00504 }
00505
00506
00507
00508 #endif //COLLISION_OBJECT_H