- Timestamp:
- Feb 27, 2011, 7:43:24 AM (14 years ago)
- Location:
- code/branches/kicklib/src/external/bullet/BulletCollision
- Files:
-
- 11 added
- 129 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h
r5781 r7983 151 151 152 152 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)); 153 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 154 153 155 154 156 void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const; … … 281 283 { 282 284 rayCallback.process(getHandle(m_pEdges[axis][i].m_handle)); 285 } 286 } 287 } 288 } 289 290 template <typename BP_FP_INT_TYPE> 291 void btAxisSweep3Internal<BP_FP_INT_TYPE>::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) 292 { 293 if (m_raycastAccelerator) 294 { 295 m_raycastAccelerator->aabbTest(aabbMin,aabbMax,callback); 296 } else 297 { 298 //choose axis? 299 BP_FP_INT_TYPE axis = 0; 300 //for each proxy 301 for (BP_FP_INT_TYPE i=1;i<m_numHandles*2+1;i++) 302 { 303 if (m_pEdges[axis][i].IsMax()) 304 { 305 Handle* handle = getHandle(m_pEdges[axis][i].m_handle); 306 if (TestAabbAgainstAabb2(aabbMin,aabbMax,handle->m_aabbMin,handle->m_aabbMax)) 307 { 308 callback.process(handle); 309 } 283 310 } 284 311 } -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
r5781 r7983 27 27 28 28 29 struct btBroadphaseRayCallback 29 struct btBroadphaseAabbCallback 30 { 31 virtual ~btBroadphaseAabbCallback() {} 32 virtual bool process(const btBroadphaseProxy* proxy) = 0; 33 }; 34 35 36 struct btBroadphaseRayCallback : public btBroadphaseAabbCallback 30 37 { 31 38 ///added some cached data to accelerate ray-AABB tests … … 35 42 36 43 virtual ~btBroadphaseRayCallback() {} 37 virtual bool process(const btBroadphaseProxy* proxy) = 0;38 44 }; 39 45 … … 55 61 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0; 56 62 63 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) = 0; 64 57 65 ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb 58 66 virtual void calculateOverlappingPairs(btDispatcher* dispatcher)=0; … … 66 74 67 75 ///reset broadphase internal structures, to ensure determinism/reproducability 68 virtual void resetPool(btDispatcher* dispatcher) { };76 virtual void resetPool(btDispatcher* dispatcher) { (void) dispatcher; }; 69 77 70 78 virtual void printStats() = 0; -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
r5781 r7983 47 47 MINKOWSKI_SUM_SHAPE_PROXYTYPE, 48 48 MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE, 49 BOX_2D_SHAPE_PROXYTYPE, 50 CONVEX_2D_SHAPE_PROXYTYPE, 49 51 CUSTOM_CONVEX_SHAPE_TYPE, 50 52 //concave shapes … … 140 142 } 141 143 144 static SIMD_FORCE_INLINE bool isNonMoving(int proxyType) 145 { 146 return (isConcave(proxyType) && !(proxyType==GIMPACT_SHAPE_PROXYTYPE)); 147 } 148 142 149 static SIMD_FORCE_INLINE bool isConcave(int proxyType) 143 150 { … … 149 156 return (proxyType == COMPOUND_SHAPE_PROXYTYPE); 150 157 } 158 159 static SIMD_FORCE_INLINE bool isSoftBody(int proxyType) 160 { 161 return (proxyType == SOFTBODY_SHAPE_PROXYTYPE); 162 } 163 151 164 static SIMD_FORCE_INLINE bool isInfinite(int proxyType) 152 165 { 153 166 return (proxyType == STATIC_PLANE_PROXYTYPE); 154 167 } 168 169 static SIMD_FORCE_INLINE bool isConvex2d(int proxyType) 170 { 171 return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE); 172 } 173 155 174 156 175 } -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp
r5781 r7983 62 62 { 63 63 getmaxdepth(node->childs[0],depth+1,maxdepth); 64 getmaxdepth(node->childs[ 0],depth+1,maxdepth);64 getmaxdepth(node->childs[1],depth+1,maxdepth); 65 65 } else maxdepth=btMax(maxdepth,depth); 66 66 } … … 239 239 for(int i=0,ni=leaves.size();i<ni;++i) 240 240 { 241 if( dot(axis,leaves[i]->volume.Center()-org)<0)241 if(btDot(axis,leaves[i]->volume.Center()-org)<0) 242 242 left.push_back(leaves[i]); 243 243 else … … 320 320 for(int j=0;j<3;++j) 321 321 { 322 ++splitcount[j][ dot(x,axis[j])>0?1:0];322 ++splitcount[j][btDot(x,axis[j])>0?1:0]; 323 323 } 324 324 } -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvt.h
r5781 r7983 33 33 34 34 // Template implementation of ICollide 35 #ifdef WIN3235 #ifdef _WIN32 36 36 #if (defined (_MSC_VER) && _MSC_VER >= 1400) 37 37 #define DBVT_USE_TEMPLATE 1 … … 58 58 59 59 //SSE gives errors on a MSVC 7.1 60 #if def BT_USE_SSE60 #if defined (BT_USE_SSE) && defined (_WIN32) 61 61 #define DBVT_SELECT_IMPL DBVT_IMPL_SSE 62 62 #define DBVT_MERGE_IMPL DBVT_IMPL_SSE … … 93 93 94 94 #if DBVT_USE_MEMMOVE 95 #if ndef __CELLOS_LV2__95 #if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) 96 96 #include <memory.h> 97 97 #endif … … 485 485 pi=btVector3(mi.x(),mi.y(),mi.z());break; 486 486 } 487 if(( dot(n,px)+o)<0) return(-1);488 if(( dot(n,pi)+o)>=0) return(+1);487 if((btDot(n,px)+o)<0) return(-1); 488 if((btDot(n,pi)+o)>=0) return(+1); 489 489 return(0); 490 490 } … … 497 497 b[(signs>>1)&1]->y(), 498 498 b[(signs>>2)&1]->z()); 499 return( dot(p,v));499 return(btDot(p,v)); 500 500 } 501 501 … … 948 948 DBVT_IPOLICY) const 949 949 { 950 (void) rayTo; 950 951 DBVT_CHECKTYPE 951 952 if(root) … … 962 963 { 963 964 const btDbvtNode* node=stack[--depth]; 964 bounds[0] = node->volume.Mins() +aabbMin;965 bounds[1] = node->volume.Maxs() +aabbMax;965 bounds[0] = node->volume.Mins()-aabbMax; 966 bounds[1] = node->volume.Maxs()-aabbMin; 966 967 btScalar tmin=1.f,lambda_min=0.f; 967 968 unsigned int result1=false; … … 1001 1002 rayDir.normalize (); 1002 1003 1003 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e301004 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 1004 1005 btVector3 rayDirectionInverse; 1005 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];1006 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];1007 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];1006 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 1007 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 1008 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 1008 1009 unsigned int signs[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; 1009 1010 -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 7 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 ///btDbvtBroadphase implementation by Nathanael Presson 16 17 … … 124 125 m_needcleanup = true; 125 126 m_releasepaircache = (paircache!=0)?false:true; 126 m_prediction = 1/(btScalar)2;127 m_prediction = 0; 127 128 m_stageCurrent = 0; 128 129 m_fixedleft = 0; … … 250 251 } 251 252 253 254 struct BroadphaseAabbTester : btDbvt::ICollide 255 { 256 btBroadphaseAabbCallback& m_aabbCallback; 257 BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback) 258 :m_aabbCallback(orgCallback) 259 { 260 } 261 void Process(const btDbvtNode* leaf) 262 { 263 btDbvtProxy* proxy=(btDbvtProxy*)leaf->data; 264 m_aabbCallback.process(proxy); 265 } 266 }; 267 268 void btDbvtBroadphase::aabbTest(const btVector3& aabbMin,const btVector3& aabbMax,btBroadphaseAabbCallback& aabbCallback) 269 { 270 BroadphaseAabbTester callback(aabbCallback); 271 272 const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(aabbMin,aabbMax); 273 //process all children, that overlap with the given AABB bounds 274 m_sets[0].collideTV(m_sets[0].m_root,bounds,callback); 275 m_sets[1].collideTV(m_sets[1].m_root,bounds,callback); 276 277 } 278 279 280 252 281 // 253 282 void btDbvtBroadphase::setAabb( btBroadphaseProxy* absproxy, … … 315 344 } 316 345 } 346 } 347 348 349 // 350 void btDbvtBroadphase::setAabbForceUpdate( btBroadphaseProxy* absproxy, 351 const btVector3& aabbMin, 352 const btVector3& aabbMax, 353 btDispatcher* /*dispatcher*/) 354 { 355 btDbvtProxy* proxy=(btDbvtProxy*)absproxy; 356 ATTRIBUTE_ALIGNED16(btDbvtVolume) aabb=btDbvtVolume::FromMM(aabbMin,aabbMax); 357 bool docollide=false; 358 if(proxy->stage==STAGECOUNT) 359 {/* fixed -> dynamic set */ 360 m_sets[1].remove(proxy->leaf); 361 proxy->leaf=m_sets[0].insert(aabb,proxy); 362 docollide=true; 363 } 364 else 365 {/* dynamic set */ 366 ++m_updates_call; 367 /* Teleporting */ 368 m_sets[0].update(proxy->leaf,aabb); 369 ++m_updates_done; 370 docollide=true; 371 } 372 listremove(proxy,m_stageRoots[proxy->stage]); 373 proxy->m_aabbMin = aabbMin; 374 proxy->m_aabbMax = aabbMax; 375 proxy->stage = m_stageCurrent; 376 listappend(proxy,m_stageRoots[m_stageCurrent]); 377 if(docollide) 378 { 379 m_needcleanup=true; 380 if(!m_deferedcollide) 381 { 382 btDbvtTreeCollider collider(this); 383 m_sets[1].collideTTpersistentStack(m_sets[1].m_root,proxy->leaf,collider); 384 m_sets[0].collideTTpersistentStack(m_sets[0].m_root,proxy->leaf,collider); 385 } 386 } 317 387 } 318 388 … … 572 642 m_deferedcollide = false; 573 643 m_needcleanup = true; 574 m_prediction = 1/(btScalar)2;575 644 m_stageCurrent = 0; 576 645 m_fixedleft = 0; -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 7 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 ///btDbvtBroadphase implementation by Nathanael Presson 16 17 #ifndef BT_DBVT_BROADPHASE_H … … 102 103 void collide(btDispatcher* dispatcher); 103 104 void optimize(); 104 /* btBroadphaseInterface Implementation */ 105 106 /* btBroadphaseInterface Implementation */ 105 107 btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy); 106 void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); 107 void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher); 108 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)); 108 virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); 109 virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher); 110 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)); 111 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 109 112 110 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const; 111 void calculateOverlappingPairs(btDispatcher* dispatcher); 112 btOverlappingPairCache* getOverlappingPairCache(); 113 const btOverlappingPairCache* getOverlappingPairCache() const; 114 void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const; 115 void printStats(); 116 static void benchmark(btBroadphaseInterface*); 113 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const; 114 virtual void calculateOverlappingPairs(btDispatcher* dispatcher); 115 virtual btOverlappingPairCache* getOverlappingPairCache(); 116 virtual const btOverlappingPairCache* getOverlappingPairCache() const; 117 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const; 118 virtual void printStats(); 117 119 118 119 void performDeferredRemoval(btDispatcher* dispatcher);120 120 121 121 ///reset broadphase internal structures, to ensure determinism/reproducability 122 122 virtual void resetPool(btDispatcher* dispatcher); 123 123 124 void performDeferredRemoval(btDispatcher* dispatcher); 125 126 void setVelocityPrediction(btScalar prediction) 127 { 128 m_prediction = prediction; 129 } 130 btScalar getVelocityPrediction() const 131 { 132 return m_prediction; 133 } 134 135 ///this setAabbForceUpdate is similar to setAabb but always forces the aabb update. 136 ///it is not part of the btBroadphaseInterface but specific to btDbvtBroadphase. 137 ///it bypasses certain optimizations that prevent aabb updates (when the aabb shrinks), see 138 ///http://code.google.com/p/bullet/issues/detail?id=223 139 void setAabbForceUpdate( btBroadphaseProxy* absproxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* /*dispatcher*/); 140 141 static void benchmark(btBroadphaseInterface*); 142 143 124 144 }; 125 145 -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btDispatcher.h
r5781 r7983 47 47 m_useEpa(true), 48 48 m_allowedCcdPenetration(btScalar(0.04)), 49 m_useConvexConservativeDistanceUtil( true),49 m_useConvexConservativeDistanceUtil(false), 50 50 m_convexConservativeDistanceThreshold(0.0f), 51 m_convexMaxDistanceUseCPT(false), 51 52 m_stackAllocator(0) 52 53 { … … 65 66 bool m_useConvexConservativeDistanceUtil; 66 67 btScalar m_convexConservativeDistanceThreshold; 68 bool m_convexMaxDistanceUseCPT; 67 69 btStackAlloc* m_stackAllocator; 68 70 }; -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h
r5781 r7983 134 134 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const 135 135 { 136 aabbMin.setValue(- 1e30f,-1e30f,-1e30f);137 aabbMax.setValue( 1e30f,1e30f,1e30f);136 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 137 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 138 138 } 139 139 -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
r5781 r7983 241 241 int count = m_overlappingPairArray.size(); 242 242 int oldCapacity = m_overlappingPairArray.capacity(); 243 void* mem = &m_overlappingPairArray.expand ();243 void* mem = &m_overlappingPairArray.expandNonInitializing(); 244 244 245 245 //this is where we add an actual pair, so also call the 'ghost' … … 468 468 return 0; 469 469 470 void* mem = &m_overlappingPairArray.expand ();470 void* mem = &m_overlappingPairArray.expandNonInitializing(); 471 471 btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1); 472 472 -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
r5781 r7983 458 458 virtual void sortOverlappingPairs(btDispatcher* dispatcher) 459 459 { 460 (void) dispatcher; 460 461 } 461 462 -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
r5781 r7983 18 18 #include "LinearMath/btAabbUtil2.h" 19 19 #include "LinearMath/btIDebugDraw.h" 20 #include "LinearMath/btSerializer.h" 20 21 21 22 #define RAYAABB2 … … 79 80 btVector3 color[4]= 80 81 { 81 btVector3( 255,0,0),82 btVector3(0, 255,0),83 btVector3(0,0, 255),84 btVector3(0, 255,255)82 btVector3(1,0,0), 83 btVector3(0,1,0), 84 btVector3(0,0,1), 85 btVector3(0,1,1) 85 86 }; 86 87 #endif //DEBUG_PATCH_COLORS … … 475 476 ///what about division by zero? --> just set rayDirection[i] to 1.0 476 477 btVector3 rayDirectionInverse; 477 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];478 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];479 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];478 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 479 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 480 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 480 481 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; 481 482 #endif … … 494 495 bounds[1] = rootNode->m_aabbMaxOrg; 495 496 /* Add box cast extents */ 496 bounds[0] += aabbMin;497 bounds[1] += aabbMax;497 bounds[0] -= aabbMax; 498 bounds[1] -= aabbMin; 498 499 499 500 aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg); … … 562 563 lambda_max = rayDirection.dot(rayTarget-raySource); 563 564 ///what about division by zero? --> just set rayDirection[i] to 1.0 564 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[0];565 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[1];566 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[2];565 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0]; 566 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[1]; 567 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[2]; 567 568 unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0}; 568 569 #endif … … 618 619 bounds[1] = unQuantize(rootNode->m_quantizedAabbMax); 619 620 /* Add box cast extents */ 620 bounds[0] += aabbMin;621 bounds[1] += aabbMax;621 bounds[0] -= aabbMax; 622 bounds[1] -= aabbMin; 622 623 btVector3 normal; 623 624 #if 0 … … 831 832 } 832 833 833 unsigned btQuantizedBvh::calculateSerializeBufferSize() 834 unsigned btQuantizedBvh::calculateSerializeBufferSize() const 834 835 { 835 836 unsigned baseSize = sizeof(btQuantizedBvh) + getAlignmentSerializationPadding(); … … 842 843 } 843 844 844 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) 845 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) const 845 846 { 846 847 btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size()); … … 1144 1145 } 1145 1146 1146 1147 1148 1147 void btQuantizedBvh::deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData) 1148 { 1149 m_bvhAabbMax.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMax); 1150 m_bvhAabbMin.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMin); 1151 m_bvhQuantization.deSerializeFloat(quantizedBvhFloatData.m_bvhQuantization); 1152 1153 m_curNodeIndex = quantizedBvhFloatData.m_curNodeIndex; 1154 m_useQuantization = quantizedBvhFloatData.m_useQuantization!=0; 1155 1156 { 1157 int numElem = quantizedBvhFloatData.m_numContiguousLeafNodes; 1158 m_contiguousNodes.resize(numElem); 1159 1160 if (numElem) 1161 { 1162 btOptimizedBvhNodeFloatData* memPtr = quantizedBvhFloatData.m_contiguousNodesPtr; 1163 1164 for (int i=0;i<numElem;i++,memPtr++) 1165 { 1166 m_contiguousNodes[i].m_aabbMaxOrg.deSerializeFloat(memPtr->m_aabbMaxOrg); 1167 m_contiguousNodes[i].m_aabbMinOrg.deSerializeFloat(memPtr->m_aabbMinOrg); 1168 m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex; 1169 m_contiguousNodes[i].m_subPart = memPtr->m_subPart; 1170 m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex; 1171 } 1172 } 1173 } 1174 1175 { 1176 int numElem = quantizedBvhFloatData.m_numQuantizedContiguousNodes; 1177 m_quantizedContiguousNodes.resize(numElem); 1178 1179 if (numElem) 1180 { 1181 btQuantizedBvhNodeData* memPtr = quantizedBvhFloatData.m_quantizedContiguousNodesPtr; 1182 for (int i=0;i<numElem;i++,memPtr++) 1183 { 1184 m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex; 1185 m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0]; 1186 m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1187 m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1188 m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1189 m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1190 m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1191 } 1192 } 1193 } 1194 1195 m_traversalMode = btTraversalMode(quantizedBvhFloatData.m_traversalMode); 1196 1197 { 1198 int numElem = quantizedBvhFloatData.m_numSubtreeHeaders; 1199 m_SubtreeHeaders.resize(numElem); 1200 if (numElem) 1201 { 1202 btBvhSubtreeInfoData* memPtr = quantizedBvhFloatData.m_subTreeInfoPtr; 1203 for (int i=0;i<numElem;i++,memPtr++) 1204 { 1205 m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ; 1206 m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1207 m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1208 m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1209 m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1210 m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1211 m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex; 1212 m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize; 1213 } 1214 } 1215 } 1216 } 1217 1218 void btQuantizedBvh::deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData) 1219 { 1220 m_bvhAabbMax.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMax); 1221 m_bvhAabbMin.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMin); 1222 m_bvhQuantization.deSerializeDouble(quantizedBvhDoubleData.m_bvhQuantization); 1223 1224 m_curNodeIndex = quantizedBvhDoubleData.m_curNodeIndex; 1225 m_useQuantization = quantizedBvhDoubleData.m_useQuantization!=0; 1226 1227 { 1228 int numElem = quantizedBvhDoubleData.m_numContiguousLeafNodes; 1229 m_contiguousNodes.resize(numElem); 1230 1231 if (numElem) 1232 { 1233 btOptimizedBvhNodeDoubleData* memPtr = quantizedBvhDoubleData.m_contiguousNodesPtr; 1234 1235 for (int i=0;i<numElem;i++,memPtr++) 1236 { 1237 m_contiguousNodes[i].m_aabbMaxOrg.deSerializeDouble(memPtr->m_aabbMaxOrg); 1238 m_contiguousNodes[i].m_aabbMinOrg.deSerializeDouble(memPtr->m_aabbMinOrg); 1239 m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex; 1240 m_contiguousNodes[i].m_subPart = memPtr->m_subPart; 1241 m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex; 1242 } 1243 } 1244 } 1245 1246 { 1247 int numElem = quantizedBvhDoubleData.m_numQuantizedContiguousNodes; 1248 m_quantizedContiguousNodes.resize(numElem); 1249 1250 if (numElem) 1251 { 1252 btQuantizedBvhNodeData* memPtr = quantizedBvhDoubleData.m_quantizedContiguousNodesPtr; 1253 for (int i=0;i<numElem;i++,memPtr++) 1254 { 1255 m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex; 1256 m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0]; 1257 m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1258 m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1259 m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1260 m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1261 m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1262 } 1263 } 1264 } 1265 1266 m_traversalMode = btTraversalMode(quantizedBvhDoubleData.m_traversalMode); 1267 1268 { 1269 int numElem = quantizedBvhDoubleData.m_numSubtreeHeaders; 1270 m_SubtreeHeaders.resize(numElem); 1271 if (numElem) 1272 { 1273 btBvhSubtreeInfoData* memPtr = quantizedBvhDoubleData.m_subTreeInfoPtr; 1274 for (int i=0;i<numElem;i++,memPtr++) 1275 { 1276 m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ; 1277 m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1278 m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1279 m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1280 m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1281 m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1282 m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex; 1283 m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize; 1284 } 1285 } 1286 } 1287 1288 } 1289 1290 1291 1292 ///fills the dataBuffer and returns the struct name (and 0 on failure) 1293 const char* btQuantizedBvh::serialize(void* dataBuffer, btSerializer* serializer) const 1294 { 1295 btQuantizedBvhData* quantizedData = (btQuantizedBvhData*)dataBuffer; 1296 1297 m_bvhAabbMax.serialize(quantizedData->m_bvhAabbMax); 1298 m_bvhAabbMin.serialize(quantizedData->m_bvhAabbMin); 1299 m_bvhQuantization.serialize(quantizedData->m_bvhQuantization); 1300 1301 quantizedData->m_curNodeIndex = m_curNodeIndex; 1302 quantizedData->m_useQuantization = m_useQuantization; 1303 1304 quantizedData->m_numContiguousLeafNodes = m_contiguousNodes.size(); 1305 quantizedData->m_contiguousNodesPtr = (btOptimizedBvhNodeData*) (m_contiguousNodes.size() ? serializer->getUniquePointer((void*)&m_contiguousNodes[0]) : 0); 1306 if (quantizedData->m_contiguousNodesPtr) 1307 { 1308 int sz = sizeof(btOptimizedBvhNodeData); 1309 int numElem = m_contiguousNodes.size(); 1310 btChunk* chunk = serializer->allocate(sz,numElem); 1311 btOptimizedBvhNodeData* memPtr = (btOptimizedBvhNodeData*)chunk->m_oldPtr; 1312 for (int i=0;i<numElem;i++,memPtr++) 1313 { 1314 m_contiguousNodes[i].m_aabbMaxOrg.serialize(memPtr->m_aabbMaxOrg); 1315 m_contiguousNodes[i].m_aabbMinOrg.serialize(memPtr->m_aabbMinOrg); 1316 memPtr->m_escapeIndex = m_contiguousNodes[i].m_escapeIndex; 1317 memPtr->m_subPart = m_contiguousNodes[i].m_subPart; 1318 memPtr->m_triangleIndex = m_contiguousNodes[i].m_triangleIndex; 1319 } 1320 serializer->finalizeChunk(chunk,"btOptimizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_contiguousNodes[0]); 1321 } 1322 1323 quantizedData->m_numQuantizedContiguousNodes = m_quantizedContiguousNodes.size(); 1324 // printf("quantizedData->m_numQuantizedContiguousNodes=%d\n",quantizedData->m_numQuantizedContiguousNodes); 1325 quantizedData->m_quantizedContiguousNodesPtr =(btQuantizedBvhNodeData*) (m_quantizedContiguousNodes.size() ? serializer->getUniquePointer((void*)&m_quantizedContiguousNodes[0]) : 0); 1326 if (quantizedData->m_quantizedContiguousNodesPtr) 1327 { 1328 int sz = sizeof(btQuantizedBvhNodeData); 1329 int numElem = m_quantizedContiguousNodes.size(); 1330 btChunk* chunk = serializer->allocate(sz,numElem); 1331 btQuantizedBvhNodeData* memPtr = (btQuantizedBvhNodeData*)chunk->m_oldPtr; 1332 for (int i=0;i<numElem;i++,memPtr++) 1333 { 1334 memPtr->m_escapeIndexOrTriangleIndex = m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex; 1335 memPtr->m_quantizedAabbMax[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[0]; 1336 memPtr->m_quantizedAabbMax[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[1]; 1337 memPtr->m_quantizedAabbMax[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[2]; 1338 memPtr->m_quantizedAabbMin[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[0]; 1339 memPtr->m_quantizedAabbMin[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[1]; 1340 memPtr->m_quantizedAabbMin[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[2]; 1341 } 1342 serializer->finalizeChunk(chunk,"btQuantizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_quantizedContiguousNodes[0]); 1343 } 1344 1345 quantizedData->m_traversalMode = int(m_traversalMode); 1346 quantizedData->m_numSubtreeHeaders = m_SubtreeHeaders.size(); 1347 1348 quantizedData->m_subTreeInfoPtr = (btBvhSubtreeInfoData*) (m_SubtreeHeaders.size() ? serializer->getUniquePointer((void*)&m_SubtreeHeaders[0]) : 0); 1349 if (quantizedData->m_subTreeInfoPtr) 1350 { 1351 int sz = sizeof(btBvhSubtreeInfoData); 1352 int numElem = m_SubtreeHeaders.size(); 1353 btChunk* chunk = serializer->allocate(sz,numElem); 1354 btBvhSubtreeInfoData* memPtr = (btBvhSubtreeInfoData*)chunk->m_oldPtr; 1355 for (int i=0;i<numElem;i++,memPtr++) 1356 { 1357 memPtr->m_quantizedAabbMax[0] = m_SubtreeHeaders[i].m_quantizedAabbMax[0]; 1358 memPtr->m_quantizedAabbMax[1] = m_SubtreeHeaders[i].m_quantizedAabbMax[1]; 1359 memPtr->m_quantizedAabbMax[2] = m_SubtreeHeaders[i].m_quantizedAabbMax[2]; 1360 memPtr->m_quantizedAabbMin[0] = m_SubtreeHeaders[i].m_quantizedAabbMin[0]; 1361 memPtr->m_quantizedAabbMin[1] = m_SubtreeHeaders[i].m_quantizedAabbMin[1]; 1362 memPtr->m_quantizedAabbMin[2] = m_SubtreeHeaders[i].m_quantizedAabbMin[2]; 1363 1364 memPtr->m_rootNodeIndex = m_SubtreeHeaders[i].m_rootNodeIndex; 1365 memPtr->m_subtreeSize = m_SubtreeHeaders[i].m_subtreeSize; 1366 } 1367 serializer->finalizeChunk(chunk,"btBvhSubtreeInfoData",BT_ARRAY_CODE,(void*)&m_SubtreeHeaders[0]); 1368 } 1369 return btQuantizedBvhDataName; 1370 } 1371 1372 1373 1374 1375 -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
r5781 r7983 17 17 #define QUANTIZED_BVH_H 18 18 19 class btSerializer; 20 19 21 //#define DEBUG_CHECK_DEQUANTIZATION 1 20 22 #ifdef DEBUG_CHECK_DEQUANTIZATION … … 29 31 #include "LinearMath/btVector3.h" 30 32 #include "LinearMath/btAlignedAllocator.h" 33 34 #ifdef BT_USE_DOUBLE_PRECISION 35 #define btQuantizedBvhData btQuantizedBvhDoubleData 36 #define btOptimizedBvhNodeData btOptimizedBvhNodeDoubleData 37 #define btQuantizedBvhDataName "btQuantizedBvhDoubleData" 38 #else 39 #define btQuantizedBvhData btQuantizedBvhFloatData 40 #define btOptimizedBvhNodeData btOptimizedBvhNodeFloatData 41 #define btQuantizedBvhDataName "btQuantizedBvhFloatData" 42 #endif 43 31 44 32 45 … … 191 204 192 205 //This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray 193 int m_subtreeHeaderCount;206 mutable int m_subtreeHeaderCount; 194 207 195 208 … … 444 457 } 445 458 459 //////////////////////////////////////////////////////////////////// 446 460 447 461 /////Calculate space needed to store BVH for serialization 448 unsigned calculateSerializeBufferSize() ;462 unsigned calculateSerializeBufferSize() const; 449 463 450 464 /// Data buffer MUST be 16 byte aligned 451 virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) ;465 virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const; 452 466 453 467 ///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place' … … 455 469 456 470 static unsigned int getAlignmentSerializationPadding(); 471 ////////////////////////////////////////////////////////////////////// 472 473 474 virtual int calculateSerializeBufferSizeNew() const; 475 476 ///fills the dataBuffer and returns the struct name (and 0 on failure) 477 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 478 479 virtual void deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData); 480 481 virtual void deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData); 482 483 484 //////////////////////////////////////////////////////////////////// 457 485 458 486 SIMD_FORCE_INLINE bool isQuantized() … … 471 499 472 500 501 struct btBvhSubtreeInfoData 502 { 503 int m_rootNodeIndex; 504 int m_subtreeSize; 505 unsigned short m_quantizedAabbMin[3]; 506 unsigned short m_quantizedAabbMax[3]; 507 }; 508 509 struct btOptimizedBvhNodeFloatData 510 { 511 btVector3FloatData m_aabbMinOrg; 512 btVector3FloatData m_aabbMaxOrg; 513 int m_escapeIndex; 514 int m_subPart; 515 int m_triangleIndex; 516 char m_pad[4]; 517 }; 518 519 struct btOptimizedBvhNodeDoubleData 520 { 521 btVector3DoubleData m_aabbMinOrg; 522 btVector3DoubleData m_aabbMaxOrg; 523 int m_escapeIndex; 524 int m_subPart; 525 int m_triangleIndex; 526 char m_pad[4]; 527 }; 528 529 530 struct btQuantizedBvhNodeData 531 { 532 unsigned short m_quantizedAabbMin[3]; 533 unsigned short m_quantizedAabbMax[3]; 534 int m_escapeIndexOrTriangleIndex; 535 }; 536 537 struct btQuantizedBvhFloatData 538 { 539 btVector3FloatData m_bvhAabbMin; 540 btVector3FloatData m_bvhAabbMax; 541 btVector3FloatData m_bvhQuantization; 542 int m_curNodeIndex; 543 int m_useQuantization; 544 int m_numContiguousLeafNodes; 545 int m_numQuantizedContiguousNodes; 546 btOptimizedBvhNodeFloatData *m_contiguousNodesPtr; 547 btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; 548 btBvhSubtreeInfoData *m_subTreeInfoPtr; 549 int m_traversalMode; 550 int m_numSubtreeHeaders; 551 552 }; 553 554 struct btQuantizedBvhDoubleData 555 { 556 btVector3DoubleData m_bvhAabbMin; 557 btVector3DoubleData m_bvhAabbMax; 558 btVector3DoubleData m_bvhQuantization; 559 int m_curNodeIndex; 560 int m_useQuantization; 561 int m_numContiguousLeafNodes; 562 int m_numQuantizedContiguousNodes; 563 btOptimizedBvhNodeDoubleData *m_contiguousNodesPtr; 564 btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; 565 566 int m_traversalMode; 567 int m_numSubtreeHeaders; 568 btBvhSubtreeInfoData *m_subTreeInfoPtr; 569 }; 570 571 572 SIMD_FORCE_INLINE int btQuantizedBvh::calculateSerializeBufferSizeNew() const 573 { 574 return sizeof(btQuantizedBvhData); 575 } 576 577 578 473 579 #endif //QUANTIZED_BVH_H -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
r5781 r7983 21 21 #include "LinearMath/btTransform.h" 22 22 #include "LinearMath/btMatrix3x3.h" 23 #include "LinearMath/btAabbUtil2.h" 24 23 25 #include <new> 24 26 … … 163 165 } 164 166 rayCallback.process(proxy); 167 } 168 } 169 170 171 void btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) 172 { 173 for (int i=0; i <= m_LastHandleIndex; i++) 174 { 175 btSimpleBroadphaseProxy* proxy = &m_pHandles[i]; 176 if(!proxy->m_clientObject) 177 { 178 continue; 179 } 180 if (TestAabbAgainstAabb2(aabbMin,aabbMax,proxy->m_aabbMin,proxy->m_aabbMax)) 181 { 182 callback.process(proxy); 183 } 165 184 } 166 185 } -
code/branches/kicklib/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
r5781 r7983 137 137 138 138 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0)); 139 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 139 140 140 141 btOverlappingPairCache* getOverlappingPairCache() … … 154 155 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const 155 156 { 156 aabbMin.setValue(- 1e30f,-1e30f,-1e30f);157 aabbMax.setValue( 1e30f,1e30f,1e30f);157 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 158 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 158 159 } 159 160 -
code/branches/kicklib/src/external/bullet/BulletCollision/CMakeLists.txt
r7982 r7983 6 6 BroadphaseCollision/btBroadphaseProxy.cpp 7 7 BroadphaseCollision/btCollisionAlgorithm.cpp 8 BroadphaseCollision/btDbvt.cpp 9 BroadphaseCollision/btDbvtBroadphase.cpp 8 10 BroadphaseCollision/btDispatcher.cpp 9 BroadphaseCollision/btDbvtBroadphase.cpp10 BroadphaseCollision/btDbvt.cpp11 11 BroadphaseCollision/btMultiSapBroadphase.cpp 12 12 BroadphaseCollision/btOverlappingPairCache.cpp … … 15 15 16 16 CollisionDispatch/btActivatingCollisionAlgorithm.cpp 17 CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp 18 CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp 19 CollisionDispatch/btBoxBoxDetector.cpp 17 20 CollisionDispatch/btCollisionDispatcher.cpp 18 21 CollisionDispatch/btCollisionObject.cpp … … 20 23 CollisionDispatch/btCompoundCollisionAlgorithm.cpp 21 24 CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp 25 CollisionDispatch/btConvexConvexAlgorithm.cpp 26 CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp 27 CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp 22 28 CollisionDispatch/btDefaultCollisionConfiguration.cpp 23 CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp 24 CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp 25 CollisionDispatch/btBoxBoxDetector.cpp 29 CollisionDispatch/btEmptyCollisionAlgorithm.cpp 26 30 CollisionDispatch/btGhostObject.cpp 27 CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp 28 CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp 29 CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp 30 CollisionDispatch/btConvexConvexAlgorithm.cpp 31 CollisionDispatch/btEmptyCollisionAlgorithm.cpp 31 CollisionDispatch/btInternalEdgeUtility.cpp 32 CollisionDispatch/btInternalEdgeUtility.h 32 33 CollisionDispatch/btManifoldResult.cpp 33 34 CollisionDispatch/btSimulationIslandManager.cpp 35 CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp 36 CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp 37 CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp 34 38 CollisionDispatch/btUnionFind.cpp 35 39 CollisionDispatch/SphereTriangleDetector.cpp 36 40 37 41 CollisionShapes/btBoxShape.cpp 42 CollisionShapes/btBox2dShape.cpp 38 43 CollisionShapes/btBvhTriangleMeshShape.cpp 39 44 CollisionShapes/btCapsuleShape.cpp … … 43 48 CollisionShapes/btConeShape.cpp 44 49 CollisionShapes/btConvexHullShape.cpp 50 CollisionShapes/btConvexInternalShape.cpp 45 51 CollisionShapes/btConvexPointCloudShape.cpp 46 52 CollisionShapes/btConvexShape.cpp 47 CollisionShapes/btConvex InternalShape.cpp53 CollisionShapes/btConvex2dShape.cpp 48 54 CollisionShapes/btConvexTriangleMeshShape.cpp 49 55 CollisionShapes/btCylinderShape.cpp … … 56 62 CollisionShapes/btPolyhedralConvexShape.cpp 57 63 CollisionShapes/btScaledBvhTriangleMeshShape.cpp 58 CollisionShapes/bt TetrahedronShape.cpp64 CollisionShapes/btShapeHull.cpp 59 65 CollisionShapes/btSphereShape.cpp 60 CollisionShapes/btShapeHull.cpp61 66 CollisionShapes/btStaticPlaneShape.cpp 62 67 CollisionShapes/btStridingMeshInterface.cpp 68 CollisionShapes/btTetrahedronShape.cpp 69 CollisionShapes/btTriangleBuffer.cpp 63 70 CollisionShapes/btTriangleCallback.cpp 64 CollisionShapes/btTriangleBuffer.cpp65 71 CollisionShapes/btTriangleIndexVertexArray.cpp 66 72 CollisionShapes/btTriangleIndexVertexMaterialArray.cpp … … 70 76 71 77 NarrowPhaseCollision/btContinuousConvexCollision.cpp 78 NarrowPhaseCollision/btConvexCast.cpp 79 NarrowPhaseCollision/btGjkConvexCast.cpp 72 80 NarrowPhaseCollision/btGjkEpa2.cpp 73 81 NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp 74 NarrowPhaseCollision/btConvexCast.cpp75 NarrowPhaseCollision/btGjkConvexCast.cpp76 82 NarrowPhaseCollision/btGjkPairDetector.cpp 77 83 NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp … … 88 94 BroadphaseCollision/btBroadphaseProxy.h 89 95 BroadphaseCollision/btCollisionAlgorithm.h 96 BroadphaseCollision/btDbvt.h 97 BroadphaseCollision/btDbvtBroadphase.h 90 98 BroadphaseCollision/btDispatcher.h 91 BroadphaseCollision/btDbvtBroadphase.h92 BroadphaseCollision/btDbvt.h93 99 BroadphaseCollision/btMultiSapBroadphase.h 94 100 BroadphaseCollision/btOverlappingPairCache.h … … 98 104 99 105 CollisionDispatch/btActivatingCollisionAlgorithm.h 106 CollisionDispatch/btBoxBoxCollisionAlgorithm.h 107 CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h 108 CollisionDispatch/btBoxBoxDetector.h 100 109 CollisionDispatch/btCollisionConfiguration.h 101 110 CollisionDispatch/btCollisionCreateFunc.h … … 105 114 CollisionDispatch/btCompoundCollisionAlgorithm.h 106 115 CollisionDispatch/btConvexConcaveCollisionAlgorithm.h 116 CollisionDispatch/btConvexConvexAlgorithm.h 117 CollisionDispatch/btConvex2dConvex2dAlgorithm.h 118 CollisionDispatch/btConvexPlaneCollisionAlgorithm.h 107 119 CollisionDispatch/btDefaultCollisionConfiguration.h 108 CollisionDispatch/btSphereSphereCollisionAlgorithm.h 109 CollisionDispatch/btBoxBoxCollisionAlgorithm.h 110 CollisionDispatch/btBoxBoxDetector.h 120 CollisionDispatch/btEmptyCollisionAlgorithm.h 111 121 CollisionDispatch/btGhostObject.h 112 CollisionDispatch/btSphereBoxCollisionAlgorithm.h113 CollisionDispatch/btConvexPlaneCollisionAlgorithm.h114 CollisionDispatch/btSphereTriangleCollisionAlgorithm.h115 CollisionDispatch/btConvexConvexAlgorithm.h116 CollisionDispatch/btEmptyCollisionAlgorithm.h117 122 CollisionDispatch/btManifoldResult.h 118 123 CollisionDispatch/btSimulationIslandManager.h 124 CollisionDispatch/btSphereBoxCollisionAlgorithm.h 125 CollisionDispatch/btSphereSphereCollisionAlgorithm.h 126 CollisionDispatch/btSphereTriangleCollisionAlgorithm.h 119 127 CollisionDispatch/btUnionFind.h 120 128 CollisionDispatch/SphereTriangleDetector.h 121 129 122 130 CollisionShapes/btBoxShape.h 131 CollisionShapes/btBox2dShape.h 123 132 CollisionShapes/btBvhTriangleMeshShape.h 124 133 CollisionShapes/btCapsuleShape.h 125 CollisionShapes/btCollisionMargin 134 CollisionShapes/btCollisionMargin.h 126 135 CollisionShapes/btCollisionShape.h 127 136 CollisionShapes/btCompoundShape.h … … 129 138 CollisionShapes/btConeShape.h 130 139 CollisionShapes/btConvexHullShape.h 140 CollisionShapes/btConvexInternalShape.h 131 141 CollisionShapes/btConvexPointCloudShape.h 132 142 CollisionShapes/btConvexShape.h 133 CollisionShapes/btConvex InternalShape.h143 CollisionShapes/btConvex2dShape.h 134 144 CollisionShapes/btConvexTriangleMeshShape.h 135 145 CollisionShapes/btCylinderShape.h 136 146 CollisionShapes/btEmptyShape.h 137 147 CollisionShapes/btHeightfieldTerrainShape.h 148 CollisionShapes/btMaterial.h 138 149 CollisionShapes/btMinkowskiSumShape.h 139 CollisionShapes/btMaterial.h140 150 CollisionShapes/btMultimaterialTriangleMeshShape.h 141 151 CollisionShapes/btMultiSphereShape.h … … 143 153 CollisionShapes/btPolyhedralConvexShape.h 144 154 CollisionShapes/btScaledBvhTriangleMeshShape.h 145 CollisionShapes/bt TetrahedronShape.h155 CollisionShapes/btShapeHull.h 146 156 CollisionShapes/btSphereShape.h 147 CollisionShapes/btShapeHull.h148 157 CollisionShapes/btStaticPlaneShape.h 149 158 CollisionShapes/btStridingMeshInterface.h 159 CollisionShapes/btTetrahedronShape.h 160 CollisionShapes/btTriangleBuffer.h 150 161 CollisionShapes/btTriangleCallback.h 151 CollisionShapes/btTriangleBuffer.h152 162 CollisionShapes/btTriangleIndexVertexArray.h 153 163 CollisionShapes/btTriangleIndexVertexMaterialArray.h 164 CollisionShapes/btTriangleInfoMap.h 154 165 CollisionShapes/btTriangleMesh.h 155 166 CollisionShapes/btTriangleMeshShape.h 167 CollisionShapes/btTriangleShape.h 156 168 CollisionShapes/btUniformScalingShape.h 157 169 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
r5781 r7983 38 38 btScalar timeOfImpact = btScalar(1.); 39 39 btScalar depth = btScalar(0.); 40 // output.m_distance = btScalar( 1e30);40 // output.m_distance = btScalar(BT_LARGE_FLOAT); 41 41 //move sphere into triangle space 42 42 btTransform sphereInTr = transformB.inverseTimes(transformA); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
r5781 r7983 35 35 virtual ~SphereTriangleDetector() {}; 36 36 37 bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold); 38 37 39 private: 38 40 39 bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold);41 40 42 bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p ); 41 43 bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
r5781 r7983 62 62 63 63 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 64 input.m_maximumDistanceSquared = 1e30f;64 input.m_maximumDistanceSquared = BT_LARGE_FLOAT; 65 65 input.m_transformA = body0->getWorldTransform(); 66 66 input.m_transformB = body1->getWorldTransform(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
r5781 r7983 1 2 1 /* 3 2 * Box-Box collision detection re-distributed under the ZLib license with permission from Russell L. Smith … … 213 212 } else 214 213 { 215 a= 1e30f;214 a=BT_LARGE_FLOAT; 216 215 } 217 216 cx = a*(cx + q*(p[n*2-2]+p[0])); … … 268 267 { 269 268 const btScalar fudge_factor = btScalar(1.05); 270 btVector3 p,pp,normalC ;269 btVector3 p,pp,normalC(0.f,0.f,0.f); 271 270 const btScalar *normalR = 0; 272 271 btScalar A[3],B[3],R11,R12,R13,R21,R22,R23,R31,R32,R33, … … 334 333 #define TST(expr1,expr2,n1,n2,n3,cc) \ 335 334 s2 = btFabs(expr1) - (expr2); \ 336 if (s2 > 0) return 0; \335 if (s2 > SIMD_EPSILON) return 0; \ 337 336 l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \ 338 if (l > 0) { \337 if (l > SIMD_EPSILON) { \ 339 338 s2 /= l; \ 340 339 if (s2*fudge_factor > s) { \ … … 346 345 } \ 347 346 } 347 348 btScalar fudge2 (1.0e-5f); 349 350 Q11 += fudge2; 351 Q12 += fudge2; 352 Q13 += fudge2; 353 354 Q21 += fudge2; 355 Q22 += fudge2; 356 Q23 += fudge2; 357 358 Q31 += fudge2; 359 Q32 += fudge2; 360 Q33 += fudge2; 348 361 349 362 // separating axis = u1 x (v1,v2,v3) … … 425 438 #else 426 439 output.addContactPoint(-normal,pb,-*depth); 440 427 441 #endif // 428 442 *return_code = code; … … 594 608 595 609 if (cnum <= maxc) { 610 611 if (code<4) 612 { 596 613 // we have less contacts than we need, so we use them all 597 for (j=0; j < cnum; j++) { 598 599 //AddContactPoint... 600 601 //dContactGeom *con = CONTACT(contact,skip*j); 602 //for (i=0; i<3; i++) con->pos[i] = point[j*3+i] + pa[i]; 603 //con->depth = dep[j]; 604 614 for (j=0; j < cnum; j++) 615 { 605 616 btVector3 pointInWorld; 606 617 for (i=0; i<3; i++) … … 609 620 610 621 } 622 } else 623 { 624 // we have less contacts than we need, so we use them all 625 for (j=0; j < cnum; j++) 626 { 627 btVector3 pointInWorld; 628 for (i=0; i<3; i++) 629 pointInWorld[i] = point[j*3+i] + pa[i]-normal[i]*dep[j]; 630 //pointInWorld[i] = point[j*3+i] + pa[i]; 631 output.addContactPoint(-normal,pointInWorld,-dep[j]); 632 } 633 } 611 634 } 612 635 else { … … 633 656 for (i=0; i<3; i++) 634 657 posInWorld[i] = point[iret[j]*3+i] + pa[i]; 635 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]); 658 if (code<4) 659 { 660 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]); 661 } else 662 { 663 output.addContactPoint(-normal,posInWorld-normal*dep[iret[j]],-dep[iret[j]]); 664 } 636 665 } 637 666 cnum = maxc; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
r5781 r7983 35 35 36 36 btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): 37 m_count(0), 38 m_useIslands(true), 39 m_staticWarningReported(false), 37 m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD), 40 38 m_collisionConfiguration(collisionConfiguration) 41 39 { … … 80 78 btCollisionObject* body1 = (btCollisionObject*)b1; 81 79 82 //test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold' 83 //btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold())); 84 btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()); 80 //optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance) 81 82 btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ? 83 btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold)) 84 : gContactBreakingThreshold ; 85 85 86 86 btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold()); … … 170 170 171 171 #ifdef BT_DEBUG 172 if (! m_staticWarningReported)172 if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED)) 173 173 { 174 174 //broadphase filtering already deals with this … … 176 176 (body1->isStaticObject() || body1->isKinematicObject())) 177 177 { 178 m_ staticWarningReported = true;178 m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED; 179 179 printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); 180 180 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
r5781 r7983 43 43 class btCollisionDispatcher : public btDispatcher 44 44 { 45 int m_count;45 int m_dispatcherFlags; 46 46 47 47 btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr; 48 48 49 bool m_useIslands;50 51 bool m_staticWarningReported;52 53 49 btManifoldResult m_defaultManifoldResult; 54 50 … … 60 56 61 57 btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]; 62 63 58 64 59 btCollisionConfiguration* m_collisionConfiguration; … … 66 61 67 62 public: 63 64 enum DispatcherFlags 65 { 66 CD_STATIC_STATIC_REPORTED = 1, 67 CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2 68 }; 69 70 int getDispatcherFlags() const 71 { 72 return m_dispatcherFlags; 73 } 74 75 void setDispatcherFlags(int flags) 76 { 77 (void) flags; 78 m_dispatcherFlags = 0; 79 } 68 80 69 81 ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp
r5781 r7983 16 16 17 17 #include "btCollisionObject.h" 18 #include "LinearMath/btSerializer.h" 18 19 19 20 btCollisionObject::btCollisionObject() 20 21 : m_anisotropicFriction(1.f,1.f,1.f), 21 22 m_hasAnisotropicFriction(false), 22 m_contactProcessingThreshold( 1e30f),23 m_contactProcessingThreshold(BT_LARGE_FLOAT), 23 24 m_broadphaseHandle(0), 24 25 m_collisionShape(0), 26 m_extensionPointer(0), 25 27 m_rootCollisionShape(0), 26 28 m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT), … … 31 33 m_friction(btScalar(0.5)), 32 34 m_restitution(btScalar(0.)), 35 m_internalType(CO_COLLISION_OBJECT), 33 36 m_userObjectPointer(0), 34 m_internalType(CO_COLLISION_OBJECT),35 37 m_hitFraction(btScalar(1.)), 36 38 m_ccdSweptSphereRadius(btScalar(0.)), … … 38 40 m_checkCollideWith(false) 39 41 { 40 42 m_worldTransform.setIdentity(); 41 43 } 42 44 … … 65 67 } 66 68 69 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const 70 { 71 72 btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer; 73 74 m_worldTransform.serialize(dataOut->m_worldTransform); 75 m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform); 76 m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity); 77 m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity); 78 m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction); 79 dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction; 80 dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold; 81 dataOut->m_broadphaseHandle = 0; 82 dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape); 83 dataOut->m_rootCollisionShape = 0;//@todo 84 dataOut->m_collisionFlags = m_collisionFlags; 85 dataOut->m_islandTag1 = m_islandTag1; 86 dataOut->m_companionId = m_companionId; 87 dataOut->m_activationState1 = m_activationState1; 88 dataOut->m_activationState1 = m_activationState1; 89 dataOut->m_deactivationTime = m_deactivationTime; 90 dataOut->m_friction = m_friction; 91 dataOut->m_restitution = m_restitution; 92 dataOut->m_internalType = m_internalType; 93 94 char* name = (char*) serializer->findNameForPointer(this); 95 dataOut->m_name = (char*)serializer->getUniquePointer(name); 96 if (dataOut->m_name) 97 { 98 serializer->serializeName(name); 99 } 100 dataOut->m_hitFraction = m_hitFraction; 101 dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius; 102 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 103 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 104 dataOut->m_checkCollideWith = m_checkCollideWith; 105 106 return btCollisionObjectDataName; 107 } 67 108 68 109 110 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const 111 { 112 int len = calculateSerializeBufferSize(); 113 btChunk* chunk = serializer->allocate(len,1); 114 const char* structType = serialize(chunk->m_oldPtr, serializer); 115 serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this); 116 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
r5781 r7983 28 28 struct btBroadphaseProxy; 29 29 class btCollisionShape; 30 struct btCollisionShapeData; 30 31 #include "LinearMath/btMotionState.h" 31 32 #include "LinearMath/btAlignedAllocator.h" 32 33 #include "LinearMath/btAlignedObjectArray.h" 33 34 34 35 35 typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray; 36 37 #ifdef BT_USE_DOUBLE_PRECISION 38 #define btCollisionObjectData btCollisionObjectDoubleData 39 #define btCollisionObjectDataName "btCollisionObjectDoubleData" 40 #else 41 #define btCollisionObjectData btCollisionObjectFloatData 42 #define btCollisionObjectDataName "btCollisionObjectFloatData" 43 #endif 36 44 37 45 … … 54 62 btVector3 m_interpolationAngularVelocity; 55 63 56 btVector3 57 boolm_hasAnisotropicFriction;58 btScalar 64 btVector3 m_anisotropicFriction; 65 int m_hasAnisotropicFriction; 66 btScalar m_contactProcessingThreshold; 59 67 60 68 btBroadphaseProxy* m_broadphaseHandle; 61 69 btCollisionShape* m_collisionShape; 70 ///m_extensionPointer is used by some internal low-level Bullet extensions. 71 void* m_extensionPointer; 62 72 63 73 ///m_rootCollisionShape is temporarily used to store the original collision shape … … 77 87 btScalar m_restitution; 78 88 79 ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer80 void* m_userObjectPointer;81 82 89 ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc. 83 90 ///do not assign your own m_internalType unless you write a new dynamics object class. 84 91 int m_internalType; 85 92 93 ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer 94 void* m_userObjectPointer; 95 86 96 ///time of impact calculation 87 97 btScalar m_hitFraction; … … 94 104 95 105 /// If some object should have elaborate collision filtering by sub-classes 96 bool m_checkCollideWith; 97 98 char m_pad[7]; 106 int m_checkCollideWith; 99 107 100 108 virtual bool checkCollideWithOverride(btCollisionObject* /* co */) … … 113 121 CF_NO_CONTACT_RESPONSE = 4, 114 122 CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution) 115 CF_CHARACTER_OBJECT = 16 123 CF_CHARACTER_OBJECT = 16, 124 CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing 125 CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing 116 126 }; 117 127 … … 119 129 { 120 130 CO_COLLISION_OBJECT =1, 121 CO_RIGID_BODY ,131 CO_RIGID_BODY=2, 122 132 ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter 123 133 ///It is useful for collision sensors, explosion objects, character controller etc. 124 CO_GHOST_OBJECT, 125 CO_SOFT_BODY, 126 CO_HF_FLUID 134 CO_GHOST_OBJECT=4, 135 CO_SOFT_BODY=8, 136 CO_HF_FLUID=16, 137 CO_USER_TYPE=32 127 138 }; 128 139 … … 144 155 bool hasAnisotropicFriction() const 145 156 { 146 return m_hasAnisotropicFriction ;157 return m_hasAnisotropicFriction!=0; 147 158 } 148 159 … … 214 225 } 215 226 227 ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions. 228 ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead. 229 void* internalGetExtensionPointer() const 230 { 231 return m_extensionPointer; 232 } 233 ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions 234 ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead. 235 void internalSetExtensionPointer(void* pointer) 236 { 237 m_extensionPointer = pointer; 238 } 239 216 240 SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;} 217 241 … … 394 418 void setCcdMotionThreshold(btScalar ccdMotionThreshold) 395 419 { 396 m_ccdMotionThreshold = ccdMotionThreshold *ccdMotionThreshold;420 m_ccdMotionThreshold = ccdMotionThreshold; 397 421 } 398 422 … … 417 441 return true; 418 442 } 443 444 virtual int calculateSerializeBufferSize() const; 445 446 ///fills the dataBuffer and returns the struct name (and 0 on failure) 447 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const; 448 449 virtual void serializeSingleObject(class btSerializer* serializer) const; 450 419 451 }; 420 452 453 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 454 struct btCollisionObjectDoubleData 455 { 456 void *m_broadphaseHandle; 457 void *m_collisionShape; 458 btCollisionShapeData *m_rootCollisionShape; 459 char *m_name; 460 461 btTransformDoubleData m_worldTransform; 462 btTransformDoubleData m_interpolationWorldTransform; 463 btVector3DoubleData m_interpolationLinearVelocity; 464 btVector3DoubleData m_interpolationAngularVelocity; 465 btVector3DoubleData m_anisotropicFriction; 466 double m_contactProcessingThreshold; 467 double m_deactivationTime; 468 double m_friction; 469 double m_restitution; 470 double m_hitFraction; 471 double m_ccdSweptSphereRadius; 472 double m_ccdMotionThreshold; 473 474 int m_hasAnisotropicFriction; 475 int m_collisionFlags; 476 int m_islandTag1; 477 int m_companionId; 478 int m_activationState1; 479 int m_internalType; 480 int m_checkCollideWith; 481 482 char m_padding[4]; 483 }; 484 485 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 486 struct btCollisionObjectFloatData 487 { 488 void *m_broadphaseHandle; 489 void *m_collisionShape; 490 btCollisionShapeData *m_rootCollisionShape; 491 char *m_name; 492 493 btTransformFloatData m_worldTransform; 494 btTransformFloatData m_interpolationWorldTransform; 495 btVector3FloatData m_interpolationLinearVelocity; 496 btVector3FloatData m_interpolationAngularVelocity; 497 btVector3FloatData m_anisotropicFriction; 498 float m_contactProcessingThreshold; 499 float m_deactivationTime; 500 float m_friction; 501 float m_restitution; 502 float m_hitFraction; 503 float m_ccdSweptSphereRadius; 504 float m_ccdMotionThreshold; 505 506 int m_hasAnisotropicFriction; 507 int m_collisionFlags; 508 int m_islandTag1; 509 int m_companionId; 510 int m_activationState1; 511 int m_internalType; 512 int m_checkCollideWith; 513 }; 514 515 516 517 SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const 518 { 519 return sizeof(btCollisionObjectData); 520 } 521 522 523 421 524 #endif //COLLISION_OBJECT_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
r5781 r7983 27 27 #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h" 28 28 #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h" 29 29 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 30 30 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" 31 31 #include "LinearMath/btAabbUtil2.h" 32 32 #include "LinearMath/btQuickprof.h" 33 33 #include "LinearMath/btStackAlloc.h" 34 #include "LinearMath/btSerializer.h" 34 35 35 36 //#define USE_BRUTEFORCE_RAYBROADPHASE 1 … … 43 44 44 45 46 ///for debug drawing 47 48 //for debug rendering 49 #include "BulletCollision/CollisionShapes/btBoxShape.h" 50 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 51 #include "BulletCollision/CollisionShapes/btCompoundShape.h" 52 #include "BulletCollision/CollisionShapes/btConeShape.h" 53 #include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h" 54 #include "BulletCollision/CollisionShapes/btCylinderShape.h" 55 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h" 56 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 57 #include "BulletCollision/CollisionShapes/btSphereShape.h" 58 #include "BulletCollision/CollisionShapes/btTriangleCallback.h" 59 #include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" 60 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 61 62 63 45 64 btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration) 46 65 :m_dispatcher1(dispatcher), 47 66 m_broadphasePairCache(pairCache), 48 m_debugDrawer(0) 67 m_debugDrawer(0), 68 m_forceUpdateAllAabbs(true) 49 69 { 50 70 m_stackAlloc = collisionConfiguration->getStackAllocator(); … … 89 109 { 90 110 111 btAssert(collisionObject); 112 91 113 //check that the object isn't already added 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 114 btAssert( m_collisionObjects.findLinearSearch(collisionObject) == m_collisionObjects.size()); 115 116 m_collisionObjects.push_back(collisionObject); 117 118 //calculate new AABB 119 btTransform trans = collisionObject->getWorldTransform(); 120 121 btVector3 minAabb; 122 btVector3 maxAabb; 123 collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb); 124 125 int type = collisionObject->getCollisionShape()->getShapeType(); 126 collisionObject->setBroadphaseHandle( getBroadphase()->createProxy( 127 minAabb, 128 maxAabb, 129 type, 130 collisionObject, 131 collisionFilterGroup, 132 collisionFilterMask, 133 m_dispatcher1,0 134 )) ; 113 135 114 136 … … 163 185 164 186 //only update aabb of active objects 165 if ( colObj->isActive())187 if (m_forceUpdateAllAabbs || colObj->isActive()) 166 188 { 167 189 updateSingleAabb(colObj); … … 226 248 227 249 void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans, 228 229 230 231 250 btCollisionObject* collisionObject, 251 const btCollisionShape* collisionShape, 252 const btTransform& colObjWorldTransform, 253 RayResultCallback& resultCallback) 232 254 { 233 255 btSphereShape pointShape(btScalar(0.0)); … … 237 259 if (collisionShape->isConvex()) 238 260 { 239 // BT_PROFILE("rayTestConvex");261 // BT_PROFILE("rayTestConvex"); 240 262 btConvexCast::CastResult castResult; 241 263 castResult.m_fraction = resultCallback.m_closestHitFraction; … … 266 288 btCollisionWorld::LocalRayResult localRayResult 267 289 ( 268 269 270 271 290 collisionObject, 291 0, 292 castResult.m_normal, 293 castResult.m_fraction 272 294 ); 273 295 … … 281 303 if (collisionShape->isConcave()) 282 304 { 283 // BT_PROFILE("rayTestConcave");305 // BT_PROFILE("rayTestConcave"); 284 306 if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE) 285 307 { … … 297 319 btTriangleMeshShape* m_triangleMesh; 298 320 321 btTransform m_colObjWorldTransform; 322 299 323 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 300 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh): 301 //@BP Mod 302 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 303 m_resultCallback(resultCallback), 304 m_collisionObject(collisionObject), 305 m_triangleMesh(triangleMesh) 306 { 307 } 324 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh,const btTransform& colObjWorldTransform): 325 //@BP Mod 326 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 327 m_resultCallback(resultCallback), 328 m_collisionObject(collisionObject), 329 m_triangleMesh(triangleMesh), 330 m_colObjWorldTransform(colObjWorldTransform) 331 { 332 } 308 333 309 334 … … 314 339 shapeInfo.m_triangleIndex = triangleIndex; 315 340 341 btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal; 342 316 343 btCollisionWorld::LocalRayResult rayResult 317 (m_collisionObject,344 (m_collisionObject, 318 345 &shapeInfo, 319 hitNormal Local,346 hitNormalWorld, 320 347 hitFraction); 321 348 322 bool normalInWorldSpace = false;349 bool normalInWorldSpace = true; 323 350 return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace); 324 351 } … … 326 353 }; 327 354 328 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh );355 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh,colObjWorldTransform); 329 356 rcb.m_hitFraction = resultCallback.m_closestHitFraction; 330 357 triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal); … … 347 374 btConcaveShape* m_triangleMesh; 348 375 376 btTransform m_colObjWorldTransform; 377 349 378 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 350 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh): 351 //@BP Mod 352 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 353 m_resultCallback(resultCallback), 354 m_collisionObject(collisionObject), 355 m_triangleMesh(triangleMesh) 356 { 357 } 379 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& colObjWorldTransform): 380 //@BP Mod 381 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 382 m_resultCallback(resultCallback), 383 m_collisionObject(collisionObject), 384 m_triangleMesh(triangleMesh), 385 m_colObjWorldTransform(colObjWorldTransform) 386 { 387 } 358 388 359 389 … … 364 394 shapeInfo.m_triangleIndex = triangleIndex; 365 395 396 btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal; 397 366 398 btCollisionWorld::LocalRayResult rayResult 367 (m_collisionObject,399 (m_collisionObject, 368 400 &shapeInfo, 369 hitNormal Local,401 hitNormalWorld, 370 402 hitFraction); 371 403 372 bool normalInWorldSpace = false;404 bool normalInWorldSpace = true; 373 405 return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace); 374 375 376 406 } 377 407 … … 379 409 380 410 381 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape );411 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape, colObjWorldTransform); 382 412 rcb.m_hitFraction = resultCallback.m_closestHitFraction; 383 413 … … 390 420 } 391 421 } else { 392 // BT_PROFILE("rayTestCompound");422 // BT_PROFILE("rayTestCompound"); 393 423 ///@todo: use AABB tree or other BVH acceleration structure, see btDbvt 394 424 if (collisionShape->isCompound()) … … 404 434 btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape(); 405 435 collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape); 436 struct LocalInfoAdder2 : public RayResultCallback { 437 RayResultCallback* m_userCallback; 438 int m_i; 439 LocalInfoAdder2 (int i, RayResultCallback *user) 440 : m_userCallback(user), 441 m_i(i) 442 { 443 m_closestHitFraction = m_userCallback->m_closestHitFraction; 444 } 445 virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b) 446 { 447 btCollisionWorld::LocalShapeInfo shapeInfo; 448 shapeInfo.m_shapePart = -1; 449 shapeInfo.m_triangleIndex = m_i; 450 if (r.m_localShapeInfo == NULL) 451 r.m_localShapeInfo = &shapeInfo; 452 453 const btScalar result = m_userCallback->addSingleResult(r, b); 454 m_closestHitFraction = m_userCallback->m_closestHitFraction; 455 return result; 456 } 457 }; 458 459 LocalInfoAdder2 my_cb(i, &resultCallback); 460 406 461 rayTestSingle(rayFromTrans,rayToTrans, 407 462 collisionObject, 408 463 childCollisionShape, 409 464 childWorldTrans, 410 resultCallback);465 my_cb); 411 466 // restore 412 467 collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); … … 418 473 419 474 void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans, 420 421 422 423 475 btCollisionObject* collisionObject, 476 const btCollisionShape* collisionShape, 477 const btTransform& colObjWorldTransform, 478 ConvexResultCallback& resultCallback, btScalar allowedPenetration) 424 479 { 425 480 if (collisionShape->isConvex()) … … 433 488 btVoronoiSimplexSolver simplexSolver; 434 489 btGjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver; 435 490 436 491 btContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver); 437 492 //btGjkConvexCast convexCaster2(castShape,convexShape,&simplexSolver); … … 439 494 440 495 btConvexCast* castPtr = &convexCaster1; 441 442 443 496 497 498 444 499 if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult)) 445 500 { … … 451 506 castResult.m_normal.normalize(); 452 507 btCollisionWorld::LocalConvexResult localConvexResult 453 454 455 456 457 458 459 508 ( 509 collisionObject, 510 0, 511 castResult.m_normal, 512 castResult.m_hitPoint, 513 castResult.m_fraction 514 ); 460 515 461 516 bool normalInWorldSpace = true; … … 487 542 BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to, 488 543 btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld): 489 490 491 492 493 494 544 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), 545 m_resultCallback(resultCallback), 546 m_collisionObject(collisionObject), 547 m_triangleMesh(triangleMesh) 548 { 549 } 495 550 496 551 … … 504 559 505 560 btCollisionWorld::LocalConvexResult convexResult 506 (m_collisionObject,561 (m_collisionObject, 507 562 &shapeInfo, 508 563 hitNormalLocal, … … 544 599 BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to, 545 600 btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& triangleToWorld): 546 547 548 549 550 551 601 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), 602 m_resultCallback(resultCallback), 603 m_collisionObject(collisionObject), 604 m_triangleMesh(triangleMesh) 605 { 606 } 552 607 553 608 … … 561 616 562 617 btCollisionWorld::LocalConvexResult convexResult 563 (m_collisionObject,618 (m_collisionObject, 564 619 &shapeInfo, 565 620 hitNormalLocal, … … 604 659 btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape(); 605 660 collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape); 661 struct LocalInfoAdder : public ConvexResultCallback { 662 ConvexResultCallback* m_userCallback; 663 int m_i; 664 665 LocalInfoAdder (int i, ConvexResultCallback *user) 666 : m_userCallback(user), m_i(i) 667 { 668 m_closestHitFraction = m_userCallback->m_closestHitFraction; 669 } 670 virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult& r, bool b) 671 { 672 btCollisionWorld::LocalShapeInfo shapeInfo; 673 shapeInfo.m_shapePart = -1; 674 shapeInfo.m_triangleIndex = m_i; 675 if (r.m_localShapeInfo == NULL) 676 r.m_localShapeInfo = &shapeInfo; 677 const btScalar result = m_userCallback->addSingleResult(r, b); 678 m_closestHitFraction = m_userCallback->m_closestHitFraction; 679 return result; 680 681 } 682 }; 683 684 LocalInfoAdder my_cb(i, &resultCallback); 685 686 606 687 objectQuerySingle(castShape, convexFromTrans,convexToTrans, 607 688 collisionObject, 608 689 childCollisionShape, 609 690 childWorldTrans, 610 resultCallback, allowedPenetration);691 my_cb, allowedPenetration); 611 692 // restore 612 693 collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); … … 631 712 632 713 btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback) 633 :m_rayFromWorld(rayFromWorld),634 m_rayToWorld(rayToWorld),635 m_world(world),636 m_resultCallback(resultCallback)714 :m_rayFromWorld(rayFromWorld), 715 m_rayToWorld(rayToWorld), 716 m_world(world), 717 m_resultCallback(resultCallback) 637 718 { 638 719 m_rayFromTrans.setIdentity(); … … 644 725 645 726 rayDir.normalize (); 646 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e30647 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];648 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];649 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];727 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 728 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 729 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 730 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 650 731 m_signs[0] = m_rayDirectionInverse[0] < 0.0; 651 732 m_signs[1] = m_rayDirectionInverse[1] < 0.0; … … 656 737 } 657 738 658 739 659 740 660 741 virtual bool process(const btBroadphaseProxy* proxy) … … 687 768 m_world->rayTestSingle(m_rayFromTrans,m_rayToTrans, 688 769 collisionObject, 689 690 691 770 collisionObject->getCollisionShape(), 771 collisionObject->getWorldTransform(), 772 m_resultCallback); 692 773 } 693 774 } … … 698 779 void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const 699 780 { 700 BT_PROFILE("rayTest");781 //BT_PROFILE("rayTest"); 701 782 /// use the broadphase to accelerate the search for objects, based on their aabb 702 783 /// and for each object with ray-aabb overlap, perform an exact ray test … … 737 818 btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin()-m_convexFromTrans.getOrigin()); 738 819 btVector3 rayDir = unnormalizedRayDir.normalized(); 739 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e30740 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];741 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];742 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];820 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 821 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 822 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 823 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 743 824 m_signs[0] = m_rayDirectionInverse[0] < 0.0; 744 825 m_signs[1] = m_rayDirectionInverse[1] < 0.0; … … 761 842 //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject(); 762 843 m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans, 763 764 765 766 767 768 } 769 844 collisionObject, 845 collisionObject->getCollisionShape(), 846 collisionObject->getWorldTransform(), 847 m_resultCallback, 848 m_allowedCcdPenetration); 849 } 850 770 851 return true; 771 852 } … … 782 863 /// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical 783 864 784 865 785 866 786 867 btTransform convexFromTrans,convexToTrans; … … 825 906 objectQuerySingle(castShape, convexFromTrans,convexToTrans, 826 907 collisionObject, 827 828 829 830 908 collisionObject->getCollisionShape(), 909 collisionObject->getWorldTransform(), 910 resultCallback, 911 allowedCcdPenetration); 831 912 } 832 913 } … … 834 915 #endif //USE_BRUTEFORCE_RAYBROADPHASE 835 916 } 917 918 919 920 struct btBridgedManifoldResult : public btManifoldResult 921 { 922 923 btCollisionWorld::ContactResultCallback& m_resultCallback; 924 925 btBridgedManifoldResult( btCollisionObject* obj0,btCollisionObject* obj1,btCollisionWorld::ContactResultCallback& resultCallback ) 926 :btManifoldResult(obj0,obj1), 927 m_resultCallback(resultCallback) 928 { 929 } 930 931 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) 932 { 933 bool isSwapped = m_manifoldPtr->getBody0() != m_body0; 934 btVector3 pointA = pointInWorld + normalOnBInWorld * depth; 935 btVector3 localA; 936 btVector3 localB; 937 if (isSwapped) 938 { 939 localA = m_rootTransB.invXform(pointA ); 940 localB = m_rootTransA.invXform(pointInWorld); 941 } else 942 { 943 localA = m_rootTransA.invXform(pointA ); 944 localB = m_rootTransB.invXform(pointInWorld); 945 } 946 947 btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth); 948 newPt.m_positionWorldOnA = pointA; 949 newPt.m_positionWorldOnB = pointInWorld; 950 951 //BP mod, store contact triangles. 952 if (isSwapped) 953 { 954 newPt.m_partId0 = m_partId1; 955 newPt.m_partId1 = m_partId0; 956 newPt.m_index0 = m_index1; 957 newPt.m_index1 = m_index0; 958 } else 959 { 960 newPt.m_partId0 = m_partId0; 961 newPt.m_partId1 = m_partId1; 962 newPt.m_index0 = m_index0; 963 newPt.m_index1 = m_index1; 964 } 965 966 //experimental feature info, for per-triangle material etc. 967 btCollisionObject* obj0 = isSwapped? m_body1 : m_body0; 968 btCollisionObject* obj1 = isSwapped? m_body0 : m_body1; 969 m_resultCallback.addSingleResult(newPt,obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1); 970 971 } 972 973 }; 974 975 976 977 struct btSingleContactCallback : public btBroadphaseAabbCallback 978 { 979 980 btCollisionObject* m_collisionObject; 981 btCollisionWorld* m_world; 982 btCollisionWorld::ContactResultCallback& m_resultCallback; 983 984 985 btSingleContactCallback(btCollisionObject* collisionObject, btCollisionWorld* world,btCollisionWorld::ContactResultCallback& resultCallback) 986 :m_collisionObject(collisionObject), 987 m_world(world), 988 m_resultCallback(resultCallback) 989 { 990 } 991 992 virtual bool process(const btBroadphaseProxy* proxy) 993 { 994 btCollisionObject* collisionObject = (btCollisionObject*)proxy->m_clientObject; 995 if (collisionObject == m_collisionObject) 996 return true; 997 998 //only perform raycast if filterMask matches 999 if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 1000 { 1001 btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(m_collisionObject,collisionObject); 1002 if (algorithm) 1003 { 1004 btBridgedManifoldResult contactPointResult(m_collisionObject,collisionObject, m_resultCallback); 1005 //discrete collision detection query 1006 algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult); 1007 1008 algorithm->~btCollisionAlgorithm(); 1009 m_world->getDispatcher()->freeCollisionAlgorithm(algorithm); 1010 } 1011 } 1012 return true; 1013 } 1014 }; 1015 1016 1017 ///contactTest performs a discrete collision test against all objects in the btCollisionWorld, and calls the resultCallback. 1018 ///it reports one or more contact points for every overlapping object (including the one with deepest penetration) 1019 void btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCallback& resultCallback) 1020 { 1021 btVector3 aabbMin,aabbMax; 1022 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax); 1023 btSingleContactCallback contactCB(colObj,this,resultCallback); 1024 1025 m_broadphasePairCache->aabbTest(aabbMin,aabbMax,contactCB); 1026 } 1027 1028 1029 ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected. 1030 ///it reports one or more contact points (including the one with deepest penetration) 1031 void btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback) 1032 { 1033 btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(colObjA,colObjB); 1034 if (algorithm) 1035 { 1036 btBridgedManifoldResult contactPointResult(colObjA,colObjB, resultCallback); 1037 //discrete collision detection query 1038 algorithm->processCollision(colObjA,colObjB, getDispatchInfo(),&contactPointResult); 1039 1040 algorithm->~btCollisionAlgorithm(); 1041 getDispatcher()->freeCollisionAlgorithm(algorithm); 1042 } 1043 1044 } 1045 1046 1047 1048 1049 class DebugDrawcallback : public btTriangleCallback, public btInternalTriangleIndexCallback 1050 { 1051 btIDebugDraw* m_debugDrawer; 1052 btVector3 m_color; 1053 btTransform m_worldTrans; 1054 1055 public: 1056 1057 DebugDrawcallback(btIDebugDraw* debugDrawer,const btTransform& worldTrans,const btVector3& color) : 1058 m_debugDrawer(debugDrawer), 1059 m_color(color), 1060 m_worldTrans(worldTrans) 1061 { 1062 } 1063 1064 virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) 1065 { 1066 processTriangle(triangle,partId,triangleIndex); 1067 } 1068 1069 virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex) 1070 { 1071 (void)partId; 1072 (void)triangleIndex; 1073 1074 btVector3 wv0,wv1,wv2; 1075 wv0 = m_worldTrans*triangle[0]; 1076 wv1 = m_worldTrans*triangle[1]; 1077 wv2 = m_worldTrans*triangle[2]; 1078 btVector3 center = (wv0+wv1+wv2)*btScalar(1./3.); 1079 1080 btVector3 normal = (wv1-wv0).cross(wv2-wv0); 1081 normal.normalize(); 1082 btVector3 normalColor(1,1,0); 1083 m_debugDrawer->drawLine(center,center+normal,normalColor); 1084 1085 1086 1087 1088 m_debugDrawer->drawLine(wv0,wv1,m_color); 1089 m_debugDrawer->drawLine(wv1,wv2,m_color); 1090 m_debugDrawer->drawLine(wv2,wv0,m_color); 1091 } 1092 }; 1093 1094 1095 void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color) 1096 { 1097 // Draw a small simplex at the center of the object 1098 getDebugDrawer()->drawTransform(worldTransform,1); 1099 1100 if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) 1101 { 1102 const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape); 1103 for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--) 1104 { 1105 btTransform childTrans = compoundShape->getChildTransform(i); 1106 const btCollisionShape* colShape = compoundShape->getChildShape(i); 1107 debugDrawObject(worldTransform*childTrans,colShape,color); 1108 } 1109 1110 } else 1111 { 1112 switch (shape->getShapeType()) 1113 { 1114 1115 case BOX_SHAPE_PROXYTYPE: 1116 { 1117 const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape); 1118 btVector3 halfExtents = boxShape->getHalfExtentsWithMargin(); 1119 getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color); 1120 break; 1121 } 1122 1123 case SPHERE_SHAPE_PROXYTYPE: 1124 { 1125 const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape); 1126 btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin 1127 1128 getDebugDrawer()->drawSphere(radius, worldTransform, color); 1129 break; 1130 } 1131 case MULTI_SPHERE_SHAPE_PROXYTYPE: 1132 { 1133 const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape); 1134 1135 btTransform childTransform; 1136 childTransform.setIdentity(); 1137 1138 for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--) 1139 { 1140 childTransform.setOrigin(multiSphereShape->getSpherePosition(i)); 1141 getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color); 1142 } 1143 1144 break; 1145 } 1146 case CAPSULE_SHAPE_PROXYTYPE: 1147 { 1148 const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape); 1149 1150 btScalar radius = capsuleShape->getRadius(); 1151 btScalar halfHeight = capsuleShape->getHalfHeight(); 1152 1153 int upAxis = capsuleShape->getUpAxis(); 1154 1155 1156 btVector3 capStart(0.f,0.f,0.f); 1157 capStart[upAxis] = -halfHeight; 1158 1159 btVector3 capEnd(0.f,0.f,0.f); 1160 capEnd[upAxis] = halfHeight; 1161 1162 // Draw the ends 1163 { 1164 1165 btTransform childTransform = worldTransform; 1166 childTransform.getOrigin() = worldTransform * capStart; 1167 getDebugDrawer()->drawSphere(radius, childTransform, color); 1168 } 1169 1170 { 1171 btTransform childTransform = worldTransform; 1172 childTransform.getOrigin() = worldTransform * capEnd; 1173 getDebugDrawer()->drawSphere(radius, childTransform, color); 1174 } 1175 1176 // Draw some additional lines 1177 btVector3 start = worldTransform.getOrigin(); 1178 1179 1180 capStart[(upAxis+1)%3] = radius; 1181 capEnd[(upAxis+1)%3] = radius; 1182 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1183 capStart[(upAxis+1)%3] = -radius; 1184 capEnd[(upAxis+1)%3] = -radius; 1185 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1186 1187 capStart[(upAxis+1)%3] = 0.f; 1188 capEnd[(upAxis+1)%3] = 0.f; 1189 1190 capStart[(upAxis+2)%3] = radius; 1191 capEnd[(upAxis+2)%3] = radius; 1192 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1193 capStart[(upAxis+2)%3] = -radius; 1194 capEnd[(upAxis+2)%3] = -radius; 1195 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1196 1197 1198 break; 1199 } 1200 case CONE_SHAPE_PROXYTYPE: 1201 { 1202 const btConeShape* coneShape = static_cast<const btConeShape*>(shape); 1203 btScalar radius = coneShape->getRadius();//+coneShape->getMargin(); 1204 btScalar height = coneShape->getHeight();//+coneShape->getMargin(); 1205 btVector3 start = worldTransform.getOrigin(); 1206 1207 int upAxis= coneShape->getConeUpIndex(); 1208 1209 1210 btVector3 offsetHeight(0,0,0); 1211 offsetHeight[upAxis] = height * btScalar(0.5); 1212 btVector3 offsetRadius(0,0,0); 1213 offsetRadius[(upAxis+1)%3] = radius; 1214 btVector3 offset2Radius(0,0,0); 1215 offset2Radius[(upAxis+2)%3] = radius; 1216 1217 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color); 1218 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color); 1219 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color); 1220 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color); 1221 1222 // Drawing the base of the cone 1223 btVector3 yaxis(0,0,0); 1224 yaxis[upAxis] = btScalar(1.0); 1225 btVector3 xaxis(0,0,0); 1226 xaxis[(upAxis+1)%3] = btScalar(1.0); 1227 getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,10.0); 1228 break; 1229 1230 } 1231 case CYLINDER_SHAPE_PROXYTYPE: 1232 { 1233 const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape); 1234 int upAxis = cylinder->getUpAxis(); 1235 btScalar radius = cylinder->getRadius(); 1236 btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis]; 1237 btVector3 start = worldTransform.getOrigin(); 1238 btVector3 offsetHeight(0,0,0); 1239 offsetHeight[upAxis] = halfHeight; 1240 btVector3 offsetRadius(0,0,0); 1241 offsetRadius[(upAxis+1)%3] = radius; 1242 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color); 1243 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color); 1244 1245 // Drawing top and bottom caps of the cylinder 1246 btVector3 yaxis(0,0,0); 1247 yaxis[upAxis] = btScalar(1.0); 1248 btVector3 xaxis(0,0,0); 1249 xaxis[(upAxis+1)%3] = btScalar(1.0); 1250 getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0)); 1251 getDebugDrawer()->drawArc(start+worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0)); 1252 break; 1253 } 1254 1255 case STATIC_PLANE_PROXYTYPE: 1256 { 1257 const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape); 1258 btScalar planeConst = staticPlaneShape->getPlaneConstant(); 1259 const btVector3& planeNormal = staticPlaneShape->getPlaneNormal(); 1260 btVector3 planeOrigin = planeNormal * planeConst; 1261 btVector3 vec0,vec1; 1262 btPlaneSpace1(planeNormal,vec0,vec1); 1263 btScalar vecLen = 100.f; 1264 btVector3 pt0 = planeOrigin + vec0*vecLen; 1265 btVector3 pt1 = planeOrigin - vec0*vecLen; 1266 btVector3 pt2 = planeOrigin + vec1*vecLen; 1267 btVector3 pt3 = planeOrigin - vec1*vecLen; 1268 getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color); 1269 getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color); 1270 break; 1271 1272 } 1273 default: 1274 { 1275 1276 if (shape->isConcave()) 1277 { 1278 btConcaveShape* concaveMesh = (btConcaveShape*) shape; 1279 1280 ///@todo pass camera, for some culling? no -> we are not a graphics lib 1281 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 1282 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 1283 1284 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); 1285 concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax); 1286 1287 } 1288 1289 if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE) 1290 { 1291 btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape; 1292 //todo: pass camera for some culling 1293 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 1294 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 1295 //DebugDrawcallback drawCallback; 1296 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); 1297 convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax); 1298 } 1299 1300 1301 /// for polyhedral shapes 1302 if (shape->isPolyhedral()) 1303 { 1304 btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape; 1305 1306 int i; 1307 for (i=0;i<polyshape->getNumEdges();i++) 1308 { 1309 btVector3 a,b; 1310 polyshape->getEdge(i,a,b); 1311 btVector3 wa = worldTransform * a; 1312 btVector3 wb = worldTransform * b; 1313 getDebugDrawer()->drawLine(wa,wb,color); 1314 1315 } 1316 1317 1318 } 1319 } 1320 } 1321 } 1322 } 1323 1324 1325 void btCollisionWorld::debugDrawWorld() 1326 { 1327 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) 1328 { 1329 int numManifolds = getDispatcher()->getNumManifolds(); 1330 btVector3 color(0,0,0); 1331 for (int i=0;i<numManifolds;i++) 1332 { 1333 btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i); 1334 //btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0()); 1335 //btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1()); 1336 1337 int numContacts = contactManifold->getNumContacts(); 1338 for (int j=0;j<numContacts;j++) 1339 { 1340 btManifoldPoint& cp = contactManifold->getContactPoint(j); 1341 getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color); 1342 } 1343 } 1344 } 1345 1346 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)) 1347 { 1348 int i; 1349 1350 for ( i=0;i<m_collisionObjects.size();i++) 1351 { 1352 btCollisionObject* colObj = m_collisionObjects[i]; 1353 if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0) 1354 { 1355 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe) 1356 { 1357 btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.)); 1358 switch(colObj->getActivationState()) 1359 { 1360 case ACTIVE_TAG: 1361 color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break; 1362 case ISLAND_SLEEPING: 1363 color = btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break; 1364 case WANTS_DEACTIVATION: 1365 color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break; 1366 case DISABLE_DEACTIVATION: 1367 color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break; 1368 case DISABLE_SIMULATION: 1369 color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break; 1370 default: 1371 { 1372 color = btVector3(btScalar(1),btScalar(0.),btScalar(0.)); 1373 } 1374 }; 1375 1376 debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color); 1377 } 1378 if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) 1379 { 1380 btVector3 minAabb,maxAabb; 1381 btVector3 colorvec(1,0,0); 1382 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); 1383 m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec); 1384 } 1385 } 1386 1387 } 1388 } 1389 } 1390 1391 1392 void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) 1393 { 1394 int i; 1395 //serialize all collision objects 1396 for (i=0;i<m_collisionObjects.size();i++) 1397 { 1398 btCollisionObject* colObj = m_collisionObjects[i]; 1399 if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT) 1400 { 1401 colObj->serializeSingleObject(serializer); 1402 } 1403 } 1404 1405 ///keep track of shapes already serialized 1406 btHashMap<btHashPtr,btCollisionShape*> serializedShapes; 1407 1408 for (i=0;i<m_collisionObjects.size();i++) 1409 { 1410 btCollisionObject* colObj = m_collisionObjects[i]; 1411 btCollisionShape* shape = colObj->getCollisionShape(); 1412 1413 if (!serializedShapes.find(shape)) 1414 { 1415 serializedShapes.insert(shape,shape); 1416 shape->serializeSingleShape(serializer); 1417 } 1418 } 1419 1420 } 1421 1422 1423 void btCollisionWorld::serialize(btSerializer* serializer) 1424 { 1425 1426 serializer->startSerialization(); 1427 1428 serializeCollisionObjects(serializer); 1429 1430 serializer->finishSerialization(); 1431 } 1432 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
r5781 r7983 23 23 * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ). 24 24 * 25 * The main documentation is Bullet_User_Manual.pdf, included in the source code distribution. 25 26 * There is the Physics Forum for feedback and general Collision Detection and Physics discussions. 26 27 * Please visit http://www.bulletphysics.com … … 30 31 * @subsection step1 Step 1: Download 31 32 * You can download the Bullet Physics Library from the Google Code repository: http://code.google.com/p/bullet/downloads/list 33 * 32 34 * @subsection step2 Step 2: Building 33 * Bullet comes with autogenerated Project Files for Microsoft Visual Studio 6, 7, 7.1 and 8. 34 * The main Workspace/Solution is located in Bullet/msvc/8/wksbullet.sln (replace 8 with your version). 35 * 36 * Under other platforms, like Linux or Mac OS-X, Bullet can be build using either using make, cmake, http://www.cmake.org , or jam, http://www.perforce.com/jam/jam.html . cmake can autogenerate Xcode, KDevelop, MSVC and other build systems. just run cmake . in the root of Bullet. 37 * So if you are not using MSVC or cmake, you can run ./autogen.sh ./configure to create both Makefile and Jamfile and then run make or jam. 38 * Jam is a build system that can build the library, demos and also autogenerate the MSVC Project Files. 39 * If you don't have jam installed, you can make jam from the included jam-2.5 sources, or download jam from ftp://ftp.perforce.com/jam 35 * Bullet main build system for all platforms is cmake, you can download http://www.cmake.org 36 * cmake can autogenerate projectfiles for Microsoft Visual Studio, Apple Xcode, KDevelop and Unix Makefiles. 37 * The easiest is to run the CMake cmake-gui graphical user interface and choose the options and generate projectfiles. 38 * You can also use cmake in the command-line. Here are some examples for various platforms: 39 * cmake . -G "Visual Studio 9 2008" 40 * cmake . -G Xcode 41 * cmake . -G "Unix Makefiles" 42 * Although cmake is recommended, you can also use autotools for UNIX: ./autogen.sh ./configure to create a Makefile and then run make. 40 43 * 41 44 * @subsection step3 Step 3: Testing demos … … 54 57 * 55 58 * @section copyright Copyright 56 * Copyright (C) 2005-2008 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon 57 * Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, John McCutchan, Nathanael Presson, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky, 58 * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren, Marten Svanfeldt. 59 * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf 59 60 * 60 61 */ 61 62 63 62 64 63 … … 71 70 class btConvexShape; 72 71 class btBroadphaseInterface; 72 class btSerializer; 73 73 74 #include "LinearMath/btVector3.h" 74 75 #include "LinearMath/btTransform.h" … … 82 83 { 83 84 84 85 85 86 86 protected: 87 87 88 88 btAlignedObjectArray<btCollisionObject*> m_collisionObjects; 89 90 89 91 90 btDispatcher* m_dispatcher1; … … 99 98 btIDebugDraw* m_debugDrawer; 100 99 101 102 100 ///m_forceUpdateAllAabbs can be set to false as an optimization to only update active object AABBs 101 ///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB) 102 bool m_forceUpdateAllAabbs; 103 104 void serializeCollisionObjects(btSerializer* serializer); 105 103 106 public: 104 107 … … 142 145 143 146 virtual void updateAabbs(); 144 145 147 146 148 virtual void setDebugDrawer(btIDebugDraw* debugDrawer) … … 153 155 return m_debugDrawer; 154 156 } 157 158 virtual void debugDrawWorld(); 159 160 virtual void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color); 155 161 156 162 … … 161 167 int m_shapePart; 162 168 int m_triangleIndex; 163 164 169 165 170 //const btCollisionShape* m_shapeTemp; … … 239 244 btVector3 m_hitNormalWorld; 240 245 btVector3 m_hitPointWorld; 241 242 246 243 247 virtual btScalar addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) … … 245 249 //caller already does the filter on the m_closestHitFraction 246 250 btAssert(rayResult.m_hitFraction <= m_closestHitFraction); 247 248 251 249 252 m_closestHitFraction = rayResult.m_hitFraction; … … 262 265 }; 263 266 267 struct AllHitsRayResultCallback : public RayResultCallback 268 { 269 AllHitsRayResultCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld) 270 :m_rayFromWorld(rayFromWorld), 271 m_rayToWorld(rayToWorld) 272 { 273 } 274 275 btAlignedObjectArray<btCollisionObject*> m_collisionObjects; 276 277 btVector3 m_rayFromWorld;//used to calculate hitPointWorld from hitFraction 278 btVector3 m_rayToWorld; 279 280 btAlignedObjectArray<btVector3> m_hitNormalWorld; 281 btAlignedObjectArray<btVector3> m_hitPointWorld; 282 btAlignedObjectArray<btScalar> m_hitFractions; 283 284 virtual btScalar addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) 285 { 286 m_collisionObject = rayResult.m_collisionObject; 287 m_collisionObjects.push_back(rayResult.m_collisionObject); 288 btVector3 hitNormalWorld; 289 if (normalInWorldSpace) 290 { 291 hitNormalWorld = rayResult.m_hitNormalLocal; 292 } else 293 { 294 ///need to transform normal into worldspace 295 hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal; 296 } 297 m_hitNormalWorld.push_back(hitNormalWorld); 298 btVector3 hitPointWorld; 299 hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction); 300 m_hitPointWorld.push_back(hitPointWorld); 301 m_hitFractions.push_back(rayResult.m_hitFraction); 302 return m_closestHitFraction; 303 } 304 }; 305 264 306 265 307 struct LocalConvexResult … … 292 334 short int m_collisionFilterGroup; 293 335 short int m_collisionFilterMask; 294 295 336 296 337 ConvexResultCallback() … … 304 345 { 305 346 } 306 307 347 308 348 bool hasHit() const … … 310 350 return (m_closestHitFraction < btScalar(1.)); 311 351 } 312 313 352 314 353 … … 339 378 btVector3 m_hitPointWorld; 340 379 btCollisionObject* m_hitCollisionObject; 341 342 380 343 381 virtual btScalar addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace) … … 345 383 //caller already does the filter on the m_closestHitFraction 346 384 btAssert(convexResult.m_hitFraction <= m_closestHitFraction); 347 348 385 349 386 m_closestHitFraction = convexResult.m_hitFraction; … … 362 399 }; 363 400 401 ///ContactResultCallback is used to report contact points 402 struct ContactResultCallback 403 { 404 short int m_collisionFilterGroup; 405 short int m_collisionFilterMask; 406 407 ContactResultCallback() 408 :m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter), 409 m_collisionFilterMask(btBroadphaseProxy::AllFilter) 410 { 411 } 412 413 virtual ~ContactResultCallback() 414 { 415 } 416 417 virtual bool needsCollision(btBroadphaseProxy* proxy0) const 418 { 419 bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0; 420 collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask); 421 return collides; 422 } 423 424 virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) = 0; 425 }; 426 427 428 364 429 int getNumCollisionObjects() const 365 430 { … … 369 434 /// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback 370 435 /// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback. 371 v oidrayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;372 373 // convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback374 // This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.436 virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const; 437 438 /// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback 439 /// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback. 375 440 void convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = btScalar(0.)) const; 441 442 ///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback. 443 ///it reports one or more contact points for every overlapping object (including the one with deepest penetration) 444 void contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback); 445 446 ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected. 447 ///it reports one or more contact points (including the one with deepest penetration) 448 void contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback); 376 449 377 450 … … 392 465 ConvexResultCallback& resultCallback, btScalar allowedPenetration); 393 466 394 v oid addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);467 virtual void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter); 395 468 396 469 btCollisionObjectArray& getCollisionObjectArray() … … 405 478 406 479 407 v oid removeCollisionObject(btCollisionObject* collisionObject);480 virtual void removeCollisionObject(btCollisionObject* collisionObject); 408 481 409 482 virtual void performDiscreteCollisionDetection(); … … 418 491 return m_dispatchInfo; 419 492 } 493 494 bool getForceUpdateAllAabbs() const 495 { 496 return m_forceUpdateAllAabbs; 497 } 498 void setForceUpdateAllAabbs( bool forceUpdateAllAabbs) 499 { 500 m_forceUpdateAllAabbs = forceUpdateAllAabbs; 501 } 502 503 ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo) 504 virtual void serialize(btSerializer* serializer); 420 505 421 506 }; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
r5781 r7983 115 115 void ProcessChildShape(btCollisionShape* childShape,int index) 116 116 { 117 117 btAssert(index>=0); 118 118 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape()); 119 btAssert(index<compoundShape->getNumChildShapes()); 119 120 120 121 … … 142 143 if (!m_childCollisionAlgorithms[index]) 143 144 m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold); 145 146 ///detect swapping case 147 if (m_resultOut->getBody0Internal() == m_compoundColObj) 148 { 149 m_resultOut->setShapeIdentifiersA(-1,index); 150 } else 151 { 152 m_resultOut->setShapeIdentifiersB(-1,index); 153 } 144 154 145 155 m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut); … … 258 268 int i; 259 269 btManifoldArray manifoldArray; 260 270 btCollisionShape* childShape = 0; 271 btTransform orgTrans; 272 btTransform orgInterpolationTrans; 273 btTransform newChildWorldTrans; 274 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1; 275 261 276 for (i=0;i<numChildren;i++) 262 277 { 263 278 if (m_childCollisionAlgorithms[i]) 264 279 { 265 btCollisionShape*childShape = compoundShape->getChildShape(i);280 childShape = compoundShape->getChildShape(i); 266 281 //if not longer overlapping, remove the algorithm 267 btTransformorgTrans = colObj->getWorldTransform();268 btTransformorgInterpolationTrans = colObj->getInterpolationWorldTransform();282 orgTrans = colObj->getWorldTransform(); 283 orgInterpolationTrans = colObj->getInterpolationWorldTransform(); 269 284 const btTransform& childTrans = compoundShape->getChildTransform(i); 270 btTransformnewChildWorldTrans = orgTrans*childTrans ;285 newChildWorldTrans = orgTrans*childTrans ; 271 286 272 287 //perform an AABB check first 273 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;274 288 childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0); 275 289 otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1); … … 281 295 m_childCollisionAlgorithms[i] = 0; 282 296 } 283 284 297 } 285 286 } 287 288 289 298 } 290 299 } 291 300 } … … 312 321 int numChildren = m_childCollisionAlgorithms.size(); 313 322 int i; 323 btTransform orgTrans; 324 btScalar frac; 314 325 for (i=0;i<numChildren;i++) 315 326 { … … 318 329 319 330 //backup 320 btTransformorgTrans = colObj->getWorldTransform();331 orgTrans = colObj->getWorldTransform(); 321 332 322 333 const btTransform& childTrans = compoundShape->getChildTransform(i); … … 326 337 btCollisionShape* tmpShape = colObj->getCollisionShape(); 327 338 colObj->internalSetTemporaryCollisionShape( childShape ); 328 btScalarfrac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);339 frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut); 329 340 if (frac<hitFraction) 330 341 { -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
r5781 r7983 96 96 if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe )) 97 97 { 98 btVector3 color( 255,255,0);98 btVector3 color(1,1,0); 99 99 btTransform& tr = ob->getWorldTransform(); 100 100 m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color); … … 122 122 123 123 btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr); 124 ///this should use the btDispatcher, so the actual registered algorithm is used 125 // btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody); 126 127 m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex); 128 // cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex); 129 // cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); 124 125 if (m_resultOut->getBody0Internal() == m_triBody) 126 { 127 m_resultOut->setShapeIdentifiersA(partId,triangleIndex); 128 } 129 else 130 { 131 m_resultOut->setShapeIdentifiersB(partId,triangleIndex); 132 } 133 130 134 colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); 131 135 colAlgo->~btCollisionAlgorithm(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
r5781 r7983 14 14 */ 15 15 16 ///Specialized capsule-capsule collision algorithm has been added for Bullet 2.75 release to increase ragdoll performance 17 ///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums 18 ///with reproduction case 19 //define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1 20 16 21 #include "btConvexConvexAlgorithm.h" 17 22 … … 21 26 #include "BulletCollision/CollisionDispatch/btCollisionObject.h" 22 27 #include "BulletCollision/CollisionShapes/btConvexShape.h" 28 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 29 30 23 31 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" 24 32 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" … … 44 52 45 53 46 54 /////////// 55 56 57 58 static SIMD_FORCE_INLINE void segmentsClosestPoints( 59 btVector3& ptsVector, 60 btVector3& offsetA, 61 btVector3& offsetB, 62 btScalar& tA, btScalar& tB, 63 const btVector3& translation, 64 const btVector3& dirA, btScalar hlenA, 65 const btVector3& dirB, btScalar hlenB ) 66 { 67 // compute the parameters of the closest points on each line segment 68 69 btScalar dirA_dot_dirB = btDot(dirA,dirB); 70 btScalar dirA_dot_trans = btDot(dirA,translation); 71 btScalar dirB_dot_trans = btDot(dirB,translation); 72 73 btScalar denom = 1.0f - dirA_dot_dirB * dirA_dot_dirB; 74 75 if ( denom == 0.0f ) { 76 tA = 0.0f; 77 } else { 78 tA = ( dirA_dot_trans - dirB_dot_trans * dirA_dot_dirB ) / denom; 79 if ( tA < -hlenA ) 80 tA = -hlenA; 81 else if ( tA > hlenA ) 82 tA = hlenA; 83 } 84 85 tB = tA * dirA_dot_dirB - dirB_dot_trans; 86 87 if ( tB < -hlenB ) { 88 tB = -hlenB; 89 tA = tB * dirA_dot_dirB + dirA_dot_trans; 90 91 if ( tA < -hlenA ) 92 tA = -hlenA; 93 else if ( tA > hlenA ) 94 tA = hlenA; 95 } else if ( tB > hlenB ) { 96 tB = hlenB; 97 tA = tB * dirA_dot_dirB + dirA_dot_trans; 98 99 if ( tA < -hlenA ) 100 tA = -hlenA; 101 else if ( tA > hlenA ) 102 tA = hlenA; 103 } 104 105 // compute the closest points relative to segment centers. 106 107 offsetA = dirA * tA; 108 offsetB = dirB * tB; 109 110 ptsVector = translation - offsetA + offsetB; 111 } 112 113 114 static SIMD_FORCE_INLINE btScalar capsuleCapsuleDistance( 115 btVector3& normalOnB, 116 btVector3& pointOnB, 117 btScalar capsuleLengthA, 118 btScalar capsuleRadiusA, 119 btScalar capsuleLengthB, 120 btScalar capsuleRadiusB, 121 int capsuleAxisA, 122 int capsuleAxisB, 123 const btTransform& transformA, 124 const btTransform& transformB, 125 btScalar distanceThreshold ) 126 { 127 btVector3 directionA = transformA.getBasis().getColumn(capsuleAxisA); 128 btVector3 translationA = transformA.getOrigin(); 129 btVector3 directionB = transformB.getBasis().getColumn(capsuleAxisB); 130 btVector3 translationB = transformB.getOrigin(); 131 132 // translation between centers 133 134 btVector3 translation = translationB - translationA; 135 136 // compute the closest points of the capsule line segments 137 138 btVector3 ptsVector; // the vector between the closest points 139 140 btVector3 offsetA, offsetB; // offsets from segment centers to their closest points 141 btScalar tA, tB; // parameters on line segment 142 143 segmentsClosestPoints( ptsVector, offsetA, offsetB, tA, tB, translation, 144 directionA, capsuleLengthA, directionB, capsuleLengthB ); 145 146 btScalar distance = ptsVector.length() - capsuleRadiusA - capsuleRadiusB; 147 148 if ( distance > distanceThreshold ) 149 return distance; 150 151 btScalar lenSqr = ptsVector.length2(); 152 if (lenSqr<= (SIMD_EPSILON*SIMD_EPSILON)) 153 { 154 //degenerate case where 2 capsules are likely at the same location: take a vector tangential to 'directionA' 155 btVector3 q; 156 btPlaneSpace1(directionA,normalOnB,q); 157 } else 158 { 159 // compute the contact normal 160 normalOnB = ptsVector*-btRecipSqrt(lenSqr); 161 } 162 pointOnB = transformB.getOrigin()+offsetB + normalOnB * capsuleRadiusB; 163 164 return distance; 165 } 166 167 168 169 170 171 172 173 ////////// 47 174 48 175 … … 70 197 m_lowLevelOfDetail(false), 71 198 #ifdef USE_SEPDISTANCE_UTIL2 72 ,m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(),199 m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(), 73 200 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()), 74 201 #endif … … 112 239 m_transformA(transformA), 113 240 m_transformB(transformB), 241 m_unPerturbedTransform(unPerturbedTransform), 114 242 m_perturbA(perturbA), 115 m_unPerturbedTransform(unPerturbedTransform),116 243 m_debugDrawer(debugDrawer) 117 244 { … … 156 283 extern btScalar gContactBreakingThreshold; 157 284 285 158 286 // 159 287 // Convex-Convex collision algorithm … … 177 305 btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape()); 178 306 307 btVector3 normalOnB; 308 btVector3 pointOnBWorld; 309 #ifndef BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 310 if ((min0->getShapeType() == CAPSULE_SHAPE_PROXYTYPE) && (min1->getShapeType() == CAPSULE_SHAPE_PROXYTYPE)) 311 { 312 btCapsuleShape* capsuleA = (btCapsuleShape*) min0; 313 btCapsuleShape* capsuleB = (btCapsuleShape*) min1; 314 btVector3 localScalingA = capsuleA->getLocalScaling(); 315 btVector3 localScalingB = capsuleB->getLocalScaling(); 316 317 btScalar threshold = m_manifoldPtr->getContactBreakingThreshold(); 318 319 btScalar dist = capsuleCapsuleDistance(normalOnB, pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(), 320 capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(), 321 body0->getWorldTransform(),body1->getWorldTransform(),threshold); 322 323 if (dist<threshold) 324 { 325 btAssert(normalOnB.length2()>=(SIMD_EPSILON*SIMD_EPSILON)); 326 resultOut->addContactPoint(normalOnB,pointOnBWorld,dist); 327 } 328 resultOut->refreshContactPoints(); 329 return; 330 } 331 #endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 332 333 179 334 #ifdef USE_SEPDISTANCE_UTIL2 180 m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); 335 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 336 { 337 m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); 338 } 339 181 340 if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f) 182 341 #endif //USE_SEPDISTANCE_UTIL2 … … 195 354 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 196 355 { 197 input.m_maximumDistanceSquared = 1e30f;356 input.m_maximumDistanceSquared = BT_LARGE_FLOAT; 198 357 } else 199 358 #endif //USE_SEPDISTANCE_UTIL2 200 359 { 201 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); 360 if (dispatchInfo.m_convexMaxDistanceUseCPT) 361 { 362 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold(); 363 } else 364 { 365 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); 366 } 202 367 input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared; 203 368 } … … 208 373 209 374 gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); 210 btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold; 211 212 //now perturbe directions to get multiple contact points 213 btVector3 v0,v1; 214 btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 215 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 375 376 377 378 #ifdef USE_SEPDISTANCE_UTIL2 379 btScalar sepDist = 0.f; 380 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 381 { 382 sepDist = gjkPairDetector.getCachedSeparatingDistance(); 383 if (sepDist>SIMD_EPSILON) 384 { 385 sepDist += dispatchInfo.m_convexConservativeDistanceThreshold; 386 //now perturbe directions to get multiple contact points 387 388 } 389 } 390 #endif //USE_SEPDISTANCE_UTIL2 391 216 392 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects 217 393 218 394 //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points 219 if ( resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)395 if (m_numPerturbationIterations && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold) 220 396 { 221 397 222 398 int i; 399 btVector3 v0,v1; 400 btVector3 sepNormalWorldSpace; 401 402 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 403 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 404 223 405 224 406 bool perturbeA = true; … … 250 432 for ( i=0;i<m_numPerturbationIterations;i++) 251 433 { 434 if (v0.length2()>SIMD_EPSILON) 435 { 252 436 btQuaternion perturbeRot(v0,perturbeAngle); 253 437 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); … … 273 457 btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); 274 458 gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); 459 } 275 460 276 277 461 } 278 462 } … … 281 465 282 466 #ifdef USE_SEPDISTANCE_UTIL2 283 if (dispatchInfo.m_useConvexConservativeDistanceUtil )467 if (dispatchInfo.m_useConvexConservativeDistanceUtil && (sepDist>SIMD_EPSILON)) 284 468 { 285 469 m_sepDistance.initSeparatingDistance(gjkPairDetector.getCachedSeparatingAxis(),sepDist,body0->getWorldTransform(),body1->getWorldTransform()); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
r5781 r7983 32 32 ///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util 33 33 ///for certain pairs that have a small size ratio 34 ///#define USE_SEPDISTANCE_UTIL2 1 34 35 //#define USE_SEPDISTANCE_UTIL2 1 35 36 36 37 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
r5781 r7983 103 103 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 104 104 105 bool hasCollision = false;105 106 106 const btVector3& planeNormal = planeShape->getPlaneNormal(); 107 const btScalar& planeConstant = planeShape->getPlaneConstant();107 //const btScalar& planeConstant = planeShape->getPlaneConstant(); 108 108 109 109 //first perform a collision query with the non-perturbated collision objects -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
r5781 r7983 61 61 62 62 CreateFunc() 63 : m_numPerturbationIterations( 3),64 m_minimumPointsPerturbationThreshold( 3)63 : m_numPerturbationIterations(1), 64 m_minimumPointsPerturbationThreshold(1) 65 65 { 66 66 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
r5781 r7983 46 46 void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16); 47 47 m_simplexSolver = new (mem)btVoronoiSimplexSolver(); 48 49 #define USE_EPA 1 50 #ifdef USE_EPA 51 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);52 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;53 #else54 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);55 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;56 #endif//USE_EPA 57 58 48 49 if (constructionInfo.m_useEpaPenetrationAlgorithm) 50 { 51 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16); 52 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver; 53 }else 54 { 55 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16); 56 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver; 57 } 58 59 59 //default CreationFunctions, filling the m_doubleDispatch table 60 60 mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16); … … 103 103 int sl = sizeof(btConvexSeparatingDistanceUtil); 104 104 sl = sizeof(btGjkPairDetector); 105 int collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2); 105 int collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize); 106 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2); 106 107 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3); 107 108 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
r5781 r7983 28 28 int m_defaultMaxPersistentManifoldPoolSize; 29 29 int m_defaultMaxCollisionAlgorithmPoolSize; 30 int m_customCollisionAlgorithmMaxElementSize; 30 31 int m_defaultStackAllocatorSize; 32 int m_useEpaPenetrationAlgorithm; 31 33 32 34 btDefaultCollisionConstructionInfo() … … 36 38 m_defaultMaxPersistentManifoldPoolSize(4096), 37 39 m_defaultMaxCollisionAlgorithmPoolSize(4096), 38 m_defaultStackAllocatorSize(0) 40 m_customCollisionAlgorithmMaxElementSize(0), 41 m_defaultStackAllocatorSize(0), 42 m_useEpaPenetrationAlgorithm(true) 39 43 { 40 44 } … … 109 113 } 110 114 115 virtual btVoronoiSimplexSolver* getSimplexSolver() 116 { 117 return m_simplexSolver; 118 } 119 111 120 112 121 virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btGhostObject.h
r5781 r7983 161 161 } 162 162 163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0,btDispatcher* dispatcher)163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/) 164 164 { 165 165 btAssert(0); … … 173 173 174 174 #endif 175 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp
r5781 r7983 48 48 m_body0(body0), 49 49 m_body1(body1) 50 #ifdef DEBUG_PART_INDEX 51 ,m_partId0(-1), 52 m_partId1(-1), 53 m_index0(-1), 54 m_index1(-1) 55 #endif //DEBUG_PART_INDEX 50 56 { 51 57 m_rootTransA = body0->getWorldTransform(); … … 89 95 90 96 //BP mod, store contact triangles. 91 newPt.m_partId0 = m_partId0; 92 newPt.m_partId1 = m_partId1; 93 newPt.m_index0 = m_index0; 94 newPt.m_index1 = m_index1; 97 if (isSwapped) 98 { 99 newPt.m_partId0 = m_partId1; 100 newPt.m_partId1 = m_partId0; 101 newPt.m_index0 = m_index1; 102 newPt.m_index1 = m_index0; 103 } else 104 { 105 newPt.m_partId0 = m_partId0; 106 newPt.m_partId1 = m_partId1; 107 newPt.m_index0 = m_index0; 108 newPt.m_index1 = m_index1; 109 } 95 110 //printf("depth=%f\n",depth); 96 111 ///@todo, check this for any side effects … … 113 128 btCollisionObject* obj0 = isSwapped? m_body1 : m_body0; 114 129 btCollisionObject* obj1 = isSwapped? m_body0 : m_body1; 115 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0, m_partId0,m_index0,obj1,m_partId1,m_index1);130 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1); 116 131 } 117 132 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h
r5781 r7983 29 29 extern ContactAddedCallback gContactAddedCallback; 30 30 31 //#define DEBUG_PART_INDEX 1 31 32 32 33 … … 34 35 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result 35 36 { 37 protected: 38 36 39 btPersistentManifold* m_manifoldPtr; 37 40 … … 51 54 52 55 btManifoldResult() 56 #ifdef DEBUG_PART_INDEX 57 : 58 m_partId0(-1), 59 m_partId1(-1), 60 m_index0(-1), 61 m_index1(-1) 62 #endif //DEBUG_PART_INDEX 53 63 { 54 64 } … … 72 82 } 73 83 74 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)84 virtual void setShapeIdentifiersA(int partId0,int index0) 75 85 { 76 m_partId0=partId0; 77 m_partId1=partId1; 78 m_index0=index0; 79 m_index1=index1; 86 m_partId0=partId0; 87 m_index0=index0; 88 } 89 90 virtual void setShapeIdentifiersB( int partId1,int index1) 91 { 92 m_partId1=partId1; 93 m_index1=index1; 80 94 } 81 95 … … 100 114 } 101 115 116 const btCollisionObject* getBody0Internal() const 117 { 118 return m_body0; 119 } 102 120 121 const btCollisionObject* getBody1Internal() const 122 { 123 return m_body1; 124 } 125 103 126 }; 104 127 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
r5781 r7983 1 1 2 /* 2 3 Bullet Continuous Collision Detection and Physics Library … … 45 46 46 47 { 48 btOverlappingPairCache* pairCachePtr = colWorld->getPairCache(); 49 const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs(); 50 btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr(); 47 51 48 for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++) 49 { 50 btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr(); 52 for (int i=0;i<numOverlappingPairs;i++) 53 { 51 54 const btBroadphasePair& collisionPair = pairPtr[i]; 52 55 btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject; … … 64 67 } 65 68 66 69 #ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION 70 void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher) 71 { 72 73 // put the index into m_controllers into m_tag 74 int index = 0; 75 { 76 77 int i; 78 for (i=0;i<colWorld->getCollisionObjectArray().size(); i++) 79 { 80 btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i]; 81 //Adding filtering here 82 if (!collisionObject->isStaticOrKinematicObject()) 83 { 84 collisionObject->setIslandTag(index++); 85 } 86 collisionObject->setCompanionId(-1); 87 collisionObject->setHitFraction(btScalar(1.)); 88 } 89 } 90 // do the union find 91 92 initUnionFind( index ); 93 94 findUnions(dispatcher,colWorld); 95 } 96 97 void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld) 98 { 99 // put the islandId ('find' value) into m_tag 100 { 101 int index = 0; 102 int i; 103 for (i=0;i<colWorld->getCollisionObjectArray().size();i++) 104 { 105 btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i]; 106 if (!collisionObject->isStaticOrKinematicObject()) 107 { 108 collisionObject->setIslandTag( m_unionFind.find(index) ); 109 //Set the correct object offset in Collision Object Array 110 m_unionFind.getElement(index).m_sz = i; 111 collisionObject->setCompanionId(-1); 112 index++; 113 } else 114 { 115 collisionObject->setIslandTag(-1); 116 collisionObject->setCompanionId(-2); 117 } 118 } 119 } 120 } 121 122 123 #else //STATIC_SIMULATION_ISLAND_OPTIMIZATION 67 124 void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher) 68 125 { 69 126 70 127 initUnionFind( int (colWorld->getCollisionObjectArray().size())); 71 128 72 129 // put the index into m_controllers into m_tag 73 130 { 74 131 75 132 int index = 0; 76 133 int i; … … 82 139 collisionObject->setHitFraction(btScalar(1.)); 83 140 index++; 84 141 85 142 } 86 143 } 87 144 // do the union find 88 145 89 146 findUnions(dispatcher,colWorld); 90 91 92 93 } 94 95 96 147 } 97 148 98 149 void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld) … … 100 151 // put the islandId ('find' value) into m_tag 101 152 { 102 103 153 154 104 155 int index = 0; 105 156 int i; … … 120 171 } 121 172 } 173 174 #endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION 122 175 123 176 inline int getIslandId(const btPersistentManifold* lhs) -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
r5781 r7983 60 60 61 61 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 62 input.m_maximumDistanceSquared = btScalar( 1e30);///@todo: tighter bounds62 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds 63 63 input.m_transformA = sphereObj->getWorldTransform(); 64 64 input.m_transformB = triObj->getWorldTransform(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp
r5781 r7983 71 71 { 72 72 m_elements[i].m_id = find(i); 73 #ifndef STATIC_SIMULATION_ISLAND_OPTIMIZATION 73 74 m_elements[i].m_sz = i; 75 #endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION 74 76 } 75 77 … … 79 81 80 82 } 81 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h
r5781 r7983 19 19 #include "LinearMath/btAlignedObjectArray.h" 20 20 21 #define USE_PATH_COMPRESSION 1 21 #define USE_PATH_COMPRESSION 1 22 23 ///see for discussion of static island optimizations by Vroonsh here: http://code.google.com/p/bullet/issues/detail?id=406 24 #define STATIC_SIMULATION_ISLAND_OPTIMIZATION 1 22 25 23 26 struct btElement … … 107 110 108 111 #ifdef USE_PATH_COMPRESSION 109 // 110 m_elements[x].m_id = m_elements[m_elements[x].m_id].m_id; 111 #endif // 112 const btElement* elementPtr = &m_elements[m_elements[x].m_id]; 113 m_elements[x].m_id = elementPtr->m_id; 114 x = elementPtr->m_id; 115 #else// 112 116 x = m_elements[x].m_id; 117 #endif 113 118 //btAssert(x < m_N); 114 119 //btAssert(x >= 0); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 #include "btBoxShape.h" 17 16 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 42 42 const btVector3& getHalfExtentsWithoutMargin() const 43 43 { 44 return m_implicitShapeDimensions;// changed in Bullet 2.63: assume the scaling and margin are included44 return m_implicitShapeDimensions;//scaling is included, margin is not 45 45 } 46 46 … … 313 313 }; 314 314 315 315 316 #endif //OBB_BOX_MINKOWSKI_H 316 317 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 18 18 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" 19 19 #include "BulletCollision/CollisionShapes/btOptimizedBvh.h" 20 #include "LinearMath/btSerializer.h" 20 21 21 22 ///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization. … … 24 25 :btTriangleMeshShape(meshInterface), 25 26 m_bvh(0), 27 m_triangleInfoMap(0), 26 28 m_useQuantizedAabbCompression(useQuantizedAabbCompression), 27 29 m_ownsBvh(false) … … 31 33 #ifndef DISABLE_BVH 32 34 33 btVector3 bvhAabbMin,bvhAabbMax;34 if(meshInterface->hasPremadeAabb())35 {36 meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);37 }38 else39 {40 meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);41 }42 43 35 if (buildBvh) 44 36 { 45 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 46 m_bvh = new (mem) btOptimizedBvh(); 47 m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax); 48 m_ownsBvh = true; 37 buildOptimizedBvh(); 49 38 } 50 39 … … 56 45 :btTriangleMeshShape(meshInterface), 57 46 m_bvh(0), 47 m_triangleInfoMap(0), 58 48 m_useQuantizedAabbCompression(useQuantizedAabbCompression), 59 49 m_ownsBvh(false) … … 344 334 { 345 335 btTriangleMeshShape::setLocalScaling(scaling); 346 if (m_ownsBvh) 347 { 348 m_bvh->~btOptimizedBvh(); 349 btAlignedFree(m_bvh); 350 } 351 ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work 352 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 353 m_bvh = new(mem) btOptimizedBvh(); 354 //rebuild the bvh... 355 m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); 356 m_ownsBvh = true; 336 buildOptimizedBvh(); 357 337 } 338 } 339 340 void btBvhTriangleMeshShape::buildOptimizedBvh() 341 { 342 if (m_ownsBvh) 343 { 344 m_bvh->~btOptimizedBvh(); 345 btAlignedFree(m_bvh); 346 } 347 ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work 348 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 349 m_bvh = new(mem) btOptimizedBvh(); 350 //rebuild the bvh... 351 m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); 352 m_ownsBvh = true; 358 353 } 359 354 … … 373 368 374 369 370 371 ///fills the dataBuffer and returns the struct name (and 0 on failure) 372 const char* btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const 373 { 374 btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer; 375 376 btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer); 377 378 m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer); 379 380 trimeshData->m_collisionMargin = float(m_collisionMargin); 381 382 383 384 if (m_bvh && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_BVH)) 385 { 386 void* chunk = serializer->findPointer(m_bvh); 387 if (chunk) 388 { 389 #ifdef BT_USE_DOUBLE_PRECISION 390 trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk; 391 trimeshData->m_quantizedFloatBvh = 0; 392 #else 393 trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)chunk; 394 trimeshData->m_quantizedDoubleBvh= 0; 395 #endif //BT_USE_DOUBLE_PRECISION 396 } else 397 { 398 399 #ifdef BT_USE_DOUBLE_PRECISION 400 trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh); 401 trimeshData->m_quantizedFloatBvh = 0; 402 #else 403 trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh); 404 trimeshData->m_quantizedDoubleBvh= 0; 405 #endif //BT_USE_DOUBLE_PRECISION 406 407 int sz = m_bvh->calculateSerializeBufferSizeNew(); 408 btChunk* chunk = serializer->allocate(sz,1); 409 const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); 410 serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,m_bvh); 411 } 412 } else 413 { 414 trimeshData->m_quantizedFloatBvh = 0; 415 trimeshData->m_quantizedDoubleBvh = 0; 416 } 417 418 419 420 if (m_triangleInfoMap && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_TRIANGLEINFOMAP)) 421 { 422 void* chunk = serializer->findPointer(m_triangleInfoMap); 423 if (chunk) 424 { 425 trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)chunk; 426 } else 427 { 428 trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)serializer->getUniquePointer(m_triangleInfoMap); 429 int sz = m_triangleInfoMap->calculateSerializeBufferSize(); 430 btChunk* chunk = serializer->allocate(sz,1); 431 const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); 432 serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,m_triangleInfoMap); 433 } 434 } else 435 { 436 trimeshData->m_triangleInfoMap = 0; 437 } 438 439 return "btTriangleMeshShapeData"; 440 } 441 442 void btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const 443 { 444 if (m_bvh) 445 { 446 int len = m_bvh->calculateSerializeBufferSizeNew(); //make sure not to use calculateSerializeBufferSize because it is used for in-place 447 btChunk* chunk = serializer->allocate(len,1); 448 const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); 449 serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,(void*)m_bvh); 450 } 451 } 452 453 void btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const 454 { 455 if (m_triangleInfoMap) 456 { 457 int len = m_triangleInfoMap->calculateSerializeBufferSize(); 458 btChunk* chunk = serializer->allocate(len,1); 459 const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); 460 serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,(void*)m_triangleInfoMap); 461 } 462 } 463 464 465 466 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "btOptimizedBvh.h" 21 21 #include "LinearMath/btAlignedAllocator.h" 22 22 #include "btTriangleInfoMap.h" 23 23 24 24 ///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage. … … 30 30 31 31 btOptimizedBvh* m_bvh; 32 btTriangleInfoMap* m_triangleInfoMap; 33 32 34 bool m_useQuantizedAabbCompression; 33 35 bool m_ownsBvh; … … 38 40 BT_DECLARE_ALIGNED_ALLOCATOR(); 39 41 40 btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_ ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};42 btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_triangleInfoMap(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;}; 41 43 btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true); 42 44 … … 74 76 } 75 77 78 void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1)); 76 79 77 void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));80 void buildOptimizedBvh(); 78 81 79 82 bool usesQuantizedAabbCompression() const … … 81 84 return m_useQuantizedAabbCompression; 82 85 } 86 87 void setTriangleInfoMap(btTriangleInfoMap* triangleInfoMap) 88 { 89 m_triangleInfoMap = triangleInfoMap; 90 } 91 92 const btTriangleInfoMap* getTriangleInfoMap() const 93 { 94 return m_triangleInfoMap; 95 } 96 97 btTriangleInfoMap* getTriangleInfoMap() 98 { 99 return m_triangleInfoMap; 100 } 101 102 virtual int calculateSerializeBufferSize() const; 103 104 ///fills the dataBuffer and returns the struct name (and 0 on failure) 105 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 106 107 virtual void serializeSingleBvh(btSerializer* serializer) const; 108 109 virtual void serializeSingleTriangleInfoMap(btSerializer* serializer) const; 110 111 }; 112 113 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 114 struct btTriangleMeshShapeData 115 { 116 btCollisionShapeData m_collisionShapeData; 117 118 btStridingMeshInterfaceData m_meshInterface; 119 120 btQuantizedBvhFloatData *m_quantizedFloatBvh; 121 btQuantizedBvhDoubleData *m_quantizedDoubleBvh; 122 123 btTriangleInfoMapData *m_triangleInfoMap; 124 125 float m_collisionMargin; 126 127 char m_pad3[4]; 128 129 }; 130 131 132 SIMD_FORCE_INLINE int btBvhTriangleMeshShape::calculateSerializeBufferSize() const 133 { 134 return sizeof(btTriangleMeshShapeData); 83 135 } 84 ; 136 137 85 138 86 139 #endif //BVH_TRIANGLE_MESH_SHAPE_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 33 33 btVector3 supVec(0,0,0); 34 34 35 btScalar maxDot(btScalar(- 1e30));35 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 36 36 37 37 btVector3 vec = vec0; … … 89 89 for (int j=0;j<numVectors;j++) 90 90 { 91 btScalar maxDot(btScalar(- 1e30));91 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 92 92 const btVector3& vec = vectors[j]; 93 93 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 44 44 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 45 45 46 virtual void setMargin(btScalar collisionMargin) 47 { 48 //correct the m_implicitShapeDimensions for the margin 49 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 50 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 51 52 btConvexInternalShape::setMargin(collisionMargin); 53 btVector3 newMargin(getMargin(),getMargin(),getMargin()); 54 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; 55 56 } 57 46 58 virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const 47 59 { … … 77 89 return m_implicitShapeDimensions[m_upAxis]; 78 90 } 91 92 virtual void setLocalScaling(const btVector3& scaling) 93 { 94 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 95 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 96 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling; 97 98 btConvexInternalShape::setLocalScaling(scaling); 99 100 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin; 101 102 } 103 104 virtual int calculateSerializeBufferSize() const; 105 106 ///fills the dataBuffer and returns the struct name (and 0 on failure) 107 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 108 79 109 80 110 }; … … 114 144 }; 115 145 146 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 147 struct btCapsuleShapeData 148 { 149 btConvexInternalShapeData m_convexInternalShapeData; 116 150 151 int m_upAxis; 152 153 char m_padding[4]; 154 }; 155 156 SIMD_FORCE_INLINE int btCapsuleShape::calculateSerializeBufferSize() const 157 { 158 return sizeof(btCapsuleShapeData); 159 } 160 161 ///fills the dataBuffer and returns the struct name (and 0 on failure) 162 SIMD_FORCE_INLINE const char* btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const 163 { 164 btCapsuleShapeData* shapeData = (btCapsuleShapeData*) dataBuffer; 165 166 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer); 167 168 shapeData->m_upAxis = m_upAxis; 169 170 return "btCapsuleShapeData"; 171 } 117 172 118 173 #endif //BT_CAPSULE_SHAPE_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCollisionMargin.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 17 18 19 btScalar gContactThresholdFactor=btScalar(0.02); 20 16 #include "LinearMath/btSerializer.h" 21 17 22 18 /* … … 46 42 } 47 43 48 btScalar btCollisionShape::getContactBreakingThreshold() const 44 45 btScalar btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const 49 46 { 50 return getAngularMotionDisc() * gContactThresholdFactor;47 return getAngularMotionDisc() * defaultContactThreshold; 51 48 } 49 52 50 btScalar btCollisionShape::getAngularMotionDisc() const 53 51 { … … 97 95 temporalAabbMax += angularMotion3d; 98 96 } 97 98 ///fills the dataBuffer and returns the struct name (and 0 on failure) 99 const char* btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const 100 { 101 btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer; 102 char* name = (char*) serializer->findNameForPointer(this); 103 shapeData->m_name = (char*)serializer->getUniquePointer(name); 104 if (shapeData->m_name) 105 { 106 serializer->serializeName(name); 107 } 108 shapeData->m_shapeType = m_shapeType; 109 //shapeData->m_padding//?? 110 return "btCollisionShapeData"; 111 } 112 113 void btCollisionShape::serializeSingleShape(btSerializer* serializer) const 114 { 115 int len = calculateSerializeBufferSize(); 116 btChunk* chunk = serializer->allocate(len,1); 117 const char* structType = serialize(chunk->m_oldPtr, serializer); 118 serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this); 119 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 21 21 #include "LinearMath/btMatrix3x3.h" 22 22 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types 23 class btSerializer; 24 23 25 24 26 ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects. … … 47 49 virtual btScalar getAngularMotionDisc() const; 48 50 49 virtual btScalar getContactBreakingThreshold( ) const;51 virtual btScalar getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const; 50 52 51 53 … … 54 56 void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const; 55 57 56 #ifndef __SPU__ 58 57 59 58 60 SIMD_FORCE_INLINE bool isPolyhedral() const … … 61 63 } 62 64 65 SIMD_FORCE_INLINE bool isConvex2d() const 66 { 67 return btBroadphaseProxy::isConvex2d(getShapeType()); 68 } 69 63 70 SIMD_FORCE_INLINE bool isConvex() const 64 71 { 65 72 return btBroadphaseProxy::isConvex(getShapeType()); 73 } 74 SIMD_FORCE_INLINE bool isNonMoving() const 75 { 76 return btBroadphaseProxy::isNonMoving(getShapeType()); 66 77 } 67 78 SIMD_FORCE_INLINE bool isConcave() const … … 74 85 } 75 86 87 SIMD_FORCE_INLINE bool isSoftBody() const 88 { 89 return btBroadphaseProxy::isSoftBody(getShapeType()); 90 } 91 76 92 ///isInfinite is used to catch simulation error (aabb check) 77 93 SIMD_FORCE_INLINE bool isInfinite() const … … 80 96 } 81 97 82 98 #ifndef __SPU__ 83 99 virtual void setLocalScaling(const btVector3& scaling) =0; 84 100 virtual const btVector3& getLocalScaling() const =0; … … 107 123 } 108 124 125 virtual int calculateSerializeBufferSize() const; 126 127 ///fills the dataBuffer and returns the struct name (and 0 on failure) 128 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 129 130 virtual void serializeSingleShape(btSerializer* serializer) const; 131 109 132 }; 133 134 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 135 struct btCollisionShapeData 136 { 137 char *m_name; 138 int m_shapeType; 139 char m_padding[4]; 140 }; 141 142 SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() const 143 { 144 return sizeof(btCollisionShapeData); 145 } 146 147 110 148 111 149 #endif //COLLISION_SHAPE_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 17 17 #include "btCollisionShape.h" 18 18 #include "BulletCollision/BroadphaseCollision/btDbvt.h" 19 #include "LinearMath/btSerializer.h" 19 20 20 21 btCompoundShape::btCompoundShape(bool enableDynamicAabbTree) 21 : m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)), 22 m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)), 22 : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)), 23 m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)), 24 m_dynamicAabbTree(0), 25 m_updateRevision(1), 23 26 m_collisionMargin(btScalar(0.)), 24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), 25 m_dynamicAabbTree(0), 26 m_updateRevision(1) 27 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) 27 28 { 28 29 m_shapeType = COMPOUND_SHAPE_PROXYTYPE; … … 52 53 //m_childShapes.push_back(shape); 53 54 btCompoundShapeChild child; 55 child.m_node = 0; 54 56 child.m_transform = localTransform; 55 57 child.m_childShape = shape; … … 94 96 m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax); 95 97 ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 96 int index = m_children.size()-1;98 //int index = m_children.size()-1; 97 99 m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds); 98 100 } … … 110 112 } 111 113 m_children.swap(childShapeIndex,m_children.size()-1); 114 if (m_dynamicAabbTree) 115 m_children[childShapeIndex].m_node->dataAsInt = childShapeIndex; 112 116 m_children.pop_back(); 113 117 … … 125 129 if(m_children[i].m_childShape == shape) 126 130 { 127 m_children.swap(i,m_children.size()-1); 128 m_children.pop_back(); 129 //remove it from the m_dynamicAabbTree too 130 //@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm 131 //so effectively, removeChildShape is broken at the moment 132 //m_dynamicAabbTree->remove(m_aabbProxies[i]); 133 //m_aabbProxies.swap(i,m_children.size()-1); 134 //m_aabbProxies.pop_back(); 131 removeChildShapeByIndex(i); 135 132 } 136 133 } … … 146 143 // Brute force, it iterates over all the shapes left. 147 144 148 m_localAabbMin = btVector3(btScalar( 1e30),btScalar(1e30),btScalar(1e30));149 m_localAabbMax = btVector3(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));145 m_localAabbMin = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 146 m_localAabbMax = btVector3(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 150 147 151 148 //extend the local aabbMin/aabbMax … … 224 221 for (k = 0; k < n; k++) 225 222 { 223 btAssert(masses[k]>0); 226 224 center += m_children[k].m_transform.getOrigin() * masses[k]; 227 225 totalMass += masses[k]; 228 226 } 227 228 btAssert(totalMass>0); 229 229 230 center /= totalMass; 230 231 principal.setOrigin(center); … … 272 273 273 274 275 void btCompoundShape::setLocalScaling(const btVector3& scaling) 276 { 277 278 for(int i = 0; i < m_children.size(); i++) 279 { 280 btTransform childTrans = getChildTransform(i); 281 btVector3 childScale = m_children[i].m_childShape->getLocalScaling(); 282 // childScale = childScale * (childTrans.getBasis() * scaling); 283 childScale = childScale * scaling / m_localScaling; 284 m_children[i].m_childShape->setLocalScaling(childScale); 285 childTrans.setOrigin((childTrans.getOrigin())*scaling); 286 updateChildTransform(i, childTrans); 287 recalculateLocalAabb(); 288 } 289 m_localScaling = scaling; 290 } 291 292 293 void btCompoundShape::createAabbTreeFromChildren() 294 { 295 if ( !m_dynamicAabbTree ) 296 { 297 void* mem = btAlignedAlloc(sizeof(btDbvt),16); 298 m_dynamicAabbTree = new(mem) btDbvt(); 299 btAssert(mem==m_dynamicAabbTree); 300 301 for ( int index = 0; index < m_children.size(); index++ ) 302 { 303 btCompoundShapeChild &child = m_children[index]; 304 305 //extend the local aabbMin/aabbMax 306 btVector3 localAabbMin,localAabbMax; 307 child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax); 308 309 const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 310 child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); 311 } 312 } 313 } 314 315 316 ///fills the dataBuffer and returns the struct name (and 0 on failure) 317 const char* btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const 318 { 319 320 btCompoundShapeData* shapeData = (btCompoundShapeData*) dataBuffer; 321 btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer); 322 323 shapeData->m_collisionMargin = float(m_collisionMargin); 324 shapeData->m_numChildShapes = m_children.size(); 325 shapeData->m_childShapePtr = 0; 326 if (shapeData->m_numChildShapes) 327 { 328 btChunk* chunk = serializer->allocate(sizeof(btCompoundShapeChildData),shapeData->m_numChildShapes); 329 btCompoundShapeChildData* memPtr = (btCompoundShapeChildData*)chunk->m_oldPtr; 330 shapeData->m_childShapePtr = (btCompoundShapeChildData*)serializer->getUniquePointer(memPtr); 331 332 for (int i=0;i<shapeData->m_numChildShapes;i++,memPtr++) 333 { 334 memPtr->m_childMargin = float(m_children[i].m_childMargin); 335 memPtr->m_childShape = (btCollisionShapeData*)serializer->getUniquePointer(m_children[i].m_childShape); 336 //don't serialize shapes that already have been serialized 337 if (!serializer->findPointer(m_children[i].m_childShape)) 338 { 339 btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(),1); 340 const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr,serializer); 341 serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,m_children[i].m_childShape); 342 } 343 344 memPtr->m_childShapeType = m_children[i].m_childShapeType; 345 m_children[i].m_transform.serializeFloat(memPtr->m_transform); 346 } 347 serializer->finalizeChunk(chunk,"btCompoundShapeChildData",BT_ARRAY_CODE,chunk->m_oldPtr); 348 } 349 return "btCompoundShapeData"; 350 } 351 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 63 63 int m_updateRevision; 64 64 65 btScalar m_collisionMargin; 66 67 protected: 68 btVector3 m_localScaling; 69 65 70 public: 66 71 BT_DECLARE_ALIGNED_ALLOCATOR(); … … 117 122 virtual void recalculateLocalAabb(); 118 123 119 virtual void setLocalScaling(const btVector3& scaling) 120 { 121 m_localScaling = scaling; 122 } 124 virtual void setLocalScaling(const btVector3& scaling); 125 123 126 virtual const btVector3& getLocalScaling() const 124 127 { … … 141 144 } 142 145 143 //this is optional, but should make collision queries faster, by culling non-overlapping nodes144 void createAabbTreeFromChildren();145 146 146 147 btDbvt* getDynamicAabbTree() … … 148 149 return m_dynamicAabbTree; 149 150 } 151 152 void createAabbTreeFromChildren(); 150 153 151 154 ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia … … 161 164 } 162 165 163 private: 164 btScalar m_collisionMargin; 165 protected: 166 btVector3 m_localScaling; 167 168 }; 166 virtual int calculateSerializeBufferSize() const; 167 168 ///fills the dataBuffer and returns the struct name (and 0 on failure) 169 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 170 171 172 }; 173 174 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 175 struct btCompoundShapeChildData 176 { 177 btTransformFloatData m_transform; 178 btCollisionShapeData *m_childShape; 179 int m_childShapeType; 180 float m_childMargin; 181 }; 182 183 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 184 struct btCompoundShapeData 185 { 186 btCollisionShapeData m_collisionShapeData; 187 188 btCompoundShapeChildData *m_childShapePtr; 189 190 int m_numChildShapes; 191 192 float m_collisionMargin; 193 194 }; 195 196 197 SIMD_FORCE_INLINE int btCompoundShape::calculateSerializeBufferSize() const 198 { 199 return sizeof(btCompoundShapeData); 200 } 201 202 203 204 169 205 170 206 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.cpp
r5781 r7983 1 2 1 /* 3 2 Bullet Continuous Collision Detection and Physics Library 4 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 5 4 6 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btConvexHullShape.h" 16 17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" 17 18 18 19 #include "LinearMath/btQuaternion.h" 19 20 21 22 btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexShape () 20 #include "LinearMath/btSerializer.h" 21 22 btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexAabbCachingShape () 23 23 { 24 24 m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE; 25 25 m_unscaledPoints.resize(numPoints); 26 26 27 unsigned char* points BaseAddress = (unsigned char*)points;27 unsigned char* pointsAddress = (unsigned char*)points; 28 28 29 29 for (int i=0;i<numPoints;i++) 30 30 { 31 btVector3* point = (btVector3*)(pointsBaseAddress + i*stride); 32 m_unscaledPoints[i] = point[0]; 31 btScalar* point = (btScalar*)pointsAddress; 32 m_unscaledPoints[i] = btVector3(point[0], point[1], point[2]); 33 pointsAddress += stride; 33 34 } 34 35 … … 52 53 } 53 54 54 btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec 0)const55 btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const 55 56 { 56 57 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); 57 btScalar newDot,maxDot = btScalar(-1e30); 58 59 btVector3 vec = vec0; 60 btScalar lenSqr = vec.length2(); 61 if (lenSqr < btScalar(0.0001)) 62 { 63 vec.setValue(1,0,0); 64 } else 65 { 66 btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); 67 vec *= rlen; 68 } 69 58 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT); 70 59 71 60 for (int i=0;i<m_unscaledPoints.size();i++) … … 90 79 for (int i=0;i<numVectors;i++) 91 80 { 92 supportVerticesOut[i][3] = btScalar(- 1e30);81 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 93 82 } 94 83 } … … 186 175 } 187 176 177 ///fills the dataBuffer and returns the struct name (and 0 on failure) 178 const char* btConvexHullShape::serialize(void* dataBuffer, btSerializer* serializer) const 179 { 180 //int szc = sizeof(btConvexHullShapeData); 181 btConvexHullShapeData* shapeData = (btConvexHullShapeData*) dataBuffer; 182 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer); 183 184 int numElem = m_unscaledPoints.size(); 185 shapeData->m_numUnscaledPoints = numElem; 186 #ifdef BT_USE_DOUBLE_PRECISION 187 shapeData->m_unscaledPointsFloatPtr = 0; 188 shapeData->m_unscaledPointsDoublePtr = numElem ? (btVector3Data*)serializer->getUniquePointer((void*)&m_unscaledPoints[0]): 0; 189 #else 190 shapeData->m_unscaledPointsFloatPtr = numElem ? (btVector3Data*)serializer->getUniquePointer((void*)&m_unscaledPoints[0]): 0; 191 shapeData->m_unscaledPointsDoublePtr = 0; 192 #endif 193 194 if (numElem) 195 { 196 int sz = sizeof(btVector3Data); 197 // int sz2 = sizeof(btVector3DoubleData); 198 // int sz3 = sizeof(btVector3FloatData); 199 btChunk* chunk = serializer->allocate(sz,numElem); 200 btVector3Data* memPtr = (btVector3Data*)chunk->m_oldPtr; 201 for (int i=0;i<numElem;i++,memPtr++) 202 { 203 m_unscaledPoints[i].serialize(*memPtr); 204 } 205 serializer->finalizeChunk(chunk,btVector3DataName,BT_ARRAY_CODE,(void*)&m_unscaledPoints[0]); 206 } 207 208 return "btConvexHullShapeData"; 209 } 210 211 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 21 21 #include "LinearMath/btAlignedObjectArray.h" 22 22 23 23 24 ///The btConvexHullShape implements an implicit convex hull of an array of vertices. 24 25 ///Bullet provides a general and fast collision detector for convex shapes based on GJK and EPA using localGetSupportingVertex. 25 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvex Shape26 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexAabbCachingShape 26 27 { 27 28 btAlignedObjectArray<btVector3> m_unscaledPoints; … … 89 90 virtual void setLocalScaling(const btVector3& scaling); 90 91 92 virtual int calculateSerializeBufferSize() const; 93 94 ///fills the dataBuffer and returns the struct name (and 0 on failure) 95 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 96 91 97 }; 98 99 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 100 struct btConvexHullShapeData 101 { 102 btConvexInternalShapeData m_convexInternalShapeData; 103 104 btVector3FloatData *m_unscaledPointsFloatPtr; 105 btVector3DoubleData *m_unscaledPointsDoublePtr; 106 107 int m_numUnscaledPoints; 108 char m_padding3[4]; 109 110 }; 111 112 113 SIMD_FORCE_INLINE int btConvexHullShape::calculateSerializeBufferSize() const 114 { 115 return sizeof(btConvexHullShapeData); 116 } 92 117 93 118 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 35 35 void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const 36 36 { 37 37 #ifndef __SPU__ 38 //use localGetSupportingVertexWithoutMargin? 38 39 btScalar margin = getMargin(); 39 40 for (int i=0;i<3;i++) … … 50 51 minAabb[i] = tmp[i]-margin; 51 52 } 53 #endif 52 54 } 53 55 … … 80 82 81 83 84 btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape() 85 : btConvexInternalShape(), 86 m_localAabbMin(1,1,1), 87 m_localAabbMax(-1,-1,-1), 88 m_isLocalAabbValid(false) 89 { 90 } 91 92 93 void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 94 { 95 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 96 } 97 98 void btConvexInternalAabbCachingShape::setLocalScaling(const btVector3& scaling) 99 { 100 btConvexInternalShape::setLocalScaling(scaling); 101 recalcLocalAabb(); 102 } 103 104 105 void btConvexInternalAabbCachingShape::recalcLocalAabb() 106 { 107 m_isLocalAabbValid = true; 108 109 #if 1 110 static const btVector3 _directions[] = 111 { 112 btVector3( 1., 0., 0.), 113 btVector3( 0., 1., 0.), 114 btVector3( 0., 0., 1.), 115 btVector3( -1., 0., 0.), 116 btVector3( 0., -1., 0.), 117 btVector3( 0., 0., -1.) 118 }; 119 120 btVector3 _supporting[] = 121 { 122 btVector3( 0., 0., 0.), 123 btVector3( 0., 0., 0.), 124 btVector3( 0., 0., 0.), 125 btVector3( 0., 0., 0.), 126 btVector3( 0., 0., 0.), 127 btVector3( 0., 0., 0.) 128 }; 129 130 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6); 131 132 for ( int i = 0; i < 3; ++i ) 133 { 134 m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin; 135 m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin; 136 } 137 138 #else 139 140 for (int i=0;i<3;i++) 141 { 142 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); 143 vec[i] = btScalar(1.); 144 btVector3 tmp = localGetSupportingVertex(vec); 145 m_localAabbMax[i] = tmp[i]+m_collisionMargin; 146 vec[i] = btScalar(-1.); 147 tmp = localGetSupportingVertex(vec); 148 m_localAabbMin[i] = tmp[i]-m_collisionMargin; 149 } 150 #endif 151 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h
r5781 r7983 1 /* 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 5 This software is provided 'as-is', without any express or implied warranty. 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 subject to the following restrictions: 10 11 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. 12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 13 3. This notice may not be removed or altered from any source distribution. 14 */ 1 15 2 16 #ifndef BT_CONVEX_INTERNAL_SHAPE_H … … 4 18 5 19 #include "btConvexShape.h" 20 #include "LinearMath/btAabbUtil2.h" 21 6 22 7 23 ///The btConvexInternalShape is an internal base class, shared by most convex shape implementations. … … 36 52 { 37 53 return m_implicitShapeDimensions; 54 } 55 56 ///warning: use setImplicitShapeDimensions with care 57 ///changing a collision shape while the body is in the world is not recommended, 58 ///it is best to remove the body from the world, then make the change, and re-add it 59 ///alternatively flush the contact points, see documentation for 'cleanProxyFromPairs' 60 void setImplicitShapeDimensions(const btVector3& dimensions) 61 { 62 m_implicitShapeDimensions = dimensions; 38 63 } 39 64 … … 86 111 } 87 112 113 virtual int calculateSerializeBufferSize() const; 114 115 ///fills the dataBuffer and returns the struct name (and 0 on failure) 116 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 88 117 89 118 90 119 }; 91 120 121 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 122 struct btConvexInternalShapeData 123 { 124 btCollisionShapeData m_collisionShapeData; 125 126 btVector3FloatData m_localScaling; 127 128 btVector3FloatData m_implicitShapeDimensions; 129 130 float m_collisionMargin; 131 132 int m_padding; 133 134 }; 135 136 137 138 SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize() const 139 { 140 return sizeof(btConvexInternalShapeData); 141 } 142 143 ///fills the dataBuffer and returns the struct name (and 0 on failure) 144 SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer, btSerializer* serializer) const 145 { 146 btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer; 147 btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer); 148 149 m_implicitShapeDimensions.serializeFloat(shapeData->m_implicitShapeDimensions); 150 m_localScaling.serializeFloat(shapeData->m_localScaling); 151 shapeData->m_collisionMargin = float(m_collisionMargin); 152 153 return "btConvexInternalShapeData"; 154 } 155 156 157 158 159 ///btConvexInternalAabbCachingShape adds local aabb caching for convex shapes, to avoid expensive bounding box calculations 160 class btConvexInternalAabbCachingShape : public btConvexInternalShape 161 { 162 btVector3 m_localAabbMin; 163 btVector3 m_localAabbMax; 164 bool m_isLocalAabbValid; 165 166 protected: 167 168 btConvexInternalAabbCachingShape(); 169 170 void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax) 171 { 172 m_isLocalAabbValid = true; 173 m_localAabbMin = aabbMin; 174 m_localAabbMax = aabbMax; 175 } 176 177 inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const 178 { 179 btAssert(m_isLocalAabbValid); 180 aabbMin = m_localAabbMin; 181 aabbMax = m_localAabbMax; 182 } 183 184 inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const 185 { 186 187 //lazy evaluation of local aabb 188 btAssert(m_isLocalAabbValid); 189 btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax); 190 } 191 192 public: 193 194 virtual void setLocalScaling(const btVector3& scaling); 195 196 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 197 198 void recalcLocalAabb(); 199 200 }; 92 201 93 202 #endif //BT_CONVEX_INTERNAL_SHAPE_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btConvexPointCloudShape.h" 16 17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" … … 28 29 { 29 30 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); 30 btScalar newDot,maxDot = btScalar(- 1e30);31 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT); 31 32 32 33 btVector3 vec = vec0; … … 63 64 for (int i=0;i<numVectors;i++) 64 65 { 65 supportVerticesOut[i][3] = btScalar(- 1e30);66 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 66 67 } 67 68 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 22 22 23 23 ///The btConvexPointCloudShape implements an implicit convex hull of an array of vertices. 24 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvex Shape24 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexAabbCachingShape 25 25 { 26 26 btVector3* m_unscaledPoints; … … 29 29 public: 30 30 BT_DECLARE_ALIGNED_ALLOCATOR(); 31 32 btConvexPointCloudShape() 33 { 34 m_localScaling.setValue(1.f,1.f,1.f); 35 m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE; 36 m_unscaledPoints = 0; 37 m_numPoints = 0; 38 } 31 39 32 40 btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true) … … 41 49 } 42 50 43 void setPoints (btVector3* points, int numPoints, bool computeAabb = true )51 void setPoints (btVector3* points, int numPoints, bool computeAabb = true,const btVector3& localScaling=btVector3(1.f,1.f,1.f)) 44 52 { 45 53 m_unscaledPoints = points; 46 54 m_numPoints = numPoints; 55 m_localScaling = localScaling; 47 56 48 57 if (computeAabb) -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 22 22 #include "btConvexPointCloudShape.h" 23 23 24 ///not supported on IBM SDK, until we fix the alignment of btVector3 25 #if defined (__CELLOS_LV2__) && defined (__SPU__) 26 #include <spu_intrinsics.h> 27 static inline vec_float4 vec_dot3( vec_float4 vec0, vec_float4 vec1 ) 28 { 29 vec_float4 result; 30 result = spu_mul( vec0, vec1 ); 31 result = spu_madd( spu_rlqwbyte( vec0, 4 ), spu_rlqwbyte( vec1, 4 ), result ); 32 return spu_madd( spu_rlqwbyte( vec0, 8 ), spu_rlqwbyte( vec1, 8 ), result ); 33 } 34 #endif //__SPU__ 35 24 36 btConvexShape::btConvexShape () 25 37 { … … 33 45 34 46 35 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling) 36 { 37 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); 38 btScalar newDot,maxDot = btScalar(-1e30); 39 40 btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ()); 41 btVector3 vec = vec0; 42 btScalar lenSqr = vec.length2(); 43 if (lenSqr < btScalar(0.0001)) 44 { 45 vec.setValue(1,0,0); 46 } else { 47 btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); 48 vec *= rlen; 49 } 50 47 static btVector3 convexHullSupport (const btVector3& localDirOrg, const btVector3* points, int numPoints, const btVector3& localScaling) 48 { 49 50 btVector3 vec = localDirOrg * localScaling; 51 52 #if defined (__CELLOS_LV2__) && defined (__SPU__) 53 54 btVector3 localDir = vec; 55 56 vec_float4 v_distMax = {-FLT_MAX,0,0,0}; 57 vec_int4 v_idxMax = {-999,0,0,0}; 58 int v=0; 59 int numverts = numPoints; 60 61 for(;v<(int)numverts-4;v+=4) { 62 vec_float4 p0 = vec_dot3(points[v ].get128(),localDir.get128()); 63 vec_float4 p1 = vec_dot3(points[v+1].get128(),localDir.get128()); 64 vec_float4 p2 = vec_dot3(points[v+2].get128(),localDir.get128()); 65 vec_float4 p3 = vec_dot3(points[v+3].get128(),localDir.get128()); 66 const vec_int4 i0 = {v ,0,0,0}; 67 const vec_int4 i1 = {v+1,0,0,0}; 68 const vec_int4 i2 = {v+2,0,0,0}; 69 const vec_int4 i3 = {v+3,0,0,0}; 70 vec_uint4 retGt01 = spu_cmpgt(p0,p1); 71 vec_float4 pmax01 = spu_sel(p1,p0,retGt01); 72 vec_int4 imax01 = spu_sel(i1,i0,retGt01); 73 vec_uint4 retGt23 = spu_cmpgt(p2,p3); 74 vec_float4 pmax23 = spu_sel(p3,p2,retGt23); 75 vec_int4 imax23 = spu_sel(i3,i2,retGt23); 76 vec_uint4 retGt0123 = spu_cmpgt(pmax01,pmax23); 77 vec_float4 pmax0123 = spu_sel(pmax23,pmax01,retGt0123); 78 vec_int4 imax0123 = spu_sel(imax23,imax01,retGt0123); 79 vec_uint4 retGtMax = spu_cmpgt(v_distMax,pmax0123); 80 v_distMax = spu_sel(pmax0123,v_distMax,retGtMax); 81 v_idxMax = spu_sel(imax0123,v_idxMax,retGtMax); 82 } 83 for(;v<(int)numverts;v++) { 84 vec_float4 p = vec_dot3(points[v].get128(),localDir.get128()); 85 const vec_int4 i = {v,0,0,0}; 86 vec_uint4 retGtMax = spu_cmpgt(v_distMax,p); 87 v_distMax = spu_sel(p,v_distMax,retGtMax); 88 v_idxMax = spu_sel(i,v_idxMax,retGtMax); 89 } 90 int ptIndex = spu_extract(v_idxMax,0); 91 const btVector3& supVec= points[ptIndex] * localScaling; 92 return supVec; 93 #else 94 95 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT); 96 int ptIndex = -1; 51 97 52 98 for (int i=0;i<numPoints;i++) 53 99 { 54 btVector3 vtx = points[i] * localScaling; 55 56 newDot = vec.dot(vtx); 100 101 newDot = vec.dot(points[i]); 57 102 if (newDot > maxDot) 58 103 { 59 104 maxDot = newDot; 60 supVec = vtx; 61 } 62 } 63 return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()); 105 ptIndex = i; 106 } 107 } 108 btAssert(ptIndex >= 0); 109 btVector3 supVec = points[ptIndex] * localScaling; 110 return supVec; 111 #endif //__SPU__ 64 112 } 65 113 … … 161 209 btVector3 supVec(0,0,0); 162 210 163 btScalar maxDot(btScalar(- 1e30));211 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 164 212 165 213 btVector3 vec = vec0; … … 293 341 return btScalar(0.0f); 294 342 } 295 343 #ifndef __SPU__ 296 344 void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const 297 345 { … … 361 409 case CONVEX_HULL_SHAPE_PROXYTYPE: 362 410 { 363 btPolyhedralConvex Shape* convexHullShape = (btPolyhedralConvexShape*)this;411 btPolyhedralConvexAabbCachingShape* convexHullShape = (btPolyhedralConvexAabbCachingShape*)this; 364 412 btScalar margin = convexHullShape->getMarginNonVirtual(); 365 413 convexHullShape->getNonvirtualAabb (t, aabbMin, aabbMax, margin); … … 378 426 btAssert (0); 379 427 } 428 429 #endif //__SPU__ -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btConvexTriangleMeshShape.h" 16 17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" … … 21 22 22 23 btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface, bool calcAabb) 23 : btPolyhedralConvex Shape(), m_stridingMesh(meshInterface)24 : btPolyhedralConvexAabbCachingShape(), m_stridingMesh(meshInterface) 24 25 { 25 26 m_shapeType = CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE; … … 44 45 LocalSupportVertexCallback(const btVector3& supportVecLocal) 45 46 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), 46 m_maxDot(btScalar(- 1e30)),47 m_maxDot(btScalar(-BT_LARGE_FLOAT)), 47 48 m_supportVecLocal(supportVecLocal) 48 49 { … … 92 93 93 94 LocalSupportVertexCallback supportCallback(vec); 94 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));95 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 95 96 m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax); 96 97 supVec = supportCallback.GetSupportVertexLocal(); … … 105 106 for (int i=0;i<numVectors;i++) 106 107 { 107 supportVerticesOut[i][3] = btScalar(- 1e30);108 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 108 109 } 109 110 } … … 116 117 const btVector3& vec = vectors[j]; 117 118 LocalSupportVertexCallback supportCallback(vec); 118 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));119 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 119 120 m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax); 120 121 supportVerticesOut[j] = supportCallback.GetSupportVertexLocal(); … … 298 299 299 300 CenterCallback centerCallback; 300 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));301 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 301 302 m_stridingMesh->InternalProcessAllTriangles(¢erCallback, -aabbMax, aabbMax); 302 303 btVector3 center = centerCallback.getCenter(); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
r5781 r7983 1 /* 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 5 This software is provided 'as-is', without any express or implied warranty. 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 subject to the following restrictions: 10 11 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. 12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 13 3. This notice may not be removed or altered from any source distribution. 14 */ 1 15 #ifndef CONVEX_TRIANGLEMESH_SHAPE_H 2 16 #define CONVEX_TRIANGLEMESH_SHAPE_H … … 9 23 /// The btConvexTriangleMeshShape is a convex hull of a triangle mesh, but the performance is not as good as btConvexHullShape. 10 24 /// A small benefit of this class is that it uses the btStridingMeshInterface, so you can avoid the duplication of the triangle mesh data. Nevertheless, most users should use the much better performing btConvexHullShape instead. 11 class btConvexTriangleMeshShape : public btPolyhedralConvex Shape25 class btConvexTriangleMeshShape : public btPolyhedralConvexAabbCachingShape 12 26 { 13 27 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btCylinderShape.h" 16 17 17 18 btCylinderShape::btCylinderShape (const btVector3& halfExtents) 18 :bt BoxShape(halfExtents),19 :btConvexInternalShape(), 19 20 m_upAxis(1) 20 21 { 22 btVector3 margin(getMargin(),getMargin(),getMargin()); 23 m_implicitShapeDimensions = (halfExtents * m_localScaling) - margin; 21 24 m_shapeType = CYLINDER_SHAPE_PROXYTYPE; 22 recalcLocalAabb();23 25 } 24 26 … … 28 30 { 29 31 m_upAxis = 0; 30 recalcLocalAabb(); 32 31 33 } 32 34 … … 36 38 { 37 39 m_upAxis = 2; 38 recalcLocalAabb(); 40 39 41 } 40 42 41 43 void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const 42 44 { 43 //skip the box 'getAabb' 44 btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax); 45 btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax); 46 } 47 48 void btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const 49 { 50 //approximation of box shape, todo: implement cylinder shape inertia before people notice ;-) 51 btVector3 halfExtents = getHalfExtentsWithMargin(); 52 53 btScalar lx=btScalar(2.)*(halfExtents.x()); 54 btScalar ly=btScalar(2.)*(halfExtents.y()); 55 btScalar lz=btScalar(2.)*(halfExtents.z()); 56 57 inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz), 58 mass/(btScalar(12.0)) * (lx*lx + lz*lz), 59 mass/(btScalar(12.0)) * (lx*lx + ly*ly)); 60 45 61 } 46 62 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 22 22 23 23 /// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis. 24 class btCylinderShape : public bt BoxShape24 class btCylinderShape : public btConvexInternalShape 25 25 26 26 { … … 31 31 32 32 public: 33 34 btVector3 getHalfExtentsWithMargin() const 35 { 36 btVector3 halfExtents = getHalfExtentsWithoutMargin(); 37 btVector3 margin(getMargin(),getMargin(),getMargin()); 38 halfExtents += margin; 39 return halfExtents; 40 } 41 42 const btVector3& getHalfExtentsWithoutMargin() const 43 { 44 return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included 45 } 46 33 47 btCylinderShape (const btVector3& halfExtents); 34 48 35 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version36 49 void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 37 50 51 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 52 38 53 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; 39 54 40 55 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 56 57 virtual void setMargin(btScalar collisionMargin) 58 { 59 //correct the m_implicitShapeDimensions for the margin 60 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 61 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 62 63 btConvexInternalShape::setMargin(collisionMargin); 64 btVector3 newMargin(getMargin(),getMargin(),getMargin()); 65 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; 66 67 } 41 68 42 69 virtual btVector3 localGetSupportingVertex(const btVector3& vec) const … … 74 101 } 75 102 103 virtual void setLocalScaling(const btVector3& scaling) 104 { 105 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 106 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 107 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling; 108 109 btConvexInternalShape::setLocalScaling(scaling); 110 111 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin; 112 113 } 114 76 115 //debugging 77 116 virtual const char* getName()const … … 80 119 } 81 120 82 121 virtual int calculateSerializeBufferSize() const; 122 123 ///fills the dataBuffer and returns the struct name (and 0 on failure) 124 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 83 125 84 126 }; … … 113 155 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 114 156 115 virtual int getUpAxis() const116 {117 return 2;118 }119 157 //debugging 120 158 virtual const char* getName()const … … 130 168 }; 131 169 170 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 171 struct btCylinderShapeData 172 { 173 btConvexInternalShapeData m_convexInternalShapeData; 174 175 int m_upAxis; 176 177 char m_padding[4]; 178 }; 179 180 SIMD_FORCE_INLINE int btCylinderShape::calculateSerializeBufferSize() const 181 { 182 return sizeof(btCylinderShapeData); 183 } 184 185 ///fills the dataBuffer and returns the struct name (and 0 on failure) 186 SIMD_FORCE_INLINE const char* btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const 187 { 188 btCylinderShapeData* shapeData = (btCylinderShapeData*) dataBuffer; 189 190 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer); 191 192 shapeData->m_upAxis = m_upAxis; 193 194 return "btCylinderShapeData"; 195 } 196 197 132 198 133 199 #endif //CYLINDER_MINKOWSKI_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMaterial.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 33 33 34 34 #endif // MATERIAL_H 35 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "btMinkowskiSumShape.h" -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 14 14 */ 15 15 16 17 16 18 #include "btMultiSphereShape.h" 17 19 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" 18 20 #include "LinearMath/btQuaternion.h" 21 #include "LinearMath/btSerializer.h" 19 22 20 btMultiSphereShape::btMultiSphereShape (const btVector3 & inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres)21 :btConvexInternal Shape (), m_inertiaHalfExtents(inertiaHalfExtents)23 btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres) 24 :btConvexInternalAabbCachingShape () 22 25 { 23 26 m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE; 24 btScalar startMargin = btScalar(1e30);27 //btScalar startMargin = btScalar(BT_LARGE_FLOAT); 25 28 26 m_numSpheres = numSpheres; 27 for (int i=0;i<m_numSpheres;i++) 29 m_localPositionArray.resize(numSpheres); 30 m_radiArray.resize(numSpheres); 31 for (int i=0;i<numSpheres;i++) 28 32 { 29 m_localPositions[i] = positions[i]; 30 m_radi[i] = radi[i]; 31 if (radi[i] < startMargin) 32 startMargin = radi[i]; 33 m_localPositionArray[i] = positions[i]; 34 m_radiArray[i] = radi[i]; 35 33 36 } 34 setMargin(startMargin); 37 38 recalcLocalAabb(); 35 39 36 40 } 37 38 39 41 40 42 … … 44 46 btVector3 supVec(0,0,0); 45 47 46 btScalar maxDot(btScalar(- 1e30));48 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 47 49 48 50 … … 61 63 btScalar newDot; 62 64 63 const btVector3* pos = &m_localPositions[0]; 64 const btScalar* rad = &m_radi[0]; 65 const btVector3* pos = &m_localPositionArray[0]; 66 const btScalar* rad = &m_radiArray[0]; 67 int numSpheres = m_localPositionArray.size(); 65 68 66 for (i=0;i< m_numSpheres;i++)69 for (i=0;i<numSpheres;i++) 67 70 { 68 71 vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin(); … … 86 89 for (int j=0;j<numVectors;j++) 87 90 { 88 btScalar maxDot(btScalar(- 1e30));91 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 89 92 90 93 const btVector3& vec = vectors[j]; … … 93 96 btScalar newDot; 94 97 95 const btVector3* pos = &m_localPosition s[0];96 const btScalar* rad = &m_radi [0];97 98 for (int i=0;i< m_numSpheres;i++)98 const btVector3* pos = &m_localPositionArray[0]; 99 const btScalar* rad = &m_radiArray[0]; 100 int numSpheres = m_localPositionArray.size(); 101 for (int i=0;i<numSpheres;i++) 99 102 { 100 103 vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin(); … … 122 125 //as an approximation, take the inertia of the box that bounds the spheres 123 126 124 bt Transform ident;125 ident.setIdentity();126 // btVector3 aabbMin,aabbMax;127 btVector3 localAabbMin,localAabbMax; 128 getCachedLocalAabb(localAabbMin,localAabbMax); 129 btVector3 halfExtents = (localAabbMax-localAabbMin)*btScalar(0.5); 127 130 128 // getAabb(ident,aabbMin,aabbMax); 131 btScalar lx=btScalar(2.)*(halfExtents.x()); 132 btScalar ly=btScalar(2.)*(halfExtents.y()); 133 btScalar lz=btScalar(2.)*(halfExtents.z()); 129 134 130 btVector3 halfExtents = m_inertiaHalfExtents;//(aabbMax - aabbMin)* btScalar(0.5); 131 132 btScalar margin = CONVEX_DISTANCE_MARGIN; 133 134 btScalar lx=btScalar(2.)*(halfExtents[0]+margin); 135 btScalar ly=btScalar(2.)*(halfExtents[1]+margin); 136 btScalar lz=btScalar(2.)*(halfExtents[2]+margin); 137 const btScalar x2 = lx*lx; 138 const btScalar y2 = ly*ly; 139 const btScalar z2 = lz*lz; 140 const btScalar scaledmass = mass * btScalar(.08333333); 141 142 inertia[0] = scaledmass * (y2+z2); 143 inertia[1] = scaledmass * (x2+z2); 144 inertia[2] = scaledmass * (x2+y2); 135 inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz), 136 mass/(btScalar(12.0)) * (lx*lx + lz*lz), 137 mass/(btScalar(12.0)) * (lx*lx + ly*ly)); 145 138 146 139 } 147 140 148 141 142 ///fills the dataBuffer and returns the struct name (and 0 on failure) 143 const char* btMultiSphereShape::serialize(void* dataBuffer, btSerializer* serializer) const 144 { 145 btMultiSphereShapeData* shapeData = (btMultiSphereShapeData*) dataBuffer; 146 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer); 149 147 148 int numElem = m_localPositionArray.size(); 149 shapeData->m_localPositionArrayPtr = numElem ? (btPositionAndRadius*)serializer->getUniquePointer((void*)&m_localPositionArray[0]): 0; 150 151 shapeData->m_localPositionArraySize = numElem; 152 if (numElem) 153 { 154 btChunk* chunk = serializer->allocate(sizeof(btPositionAndRadius),numElem); 155 btPositionAndRadius* memPtr = (btPositionAndRadius*)chunk->m_oldPtr; 156 for (int i=0;i<numElem;i++,memPtr++) 157 { 158 m_localPositionArray[i].serializeFloat(memPtr->m_pos); 159 memPtr->m_radius = float(m_radiArray[i]); 160 } 161 serializer->finalizeChunk(chunk,"btPositionAndRadius",BT_ARRAY_CODE,(void*)&m_localPositionArray[0]); 162 } 163 164 return "btMultiSphereShapeData"; 165 } 166 167 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 19 19 #include "btConvexInternalShape.h" 20 20 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types 21 22 #define MAX_NUM_SPHERES 5 23 24 ///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes. 25 ///It is possible to animate the spheres for deformation. 26 class btMultiSphereShape : public btConvexInternalShape 27 28 { 29 30 btVector3 m_localPositions[MAX_NUM_SPHERES]; 31 btScalar m_radi[MAX_NUM_SPHERES]; 32 btVector3 m_inertiaHalfExtents; 33 34 int m_numSpheres; 35 21 #include "LinearMath/btAlignedObjectArray.h" 22 #include "LinearMath/btAabbUtil2.h" 36 23 37 24 38 25 26 ///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes. 27 ///It is possible to animate the spheres for deformation, but call 'recalcLocalAabb' after changing any sphere position/radius 28 class btMultiSphereShape : public btConvexInternalAabbCachingShape 29 { 30 31 btAlignedObjectArray<btVector3> m_localPositionArray; 32 btAlignedObjectArray<btScalar> m_radiArray; 33 39 34 public: 40 btMultiSphereShape (const btVector3 & inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres);35 btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres); 41 36 42 37 ///CollisionShape Interface … … 50 45 int getSphereCount() const 51 46 { 52 return m_ numSpheres;47 return m_localPositionArray.size(); 53 48 } 54 49 55 50 const btVector3& getSpherePosition(int index) const 56 51 { 57 return m_localPosition s[index];52 return m_localPositionArray[index]; 58 53 } 59 54 60 55 btScalar getSphereRadius(int index) const 61 56 { 62 return m_radi [index];57 return m_radiArray[index]; 63 58 } 64 59 … … 69 64 } 70 65 66 virtual int calculateSerializeBufferSize() const; 67 68 ///fills the dataBuffer and returns the struct name (and 0 on failure) 69 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 70 71 71 72 }; 72 73 73 74 75 struct btPositionAndRadius 76 { 77 btVector3FloatData m_pos; 78 float m_radius; 79 }; 80 81 struct btMultiSphereShapeData 82 { 83 btConvexInternalShapeData m_convexInternalShapeData; 84 85 btPositionAndRadius *m_localPositionArrayPtr; 86 int m_localPositionArraySize; 87 char m_padding[4]; 88 }; 89 90 91 92 SIMD_FORCE_INLINE int btMultiSphereShape::calculateSerializeBufferSize() const 93 { 94 return sizeof(btMultiSphereShapeData); 95 } 96 97 98 74 99 #endif //MULTI_SPHERE_MINKOWSKI_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 38 38 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 39 39 40 btVector3 m_triangle[3];41 40 const unsigned char *vertexbase; 42 41 int numverts; … … 72 71 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 73 72 74 btVector3 m_triangle[3];75 73 const unsigned char *vertexbase; 76 74 int numverts; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 14 14 */ 15 15 16 16 17 #include "btOptimizedBvh.h" 17 18 #include "btStridingMeshInterface.h" … … 56 57 btOptimizedBvhNode node; 57 58 btVector3 aabbMin,aabbMax; 58 aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));59 aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));59 aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 60 aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 60 61 aabbMin.setMin(triangle[0]); 61 62 aabbMax.setMax(triangle[0]); … … 104 105 btQuantizedBvhNode node; 105 106 btVector3 aabbMin,aabbMax; 106 aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));107 aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));107 aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 108 aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 108 109 aabbMin.setMin(triangle[0]); 109 110 aabbMax.setMax(triangle[0]); … … 168 169 NodeTriangleCallback callback(m_leafNodes); 169 170 170 btVector3 aabbMin(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));171 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));171 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 172 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 172 173 173 174 triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax); … … 337 338 338 339 339 aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));340 aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));340 aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 341 aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 341 342 aabbMin.setMin(triangleVerts[0]); 342 343 aabbMax.setMax(triangleVerts[0]); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 ///Contains contributions from Disney Studio's 15 17 16 18 #ifndef OPTIMIZED_BVH_H … … 46 48 47 49 /// Data buffer MUST be 16 byte aligned 48 virtual bool serialize (void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian)50 virtual bool serializeInPlace(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const 49 51 { 50 52 return btQuantizedBvh::serialize(o_alignedDataBuffer,i_dataBufferSize,i_swapEndian); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 16 16 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 17 17 18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(), 19 m_localAabbMin(1,1,1), 20 m_localAabbMax(-1,-1,-1), 21 m_isLocalAabbValid(false), 22 m_optionalHull(0) 18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape() 23 19 { 24 20 … … 28 24 btVector3 btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const 29 25 { 26 27 28 btVector3 supVec(0,0,0); 29 #ifndef __SPU__ 30 30 int i; 31 btVector3 supVec(0,0,0); 32 33 btScalar maxDot(btScalar(-1e30)); 31 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 34 32 35 33 btVector3 vec = vec0; … … 58 56 } 59 57 58 59 #endif //__SPU__ 60 60 return supVec; 61 } 61 62 62 } 63 63 64 64 65 void btPolyhedralConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const 65 66 { 67 #ifndef __SPU__ 66 68 int i; 67 69 … … 71 73 for (i=0;i<numVectors;i++) 72 74 { 73 supportVerticesOut[i][3] = btScalar(- 1e30);75 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 74 76 } 75 77 … … 91 93 } 92 94 } 95 #endif //__SPU__ 93 96 } 94 97 … … 97 100 void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const 98 101 { 102 #ifndef __SPU__ 99 103 //not yet, return box inertia 100 104 … … 116 120 117 121 inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2)); 118 122 #endif //__SPU__ 119 123 } 120 124 121 125 122 126 123 void btPolyhedralConvexShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 124 { 125 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 126 } 127 128 129 130 void btPolyhedralConvexShape::setLocalScaling(const btVector3& scaling) 127 void btPolyhedralConvexAabbCachingShape::setLocalScaling(const btVector3& scaling) 131 128 { 132 129 btConvexInternalShape::setLocalScaling(scaling); … … 134 131 } 135 132 136 void btPolyhedralConvexShape::recalcLocalAabb() 133 btPolyhedralConvexAabbCachingShape::btPolyhedralConvexAabbCachingShape() 134 :btPolyhedralConvexShape(), 135 m_localAabbMin(1,1,1), 136 m_localAabbMax(-1,-1,-1), 137 m_isLocalAabbValid(false) 138 { 139 } 140 141 void btPolyhedralConvexAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 142 { 143 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 144 } 145 146 void btPolyhedralConvexAabbCachingShape::recalcLocalAabb() 137 147 { 138 148 m_isLocalAabbValid = true; … … 182 192 } 183 193 184 185 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 18 18 19 19 #include "LinearMath/btMatrix3x3.h" 20 #include "LinearMath/btAabbUtil2.h"21 20 #include "btConvexInternalShape.h" 22 21 … … 27 26 28 27 protected: 29 btVector3 m_localAabbMin; 30 btVector3 m_localAabbMax; 31 bool m_isLocalAabbValid; 32 28 33 29 public: 34 30 … … 39 35 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; 40 36 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 41 42 37 43 38 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 39 40 41 virtual int getNumVertices() const = 0 ; 42 virtual int getNumEdges() const = 0; 43 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0; 44 virtual void getVertex(int i,btVector3& vtx) const = 0; 45 virtual int getNumPlanes() const = 0; 46 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0; 47 // virtual int getIndex(int i) const = 0 ; 44 48 49 virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0; 50 51 }; 52 53 54 ///The btPolyhedralConvexAabbCachingShape adds aabb caching to the btPolyhedralConvexShape 55 class btPolyhedralConvexAabbCachingShape : public btPolyhedralConvexShape 56 { 57 58 btVector3 m_localAabbMin; 59 btVector3 m_localAabbMax; 60 bool m_isLocalAabbValid; 61 62 protected: 45 63 46 64 void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax) … … 58 76 } 59 77 78 public: 79 80 btPolyhedralConvexAabbCachingShape(); 81 60 82 inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const 61 83 { … … 66 88 } 67 89 68 90 virtual void setLocalScaling(const btVector3& scaling); 91 69 92 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 70 93 71 virtual void setLocalScaling(const btVector3& scaling);72 73 94 void recalcLocalAabb(); 74 75 virtual int getNumVertices() const = 0 ;76 virtual int getNumEdges() const = 0;77 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0;78 virtual void getVertex(int i,btVector3& vtx) const = 0;79 virtual int getNumPlanes() const = 0;80 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0;81 // virtual int getIndex(int i) const = 0 ;82 83 virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0;84 85 /// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp86 class Hull* m_optionalHull;87 95 88 96 }; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "btScaledBvhTriangleMeshShape.h" -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.cpp
r5781 r7983 1 1 /* 2 btbtShapeHull implemented by John McCutchan.3 4 2 Bullet Continuous Collision Detection and Physics Library 5 Copyright (c) 2003-200 8 Erwin Coumans http://bulletphysics.com3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 6 4 7 5 This software is provided 'as-is', without any express or implied warranty. 8 6 In no event will the authors be held liable for any damages arising from the use of this software. 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 11 9 subject to the following restrictions: 12 10 … … 16 14 */ 17 15 16 //btShapeHull was implemented by John McCutchan. 17 18 18 19 #include "btShapeHull.h" 19 20 #include "LinearMath/btConvexHull.h" 20 21 21 22 #define NUM_UNITSPHERE_POINTS 42 22 23 static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =24 {25 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),26 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),27 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),28 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),29 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),30 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),31 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),32 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),33 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),34 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),35 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),36 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),37 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),38 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),39 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),40 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),41 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),42 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),43 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),44 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),45 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),46 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),47 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),48 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),49 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),50 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),51 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),52 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),53 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),54 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),55 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),56 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),57 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),58 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),59 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),60 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),61 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),62 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),63 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),64 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),65 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),66 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))67 };68 23 69 24 btShapeHull::btShapeHull (const btConvexShape* shape) … … 93 48 btVector3 norm; 94 49 m_shape->getPreferredPenetrationDirection(i,norm); 95 btUnitSpherePoints[numSampleDirections] = norm;50 getUnitSpherePoints()[numSampleDirections] = norm; 96 51 numSampleDirections++; 97 52 } … … 103 58 for (i = 0; i < numSampleDirections; i++) 104 59 { 105 supportPoints[i] = m_shape->localGetSupportingVertex( btUnitSpherePoints[i]);60 supportPoints[i] = m_shape->localGetSupportingVertex(getUnitSpherePoints()[i]); 106 61 } 107 62 … … 163 118 } 164 119 120 121 btVector3* btShapeHull::getUnitSpherePoints() 122 { 123 static btVector3 sUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = 124 { 125 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)), 126 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)), 127 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)), 128 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)), 129 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)), 130 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)), 131 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)), 132 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)), 133 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)), 134 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)), 135 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)), 136 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)), 137 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)), 138 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)), 139 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)), 140 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)), 141 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)), 142 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)), 143 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)), 144 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)), 145 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)), 146 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)), 147 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)), 148 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)), 149 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)), 150 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)), 151 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)), 152 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)), 153 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)), 154 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)), 155 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)), 156 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)), 157 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)), 158 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)), 159 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)), 160 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)), 161 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)), 162 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)), 163 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)), 164 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)), 165 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)), 166 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654)) 167 }; 168 return sUnitSpherePoints; 169 } 170 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.h
r5781 r7983 1 1 /* 2 btShapeHull implemented by John McCutchan.3 4 2 Bullet Continuous Collision Detection and Physics Library 5 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 6 4 7 5 This software is provided 'as-is', without any express or implied warranty. 8 6 In no event will the authors be held liable for any damages arising from the use of this software. 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 11 9 subject to the following restrictions: 12 10 … … 15 13 3. This notice may not be removed or altered from any source distribution. 16 14 */ 15 16 ///btShapeHull implemented by John McCutchan. 17 17 18 18 #ifndef _SHAPE_HULL_H … … 28 28 class btShapeHull 29 29 { 30 protected: 31 32 btAlignedObjectArray<btVector3> m_vertices; 33 btAlignedObjectArray<unsigned int> m_indices; 34 unsigned int m_numIndices; 35 const btConvexShape* m_shape; 36 37 static btVector3* getUnitSpherePoints(); 38 30 39 public: 31 40 btShapeHull (const btConvexShape* shape); … … 46 55 return &m_indices[0]; 47 56 } 48 49 protected:50 btAlignedObjectArray<btVector3> m_vertices;51 btAlignedObjectArray<unsigned int> m_indices;52 unsigned int m_numIndices;53 const btConvexShape* m_shape;54 57 }; 55 58 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 #ifndef SPHERE_MINKOWSKI_H 17 16 #define SPHERE_MINKOWSKI_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 39 39 (void)t; 40 40 /* 41 btVector3 infvec (btScalar( 1e30),btScalar(1e30),btScalar(1e30));41 btVector3 infvec (btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 42 42 43 43 btVector3 center = m_planeNormal*m_planeConstant; … … 48 48 */ 49 49 50 aabbMin.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));51 aabbMax.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));50 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 51 aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 52 52 53 53 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 21 21 22 22 ///The btStaticPlaneShape simulates an infinite non-moving (static) collision plane. 23 classbtStaticPlaneShape : public btConcaveShape23 ATTRIBUTE_ALIGNED16(class) btStaticPlaneShape : public btConcaveShape 24 24 { 25 25 protected: … … 59 59 virtual const char* getName()const {return "STATICPLANE";} 60 60 61 virtual int calculateSerializeBufferSize() const; 62 63 ///fills the dataBuffer and returns the struct name (and 0 on failure) 64 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 65 61 66 62 67 }; 63 68 69 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 70 struct btStaticPlaneShapeData 71 { 72 btCollisionShapeData m_collisionShapeData; 73 74 btVector3FloatData m_localScaling; 75 btVector3FloatData m_planeNormal; 76 float m_planeConstant; 77 char m_pad[4]; 78 }; 79 80 81 SIMD_FORCE_INLINE int btStaticPlaneShape::calculateSerializeBufferSize() const 82 { 83 return sizeof(btStaticPlaneShapeData); 84 } 85 86 ///fills the dataBuffer and returns the struct name (and 0 on failure) 87 SIMD_FORCE_INLINE const char* btStaticPlaneShape::serialize(void* dataBuffer, btSerializer* serializer) const 88 { 89 btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*) dataBuffer; 90 btCollisionShape::serialize(&planeData->m_collisionShapeData,serializer); 91 92 m_localScaling.serializeFloat(planeData->m_localScaling); 93 m_planeNormal.serializeFloat(planeData->m_planeNormal); 94 planeData->m_planeConstant = float(m_planeConstant); 95 96 return "btStaticPlaneShapeData"; 97 } 98 99 64 100 #endif //STATIC_PLANE_SHAPE_H 101 102 103 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 15 15 16 16 #include "btStridingMeshInterface.h" 17 #include "LinearMath/btSerializer.h" 17 18 18 19 btStridingMeshInterface::~btStridingMeshInterface() … … 36 37 int gfxindex; 37 38 btVector3 triangle[3]; 38 btScalar* graphicsbase;39 39 40 40 btVector3 meshScaling = getScaling(); … … 46 46 numtotalphysicsverts+=numtriangles*3; //upper bound 47 47 48 switch (gfxindextype) 48 ///unlike that developers want to pass in double-precision meshes in single-precision Bullet build 49 ///so disable this feature by default 50 ///see patch http://code.google.com/p/bullet/issues/detail?id=213 51 52 switch (type) 49 53 { 50 case PHY_INTEGER: 54 case PHY_FLOAT: 55 { 56 57 float* graphicsbase; 58 59 switch (gfxindextype) 60 { 61 case PHY_INTEGER: 62 { 63 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 64 { 65 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 66 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride); 67 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 68 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride); 69 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 70 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride); 71 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 72 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 73 } 74 break; 75 } 76 case PHY_SHORT: 77 { 78 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 79 { 80 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 81 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride); 82 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 83 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride); 84 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 85 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride); 86 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 87 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 88 } 89 break; 90 } 91 default: 92 btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT)); 93 } 94 break; 95 } 96 97 case PHY_DOUBLE: 51 98 { 52 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 53 { 54 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 55 graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); 56 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 57 graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); 58 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 59 graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride); 60 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 61 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 62 } 63 break; 64 } 65 case PHY_SHORT: 66 { 67 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 68 { 69 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 70 graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); 71 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 72 graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); 73 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 74 graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride); 75 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 76 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 99 double* graphicsbase; 100 101 switch (gfxindextype) 102 { 103 case PHY_INTEGER: 104 { 105 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 106 { 107 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 108 graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); 109 triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); 110 graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); 111 triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 112 graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); 113 triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 114 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 115 } 116 break; 117 } 118 case PHY_SHORT: 119 { 120 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 121 { 122 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 123 graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); 124 triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); 125 graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); 126 triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 127 graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); 128 triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 129 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 130 } 131 break; 132 } 133 default: 134 btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT)); 77 135 } 78 136 break; 79 137 } 80 138 default: 81 btAssert(( gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));139 btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE)); 82 140 } 83 141 … … 96 154 AabbCalculationCallback() 97 155 { 98 m_aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));99 m_aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));156 m_aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 157 m_aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 100 158 } 101 159 … … 114 172 }; 115 173 116 174 //first calculate the total aabb for all triangles 117 175 AabbCalculationCallback aabbCallback; 118 aabbMin.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));119 aabbMax.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));176 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 177 aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 120 178 InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax); 121 179 … … 123 181 aabbMax = aabbCallback.m_aabbMax; 124 182 } 183 184 185 186 ///fills the dataBuffer and returns the struct name (and 0 on failure) 187 const char* btStridingMeshInterface::serialize(void* dataBuffer, btSerializer* serializer) const 188 { 189 btStridingMeshInterfaceData* trimeshData = (btStridingMeshInterfaceData*) dataBuffer; 190 191 trimeshData->m_numMeshParts = getNumSubParts(); 192 193 //void* uniquePtr = 0; 194 195 trimeshData->m_meshPartsPtr = 0; 196 197 if (trimeshData->m_numMeshParts) 198 { 199 btChunk* chunk = serializer->allocate(sizeof(btMeshPartData),trimeshData->m_numMeshParts); 200 btMeshPartData* memPtr = (btMeshPartData*)chunk->m_oldPtr; 201 trimeshData->m_meshPartsPtr = (btMeshPartData *)serializer->getUniquePointer(memPtr); 202 203 204 // int numtotalphysicsverts = 0; 205 int part,graphicssubparts = getNumSubParts(); 206 const unsigned char * vertexbase; 207 const unsigned char * indexbase; 208 int indexstride; 209 PHY_ScalarType type; 210 PHY_ScalarType gfxindextype; 211 int stride,numverts,numtriangles; 212 int gfxindex; 213 // btVector3 triangle[3]; 214 215 btVector3 meshScaling = getScaling(); 216 217 ///if the number of parts is big, the performance might drop due to the innerloop switch on indextype 218 for (part=0;part<graphicssubparts ;part++,memPtr++) 219 { 220 getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part); 221 memPtr->m_numTriangles = numtriangles;//indices = 3*numtriangles 222 memPtr->m_numVertices = numverts; 223 memPtr->m_indices16 = 0; 224 memPtr->m_indices32 = 0; 225 memPtr->m_3indices16 = 0; 226 memPtr->m_vertices3f = 0; 227 memPtr->m_vertices3d = 0; 228 229 switch (gfxindextype) 230 { 231 case PHY_INTEGER: 232 { 233 int numindices = numtriangles*3; 234 235 if (numindices) 236 { 237 btChunk* chunk = serializer->allocate(sizeof(btIntIndexData),numindices); 238 btIntIndexData* tmpIndices = (btIntIndexData*)chunk->m_oldPtr; 239 memPtr->m_indices32 = (btIntIndexData*)serializer->getUniquePointer(tmpIndices); 240 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 241 { 242 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 243 tmpIndices[gfxindex*3].m_value = tri_indices[0]; 244 tmpIndices[gfxindex*3+1].m_value = tri_indices[1]; 245 tmpIndices[gfxindex*3+2].m_value = tri_indices[2]; 246 } 247 serializer->finalizeChunk(chunk,"btIntIndexData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 248 } 249 break; 250 } 251 case PHY_SHORT: 252 { 253 if (numtriangles) 254 { 255 btChunk* chunk = serializer->allocate(sizeof(btShortIntIndexTripletData),numtriangles); 256 btShortIntIndexTripletData* tmpIndices = (btShortIntIndexTripletData*)chunk->m_oldPtr; 257 memPtr->m_3indices16 = (btShortIntIndexTripletData*) serializer->getUniquePointer(tmpIndices); 258 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 259 { 260 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 261 tmpIndices[gfxindex].m_values[0] = tri_indices[0]; 262 tmpIndices[gfxindex].m_values[1] = tri_indices[1]; 263 tmpIndices[gfxindex].m_values[2] = tri_indices[2]; 264 } 265 serializer->finalizeChunk(chunk,"btShortIntIndexTripletData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 266 } 267 break; 268 } 269 default: 270 { 271 btAssert(0); 272 //unknown index type 273 } 274 } 275 276 switch (type) 277 { 278 case PHY_FLOAT: 279 { 280 float* graphicsbase; 281 282 if (numverts) 283 { 284 btChunk* chunk = serializer->allocate(sizeof(btVector3FloatData),numverts); 285 btVector3FloatData* tmpVertices = (btVector3FloatData*) chunk->m_oldPtr; 286 memPtr->m_vertices3f = (btVector3FloatData *)serializer->getUniquePointer(tmpVertices); 287 for (int i=0;i<numverts;i++) 288 { 289 graphicsbase = (float*)(vertexbase+i*stride); 290 tmpVertices[i].m_floats[0] = graphicsbase[0]; 291 tmpVertices[i].m_floats[1] = graphicsbase[1]; 292 tmpVertices[i].m_floats[2] = graphicsbase[2]; 293 } 294 serializer->finalizeChunk(chunk,"btVector3FloatData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 295 } 296 break; 297 } 298 299 case PHY_DOUBLE: 300 { 301 if (numverts) 302 { 303 btChunk* chunk = serializer->allocate(sizeof(btVector3DoubleData),numverts); 304 btVector3DoubleData* tmpVertices = (btVector3DoubleData*) chunk->m_oldPtr; 305 memPtr->m_vertices3d = (btVector3DoubleData *) serializer->getUniquePointer(tmpVertices); 306 for (int i=0;i<numverts;i++) 307 { 308 double* graphicsbase = (double*)(vertexbase+i*stride);//for now convert to float, might leave it at double 309 tmpVertices[i].m_floats[0] = graphicsbase[0]; 310 tmpVertices[i].m_floats[1] = graphicsbase[1]; 311 tmpVertices[i].m_floats[2] = graphicsbase[2]; 312 } 313 serializer->finalizeChunk(chunk,"btVector3DoubleData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 314 } 315 break; 316 } 317 318 default: 319 btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE)); 320 } 321 322 unLockReadOnlyVertexBase(part); 323 } 324 325 serializer->finalizeChunk(chunk,"btMeshPartData",BT_ARRAY_CODE,chunk->m_oldPtr); 326 } 327 328 329 m_scaling.serializeFloat(trimeshData->m_scaling); 330 return "btStridingMeshInterfaceData"; 331 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "btTriangleCallback.h" 21 21 #include "btConcaveShape.h" 22 23 22 24 23 25 … … 90 92 } 91 93 92 94 virtual int calculateSerializeBufferSize() const; 95 96 ///fills the dataBuffer and returns the struct name (and 0 on failure) 97 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 98 93 99 94 100 }; 95 101 102 struct btIntIndexData 103 { 104 int m_value; 105 }; 106 107 struct btShortIntIndexData 108 { 109 short m_value; 110 char m_pad[2]; 111 }; 112 113 struct btShortIntIndexTripletData 114 { 115 short m_values[3]; 116 char m_pad[2]; 117 }; 118 119 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 120 struct btMeshPartData 121 { 122 btVector3FloatData *m_vertices3f; 123 btVector3DoubleData *m_vertices3d; 124 125 btIntIndexData *m_indices32; 126 btShortIntIndexTripletData *m_3indices16; 127 128 btShortIntIndexData *m_indices16;//backwards compatibility 129 130 int m_numTriangles;//length of m_indices = m_numTriangles 131 int m_numVertices; 132 }; 133 134 135 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 136 struct btStridingMeshInterfaceData 137 { 138 btMeshPartData *m_meshPartsPtr; 139 btVector3FloatData m_scaling; 140 int m_numMeshParts; 141 char m_padding[4]; 142 }; 143 144 145 146 147 SIMD_FORCE_INLINE int btStridingMeshInterface::calculateSerializeBufferSize() const 148 { 149 return sizeof(btStridingMeshInterfaceData); 150 } 151 152 153 96 154 #endif //STRIDING_MESHINTERFACE_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp
r5781 r7983 1 2 1 /* 3 2 Bullet Continuous Collision Detection and Physics Library 4 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 5 4 6 5 This software is provided 'as-is', without any express or implied warranty. … … 14 13 3. This notice may not be removed or altered from any source distribution. 15 14 */ 15 16 16 #include "btTetrahedronShape.h" 17 17 #include "LinearMath/btMatrix3x3.h" 18 18 19 btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvex Shape (),20 m_numVertices(0) 21 { 22 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 23 } 24 25 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvex Shape (),26 m_numVertices(0) 27 { 28 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 29 addVertex(pt0); 30 } 31 32 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvex Shape (),19 btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexAabbCachingShape (), 20 m_numVertices(0) 21 { 22 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 23 } 24 25 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexAabbCachingShape (), 26 m_numVertices(0) 27 { 28 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 29 addVertex(pt0); 30 } 31 32 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexAabbCachingShape (), 33 33 m_numVertices(0) 34 34 { … … 38 38 } 39 39 40 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvex Shape (),40 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexAabbCachingShape (), 41 41 m_numVertices(0) 42 42 { … … 47 47 } 48 48 49 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvex Shape (),49 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexAabbCachingShape (), 50 50 m_numVertices(0) 51 51 { … … 58 58 59 59 60 void btBU_Simplex1to4::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const 61 { 62 #if 1 63 btPolyhedralConvexAabbCachingShape::getAabb(t,aabbMin,aabbMax); 64 #else 65 aabbMin.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 66 aabbMax.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 67 68 //just transform the vertices in worldspace, and take their AABB 69 for (int i=0;i<m_numVertices;i++) 70 { 71 btVector3 worldVertex = t(m_vertices[i]); 72 aabbMin.setMin(worldVertex); 73 aabbMax.setMax(worldVertex); 74 } 75 #endif 76 } 77 78 60 79 61 80 … … 64 83 { 65 84 m_vertices[m_numVertices++] = pt; 66 67 85 recalcLocalAabb(); 68 86 } -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 23 23 24 24 ///The btBU_Simplex1to4 implements tetrahedron, triangle, line, vertex collision shapes. In most cases it is better to use btConvexHullShape instead. 25 class btBU_Simplex1to4 : public btPolyhedralConvex Shape25 class btBU_Simplex1to4 : public btPolyhedralConvexAabbCachingShape 26 26 { 27 27 protected: … … 44 44 } 45 45 46 46 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 47 47 48 48 void addVertex(const btVector3& pt); -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. 6 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 9 subject to the following restrictions: 10 10 … … 45 45 numverts = mesh.m_numVertices; 46 46 (*vertexbase) = (unsigned char *) mesh.m_vertexBase; 47 #ifdef BT_USE_DOUBLE_PRECISION 48 type = PHY_DOUBLE; 49 #else 50 type = PHY_FLOAT; 51 #endif 47 48 type = mesh.m_vertexType; 49 52 50 vertexStride = mesh.m_vertexStride; 53 51 … … 65 63 numverts = mesh.m_numVertices; 66 64 (*vertexbase) = (const unsigned char *)mesh.m_vertexBase; 67 #ifdef BT_USE_DOUBLE_PRECISION 68 type = PHY_DOUBLE; 69 #else 70 type = PHY_FLOAT; 71 #endif 65 66 type = mesh.m_vertexType; 67 72 68 vertexStride = mesh.m_vertexStride; 73 69 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 28 28 BT_DECLARE_ALIGNED_ALLOCATOR(); 29 29 30 int m_numTriangles; 31 const unsigned char * m_triangleIndexBase; 32 int m_triangleIndexStride; 33 int m_numVertices; 34 const unsigned char * m_vertexBase; 35 int m_vertexStride; 36 // The index type is set when adding an indexed mesh to the 37 // btTriangleIndexVertexArray, do not set it manually 38 PHY_ScalarType m_indexType; 39 int pad; 30 int m_numTriangles; 31 const unsigned char * m_triangleIndexBase; 32 int m_triangleIndexStride; 33 int m_numVertices; 34 const unsigned char * m_vertexBase; 35 int m_vertexStride; 36 37 // The index type is set when adding an indexed mesh to the 38 // btTriangleIndexVertexArray, do not set it manually 39 PHY_ScalarType m_indexType; 40 41 // The vertex type has a default type similar to Bullet's precision mode (float or double) 42 // but can be set manually if you for example run Bullet with double precision but have 43 // mesh data in single precision.. 44 PHY_ScalarType m_vertexType; 45 46 47 btIndexedMesh() 48 :m_indexType(PHY_INTEGER), 49 #ifdef BT_USE_DOUBLE_PRECISION 50 m_vertexType(PHY_DOUBLE) 51 #else // BT_USE_DOUBLE_PRECISION 52 m_vertexType(PHY_FLOAT) 53 #endif // BT_USE_DOUBLE_PRECISION 54 { 55 } 40 56 } 41 57 ; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
r5781 r7983 1 2 1 /* 3 2 Bullet Continuous Collision Detection and Physics Library 4 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 5 4 6 5 This software is provided 'as-is', without any express or implied warranty. 7 6 In no event will the authors be held liable for any damages arising from the use of this software. 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 10 9 subject to the following restrictions: 11 10 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "btTriangleMesh.h" -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 17 16 #ifndef TRIANGLE_MESH_H … … 42 41 btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true); 43 42 44 int findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices);45 void addIndex(int index);46 47 43 bool getUse32bitIndices() const 48 44 { … … 63 59 virtual void preallocateIndices(int numindices){(void) numindices;} 64 60 61 ///findOrAddVertex is an internal method, use addTriangle instead 62 int findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices); 63 ///addIndex is an internal method, use addTriangle instead 64 void addIndex(int index); 65 65 66 66 }; -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 92 92 93 93 SupportVertexCallback(const btVector3& supportVecWorld,const btTransform& trans) 94 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(- 1e30))94 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(-BT_LARGE_FLOAT)) 95 95 96 96 { … … 200 200 SupportVertexCallback supportCallback(vec,ident); 201 201 202 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));202 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 203 203 204 204 processAllTriangles(&supportCallback,-aabbMax,aabbMax); … … 208 208 return supportVertex; 209 209 } 210 211 -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 80 80 virtual const char* getName()const {return "TRIANGLEMESH";} 81 81 82 82 83 83 84 }; 84 85 86 87 88 85 89 #endif //TRIANGLE_MESH_SHAPE_H -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btTriangleShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "btBoxShape.h" 21 21 22 classbtTriangleShape : public btPolyhedralConvexShape22 ATTRIBUTE_ALIGNED16(class) btTriangleShape : public btPolyhedralConvexShape 23 23 { 24 24 … … 31 31 { 32 32 return 3; 33 } 34 35 btVector3& getVertexPtr(int index) 36 { 37 return m_vertices1[index]; 33 38 } 34 39 … … 78 83 } 79 84 80 85 btTriangleShape() : btPolyhedralConvexShape () 86 { 87 m_shapeType = TRIANGLE_SHAPE_PROXYTYPE; 88 } 81 89 82 90 btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2) : btPolyhedralConvexShape () -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.cpp
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 7 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.h
r5781 r7983 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
r5781 r7983 97 97 { 98 98 99 btGjkPairDetector gjk(m_convexA,m_convexB,m_ simplexSolver,m_penetrationDepthSolver);99 btGjkPairDetector gjk(m_convexA,m_convexB,m_convexA->getShapeType(),m_convexB->getShapeType(),m_convexA->getMargin(),m_convexB->getMargin(),m_simplexSolver,m_penetrationDepthSolver); 100 100 btGjkPairDetector::ClosestPointInput input; 101 101 … … 122 122 while (dist > radius) 123 123 { 124 if (result.m_debugDrawer) 125 { 126 result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1)); 127 } 124 128 numIter++; 125 129 if (numIter > maxIter) … … 170 174 btTransformUtil::integrateTransform(fromB,linVelB,angVelB,lambda,interpolatedTransB); 171 175 relativeTrans = interpolatedTransB.inverseTimes(interpolatedTransA); 176 177 if (result.m_debugDrawer) 178 { 179 result.m_debugDrawer->drawSphere(interpolatedTransA.getOrigin(),0.2f,btVector3(1,0,0)); 180 } 172 181 173 182 result.DebugDraw( lambda ); … … 198 207 return false; 199 208 } 209 200 210 201 211 } … … 225 235 226 236 } 227 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexCast.h
r5781 r7983 42 42 43 43 CastResult() 44 :m_fraction(btScalar( 1e30)),44 :m_fraction(btScalar(BT_LARGE_FLOAT)), 45 45 m_debugDrawer(0), 46 46 m_allowedPenetration(btScalar(0)) -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h
r5781 r7983 15 15 16 16 17 #ifndef CONVEX_PENETRATION_DEPTH_H18 #define CONVEX_PENETRATION_DEPTH_H17 #ifndef __CONVEX_PENETRATION_DEPTH_H 18 #define __CONVEX_PENETRATION_DEPTH_H 19 19 20 20 class btStackAlloc; -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h
r5781 r7983 34 34 virtual ~Result(){} 35 35 36 ///setShapeIdentifiers provides experimental support for per-triangle material / custom material combiner 37 virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1)=0; 36 ///setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material combiner 37 virtual void setShapeIdentifiersA(int partId0,int index0)=0; 38 virtual void setShapeIdentifiersB(int partId1,int index1)=0; 38 39 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)=0; 39 40 }; … … 42 43 { 43 44 ClosestPointInput() 44 :m_maximumDistanceSquared(btScalar( 1e30)),45 :m_maximumDistanceSquared(btScalar(BT_LARGE_FLOAT)), 45 46 m_stackAlloc(0) 46 47 { … … 69 70 btScalar m_distance; //negative means penetration ! 70 71 71 btStorageResult() : m_distance(btScalar( 1e30))72 btStorageResult() : m_distance(btScalar(BT_LARGE_FLOAT)) 72 73 { 73 74 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp
r5781 r7983 69 69 btMatrix3x3 m_toshape1; 70 70 btTransform m_toshape0; 71 #ifdef __SPU__ 72 bool m_enableMargin; 73 #else 71 74 btVector3 (btConvexShape::*Ls)(const btVector3&) const; 75 #endif//__SPU__ 76 77 78 MinkowskiDiff() 79 { 80 81 } 82 #ifdef __SPU__ 83 void EnableMargin(bool enable) 84 { 85 m_enableMargin = enable; 86 } 87 inline btVector3 Support0(const btVector3& d) const 88 { 89 if (m_enableMargin) 90 { 91 return m_shapes[0]->localGetSupportVertexNonVirtual(d); 92 } else 93 { 94 return m_shapes[0]->localGetSupportVertexWithoutMarginNonVirtual(d); 95 } 96 } 97 inline btVector3 Support1(const btVector3& d) const 98 { 99 if (m_enableMargin) 100 { 101 return m_toshape0*(m_shapes[1]->localGetSupportVertexNonVirtual(m_toshape1*d)); 102 } else 103 { 104 return m_toshape0*(m_shapes[1]->localGetSupportVertexWithoutMarginNonVirtual(m_toshape1*d)); 105 } 106 } 107 #else 72 108 void EnableMargin(bool enable) 73 109 { … … 85 121 return(m_toshape0*((m_shapes[1])->*(Ls))(m_toshape1*d)); 86 122 } 123 #endif //__SPU__ 124 87 125 inline btVector3 Support(const btVector3& d) const 88 126 { … … 203 241 } 204 242 /* Check for termination */ 205 const btScalar omega= dot(m_ray,w)/rl;243 const btScalar omega=btDot(m_ray,w)/rl; 206 244 alpha=btMax(omega,alpha); 207 245 if(((rl-alpha)-(GJK_ACCURARY*rl))<=0) … … 260 298 case eStatus::Valid: m_distance=m_ray.length();break; 261 299 case eStatus::Inside: m_distance=0;break; 300 default: 301 { 302 } 262 303 } 263 304 return(m_status); … … 289 330 btVector3 axis=btVector3(0,0,0); 290 331 axis[i]=1; 291 const btVector3 p= cross(d,axis);332 const btVector3 p=btCross(d,axis); 292 333 if(p.length2()>0) 293 334 { … … 304 345 case 3: 305 346 { 306 const btVector3 n= cross(m_simplex->c[1]->w-m_simplex->c[0]->w,347 const btVector3 n=btCross(m_simplex->c[1]->w-m_simplex->c[0]->w, 307 348 m_simplex->c[2]->w-m_simplex->c[0]->w); 308 349 if(n.length2()>0) … … 358 399 if(l>GJK_SIMPLEX2_EPS) 359 400 { 360 const btScalar t(l>0?- dot(a,d)/l:0);401 const btScalar t(l>0?-btDot(a,d)/l:0); 361 402 if(t>=1) { w[0]=0;w[1]=1;m=2;return(b.length2()); } 362 403 else if(t<=0) { w[0]=1;w[1]=0;m=1;return(a.length2()); } … … 373 414 const btVector3* vt[]={&a,&b,&c}; 374 415 const btVector3 dl[]={a-b,b-c,c-a}; 375 const btVector3 n= cross(dl[0],dl[1]);416 const btVector3 n=btCross(dl[0],dl[1]); 376 417 const btScalar l=n.length2(); 377 418 if(l>GJK_SIMPLEX3_EPS) 378 419 { 379 420 btScalar mindist=-1; 380 btScalar subw[2] ;381 U subm ;421 btScalar subw[2]={0.f,0.f}; 422 U subm(0); 382 423 for(U i=0;i<3;++i) 383 424 { 384 if( dot(*vt[i],cross(dl[i],n))>0)425 if(btDot(*vt[i],btCross(dl[i],n))>0) 385 426 { 386 427 const U j=imd3[i]; … … 398 439 if(mindist<0) 399 440 { 400 const btScalar d= dot(a,n);441 const btScalar d=btDot(a,n); 401 442 const btScalar s=btSqrt(l); 402 443 const btVector3 p=n*(d/l); 403 444 mindist = p.length2(); 404 445 m = 7; 405 w[0] = ( cross(dl[1],b-p)).length()/s;406 w[1] = ( cross(dl[2],c-p)).length()/s;446 w[0] = (btCross(dl[1],b-p)).length()/s; 447 w[1] = (btCross(dl[2],c-p)).length()/s; 407 448 w[2] = 1-(w[0]+w[1]); 408 449 } … … 421 462 const btVector3 dl[]={a-d,b-d,c-d}; 422 463 const btScalar vl=det(dl[0],dl[1],dl[2]); 423 const bool ng=(vl* dot(a,cross(b-c,a-b)))<=0;464 const bool ng=(vl*btDot(a,btCross(b-c,a-b)))<=0; 424 465 if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS)) 425 466 { 426 467 btScalar mindist=-1; 427 btScalar subw[3] ;428 U subm ;468 btScalar subw[3]={0.f,0.f,0.f}; 469 U subm(0); 429 470 for(U i=0;i<3;++i) 430 471 { 431 472 const U j=imd3[i]; 432 const btScalar s=vl* dot(d,cross(dl[i],dl[j]));473 const btScalar s=vl*btDot(d,btCross(dl[i],dl[j])); 433 474 if(s>0) 434 475 { … … 602 643 best->pass = (U1)(++pass); 603 644 gjk.getsupport(best->n,*w); 604 const btScalar wdist= dot(best->n,w->w)-best->d;645 const btScalar wdist=btDot(best->n,w->w)-best->d; 605 646 if(wdist>EPA_ACCURACY) 606 647 { … … 629 670 m_result.c[1] = outer.c[1]; 630 671 m_result.c[2] = outer.c[2]; 631 m_result.p[0] = cross( outer.c[1]->w-projection,672 m_result.p[0] = btCross( outer.c[1]->w-projection, 632 673 outer.c[2]->w-projection).length(); 633 m_result.p[1] = cross( outer.c[2]->w-projection,674 m_result.p[1] = btCross( outer.c[2]->w-projection, 634 675 outer.c[0]->w-projection).length(); 635 m_result.p[2] = cross( outer.c[0]->w-projection,676 m_result.p[2] = btCross( outer.c[0]->w-projection, 636 677 outer.c[1]->w-projection).length(); 637 678 const btScalar sum=m_result.p[0]+m_result.p[1]+m_result.p[2]; … … 667 708 face->c[1] = b; 668 709 face->c[2] = c; 669 face->n = cross(b->w-a->w,c->w-a->w);710 face->n = btCross(b->w-a->w,c->w-a->w); 670 711 const btScalar l=face->n.length(); 671 712 const bool v=l>EPA_ACCURACY; 672 713 face->p = btMin(btMin( 673 dot(a->w,cross(face->n,a->w-b->w)),674 dot(b->w,cross(face->n,b->w-c->w))),675 dot(c->w,cross(face->n,c->w-a->w))) /714 btDot(a->w,btCross(face->n,a->w-b->w)), 715 btDot(b->w,btCross(face->n,b->w-c->w))), 716 btDot(c->w,btCross(face->n,c->w-a->w))) / 676 717 (v?l:1); 677 718 face->p = face->p>=-EPA_INSIDE_EPS?0:face->p; 678 719 if(v) 679 720 { 680 face->d = dot(a->w,face->n)/l;721 face->d = btDot(a->w,face->n)/l; 681 722 face->n /= l; 682 723 if(forced||(face->d>=-EPA_PLANE_EPS)) … … 716 757 { 717 758 const U e1=i1m3[e]; 718 if(( dot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)759 if((btDot(f->n,w->w)-f->d)<-EPA_PLANE_EPS) 719 760 { 720 761 sFace* nf=newface(f->c[e1],f->c[e],w,false); … … 855 896 results.status=sResults::GJK_Failed; 856 897 break; 898 default: 899 { 900 } 857 901 } 858 902 return(false); 859 903 } 860 904 905 #ifndef __SPU__ 861 906 // 862 907 btScalar btGjkEpaSolver2::SignedDistance(const btVector3& position, … … 924 969 return(true); 925 970 } 971 #endif //__SPU__ 926 972 927 973 /* Symbols cleanup */ -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h
r5781 r7983 56 56 sResults& results, 57 57 bool usemargins=true); 58 58 #ifndef __SPU__ 59 59 static btScalar SignedDistance( const btVector3& position, 60 60 btScalar margin, … … 67 67 const btVector3& guess, 68 68 sResults& results); 69 #endif //__SPU__ 70 69 71 }; 70 72 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp
r5781 r7983 33 33 (void)simplexSolver; 34 34 35 const btScalar radialmargin(btScalar(0.));35 // const btScalar radialmargin(btScalar(0.)); 36 36 37 37 btVector3 guessVector(transformA.getOrigin()-transformB.getOrigin()); 38 38 btGjkEpaSolver2::sResults results; 39 40 39 41 if(btGjkEpaSolver2::Penetration(pConvexA,transformA, 40 42 pConvexB,transformB, … … 46 48 wWitnessOnA = results.witnesses[0]; 47 49 wWitnessOnB = results.witnesses[1]; 50 v = results.normal; 48 51 return true; 52 } else 53 { 54 if(btGjkEpaSolver2::Distance(pConvexA,transformA,pConvexB,transformB,guessVector,results)) 55 { 56 wWitnessOnA = results.witnesses[0]; 57 wWitnessOnB = results.witnesses[1]; 58 v = results.normal; 59 return false; 49 60 } 61 } 50 62 51 63 return false; -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h
r5781 r7983 26 26 public : 27 27 28 btGjkEpaPenetrationDepthSolver() 29 { 30 } 31 28 32 bool calcPenDepth( btSimplexSolverInterface& simplexSolver, 29 33 const btConvexShape* pConvexA, const btConvexShape* pConvexB, -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
r5781 r7983 39 39 40 40 41 42 41 btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) 43 :m_cachedSeparatingAxis(btScalar(0.),btScalar( 0.),btScalar(1.)),42 :m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)), 44 43 m_penetrationDepthSolver(penetrationDepthSolver), 45 44 m_simplexSolver(simplexSolver), 46 45 m_minkowskiA(objectA), 47 46 m_minkowskiB(objectB), 47 m_shapeTypeA(objectA->getShapeType()), 48 m_shapeTypeB(objectB->getShapeType()), 49 m_marginA(objectA->getMargin()), 50 m_marginB(objectB->getMargin()), 48 51 m_ignoreMargin(false), 49 52 m_lastUsedMethod(-1), … … 51 54 { 52 55 } 53 54 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults) 56 btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) 57 :m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)), 58 m_penetrationDepthSolver(penetrationDepthSolver), 59 m_simplexSolver(simplexSolver), 60 m_minkowskiA(objectA), 61 m_minkowskiB(objectB), 62 m_shapeTypeA(shapeTypeA), 63 m_shapeTypeB(shapeTypeB), 64 m_marginA(marginA), 65 m_marginB(marginB), 66 m_ignoreMargin(false), 67 m_lastUsedMethod(-1), 68 m_catchDegeneracies(1) 69 { 70 } 71 72 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults) 73 { 74 (void)swapResults; 75 76 getClosestPointsNonVirtual(input,output,debugDraw); 77 } 78 79 #ifdef __SPU__ 80 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw) 81 #else 82 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw) 83 #endif 55 84 { 56 85 m_cachedSeparatingDistance = 0.f; … … 65 94 localTransB.getOrigin() -= positionOffset; 66 95 67 #ifdef __SPU__ 68 btScalar marginA = m_minkowskiA->getMarginNonVirtual(); 69 btScalar marginB = m_minkowskiB->getMarginNonVirtual(); 70 #else 71 btScalar marginA = m_minkowskiA->getMargin(); 72 btScalar marginB = m_minkowskiB->getMargin(); 73 #ifdef TEST_NON_VIRTUAL 74 btScalar marginAv = m_minkowskiA->getMarginNonVirtual(); 75 btScalar marginBv = m_minkowskiB->getMarginNonVirtual(); 76 btAssert(marginA == marginAv); 77 btAssert(marginB == marginBv); 78 #endif //TEST_NON_VIRTUAL 79 #endif 80 81 96 bool check2d = m_minkowskiA->isConvex2d() && m_minkowskiB->isConvex2d(); 97 98 btScalar marginA = m_marginA; 99 btScalar marginB = m_marginB; 82 100 83 101 gNumGjkChecks++; … … 108 126 109 127 { 110 btScalar squaredDistance = SIMD_INFINITY;128 btScalar squaredDistance = BT_LARGE_FLOAT; 111 129 btScalar delta = btScalar(0.); 112 130 … … 124 142 btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis(); 125 143 144 #if 1 145 146 btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); 147 btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB); 148 149 // btVector3 pInA = localGetSupportingVertexWithoutMargin(m_shapeTypeA, m_minkowskiA, seperatingAxisInA,input.m_convexVertexData[0]);//, &featureIndexA); 150 // btVector3 qInB = localGetSupportingVertexWithoutMargin(m_shapeTypeB, m_minkowskiB, seperatingAxisInB,input.m_convexVertexData[1]);//, &featureIndexB); 151 152 #else 126 153 #ifdef __SPU__ 127 154 btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); … … 137 164 #endif // 138 165 #endif //__SPU__ 166 #endif 167 139 168 140 169 btVector3 pWorld = localTransA(pInA); … … 145 174 #endif 146 175 176 if (check2d) 177 { 178 pWorld[2] = 0.f; 179 qWorld[2] = 0.f; 180 } 181 147 182 btVector3 w = pWorld - qWorld; 148 183 delta = m_cachedSeparatingAxis.dot(w); … … 151 186 if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * input.m_maximumDistanceSquared)) 152 187 { 188 m_degenerateSimplex = 10; 153 189 checkSimplex=true; 154 190 //checkPenetration = false; … … 172 208 { 173 209 m_degenerateSimplex = 2; 210 } else 211 { 212 m_degenerateSimplex = 11; 174 213 } 175 214 checkSimplex = true; … … 185 224 spu_printf("addVertex 2\n"); 186 225 #endif 226 btVector3 newCachedSeparatingAxis; 227 187 228 //calculate the closest point to the origin (update vector v) 188 if (!m_simplexSolver->closest( m_cachedSeparatingAxis))229 if (!m_simplexSolver->closest(newCachedSeparatingAxis)) 189 230 { 190 231 m_degenerateSimplex = 3; … … 193 234 } 194 235 195 if( m_cachedSeparatingAxis.length2()<REL_ERROR2)236 if(newCachedSeparatingAxis.length2()<REL_ERROR2) 196 237 { 238 m_cachedSeparatingAxis = newCachedSeparatingAxis; 197 239 m_degenerateSimplex = 6; 198 240 checkSimplex = true; … … 201 243 202 244 btScalar previousSquaredDistance = squaredDistance; 203 squaredDistance = m_cachedSeparatingAxis.length2(); 245 squaredDistance = newCachedSeparatingAxis.length2(); 246 #if 0 247 ///warning: this termination condition leads to some problems in 2d test case see Bullet/Demos/Box2dDemo 248 if (squaredDistance>previousSquaredDistance) 249 { 250 m_degenerateSimplex = 7; 251 squaredDistance = previousSquaredDistance; 252 checkSimplex = false; 253 break; 254 } 255 #endif // 204 256 257 m_cachedSeparatingAxis = newCachedSeparatingAxis; 258 205 259 //redundant m_simplexSolver->compute_points(pointOnA, pointOnB); 206 260 … … 210 264 m_simplexSolver->backup_closest(m_cachedSeparatingAxis); 211 265 checkSimplex = true; 266 m_degenerateSimplex = 12; 267 212 268 break; 213 269 } … … 240 296 //do we need this backup_closest here ? 241 297 m_simplexSolver->backup_closest(m_cachedSeparatingAxis); 298 m_degenerateSimplex = 13; 242 299 break; 243 300 } … … 248 305 m_simplexSolver->compute_points(pointOnA, pointOnB); 249 306 normalInB = pointOnA-pointOnB; 250 btScalar lenSqr = m_cachedSeparatingAxis.length2(); 307 btScalar lenSqr =m_cachedSeparatingAxis.length2(); 308 251 309 //valid normal 252 310 if (lenSqr < 0.0001) … … 280 338 { 281 339 //penetration case 282 340 283 341 //if there is no way to handle penetrations, bail out 284 342 if (m_penetrationDepthSolver) … … 288 346 289 347 gNumDeepPenetrationChecks++; 348 m_cachedSeparatingAxis.setZero(); 290 349 291 350 bool isValid2 = m_penetrationDepthSolver->calcPenDepth( … … 297 356 ); 298 357 358 299 359 if (isValid2) 300 360 { 301 361 btVector3 tmpNormalInB = tmpPointOnB-tmpPointOnA; 302 362 btScalar lenSqr = tmpNormalInB.length2(); 363 if (lenSqr <= (SIMD_EPSILON*SIMD_EPSILON)) 364 { 365 tmpNormalInB = m_cachedSeparatingAxis; 366 lenSqr = m_cachedSeparatingAxis.length2(); 367 } 368 303 369 if (lenSqr > (SIMD_EPSILON*SIMD_EPSILON)) 304 370 { … … 316 382 } else 317 383 { 318 384 m_lastUsedMethod = 8; 319 385 } 320 386 } else 321 387 { 322 //isValid = false; 323 m_lastUsedMethod = 4; 388 m_lastUsedMethod = 9; 324 389 } 325 390 } else 391 326 392 { 327 m_lastUsedMethod = 5; 393 ///this is another degenerate case, where the initial GJK calculation reports a degenerate case 394 ///EPA reports no penetration, and the second GJK (using the supporting vector without margin) 395 ///reports a valid positive distance. Use the results of the second GJK instead of failing. 396 ///thanks to Jacob.Langford for the reproduction case 397 ///http://code.google.com/p/bullet/issues/detail?id=250 398 399 400 if (m_cachedSeparatingAxis.length2() > btScalar(0.)) 401 { 402 btScalar distance2 = (tmpPointOnA-tmpPointOnB).length()-margin; 403 //only replace valid distances when the distance is less 404 if (!isValid || (distance2 < distance)) 405 { 406 distance = distance2; 407 pointOnA = tmpPointOnA; 408 pointOnB = tmpPointOnB; 409 pointOnA -= m_cachedSeparatingAxis * marginA ; 410 pointOnB += m_cachedSeparatingAxis * marginB ; 411 normalInB = m_cachedSeparatingAxis; 412 normalInB.normalize(); 413 isValid = true; 414 m_lastUsedMethod = 6; 415 } else 416 { 417 m_lastUsedMethod = 5; 418 } 419 } 328 420 } 329 421 330 422 } 423 331 424 } 332 425 } 333 426 334 if (isValid) 427 428 429 if (isValid && ((distance < 0) || (distance*distance < input.m_maximumDistanceSquared))) 335 430 { 336 #ifdef __SPU__ 337 //spu_printf("distance\n"); 338 #endif //__CELLOS_LV2__ 339 340 341 #ifdef DEBUG_SPU_COLLISION_DETECTION 342 spu_printf("output 1\n"); 343 #endif 431 #if 0 432 ///some debugging 433 // if (check2d) 434 { 435 printf("n = %2.3f,%2.3f,%2.3f. ",normalInB[0],normalInB[1],normalInB[2]); 436 printf("distance = %2.3f exit=%d deg=%d\n",distance,m_lastUsedMethod,m_degenerateSimplex); 437 } 438 #endif 439 344 440 m_cachedSeparatingAxis = normalInB; 345 441 m_cachedSeparatingDistance = distance; … … 350 446 distance); 351 447 352 #ifdef DEBUG_SPU_COLLISION_DETECTION353 spu_printf("output 2\n");354 #endif355 //printf("gjk add:%f",distance);356 448 } 357 449 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h
r5781 r7983 37 37 const btConvexShape* m_minkowskiA; 38 38 const btConvexShape* m_minkowskiB; 39 int m_shapeTypeA; 40 int m_shapeTypeB; 41 btScalar m_marginA; 42 btScalar m_marginB; 43 39 44 bool m_ignoreMargin; 40 45 btScalar m_cachedSeparatingDistance; … … 51 56 52 57 btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); 58 btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); 53 59 virtual ~btGjkPairDetector() {}; 54 60 55 61 virtual void getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults=false); 62 63 void getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw); 64 56 65 57 66 void setMinkowskiA(btConvexShape* minkA) -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
r5781 r7983 20 20 #include "LinearMath/btTransformUtil.h" 21 21 22 // Don't change following order of parameters 23 ATTRIBUTE_ALIGNED16(struct) PfxConstraintRow { 24 btScalar mNormal[3]; 25 btScalar mRhs; 26 btScalar mJacDiagInv; 27 btScalar mLowerLimit; 28 btScalar mUpperLimit; 29 btScalar mAccumImpulse; 30 }; 22 31 23 32 … … 35 44 m_appliedImpulseLateral1(0.f), 36 45 m_appliedImpulseLateral2(0.f), 46 m_contactMotion1(0.f), 47 m_contactMotion2(0.f), 48 m_contactCFM1(0.f), 49 m_contactCFM2(0.f), 37 50 m_lifeTime(0) 38 51 { … … 53 66 m_appliedImpulseLateral1(0.f), 54 67 m_appliedImpulseLateral2(0.f), 68 m_contactMotion1(0.f), 69 m_contactMotion2(0.f), 70 m_contactCFM1(0.f), 71 m_contactCFM2(0.f), 55 72 m_lifeTime(0) 56 73 { 57 58 74 mConstraintRow[0].mAccumImpulse = 0.f; 75 mConstraintRow[1].mAccumImpulse = 0.f; 76 mConstraintRow[2].mAccumImpulse = 0.f; 59 77 } 60 78 … … 84 102 btScalar m_appliedImpulseLateral1; 85 103 btScalar m_appliedImpulseLateral2; 104 btScalar m_contactMotion1; 105 btScalar m_contactMotion2; 106 btScalar m_contactCFM1; 107 btScalar m_contactCFM2; 108 86 109 int m_lifeTime;//lifetime of the contactpoint in frames 87 110 88 111 btVector3 m_lateralFrictionDir1; 89 112 btVector3 m_lateralFrictionDir2; 113 114 115 116 PfxConstraintRow mConstraintRow[3]; 117 90 118 91 119 btScalar getDistance() const -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
r5781 r7983 21 21 22 22 #define NUM_UNITSPHERE_POINTS 42 23 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =24 {25 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),26 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),27 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),28 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),29 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),30 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),31 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),32 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),33 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),34 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),35 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),36 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),37 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),38 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),39 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),40 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),41 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),42 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),43 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),44 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),45 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),46 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),47 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),48 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),49 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),50 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),51 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),52 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),53 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),54 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),55 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),56 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),57 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),58 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),59 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),60 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),61 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),62 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),63 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),64 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),65 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),66 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))67 };68 23 69 24 … … 79 34 (void)v; 80 35 36 bool check2d= convexA->isConvex2d() && convexB->isConvex2d(); 81 37 82 38 struct btIntermediateResult : public btDiscreteCollisionDetectorInterface::Result … … 92 48 bool m_hasResult; 93 49 94 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)50 virtual void setShapeIdentifiersA(int partId0,int index0) 95 51 { 96 52 (void)partId0; 97 53 (void)index0; 54 } 55 virtual void setShapeIdentifiersB(int partId1,int index1) 56 { 98 57 (void)partId1; 99 58 (void)index1; … … 109 68 110 69 //just take fixed number of orientation, and sample the penetration depth in that direction 111 btScalar minProj = btScalar( 1e30);70 btScalar minProj = btScalar(BT_LARGE_FLOAT); 112 71 btVector3 minNorm(btScalar(0.), btScalar(0.), btScalar(0.)); 113 72 btVector3 minA,minB; … … 130 89 for (i=0;i<numSampleDirections;i++) 131 90 { 132 const btVector3& norm = sPenetrationDirections[i];91 btVector3 norm = getPenetrationDirections()[i]; 133 92 seperatingAxisInABatch[i] = (-norm) * transA.getBasis() ; 134 93 seperatingAxisInBBatch[i] = norm * transB.getBasis() ; … … 144 103 convexA->getPreferredPenetrationDirection(i,norm); 145 104 norm = transA.getBasis() * norm; 146 sPenetrationDirections[numSampleDirections] = norm;105 getPenetrationDirections()[numSampleDirections] = norm; 147 106 seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis(); 148 107 seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis(); … … 161 120 convexB->getPreferredPenetrationDirection(i,norm); 162 121 norm = transB.getBasis() * norm; 163 sPenetrationDirections[numSampleDirections] = norm;122 getPenetrationDirections()[numSampleDirections] = norm; 164 123 seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis(); 165 124 seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis(); … … 171 130 172 131 132 173 133 convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,numSampleDirections); 174 134 convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,numSampleDirections); … … 176 136 for (i=0;i<numSampleDirections;i++) 177 137 { 178 const btVector3& norm = sPenetrationDirections[i]; 179 seperatingAxisInA = seperatingAxisInABatch[i]; 180 seperatingAxisInB = seperatingAxisInBBatch[i]; 181 182 pInA = supportVerticesABatch[i]; 183 qInB = supportVerticesBBatch[i]; 184 185 pWorld = transA(pInA); 186 qWorld = transB(qInB); 187 w = qWorld - pWorld; 188 btScalar delta = norm.dot(w); 189 //find smallest delta 190 if (delta < minProj) 191 { 192 minProj = delta; 193 minNorm = norm; 194 minA = pWorld; 195 minB = qWorld; 138 btVector3 norm = getPenetrationDirections()[i]; 139 if (check2d) 140 { 141 norm[2] = 0.f; 142 } 143 if (norm.length2()>0.01) 144 { 145 146 seperatingAxisInA = seperatingAxisInABatch[i]; 147 seperatingAxisInB = seperatingAxisInBBatch[i]; 148 149 pInA = supportVerticesABatch[i]; 150 qInB = supportVerticesBBatch[i]; 151 152 pWorld = transA(pInA); 153 qWorld = transB(qInB); 154 if (check2d) 155 { 156 pWorld[2] = 0.f; 157 qWorld[2] = 0.f; 158 } 159 160 w = qWorld - pWorld; 161 btScalar delta = norm.dot(w); 162 //find smallest delta 163 if (delta < minProj) 164 { 165 minProj = delta; 166 minNorm = norm; 167 minA = pWorld; 168 minB = qWorld; 169 } 196 170 } 197 171 } … … 210 184 convexA->getPreferredPenetrationDirection(i,norm); 211 185 norm = transA.getBasis() * norm; 212 sPenetrationDirections[numSampleDirections] = norm;186 getPenetrationDirections()[numSampleDirections] = norm; 213 187 numSampleDirections++; 214 188 } … … 225 199 convexB->getPreferredPenetrationDirection(i,norm); 226 200 norm = transB.getBasis() * norm; 227 sPenetrationDirections[numSampleDirections] = norm;201 getPenetrationDirections()[numSampleDirections] = norm; 228 202 numSampleDirections++; 229 203 } … … 234 208 for (int i=0;i<numSampleDirections;i++) 235 209 { 236 const btVector3& norm = sPenetrationDirections[i];210 const btVector3& norm = getPenetrationDirections()[i]; 237 211 seperatingAxisInA = (-norm)* transA.getBasis(); 238 212 seperatingAxisInB = norm* transB.getBasis(); … … 262 236 return false; 263 237 264 minProj += (convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual()); 238 btScalar extraSeparation = 0.5f;///scale dependent 239 minProj += extraSeparation+(convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual()); 265 240 266 241 … … 300 275 input.m_transformA = displacedTrans; 301 276 input.m_transformB = transB; 302 input.m_maximumDistanceSquared = btScalar( 1e30);//minProj;277 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);//minProj; 303 278 304 279 btIntermediateResult res; 280 gjkdet.setCachedSeperatingAxis(-minNorm); 305 281 gjkdet.getClosestPoints(input,res,debugDraw); 306 282 … … 311 287 btScalar penetration_relaxation= btScalar(1.); 312 288 minNorm*=penetration_relaxation; 289 313 290 314 291 if (res.m_hasResult) … … 317 294 pa = res.m_pointInWorld - minNorm * correctedMinNorm; 318 295 pb = res.m_pointInWorld; 296 v = minNorm; 319 297 320 298 #ifdef DEBUG_DRAW … … 331 309 } 332 310 333 334 311 btVector3* btMinkowskiPenetrationDepthSolver::getPenetrationDirections() 312 { 313 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = 314 { 315 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)), 316 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)), 317 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)), 318 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)), 319 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)), 320 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)), 321 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)), 322 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)), 323 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)), 324 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)), 325 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)), 326 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)), 327 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)), 328 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)), 329 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)), 330 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)), 331 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)), 332 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)), 333 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)), 334 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)), 335 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)), 336 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)), 337 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)), 338 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)), 339 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)), 340 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)), 341 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)), 342 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)), 343 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)), 344 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)), 345 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)), 346 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)), 347 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)), 348 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)), 349 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)), 350 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)), 351 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)), 352 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)), 353 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)), 354 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)), 355 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)), 356 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654)) 357 }; 358 359 return sPenetrationDirections; 360 } 361 362 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h
r5781 r7983 23 23 class btMinkowskiPenetrationDepthSolver : public btConvexPenetrationDepthSolver 24 24 { 25 protected: 26 27 static btVector3* getPenetrationDirections(); 28 25 29 public: 26 30 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp
r5781 r7983 26 26 27 27 btPersistentManifold::btPersistentManifold() 28 :m_body0(0), 28 :btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE), 29 m_body0(0), 29 30 m_body1(0), 30 31 m_cachedPoints (0), -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
r5781 r7983 31 31 typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1); 32 32 extern ContactDestroyedCallback gContactDestroyedCallback; 33 34 35 33 extern ContactProcessedCallback gContactProcessedCallback; 34 35 36 enum btContactManifoldTypes 37 { 38 BT_PERSISTENT_MANIFOLD_TYPE = 1, 39 MAX_CONTACT_MANIFOLD_TYPE 40 }; 36 41 37 42 #define MANIFOLD_CACHE_SIZE 4 … … 44 49 ///the contact point with deepest penetration is always kept, and it tries to maximuze the area covered by the points 45 50 ///note that some pairs of objects might have more then one contact manifold. 46 ATTRIBUTE_ALIGNED16( class) btPersistentManifold 51 52 53 ATTRIBUTE_ALIGNED128( class) btPersistentManifold : public btTypedObject 54 //ATTRIBUTE_ALIGNED16( class) btPersistentManifold : public btTypedObject 47 55 { 48 56 … … 53 61 void* m_body0; 54 62 void* m_body1; 63 55 64 int m_cachedPoints; 56 65 … … 68 77 BT_DECLARE_ALIGNED_ALLOCATOR(); 69 78 79 int m_companionIdA; 80 int m_companionIdB; 81 70 82 int m_index1a; 71 83 … … 73 85 74 86 btPersistentManifold(void* body0,void* body1,int , btScalar contactBreakingThreshold,btScalar contactProcessingThreshold) 75 : m_body0(body0),m_body1(body1),m_cachedPoints(0), 87 : btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE), 88 m_body0(body0),m_body1(body1),m_cachedPoints(0), 76 89 m_contactBreakingThreshold(contactBreakingThreshold), 77 90 m_contactProcessingThreshold(contactProcessingThreshold) 78 91 { 79 80 92 } 81 93 … … 135 147 //get rid of duplicated userPersistentData pointer 136 148 m_pointCache[lastUsedIndex].m_userPersistentData = 0; 149 m_pointCache[lastUsedIndex].mConstraintRow[0].mAccumImpulse = 0.f; 150 m_pointCache[lastUsedIndex].mConstraintRow[1].mAccumImpulse = 0.f; 151 m_pointCache[lastUsedIndex].mConstraintRow[2].mAccumImpulse = 0.f; 152 137 153 m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f; 138 154 m_pointCache[lastUsedIndex].m_lateralFrictionInitialized = false; … … 152 168 #ifdef MAINTAIN_PERSISTENCY 153 169 int lifeTime = m_pointCache[insertIndex].getLifeTime(); 154 btScalar appliedImpulse = m_pointCache[insertIndex].m_appliedImpulse; 155 btScalar appliedLateralImpulse1 = m_pointCache[insertIndex].m_appliedImpulseLateral1; 156 btScalar appliedLateralImpulse2 = m_pointCache[insertIndex].m_appliedImpulseLateral2; 157 170 btScalar appliedImpulse = m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse; 171 btScalar appliedLateralImpulse1 = m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse; 172 btScalar appliedLateralImpulse2 = m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse; 173 // bool isLateralFrictionInitialized = m_pointCache[insertIndex].m_lateralFrictionInitialized; 174 175 176 158 177 btAssert(lifeTime>=0); 159 178 void* cache = m_pointCache[insertIndex].m_userPersistentData; … … 166 185 m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2; 167 186 187 m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse = appliedImpulse; 188 m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse = appliedLateralImpulse1; 189 m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse = appliedLateralImpulse2; 190 191 168 192 m_pointCache[insertIndex].m_lifeTime = lifeTime; 169 193 #else -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPointCollector.h
r5781 r7983 32 32 33 33 btPointCollector () 34 : m_distance(btScalar( 1e30)),m_hasResult(false)34 : m_distance(btScalar(BT_LARGE_FLOAT)),m_hasResult(false) 35 35 { 36 36 } 37 37 38 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)38 virtual void setShapeIdentifiersA(int partId0,int index0) 39 39 { 40 40 (void)partId0; 41 41 (void)index0; 42 43 } 44 virtual void setShapeIdentifiersB(int partId1,int index1) 45 { 42 46 (void)partId1; 43 47 (void)index1; 44 //??45 48 } 46 49 -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp
r5781 r7983 115 115 } 116 116 } 117 m_simplexSolver->addVertex( w, supVertexA , supVertexB); 117 ///Just like regular GJK only add the vertex if it isn't already (close) to current vertex, it would lead to divisions by zero and NaN etc. 118 if (!m_simplexSolver->inSimplex(w)) 119 m_simplexSolver->addVertex( w, supVertexA , supVertexB); 120 118 121 if (m_simplexSolver->closest(v)) 119 122 { -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
r5781 r7983 69 69 m_numVertices = 0; 70 70 m_needsUpdate = true; 71 m_lastW = btVector3(btScalar( 1e30),btScalar(1e30),btScalar(1e30));71 m_lastW = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 72 72 m_cachedBC.reset(); 73 73 } … … 290 290 for (i=0;i<numverts;i++) 291 291 { 292 #ifdef BT_USE_EQUAL_VERTEX_THRESHOLD 293 if ( m_simplexVectorW[i].distance2(w) <= m_equalVertexThreshold) 294 #else 292 295 if (m_simplexVectorW[i] == w) 296 #endif 293 297 found = true; 294 298 } -
code/branches/kicklib/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h
r5781 r7983 24 24 25 25 #define VORONOI_SIMPLEX_MAX_VERTS 5 26 27 ///disable next define, or use defaultCollisionConfiguration->getSimplexSolver()->setEqualVertexThreshold(0.f) to disable/configure 28 #define BT_USE_EQUAL_VERTEX_THRESHOLD 29 #define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 0.0001f 30 26 31 27 32 struct btUsageBitfield{ … … 107 112 btVector3 m_cachedV; 108 113 btVector3 m_lastW; 114 115 btScalar m_equalVertexThreshold; 109 116 bool m_cachedValidClosest; 117 110 118 111 119 btSubSimplexClosestResult m_cachedBC; … … 123 131 public: 124 132 133 btVoronoiSimplexSolver() 134 : m_equalVertexThreshold(VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD) 135 { 136 } 125 137 void reset(); 126 138 127 139 void addVertex(const btVector3& w, const btVector3& p, const btVector3& q); 128 140 141 void setEqualVertexThreshold(btScalar threshold) 142 { 143 m_equalVertexThreshold = threshold; 144 } 145 146 btScalar getEqualVertexThreshold() const 147 { 148 return m_equalVertexThreshold; 149 } 129 150 130 151 bool closest(btVector3& v);
Note: See TracChangeset
for help on using the changeset viewer.