Changeset 8284 for code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
- Timestamp:
- Apr 21, 2011, 6:58:23 PM (14 years ago)
- Location:
- code/branches/kicklib2
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib2
- Property svn:mergeinfo changed
-
code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
r5781 r8284 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__
Note: See TracChangeset
for help on using the changeset viewer.