Changeset 8284 for code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.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/btMultiSphereShape.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. … … 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
Note: See TracChangeset
for help on using the changeset viewer.