Back to index

supertuxkart  0.5+dfsg1
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 #include "LinearMath/btMotionState.h"
00031 #include "LinearMath/btAlignedAllocator.h"
00032 
00033 
00034 
00038 ATTRIBUTE_ALIGNED16(class)  btCollisionObject
00039 {
00040 
00041 protected:
00042 
00043        btTransform   m_worldTransform;
00044 
00047        btTransform   m_interpolationWorldTransform;
00048        //those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities) 
00049        //without destroying the continuous interpolated motion (which uses this interpolation velocities)
00050        btVector3     m_interpolationLinearVelocity;
00051        btVector3     m_interpolationAngularVelocity;
00052        btBroadphaseProxy*          m_broadphaseHandle;
00053        btCollisionShape*           m_collisionShape;
00054 
00055        int                         m_collisionFlags;
00056 
00057        int                         m_islandTag1;
00058        int                         m_companionId;
00059 
00060        int                         m_activationState1;
00061        btScalar                    m_deactivationTime;
00062 
00063        btScalar             m_friction;
00064        btScalar             m_restitution;
00065 
00067        void*                m_userObjectPointer;
00068 
00071        int                         m_internalType;
00072 
00074        btScalar             m_hitFraction; 
00075        
00077        btScalar             m_ccdSweptSphereRadius;
00078 
00080        btScalar             m_ccdSquareMotionThreshold;
00081        
00083        bool                 m_checkCollideWith;
00084 
00085        char   m_pad[7];
00086 
00087        virtual bool  checkCollideWithOverride(btCollisionObject* co)
00088        {
00089               return true;
00090        }
00091 
00092 public:
00093 
00094        BT_DECLARE_ALIGNED_ALLOCATOR();
00095 
00096        enum CollisionFlags
00097        {
00098               CF_STATIC_OBJECT= 1,
00099               CF_KINEMATIC_OBJECT= 2,
00100               CF_NO_CONTACT_RESPONSE = 4,
00101               CF_CUSTOM_MATERIAL_CALLBACK = 8//this allows per-triangle material (friction/restitution)
00102        };
00103 
00104        enum   CollisionObjectTypes
00105        {
00106               CO_COLLISION_OBJECT =1,
00107               CO_RIGID_BODY,
00108               CO_SOFT_BODY
00109        };
00110 
00111        SIMD_FORCE_INLINE bool mergesSimulationIslands() const
00112        {
00114               return  ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
00115        }
00116 
00117 
00118        SIMD_FORCE_INLINE bool             isStaticObject() const {
00119               return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
00120        }
00121 
00122        SIMD_FORCE_INLINE bool             isKinematicObject() const
00123        {
00124               return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
00125        }
00126 
00127        SIMD_FORCE_INLINE bool             isStaticOrKinematicObject() const
00128        {
00129               return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
00130        }
00131 
00132        SIMD_FORCE_INLINE bool             hasContactResponse() const {
00133               return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
00134        }
00135 
00136        
00137        btCollisionObject();
00138 
00139        virtual ~btCollisionObject();
00140 
00141        void   setCollisionShape(btCollisionShape* collisionShape)
00142        {
00143               m_collisionShape = collisionShape;
00144        }
00145 
00146        SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
00147        {
00148               return m_collisionShape;
00149        }
00150 
00151        SIMD_FORCE_INLINE btCollisionShape*       getCollisionShape()
00152        {
00153               return m_collisionShape;
00154        }
00155 
00156        
00157 
00158 
00159        int    getActivationState() const { return m_activationState1;}
00160        
00161        void setActivationState(int newState);
00162 
00163        void   setDeactivationTime(btScalar time)
00164        {
00165               m_deactivationTime = time;
00166        }
00167        btScalar      getDeactivationTime() const
00168        {
00169               return m_deactivationTime;
00170        }
00171 
00172        void forceActivationState(int newState);
00173 
00174        void   activate(bool forceActivation = false);
00175 
00176        inline bool isActive() const
00177        {
00178               return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
00179        }
00180 
00181        void   setRestitution(btScalar rest)
00182        {
00183               m_restitution = rest;
00184        }
00185        btScalar      getRestitution() const
00186        {
00187               return m_restitution;
00188        }
00189        void   setFriction(btScalar frict)
00190        {
00191               m_friction = frict;
00192        }
00193        btScalar      getFriction() const
00194        {
00195               return m_friction;
00196        }
00197 
00199        int    getInternalType() const
00200        {
00201               return m_internalType;
00202        }
00203 
00204        btTransform&  getWorldTransform()
00205        {
00206               return m_worldTransform;
00207        }
00208 
00209        const btTransform&   getWorldTransform() const
00210        {
00211               return m_worldTransform;
00212        }
00213 
00214        void   setWorldTransform(const btTransform& worldTrans)
00215        {
00216               m_worldTransform = worldTrans;
00217        }
00218 
00219 
00220        btBroadphaseProxy*   getBroadphaseHandle()
00221        {
00222               return m_broadphaseHandle;
00223        }
00224 
00225        const btBroadphaseProxy*    getBroadphaseHandle() const
00226        {
00227               return m_broadphaseHandle;
00228        }
00229 
00230        void   setBroadphaseHandle(btBroadphaseProxy* handle)
00231        {
00232               m_broadphaseHandle = handle;
00233        }
00234 
00235 
00236        const btTransform&   getInterpolationWorldTransform() const
00237        {
00238               return m_interpolationWorldTransform;
00239        }
00240 
00241        btTransform&  getInterpolationWorldTransform()
00242        {
00243               return m_interpolationWorldTransform;
00244        }
00245 
00246        void   setInterpolationWorldTransform(const btTransform&       trans)
00247        {
00248               m_interpolationWorldTransform = trans;
00249        }
00250 
00251 
00252        const btVector3&     getInterpolationLinearVelocity() const
00253        {
00254               return m_interpolationLinearVelocity;
00255        }
00256 
00257        const btVector3&     getInterpolationAngularVelocity() const
00258        {
00259               return m_interpolationAngularVelocity;
00260        }
00261 
00262        const int getIslandTag() const
00263        {
00264               return m_islandTag1;
00265        }
00266 
00267        void   setIslandTag(int tag)
00268        {
00269               m_islandTag1 = tag;
00270        }
00271 
00272        const int getCompanionId() const
00273        {
00274               return m_companionId;
00275        }
00276 
00277        void   setCompanionId(int id)
00278        {
00279               m_companionId = id;
00280        }
00281 
00282        const btScalar                     getHitFraction() const
00283        {
00284               return m_hitFraction; 
00285        }
00286 
00287        void   setHitFraction(btScalar hitFraction)
00288        {
00289               m_hitFraction = hitFraction;
00290        }
00291 
00292        
00293        const int     getCollisionFlags() const
00294        {
00295               return m_collisionFlags;
00296        }
00297 
00298        void   setCollisionFlags(int flags)
00299        {
00300               m_collisionFlags = flags;
00301        }
00302        
00304        btScalar                    getCcdSweptSphereRadius() const
00305        {
00306               return m_ccdSweptSphereRadius;
00307        }
00308 
00310        void   setCcdSweptSphereRadius(btScalar radius)
00311        {
00312               m_ccdSweptSphereRadius = radius;
00313        }
00314 
00315        btScalar      getCcdSquareMotionThreshold() const
00316        {
00317               return m_ccdSquareMotionThreshold;
00318        }
00319 
00320 
00322        void   setCcdSquareMotionThreshold(btScalar ccdSquareMotionThreshold)
00323        {
00324               m_ccdSquareMotionThreshold = ccdSquareMotionThreshold;
00325        }
00326 
00328        void*  getUserPointer() const
00329        {
00330               return m_userObjectPointer;
00331        }
00332        
00334        void   setUserPointer(void* userPointer)
00335        {
00336               m_userObjectPointer = userPointer;
00337        }
00338 
00339 
00340        inline bool checkCollideWith(btCollisionObject* co)
00341        {
00342               if (m_checkCollideWith)
00343                      return checkCollideWithOverride(co);
00344 
00345               return true;
00346        }
00347 };
00348 
00349 #endif //COLLISION_OBJECT_H