btCollisionObject.h

Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef COLLISION_OBJECT_H
00017 #define COLLISION_OBJECT_H
00018 
00019 #include "LinearMath/btTransform.h"
00020 
00021 //island management, m_activationState1
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 class   btCollisionObject
00050 {
00051 
00052 protected:
00053 
00054         btTransform     m_worldTransform;
00055 
00058         btTransform     m_interpolationWorldTransform;
00059         //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities) 
00060         //without destroying the continuous interpolated motion (which uses this interpolation velocities)
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* /* co */)
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,//this allows per-triangle material (friction/restitution)
00121                 CF_CHARACTER_OBJECT = 16,
00122                 CF_DISABLE_VISUALIZE_OBJECT = 32 //disable debug drawing
00123         };
00124 
00125         enum    CollisionObjectTypes
00126         {
00127                 CO_COLLISION_OBJECT =1,
00128                 CO_RIGID_BODY,
00131                 CO_GHOST_OBJECT,
00132                 CO_SOFT_BODY,
00133                 CO_HF_FLUID
00134         };
00135 
00136         SIMD_FORCE_INLINE bool mergesSimulationIslands() const
00137         {
00139                 return  ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
00140         }
00141 
00142         const btVector3& getAnisotropicFriction() const
00143         {
00144                 return m_anisotropicFriction;
00145         }
00146         void    setAnisotropicFriction(const btVector3& anisotropicFriction)
00147         {
00148                 m_anisotropicFriction = anisotropicFriction;
00149                 m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
00150         }
00151         bool    hasAnisotropicFriction() const
00152         {
00153                 return m_hasAnisotropicFriction!=0;
00154         }
00155 
00158         void    setContactProcessingThreshold( btScalar contactProcessingThreshold)
00159         {
00160                 m_contactProcessingThreshold = contactProcessingThreshold;
00161         }
00162         btScalar        getContactProcessingThreshold() const
00163         {
00164                 return m_contactProcessingThreshold;
00165         }
00166 
00167         SIMD_FORCE_INLINE bool          isStaticObject() const {
00168                 return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
00169         }
00170 
00171         SIMD_FORCE_INLINE bool          isKinematicObject() const
00172         {
00173                 return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
00174         }
00175 
00176         SIMD_FORCE_INLINE bool          isStaticOrKinematicObject() const
00177         {
00178                 return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
00179         }
00180 
00181         SIMD_FORCE_INLINE bool          hasContactResponse() const {
00182                 return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
00183         }
00184 
00185         
00186         btCollisionObject();
00187 
00188         virtual ~btCollisionObject();
00189 
00190         virtual void    setCollisionShape(btCollisionShape* collisionShape)
00191         {
00192                 m_collisionShape = collisionShape;
00193                 m_rootCollisionShape = collisionShape;
00194         }
00195 
00196         SIMD_FORCE_INLINE const btCollisionShape*       getCollisionShape() const
00197         {
00198                 return m_collisionShape;
00199         }
00200 
00201         SIMD_FORCE_INLINE btCollisionShape*     getCollisionShape()
00202         {
00203                 return m_collisionShape;
00204         }
00205 
00206         SIMD_FORCE_INLINE const btCollisionShape*       getRootCollisionShape() const
00207         {
00208                 return m_rootCollisionShape;
00209         }
00210 
00211         SIMD_FORCE_INLINE btCollisionShape*     getRootCollisionShape()
00212         {
00213                 return m_rootCollisionShape;
00214         }
00215 
00218         void    internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
00219         {
00220                 m_collisionShape = collisionShape;
00221         }
00222 
00223         SIMD_FORCE_INLINE       int     getActivationState() const { return m_activationState1;}
00224         
00225         void setActivationState(int newState);
00226 
00227         void    setDeactivationTime(btScalar time)
00228         {
00229                 m_deactivationTime = time;
00230         }
00231         btScalar        getDeactivationTime() const
00232         {
00233                 return m_deactivationTime;
00234         }
00235 
00236         void forceActivationState(int newState);
00237 
00238         void    activate(bool forceActivation = false);
00239 
00240         SIMD_FORCE_INLINE bool isActive() const
00241         {
00242                 return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
00243         }
00244 
00245         void    setRestitution(btScalar rest)
00246         {
00247                 m_restitution = rest;
00248         }
00249         btScalar        getRestitution() const
00250         {
00251                 return m_restitution;
00252         }
00253         void    setFriction(btScalar frict)
00254         {
00255                 m_friction = frict;
00256         }
00257         btScalar        getFriction() const
00258         {
00259                 return m_friction;
00260         }
00261 
00263         int     getInternalType() const
00264         {
00265                 return m_internalType;
00266         }
00267 
00268         btTransform&    getWorldTransform()
00269         {
00270                 return m_worldTransform;
00271         }
00272 
00273         const btTransform&      getWorldTransform() const
00274         {
00275                 return m_worldTransform;
00276         }
00277 
00278         void    setWorldTransform(const btTransform& worldTrans)
00279         {
00280                 m_worldTransform = worldTrans;
00281         }
00282 
00283 
00284         SIMD_FORCE_INLINE btBroadphaseProxy*    getBroadphaseHandle()
00285         {
00286                 return m_broadphaseHandle;
00287         }
00288 
00289         SIMD_FORCE_INLINE const btBroadphaseProxy*      getBroadphaseHandle() const
00290         {
00291                 return m_broadphaseHandle;
00292         }
00293 
00294         void    setBroadphaseHandle(btBroadphaseProxy* handle)
00295         {
00296                 m_broadphaseHandle = handle;
00297         }
00298 
00299 
00300         const btTransform&      getInterpolationWorldTransform() const
00301         {
00302                 return m_interpolationWorldTransform;
00303         }
00304 
00305         btTransform&    getInterpolationWorldTransform()
00306         {
00307                 return m_interpolationWorldTransform;
00308         }
00309 
00310         void    setInterpolationWorldTransform(const btTransform&       trans)
00311         {
00312                 m_interpolationWorldTransform = trans;
00313         }
00314 
00315         void    setInterpolationLinearVelocity(const btVector3& linvel)
00316         {
00317                 m_interpolationLinearVelocity = linvel;
00318         }
00319 
00320         void    setInterpolationAngularVelocity(const btVector3& angvel)
00321         {
00322                 m_interpolationAngularVelocity = angvel;
00323         }
00324 
00325         const btVector3&        getInterpolationLinearVelocity() const
00326         {
00327                 return m_interpolationLinearVelocity;
00328         }
00329 
00330         const btVector3&        getInterpolationAngularVelocity() const
00331         {
00332                 return m_interpolationAngularVelocity;
00333         }
00334 
00335         SIMD_FORCE_INLINE int getIslandTag() const
00336         {
00337                 return  m_islandTag1;
00338         }
00339 
00340         void    setIslandTag(int tag)
00341         {
00342                 m_islandTag1 = tag;
00343         }
00344 
00345         SIMD_FORCE_INLINE int getCompanionId() const
00346         {
00347                 return  m_companionId;
00348         }
00349 
00350         void    setCompanionId(int id)
00351         {
00352                 m_companionId = id;
00353         }
00354 
00355         SIMD_FORCE_INLINE btScalar                      getHitFraction() const
00356         {
00357                 return m_hitFraction; 
00358         }
00359 
00360         void    setHitFraction(btScalar hitFraction)
00361         {
00362                 m_hitFraction = hitFraction;
00363         }
00364 
00365         
00366         SIMD_FORCE_INLINE int   getCollisionFlags() const
00367         {
00368                 return m_collisionFlags;
00369         }
00370 
00371         void    setCollisionFlags(int flags)
00372         {
00373                 m_collisionFlags = flags;
00374         }
00375         
00377         btScalar                        getCcdSweptSphereRadius() const
00378         {
00379                 return m_ccdSweptSphereRadius;
00380         }
00381 
00383         void    setCcdSweptSphereRadius(btScalar radius)
00384         {
00385                 m_ccdSweptSphereRadius = radius;
00386         }
00387 
00388         btScalar        getCcdMotionThreshold() const
00389         {
00390                 return m_ccdMotionThreshold;
00391         }
00392 
00393         btScalar        getCcdSquareMotionThreshold() const
00394         {
00395                 return m_ccdMotionThreshold*m_ccdMotionThreshold;
00396         }
00397 
00398 
00399 
00401         void    setCcdMotionThreshold(btScalar ccdMotionThreshold)
00402         {
00403                 m_ccdMotionThreshold = ccdMotionThreshold;
00404         }
00405 
00407         void*   getUserPointer() const
00408         {
00409                 return m_userObjectPointer;
00410         }
00411         
00413         void    setUserPointer(void* userPointer)
00414         {
00415                 m_userObjectPointer = userPointer;
00416         }
00417 
00418 
00419         inline bool checkCollideWith(btCollisionObject* co)
00420         {
00421                 if (m_checkCollideWith)
00422                         return checkCollideWithOverride(co);
00423 
00424                 return true;
00425         }
00426 
00427         virtual int     calculateSerializeBufferSize()  const;
00428 
00430         virtual const char*     serialize(void* dataBuffer, class btSerializer* serializer) const;
00431 
00432 
00433 };
00434 
00436 struct  btCollisionObjectDoubleData
00437 {
00438         void                                    *m_broadphaseHandle;
00439         void                                    *m_collisionShape;
00440         btCollisionShapeData    *m_rootCollisionShape;
00441         char                                    *m_name;
00442 
00443         btTransformDoubleData   m_worldTransform;
00444         btTransformDoubleData   m_interpolationWorldTransform;
00445         btVector3DoubleData             m_interpolationLinearVelocity;
00446         btVector3DoubleData             m_interpolationAngularVelocity;
00447         btVector3DoubleData             m_anisotropicFriction;
00448         double                                  m_contactProcessingThreshold;   
00449         double                                  m_deactivationTime;
00450         double                                  m_friction;
00451         double                                  m_restitution;
00452         double                                  m_hitFraction; 
00453         double                                  m_ccdSweptSphereRadius;
00454         double                                  m_ccdMotionThreshold;
00455 
00456         int                                             m_hasAnisotropicFriction;
00457         int                                             m_collisionFlags;
00458         int                                             m_islandTag1;
00459         int                                             m_companionId;
00460         int                                             m_activationState1;
00461         int                                             m_internalType;
00462         int                                             m_checkCollideWith;
00463 
00464         char    m_padding[4];
00465 };
00466 
00468 struct  btCollisionObjectFloatData
00469 {
00470         void                                    *m_broadphaseHandle;
00471         void                                    *m_collisionShape;
00472         btCollisionShapeData    *m_rootCollisionShape;
00473         char                                    *m_name;
00474 
00475         btTransformFloatData    m_worldTransform;
00476         btTransformFloatData    m_interpolationWorldTransform;
00477         btVector3FloatData              m_interpolationLinearVelocity;
00478         btVector3FloatData              m_interpolationAngularVelocity;
00479         btVector3FloatData              m_anisotropicFriction;
00480         float                                   m_contactProcessingThreshold;   
00481         float                                   m_deactivationTime;
00482         float                                   m_friction;
00483         float                                   m_restitution;
00484         float                                   m_hitFraction; 
00485         float                                   m_ccdSweptSphereRadius;
00486         float                                   m_ccdMotionThreshold;
00487 
00488         int                                             m_hasAnisotropicFriction;
00489         int                                             m_collisionFlags;
00490         int                                             m_islandTag1;
00491         int                                             m_companionId;
00492         int                                             m_activationState1;
00493         int                                             m_internalType;
00494         int                                             m_checkCollideWith;
00495 };
00496 
00497 
00498 
00499 SIMD_FORCE_INLINE       int     btCollisionObject::calculateSerializeBufferSize() const
00500 {
00501         return sizeof(btCollisionObjectData);
00502 }
00503 
00504 
00505 
00506 #endif //COLLISION_OBJECT_H

Generated on Mon Feb 15 22:17:02 2010 for Bullet Collision Detection & Physics Library by  doxygen 1.6.1