Back to index

supertuxkart  0.5+dfsg1
btBroadphaseProxy.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 BROADPHASE_PROXY_H
00017 #define BROADPHASE_PROXY_H
00018 
00019 #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
00020 #include "LinearMath/btAlignedAllocator.h"
00021 
00022 
00026 enum BroadphaseNativeTypes
00027 {
00028 // polyhedral convex shapes
00029        BOX_SHAPE_PROXYTYPE,
00030        TRIANGLE_SHAPE_PROXYTYPE,
00031        TETRAHEDRAL_SHAPE_PROXYTYPE,
00032        CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
00033        CONVEX_HULL_SHAPE_PROXYTYPE,
00034 //implicit convex shapes
00035 IMPLICIT_CONVEX_SHAPES_START_HERE,
00036        SPHERE_SHAPE_PROXYTYPE,
00037        MULTI_SPHERE_SHAPE_PROXYTYPE,
00038        CAPSULE_SHAPE_PROXYTYPE,
00039        CONE_SHAPE_PROXYTYPE,
00040        CONVEX_SHAPE_PROXYTYPE,
00041        CYLINDER_SHAPE_PROXYTYPE,
00042        UNIFORM_SCALING_SHAPE_PROXYTYPE,
00043        MINKOWSKI_SUM_SHAPE_PROXYTYPE,
00044        MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
00045 //concave shapes
00046 CONCAVE_SHAPES_START_HERE,
00047        //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
00048        TRIANGLE_MESH_SHAPE_PROXYTYPE,
00050        FAST_CONCAVE_MESH_PROXYTYPE,
00051        //terrain
00052        TERRAIN_SHAPE_PROXYTYPE,
00054        GIMPACT_SHAPE_PROXYTYPE,
00055        
00056        EMPTY_SHAPE_PROXYTYPE,
00057        STATIC_PLANE_PROXYTYPE,
00058 CONCAVE_SHAPES_END_HERE,
00059 
00060        COMPOUND_SHAPE_PROXYTYPE,
00061 
00062        SOFTBODY_SHAPE_PROXYTYPE,
00063 
00064        MAX_BROADPHASE_COLLISION_TYPES
00065 };
00066 
00067 //#include <stdio.h>
00068 
00070 ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy
00071 {
00072 
00073 BT_DECLARE_ALIGNED_ALLOCATOR();
00074        
00076        enum CollisionFilterGroups
00077        {
00078                DefaultFilter = 1,
00079                StaticFilter = 2,
00080                KinematicFilter = 4,
00081                DebrisFilter = 8,
00082                      SensorTrigger = 16,
00083                AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
00084        };
00085 
00086        //Usually the client btCollisionObject or Rigidbody class
00087        void*  m_clientObject;
00088 
00089        short int m_collisionFilterGroup;
00090        short int m_collisionFilterMask;
00091 
00092        void*  m_multiSapParentProxy;             
00093 
00094 
00095        int                  m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
00096 
00097        SIMD_FORCE_INLINE int getUid() const
00098        {
00099               return m_uniqueId;
00100        }
00101 
00102        //used for memory pools
00103        btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0)
00104        {
00105        }
00106 
00107        btBroadphaseProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
00108               :m_clientObject(userPtr),
00109               m_collisionFilterGroup(collisionFilterGroup),
00110               m_collisionFilterMask(collisionFilterMask)
00111        {
00112               m_multiSapParentProxy = multiSapParentProxy;
00113        }
00114 
00115        
00116 
00117        static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
00118        {
00119               return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
00120        }
00121 
00122        static SIMD_FORCE_INLINE bool      isConvex(int proxyType)
00123        {
00124               return (proxyType < CONCAVE_SHAPES_START_HERE);
00125        }
00126 
00127        static SIMD_FORCE_INLINE bool      isConcave(int proxyType)
00128        {
00129               return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
00130                      (proxyType < CONCAVE_SHAPES_END_HERE));
00131        }
00132        static SIMD_FORCE_INLINE bool      isCompound(int proxyType)
00133        {
00134               return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
00135        }
00136        static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
00137        {
00138               return (proxyType == STATIC_PLANE_PROXYTYPE);
00139        }
00140        
00141 }
00142 ;
00143 
00144 class btCollisionAlgorithm;
00145 
00146 struct btBroadphaseProxy;
00147 
00148 
00149 
00151 ATTRIBUTE_ALIGNED16(struct) btBroadphasePair
00152 {
00153        btBroadphasePair ()
00154               :
00155        m_pProxy0(0),
00156               m_pProxy1(0),
00157               m_algorithm(0),
00158               m_userInfo(0)
00159        {
00160        }
00161 
00162 BT_DECLARE_ALIGNED_ALLOCATOR();
00163 
00164        btBroadphasePair(const btBroadphasePair& other)
00165               :             m_pProxy0(other.m_pProxy0),
00166                             m_pProxy1(other.m_pProxy1),
00167                             m_algorithm(other.m_algorithm),
00168                             m_userInfo(other.m_userInfo)
00169        {
00170        }
00171        btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
00172        {
00173 
00174               //keep them sorted, so the std::set operations work
00175               if (&proxy0 < &proxy1)
00176         { 
00177             m_pProxy0 = &proxy0; 
00178             m_pProxy1 = &proxy1; 
00179         }
00180         else 
00181         { 
00182                      m_pProxy0 = &proxy1; 
00183             m_pProxy1 = &proxy0; 
00184         }
00185 
00186               m_algorithm = 0;
00187               m_userInfo = 0;
00188 
00189        }
00190        
00191        btBroadphaseProxy* m_pProxy0;
00192        btBroadphaseProxy* m_pProxy1;
00193        
00194        mutable btCollisionAlgorithm* m_algorithm;
00195        mutable void* m_userInfo;
00196 
00197 };
00198 
00199 /*
00200 //comparison for set operation, see Solid DT_Encounter
00201 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b) 
00202 { 
00203     return a.m_pProxy0 < b.m_pProxy0 || 
00204         (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1); 
00205 }
00206 */
00207 
00208 
00209 
00210 class btBroadphasePairSortPredicate
00211 {
00212        public:
00213 
00214               bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
00215               {
00216                       return a.m_pProxy0 > b.m_pProxy0 || 
00217                             (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 > b.m_pProxy1) ||
00218                             (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 
00219               }
00220 };
00221 
00222 
00223 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 
00224 {
00225         return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
00226 }
00227 
00228 
00229 #endif //BROADPHASE_PROXY_H
00230