Changeset 2882 for code/trunk/src/bullet/BulletCollision/CollisionShapes
- Timestamp:
- Mar 31, 2009, 8:05:51 PM (16 years ago)
- Location:
- code/trunk/src/bullet/BulletCollision/CollisionShapes
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h
r2662 r2882 162 162 { 163 163 case 0: 164 plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.)); 165 plane[3] = -halfExtents.x(); 164 plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.),-halfExtents.x()); 166 165 break; 167 166 case 1: 168 plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.)); 169 plane[3] = -halfExtents.x(); 167 plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.),-halfExtents.x()); 170 168 break; 171 169 case 2: 172 plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.)); 173 plane[3] = -halfExtents.y(); 170 plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.),-halfExtents.y()); 174 171 break; 175 172 case 3: 176 plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.)); 177 plane[3] = -halfExtents.y(); 173 plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.),-halfExtents.y()); 178 174 break; 179 175 case 4: 180 plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.)); 181 plane[3] = -halfExtents.z(); 176 plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.),-halfExtents.z()); 182 177 break; 183 178 case 5: 184 plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.)); 185 plane[3] = -halfExtents.z(); 179 plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.),-halfExtents.z()); 186 180 break; 187 181 default: 188 assert(0);182 btAssert(0); 189 183 } 190 184 } … … 313 307 break; 314 308 default: 315 assert(0);309 btAssert(0); 316 310 } 317 311 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
r2662 r2882 15 15 16 16 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 17 18 19 btScalar gContactThresholdFactor=btScalar(0.02); 17 20 18 21 … … 45 48 btScalar btCollisionShape::getContactBreakingThreshold() const 46 49 { 47 ///@todo make this 0.1 configurable 48 return getAngularMotionDisc() * btScalar(0.1); 50 return getAngularMotionDisc() * gContactThresholdFactor; 49 51 } 50 52 btScalar btCollisionShape::getAngularMotionDisc() const -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
r2662 r2882 23 23 m_collisionMargin(btScalar(0.)), 24 24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), 25 m_dynamicAabbTree(0) 25 m_dynamicAabbTree(0), 26 m_updateRevision(1) 26 27 { 27 28 m_shapeType = COMPOUND_SHAPE_PROXYTYPE; … … 47 48 void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape) 48 49 { 50 m_updateRevision++; 49 51 //m_childTransforms.push_back(localTransform); 50 52 //m_childShapes.push_back(shape); … … 55 57 child.m_childMargin = shape->getMargin(); 56 58 57 m_children.push_back(child); 58 59 59 60 //extend the local aabbMin/aabbMax 60 61 btVector3 localAabbMin,localAabbMax; … … 75 76 { 76 77 const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 77 int index = m_children.size() -1;78 int index = m_children.size(); 78 79 child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); 79 80 } 81 82 m_children.push_back(child); 80 83 81 84 } … … 100 103 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex) 101 104 { 105 m_updateRevision++; 102 106 btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size()); 103 107 if (m_dynamicAabbTree) … … 114 118 void btCompoundShape::removeChildShape(btCollisionShape* shape) 115 119 { 120 m_updateRevision++; 116 121 // Find the children containing the shape specified, and remove those children. 117 122 //note: there might be multiple children using the same shape! … … 140 145 // Recalculate the local aabb 141 146 // Brute force, it iterates over all the shapes left. 147 142 148 m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30)); 143 149 m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)); … … 162 168 { 163 169 btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin); 170 btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin); 171 172 //avoid an illegal AABB when there are no children 173 if (!m_children.size()) 174 { 175 localHalfExtents.setValue(0,0,0); 176 localCenter.setValue(0,0,0); 177 } 164 178 localHalfExtents += btVector3(getMargin(),getMargin(),getMargin()); 165 btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);179 166 180 167 181 btMatrix3x3 abs_b = trans.getBasis().absolute(); … … 174 188 aabbMin = center-extent; 175 189 aabbMax = center+extent; 176 190 177 191 } 178 192 -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
r2662 r2882 59 59 60 60 btDbvt* m_dynamicAabbTree; 61 62 ///increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be updated 63 int m_updateRevision; 61 64 62 65 public: … … 153 156 void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const; 154 157 158 int getUpdateRevision() const 159 { 160 return m_updateRevision; 161 } 155 162 156 163 private: -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
r2662 r2882 61 61 break; 62 62 default: 63 assert(0);63 btAssert(0); 64 64 }; 65 65 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
r2662 r2882 182 182 bool btConvexHullShape::isInside(const btVector3& ,btScalar ) const 183 183 { 184 assert(0);184 btAssert(0); 185 185 return false; 186 186 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
r2662 r2882 151 151 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const 152 152 { 153 assert(0);153 btAssert(0); 154 154 return false; 155 155 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
r2662 r2882 155 155 156 156 btCapsuleShape* capsuleShape = (btCapsuleShape*)this; 157 btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions();158 157 btScalar halfHeight = capsuleShape->getHalfHeight(); 159 158 int capsuleUpAxis = capsuleShape->getUpAxis(); … … 302 301 { 303 302 btSphereShape* sphereShape = (btSphereShape*)this; 304 floatradius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX();305 floatmargin = radius + sphereShape->getMarginNonVirtual();303 btScalar radius = sphereShape->getImplicitShapeDimensions().getX();// * convexShape->getLocalScaling().getX(); 304 btScalar margin = radius + sphereShape->getMarginNonVirtual(); 306 305 const btVector3& center = t.getOrigin(); 307 306 btVector3 extent(margin,margin,margin); … … 315 314 { 316 315 btBoxShape* convexShape = (btBoxShape*)this; 317 floatmargin=convexShape->getMarginNonVirtual();316 btScalar margin=convexShape->getMarginNonVirtual(); 318 317 btVector3 halfExtents = convexShape->getImplicitShapeDimensions(); 319 318 halfExtents += btVector3(margin,margin,margin); -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
r2662 r2882 145 145 } 146 146 147 btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const 147 148 /// This returns the "raw" (user's initial) height, not the actual height. 149 /// The actual height needs to be adjusted to be relative to the center 150 /// of the heightfield's AABB. 151 btScalar 152 btHeightfieldTerrainShape::getRawHeightFieldValue(int x,int y) const 148 153 { 149 154 btScalar val = 0.f; … … 182 187 183 188 184 189 /// this returns the vertex in bullet-local coordinates 185 190 void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const 186 191 { 187 188 192 btAssert(x>=0); 189 193 btAssert(y>=0); … … 191 195 btAssert(y<m_heightStickLength); 192 196 193 194 btScalar height = getHeightFieldValue(x,y); 197 btScalar height = getRawHeightFieldValue(x,y); 195 198 196 199 switch (m_upAxis) … … 199 202 { 200 203 vertex.setValue( 201 height ,204 height - m_localOrigin.getX(), 202 205 (-m_width/btScalar(2.0)) + x, 203 206 (-m_length/btScalar(2.0) ) + y … … 209 212 vertex.setValue( 210 213 (-m_width/btScalar(2.0)) + x, 211 height ,214 height - m_localOrigin.getY(), 212 215 (-m_length/btScalar(2.0)) + y 213 216 ); … … 219 222 (-m_width/btScalar(2.0)) + x, 220 223 (-m_length/btScalar(2.0)) + y, 221 height 224 height - m_localOrigin.getZ() 222 225 ); 223 226 break; … … 231 234 232 235 vertex*=m_localScaling; 233 234 236 } 235 237 … … 239 241 getQuantized 240 242 ( 241 floatx243 btScalar x 242 244 ) 243 245 { -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
r2662 r2882 30 30 center (as determined by width and length and height, with each 31 31 axis multiplied by the localScaling). 32 33 \b NOTE: be careful with coordinates. If you have a heightfield with a local 34 min height of -100m, and a max height of +500m, you may be tempted to place it 35 at the origin (0,0) and expect the heights in world coordinates to be 36 -100 to +500 meters. 37 Actually, the heights will be -300 to +300m, because bullet will re-center 38 the heightfield based on its AABB (which is determined by the min/max 39 heights). So keep in mind that once you create a btHeightfieldTerrainShape 40 object, the heights will be adjusted relative to the center of the AABB. This 41 is different to the behavior of many rendering engines, but is useful for 42 physics engines. 32 43 33 44 Most (but not all) rendering and heightfield libraries assume upAxis = 1 … … 89 100 btVector3 m_localScaling; 90 101 91 virtual btScalar get HeightFieldValue(int x,int y) const;102 virtual btScalar getRawHeightFieldValue(int x,int y) const; 92 103 void quantizeWithClamp(int* out, const btVector3& point,int isMax) const; 93 104 void getVertex(int x,int y,btVector3& vertex) const; -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
r2662 r2882 29 29 btVector3 btMinkowskiSumShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const 30 30 { 31 btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin( -vec*m_transA.getBasis()));32 btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin( vec*m_transB.getBasis()));31 btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(vec*m_transA.getBasis())); 32 btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin(-vec*m_transB.getBasis())); 33 33 return supVertexA - supVertexB; 34 34 } -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
r2662 r2882 32 32 BT_DECLARE_ALIGNED_ALLOCATOR(); 33 33 34 btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() { }34 btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() {m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;} 35 35 btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true): 36 36 btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh) 37 37 { 38 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 39 38 40 btVector3 m_triangle[3]; 39 41 const unsigned char *vertexbase; … … 68 70 btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh) 69 71 { 72 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 73 70 74 btVector3 m_triangle[3]; 71 75 const unsigned char *vertexbase; … … 108 112 */ 109 113 } 110 virtual int getShapeType() const111 {112 return MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;113 }114 115 114 //debugging 116 115 virtual const char* getName()const {return "MULTIMATERIALTRIANGLEMESH";} -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h
r2662 r2882 48 48 btScalar getRadius() const { return m_implicitShapeDimensions.getX() * m_localScaling.getX();} 49 49 50 void setUnscaledRadius(btScalar radius) 51 { 52 m_implicitShapeDimensions.setX(radius); 53 btConvexInternalShape::setMargin(radius); 54 } 55 50 56 //debugging 51 57 virtual const char* getName()const {return "SPHERE";} -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
r2662 r2882 83 83 } 84 84 85 void btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) 85 86 void btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const 86 87 { 87 88 m_aabbMin = aabbMin; … … 96 97 } 97 98 99 -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
r2662 r2882 53 53 IndexedMeshArray m_indexedMeshes; 54 54 int m_pad[2]; 55 int m_hasAabb; // using int instead of bool to maintain alignment56 btVector3 m_aabbMin;57 btVector3 m_aabbMax;55 mutable int m_hasAabb; // using int instead of bool to maintain alignment 56 mutable btVector3 m_aabbMin; 57 mutable btVector3 m_aabbMax; 58 58 59 59 public: … … 107 107 108 108 virtual bool hasPremadeAabb() const; 109 virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) ;109 virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const; 110 110 virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const; 111 111 -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
r2662 r2882 1 1 2 /* 2 3 Bullet Continuous Collision Detection and Physics Library -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
r2662 r2882 36 36 { 37 37 m_indexedMeshes[0].m_numTriangles = m_32bitIndices.size()/3; 38 m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_32bitIndices[0];38 m_indexedMeshes[0].m_triangleIndexBase = 0; 39 39 m_indexedMeshes[0].m_indexType = PHY_INTEGER; 40 40 m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(int); … … 42 42 { 43 43 m_indexedMeshes[0].m_numTriangles = m_16bitIndices.size()/3; 44 m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_16bitIndices[0];44 m_indexedMeshes[0].m_triangleIndexBase = 0; 45 45 m_indexedMeshes[0].m_indexType = PHY_SHORT; 46 46 m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(short int); … … 50 50 { 51 51 m_indexedMeshes[0].m_numVertices = m_4componentVertices.size(); 52 m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_4componentVertices[0];52 m_indexedMeshes[0].m_vertexBase = 0; 53 53 m_indexedMeshes[0].m_vertexStride = sizeof(btVector3); 54 54 } else 55 55 { 56 56 m_indexedMeshes[0].m_numVertices = m_3componentVertices.size()/3; 57 m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0];57 m_indexedMeshes[0].m_vertexBase = 0; 58 58 m_indexedMeshes[0].m_vertexStride = 3*sizeof(btScalar); 59 59 } … … 112 112 } 113 113 } 114 m_3componentVertices.push_back( vertex.getX());115 m_3componentVertices.push_back( vertex.getY());116 m_3componentVertices.push_back( vertex.getZ());114 m_3componentVertices.push_back((float)vertex.getX()); 115 m_3componentVertices.push_back((float)vertex.getY()); 116 m_3componentVertices.push_back((float)vertex.getZ()); 117 117 m_indexedMeshes[0].m_numVertices++; 118 118 m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0]; -
code/trunk/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h
r2662 r2882 41 41 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const 42 42 { 43 assert(0);43 btAssert(0); 44 44 return localGetSupportingVertex(vec); 45 45 }
Note: See TracChangeset
for help on using the changeset viewer.