- Timestamp:
- Dec 13, 2008, 11:45:51 PM (16 years ago)
- Location:
- code/branches/physics/src/bullet/BulletCollision/CollisionShapes
- Files:
-
- 39 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h
r2192 r2430 20 20 #include "btCollisionMargin.h" 21 21 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" 22 #include "LinearMath/bt Point3.h"22 #include "LinearMath/btVector3.h" 23 23 #include "LinearMath/btMinMax.h" 24 24 … … 118 118 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 119 119 120 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i ) const120 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const 121 121 { 122 122 //this plane might not be aligned... … … 191 191 192 192 193 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const193 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const 194 194 //virtual void getEdge(int i,Edge& edge) const 195 195 { … … 262 262 263 263 264 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const264 virtual bool isInside(const btVector3& pt,btScalar tolerance) const 265 265 { 266 266 btVector3 halfExtents = getHalfExtentsWithoutMargin(); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
r2192 r2430 144 144 { 145 145 int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j]; 146 147 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride); 148 149 m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 146 147 if (type == PHY_FLOAT) 148 { 149 float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); 150 151 m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 152 } 153 else 154 { 155 double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); 156 157 m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ()); 158 } 150 159 } 151 160 … … 205 214 int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j]; 206 215 207 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride); 208 209 m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 216 if (type == PHY_FLOAT) 217 { 218 float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); 219 220 m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 221 } 222 else 223 { 224 double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); 225 226 m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ()); 227 } 210 228 } 211 229 … … 282 300 printf("%d ,",graphicsindex); 283 301 #endif //DEBUG_TRIANGLE_MESH 284 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride); 285 286 m_triangle[j] = btVector3( 287 graphicsbase[0]*meshScaling.getX(), 288 graphicsbase[1]*meshScaling.getY(), 289 graphicsbase[2]*meshScaling.getZ()); 302 if (type == PHY_FLOAT) 303 { 304 float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); 305 306 m_triangle[j] = btVector3( 307 graphicsbase[0]*meshScaling.getX(), 308 graphicsbase[1]*meshScaling.getY(), 309 graphicsbase[2]*meshScaling.getZ()); 310 } 311 else 312 { 313 double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); 314 315 m_triangle[j] = btVector3( 316 btScalar(graphicsbase[0])*meshScaling.getX(), 317 btScalar(graphicsbase[1])*meshScaling.getY(), 318 btScalar(graphicsbase[2])*meshScaling.getZ()); 319 } 290 320 #ifdef DEBUG_TRIANGLE_MESH 291 321 printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z()); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h
r2192 r2430 50 50 halfExtents += btVector3(getMargin(),getMargin(),getMargin()); 51 51 btMatrix3x3 abs_b = t.getBasis().absolute(); 52 bt Point3 center = t.getOrigin();52 btVector3 center = t.getOrigin(); 53 53 btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents)); 54 54 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
r2192 r2430 43 43 } 44 44 45 btScalar btCollisionShape::getContactBreakingThreshold() const 46 { 47 ///@todo make this 0.1 configurable 48 return getAngularMotionDisc() * btScalar(0.1); 49 } 45 50 btScalar btCollisionShape::getAngularMotionDisc() const 46 51 { 52 ///@todo cache this value, to improve performance 47 53 btVector3 center; 48 54 btScalar disc; … … 66 72 // add linear motion 67 73 btVector3 linMotion = linvel*timeStep; 68 // todo: simd would have a vector max/min operation, instead of per-element access74 ///@todo: simd would have a vector max/min operation, instead of per-element access 69 75 if (linMotion.x() > btScalar(0.)) 70 76 temporalAabbMaxx += linMotion.x(); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.h
r2192 r2430 20 20 #include "LinearMath/btVector3.h" 21 21 #include "LinearMath/btMatrix3x3.h" 22 #include "LinearMath/btPoint3.h"23 22 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types 24 23 … … 47 46 ///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations. 48 47 virtual btScalar getAngularMotionDisc() const; 48 49 virtual btScalar getContactBreakingThreshold() const; 49 50 50 51 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
r2192 r2430 18 18 #include "BulletCollision/BroadphaseCollision/btDbvt.h" 19 19 20 btCompoundShape::btCompoundShape( )20 btCompoundShape::btCompoundShape(bool enableDynamicAabbTree) 21 21 : m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)), 22 22 m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)), … … 26 26 { 27 27 m_shapeType = COMPOUND_SHAPE_PROXYTYPE; 28 void* mem = btAlignedAlloc(sizeof(btDbvt),16); 29 m_dynamicAabbTree = new(mem) btDbvt(); 30 btAssert(mem==m_dynamicAabbTree); 28 29 if (enableDynamicAabbTree) 30 { 31 void* mem = btAlignedAlloc(sizeof(btDbvt),16); 32 m_dynamicAabbTree = new(mem) btDbvt(); 33 btAssert(mem==m_dynamicAabbTree); 34 } 31 35 } 32 36 … … 77 81 } 78 82 83 void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform) 84 { 85 m_children[childIndex].m_transform = newChildTransform; 86 87 if (m_dynamicAabbTree) 88 { 89 ///update the dynamic aabb tree 90 btVector3 localAabbMin,localAabbMax; 91 m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax); 92 ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 93 int index = m_children.size()-1; 94 m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds); 95 } 96 97 recalculateLocalAabb(); 98 } 99 79 100 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex) 80 101 { … … 88 109 89 110 } 111 112 90 113 91 114 void btCompoundShape::removeChildShape(btCollisionShape* shape) … … 100 123 m_children.pop_back(); 101 124 //remove it from the m_dynamicAabbTree too 125 //@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm 126 //so effectively, removeChildShape is broken at the moment 102 127 //m_dynamicAabbTree->remove(m_aabbProxies[i]); 103 128 //m_aabbProxies.swap(i,m_children.size()-1); … … 142 167 btMatrix3x3 abs_b = trans.getBasis().absolute(); 143 168 144 bt Point3 center = trans(localCenter);169 btVector3 center = trans(localCenter); 145 170 146 171 btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents), … … 181 206 btScalar totalMass = 0; 182 207 btVector3 center(0, 0, 0); 183 for (int k = 0; k < n; k++) 208 int k; 209 210 for (k = 0; k < n; k++) 184 211 { 185 212 center += m_children[k].m_transform.getOrigin() * masses[k]; … … 190 217 191 218 btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0); 192 for ( intk = 0; k < n; k++)219 for ( k = 0; k < n; k++) 193 220 { 194 221 btVector3 i; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
r2192 r2430 47 47 } 48 48 49 /// btCompoundShape allows to store multiple other btCollisionShapes49 /// The btCompoundShape allows to store multiple other btCollisionShapes 50 50 /// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape. 51 /// It has an (optional) dynamic aabb tree to accelerate early rejection tests. 52 /// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25 53 /// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape) 51 54 ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape 52 55 { 53 //btAlignedObjectArray<btTransform> m_childTransforms;54 //btAlignedObjectArray<btCollisionShape*> m_childShapes;55 56 btAlignedObjectArray<btCompoundShapeChild> m_children; 56 57 btVector3 m_localAabbMin; 57 58 btVector3 m_localAabbMax; 58 59 59 //btOptimizedBvh* m_aabbTree;60 60 btDbvt* m_dynamicAabbTree; 61 61 … … 63 63 BT_DECLARE_ALIGNED_ALLOCATOR(); 64 64 65 btCompoundShape( );65 btCompoundShape(bool enableDynamicAabbTree = true); 66 66 67 67 virtual ~btCompoundShape(); … … 89 89 } 90 90 91 btTransform getChildTransform(int index)91 btTransform& getChildTransform(int index) 92 92 { 93 93 return m_children[index].m_transform; 94 94 } 95 const btTransform getChildTransform(int index) const95 const btTransform& getChildTransform(int index) const 96 96 { 97 97 return m_children[index].m_transform; 98 98 } 99 100 ///set a new transform for a child, and update internal data structures (local aabb and dynamic tree) 101 void updateChildTransform(int childIndex, const btTransform& newChildTransform); 99 102 100 103 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConcaveShape.h
r2192 r2430 21 21 #include "btTriangleCallback.h" 22 22 23 /// PHY_ScalarType enumerates possible scalar types. 24 /// See the btStridingMeshInterface or btHeightfieldTerrainShape for its use 25 typedef enum PHY_ScalarType { 26 PHY_FLOAT, 27 PHY_DOUBLE, 28 PHY_INTEGER, 29 PHY_SHORT, 30 PHY_FIXEDPOINT88, 31 PHY_UCHAR 32 } PHY_ScalarType; 23 33 24 34 ///The btConcaveShape class provides an interface for non-moving (static) concave shapes. -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
r2192 r2430 15 15 16 16 #include "btConeShape.h" 17 #include "LinearMath/btPoint3.h"18 17 19 18 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
r2192 r2430 23 23 { 24 24 m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE; 25 m_ points.resize(numPoints);25 m_unscaledPoints.resize(numPoints); 26 26 27 27 unsigned char* pointsBaseAddress = (unsigned char*)points; … … 29 29 for (int i=0;i<numPoints;i++) 30 30 { 31 bt Point3* point = (btPoint3*)(pointsBaseAddress + i*stride);32 m_ points[i] = point[0];31 btVector3* point = (btVector3*)(pointsBaseAddress + i*stride); 32 m_unscaledPoints[i] = point[0]; 33 33 } 34 34 … … 45 45 } 46 46 47 void btConvexHullShape::addPoint(const bt Point3& point)47 void btConvexHullShape::addPoint(const btVector3& point) 48 48 { 49 m_ points.push_back(point);49 m_unscaledPoints.push_back(point); 50 50 recalcLocalAabb(); 51 51 … … 69 69 70 70 71 for (int i=0;i<m_ points.size();i++)71 for (int i=0;i<m_unscaledPoints.size();i++) 72 72 { 73 bt Point3 vtx = m_points[i] * m_localScaling;73 btVector3 vtx = m_unscaledPoints[i] * m_localScaling; 74 74 75 75 newDot = vec.dot(vtx); … … 93 93 } 94 94 } 95 for (int i=0;i<m_ points.size();i++)95 for (int i=0;i<m_unscaledPoints.size();i++) 96 96 { 97 bt Point3 vtx = m_points[i] * m_localScaling;97 btVector3 vtx = getScaledPoint(i); 98 98 99 99 for (int j=0;j<numVectors;j++) … … 146 146 int btConvexHullShape::getNumVertices() const 147 147 { 148 return m_ points.size();148 return m_unscaledPoints.size(); 149 149 } 150 150 151 151 int btConvexHullShape::getNumEdges() const 152 152 { 153 return m_ points.size();153 return m_unscaledPoints.size(); 154 154 } 155 155 156 void btConvexHullShape::getEdge(int i,bt Point3& pa,btPoint3& pb) const156 void btConvexHullShape::getEdge(int i,btVector3& pa,btVector3& pb) const 157 157 { 158 158 159 int index0 = i%m_ points.size();160 int index1 = (i+1)%m_ points.size();161 pa = m_points[index0]*m_localScaling;162 pb = m_points[index1]*m_localScaling;159 int index0 = i%m_unscaledPoints.size(); 160 int index1 = (i+1)%m_unscaledPoints.size(); 161 pa = getScaledPoint(index0); 162 pb = getScaledPoint(index1); 163 163 } 164 164 165 void btConvexHullShape::getVertex(int i,bt Point3& vtx) const165 void btConvexHullShape::getVertex(int i,btVector3& vtx) const 166 166 { 167 vtx = m_points[i]*m_localScaling;167 vtx = getScaledPoint(i); 168 168 } 169 169 … … 173 173 } 174 174 175 void btConvexHullShape::getPlane(btVector3& ,bt Point3& ,int ) const175 void btConvexHullShape::getPlane(btVector3& ,btVector3& ,int ) const 176 176 { 177 177 … … 180 180 181 181 //not yet 182 bool btConvexHullShape::isInside(const bt Point3& ,btScalar ) const182 bool btConvexHullShape::isInside(const btVector3& ,btScalar ) const 183 183 { 184 184 assert(0); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h
r2192 r2430 25 25 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape 26 26 { 27 btAlignedObjectArray<bt Point3> m_points;27 btAlignedObjectArray<btVector3> m_unscaledPoints; 28 28 29 29 public: … … 34 34 ///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint. 35 35 ///btConvexHullShape make an internal copy of the points. 36 btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(bt Point3));36 btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btVector3)); 37 37 38 void addPoint(const bt Point3& point);38 void addPoint(const btVector3& point); 39 39 40 btPoint3* getPoints() 40 41 btVector3* getUnscaledPoints() 41 42 { 42 return &m_ points[0];43 return &m_unscaledPoints[0]; 43 44 } 44 45 45 const bt Point3* getPoints() const46 const btVector3* getUnscaledPoints() const 46 47 { 47 return &m_ points[0];48 return &m_unscaledPoints[0]; 48 49 } 49 50 50 int getNumPoints() const 51 ///getPoints is obsolete, please use getUnscaledPoints 52 const btVector3* getPoints() const 51 53 { 52 return m_points.size(); 54 return getUnscaledPoints(); 55 } 56 57 58 59 60 SIMD_FORCE_INLINE btVector3 getScaledPoint(int i) const 61 { 62 return m_unscaledPoints[i] * m_localScaling; 63 } 64 65 SIMD_FORCE_INLINE int getNumPoints() const 66 { 67 return m_unscaledPoints.size(); 53 68 } 54 69 … … 65 80 virtual int getNumVertices() const; 66 81 virtual int getNumEdges() const; 67 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const;68 virtual void getVertex(int i,bt Point3& vtx) const;82 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const; 83 virtual void getVertex(int i,btVector3& vtx) const; 69 84 virtual int getNumPlanes() const; 70 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i ) const;71 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const;85 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const; 86 virtual bool isInside(const btVector3& pt,btScalar tolerance) const; 72 87 73 88 ///in case we receive negative scaling -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
r2192 r2430 18 18 19 19 20 20 21 btConvexInternalShape::btConvexInternalShape() 21 : btConvexShape (),m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),22 : m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), 22 23 m_collisionMargin(CONVEX_DISTANCE_MARGIN) 23 24 { … … 49 50 minAabb[i] = tmp[i]-margin; 50 51 } 51 }; 52 } 53 52 54 53 55 … … 71 73 72 74 #else 75 btAssert(0); 73 76 return btVector3(0,0,0); 74 77 #endif //__SPU__ -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h
r2192 r2430 31 31 } 32 32 33 34 33 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; 35 #ifndef __SPU__36 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;37 38 //notice that the vectors should be unit length39 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;40 #endif //#ifndef __SPU__41 34 42 35 const btVector3& getImplicitShapeDimensions() const -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
r2192 r2430 18 18 #include "LinearMath/btQuaternion.h" 19 19 20 btConvexPointCloudShape::btConvexPointCloudShape (btVector3* points,int numPoints) : btPolyhedralConvexShape ()21 {22 m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;23 m_points = points;24 m_numPoints = numPoints;25 26 recalcLocalAabb();27 }28 29 void btConvexPointCloudShape::setPoints (btVector3* points, int numPoints)30 {31 m_points = points;32 m_numPoints = numPoints;33 34 recalcLocalAabb();35 }36 37 38 20 void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling) 39 21 { … … 42 24 } 43 25 26 #ifndef __SPU__ 44 27 btVector3 btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const 45 28 { … … 61 44 for (int i=0;i<m_numPoints;i++) 62 45 { 63 bt Point3 vtx = m_points[i] * m_localScaling;46 btVector3 vtx = getScaledPoint(i); 64 47 65 48 newDot = vec.dot(vtx); … … 85 68 for (int i=0;i<m_numPoints;i++) 86 69 { 87 bt Point3 vtx = m_points[i] * m_localScaling;70 btVector3 vtx = getScaledPoint(i); 88 71 89 72 for (int j=0;j<numVectors;j++) … … 125 108 126 109 127 110 #endif 128 111 129 112 … … 144 127 } 145 128 146 void btConvexPointCloudShape::getEdge(int i,bt Point3& pa,btPoint3& pb) const129 void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const 147 130 { 148 131 btAssert (0); 149 132 } 150 133 151 void btConvexPointCloudShape::getVertex(int i,bt Point3& vtx) const134 void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const 152 135 { 153 vtx = m_ points[i]*m_localScaling;136 vtx = m_unscaledPoints[i]*m_localScaling; 154 137 } 155 138 … … 159 142 } 160 143 161 void btConvexPointCloudShape::getPlane(btVector3& ,bt Point3& ,int ) const144 void btConvexPointCloudShape::getPlane(btVector3& ,btVector3& ,int ) const 162 145 { 163 146 … … 166 149 167 150 //not yet 168 bool btConvexPointCloudShape::isInside(const bt Point3& ,btScalar ) const151 bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const 169 152 { 170 153 assert(0); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h
r2192 r2430 24 24 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape 25 25 { 26 btVector3* m_ points;26 btVector3* m_unscaledPoints; 27 27 int m_numPoints; 28 28 29 public: 29 30 BT_DECLARE_ALIGNED_ALLOCATOR(); 30 31 31 btConvexPointCloudShape(btVector3* points,int numPoints); 32 btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true) 33 { 34 m_localScaling = localScaling; 35 m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE; 36 m_unscaledPoints = points; 37 m_numPoints = numPoints; 32 38 33 void setPoints (btVector3* points, int numPoints); 34 35 btPoint3* getPoints() 36 { 37 return m_points; 39 if (computeAabb) 40 recalcLocalAabb(); 38 41 } 39 42 40 const btPoint3* getPoints() const43 void setPoints (btVector3* points, int numPoints, bool computeAabb = true) 41 44 { 42 return m_points; 45 m_unscaledPoints = points; 46 m_numPoints = numPoints; 47 48 if (computeAabb) 49 recalcLocalAabb(); 43 50 } 44 51 45 int getNumPoints() const 52 SIMD_FORCE_INLINE btVector3* getUnscaledPoints() 53 { 54 return m_unscaledPoints; 55 } 56 57 SIMD_FORCE_INLINE const btVector3* getUnscaledPoints() const 58 { 59 return m_unscaledPoints; 60 } 61 62 SIMD_FORCE_INLINE int getNumPoints() const 46 63 { 47 64 return m_numPoints; 48 65 } 49 66 67 SIMD_FORCE_INLINE btVector3 getScaledPoint( int index) const 68 { 69 return m_unscaledPoints[index] * m_localScaling; 70 } 71 72 #ifndef __SPU__ 50 73 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; 51 74 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; 52 75 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 76 #endif 53 77 54 78 … … 58 82 virtual int getNumVertices() const; 59 83 virtual int getNumEdges() const; 60 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const;61 virtual void getVertex(int i,bt Point3& vtx) const;84 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const; 85 virtual void getVertex(int i,btVector3& vtx) const; 62 86 virtual int getNumPlanes() const; 63 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i ) const;64 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const;87 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const; 88 virtual bool isInside(const btVector3& pt,btScalar tolerance) const; 65 89 66 90 ///in case we receive negative scaling -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
r2192 r2430 15 15 16 16 #include "btConvexShape.h" 17 #include "btConvexInternalShape.h"18 17 #include "btTriangleShape.h" 19 18 #include "btSphereShape.h" … … 23 22 #include "btConvexPointCloudShape.h" 24 23 25 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints) 24 btConvexShape::btConvexShape () 25 { 26 } 27 28 btConvexShape::~btConvexShape() 29 { 30 31 } 32 33 34 35 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling) 26 36 { 27 37 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); … … 42 52 for (int i=0;i<numPoints;i++) 43 53 { 44 bt Point3 vtx = points[i];// * m_localScaling;54 btVector3 vtx = points[i] * localScaling; 45 55 46 56 newDot = vec.dot(vtx); … … 62 72 return btVector3(0,0,0); 63 73 } 64 break;65 74 case BOX_SHAPE_PROXYTYPE: 66 75 { 67 bt ConvexInternalShape* convexShape = (btConvexInternalShape*)this;76 btBoxShape* convexShape = (btBoxShape*)this; 68 77 const btVector3& halfExtents = convexShape->getImplicitShapeDimensions(); 69 78 … … 72 81 btFsels(localDir.z(), halfExtents.z(), -halfExtents.z())); 73 82 } 74 break;75 83 case TRIANGLE_SHAPE_PROXYTYPE: 76 84 { … … 82 90 return btVector3(sup.getX(),sup.getY(),sup.getZ()); 83 91 } 84 break;85 92 case CYLINDER_SHAPE_PROXYTYPE: 86 93 { … … 143 150 } 144 151 } 145 break;146 152 case CAPSULE_SHAPE_PROXYTYPE: 147 153 { … … 200 206 return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()); 201 207 } 202 break;203 208 case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE: 204 209 { 205 210 btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this; 206 btVector3* points = convexPointCloudShape->get Points ();211 btVector3* points = convexPointCloudShape->getUnscaledPoints (); 207 212 int numPoints = convexPointCloudShape->getNumPoints (); 208 return convexHullSupport (localDir, points, numPoints );213 return convexHullSupport (localDir, points, numPoints,convexPointCloudShape->getLocalScalingNV()); 209 214 } 210 215 case CONVEX_HULL_SHAPE_PROXYTYPE: 211 216 { 212 217 btConvexHullShape* convexHullShape = (btConvexHullShape*)this; 213 bt Point3* points = convexHullShape->getPoints();218 btVector3* points = convexHullShape->getUnscaledPoints(); 214 219 int numPoints = convexHullShape->getNumPoints (); 215 return convexHullSupport (localDir, points, numPoints); 216 } 217 break; 220 return convexHullSupport (localDir, points, numPoints,convexHullShape->getLocalScalingNV()); 221 } 218 222 default: 219 223 #ifndef __SPU__ … … 222 226 btAssert (0); 223 227 #endif 224 break;225 228 } 226 229 227 230 // should never reach here 228 231 btAssert (0); 229 return bt Point3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));232 return btVector3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f)); 230 233 } 231 234 … … 238 241 } 239 242 localDirNorm.normalize (); 240 switch (m_shapeType) 241 { 242 case SPHERE_SHAPE_PROXYTYPE: 243 { 244 return btVector3(0,0,0) + getMarginNonVirtual() * localDirNorm; 245 } 246 break; 247 case BOX_SHAPE_PROXYTYPE: 248 { 249 btConvexInternalShape* convexShape = (btConvexInternalShape*)this; 250 const btVector3& halfExtents = convexShape->getImplicitShapeDimensions(); 251 252 return btVector3(localDir.getX() < 0.0f ? -halfExtents.x() : halfExtents.x(), 253 localDir.getY() < 0.0f ? -halfExtents.y() : halfExtents.y(), 254 localDir.getZ() < 0.0f ? -halfExtents.z() : halfExtents.z()) + getMarginNonVirtual() * localDirNorm; 255 } 256 break; 257 case TRIANGLE_SHAPE_PROXYTYPE: 258 { 259 btTriangleShape* triangleShape = (btTriangleShape*)this; 260 btVector3 dir(localDir.getX(),localDir.getY(),localDir.getZ()); 261 btVector3* vertices = &triangleShape->m_vertices1[0]; 262 btVector3 dots(dir.dot(vertices[0]), dir.dot(vertices[1]), dir.dot(vertices[2])); 263 btVector3 sup = vertices[dots.maxAxis()]; 264 return btVector3(sup.getX(),sup.getY(),sup.getZ()) + getMarginNonVirtual() * localDirNorm; 265 } 266 break; 267 case CYLINDER_SHAPE_PROXYTYPE: 268 { 269 btCylinderShape* cylShape = (btCylinderShape*)this; 270 //mapping of halfextents/dimension onto radius/height depends on how cylinder local orientation is (upAxis) 271 272 btVector3 halfExtents = cylShape->getImplicitShapeDimensions(); 273 btVector3 v(localDir.getX(),localDir.getY(),localDir.getZ()); 274 int cylinderUpAxis = cylShape->getUpAxis(); 275 int XX(1),YY(0),ZZ(2); 276 277 switch (cylinderUpAxis) 278 { 279 case 0: 280 { 281 XX = 1; 282 YY = 0; 283 ZZ = 2; 284 } 285 break; 286 case 1: 287 { 288 XX = 0; 289 YY = 1; 290 ZZ = 2; 291 } 292 break; 293 case 2: 294 { 295 XX = 0; 296 YY = 2; 297 ZZ = 1; 298 299 } 300 break; 301 default: 302 btAssert(0); 303 break; 304 }; 305 306 btScalar radius = halfExtents[XX]; 307 btScalar halfHeight = halfExtents[cylinderUpAxis]; 308 309 btVector3 tmp; 310 btScalar d ; 311 312 btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]); 313 if (s != btScalar(0.0)) 314 { 315 d = radius / s; 316 tmp[XX] = v[XX] * d; 317 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; 318 tmp[ZZ] = v[ZZ] * d; 319 return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm; 320 } else { 321 tmp[XX] = radius; 322 tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight; 323 tmp[ZZ] = btScalar(0.0); 324 return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm; 325 } 326 } 327 break; 328 case CAPSULE_SHAPE_PROXYTYPE: 329 { 330 btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ()); 331 332 btCapsuleShape* capsuleShape = (btCapsuleShape*)this; 333 btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions(); 334 btScalar halfHeight = capsuleShape->getHalfHeight(); 335 int capsuleUpAxis = capsuleShape->getUpAxis(); 336 337 btScalar radius = capsuleShape->getRadius(); 338 btVector3 supVec(0,0,0); 339 340 btScalar maxDot(btScalar(-1e30)); 341 342 btVector3 vec = vec0; 343 btScalar lenSqr = vec.length2(); 344 if (lenSqr < btScalar(0.0001)) 345 { 346 vec.setValue(1,0,0); 347 } else 348 { 349 btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); 350 vec *= rlen; 351 } 352 btVector3 vtx; 353 btScalar newDot; 354 { 355 btVector3 pos(0,0,0); 356 pos[capsuleUpAxis] = halfHeight; 357 358 vtx = pos +vec*(radius); 359 newDot = vec.dot(vtx); 360 if (newDot > maxDot) 361 { 362 maxDot = newDot; 363 supVec = vtx; 364 } 365 } 366 { 367 btVector3 pos(0,0,0); 368 pos[capsuleUpAxis] = -halfHeight; 369 370 vtx = pos +vec*(radius); 371 newDot = vec.dot(vtx); 372 if (newDot > maxDot) 373 { 374 maxDot = newDot; 375 supVec = vtx; 376 } 377 } 378 return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()) + getMarginNonVirtual() * localDirNorm; 379 } 380 break; 381 case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE: 382 { 383 btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this; 384 btVector3* points = convexPointCloudShape->getPoints (); 385 int numPoints = convexPointCloudShape->getNumPoints (); 386 return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm; 387 } 388 case CONVEX_HULL_SHAPE_PROXYTYPE: 389 { 390 btConvexHullShape* convexHullShape = (btConvexHullShape*)this; 391 btPoint3* points = convexHullShape->getPoints (); 392 int numPoints = convexHullShape->getNumPoints (); 393 return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm; 394 } 395 break; 396 default: 397 #ifndef __SPU__ 398 return this->localGetSupportingVertex (localDir); 399 #else 400 btAssert (0); 401 #endif 402 break; 403 } 404 405 // should never reach here 406 btAssert (0); 407 return btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f)); 243 244 return localGetSupportVertexWithoutMarginNonVirtual(localDirNorm)+ getMarginNonVirtual() * localDirNorm; 408 245 } 409 246 … … 418 255 return sphereShape->getRadius (); 419 256 } 420 break;421 257 case BOX_SHAPE_PROXYTYPE: 422 258 { 423 bt ConvexInternalShape* convexShape = (btConvexInternalShape*)this;259 btBoxShape* convexShape = (btBoxShape*)this; 424 260 return convexShape->getMarginNV (); 425 261 } 426 break;427 262 case TRIANGLE_SHAPE_PROXYTYPE: 428 263 { … … 430 265 return triangleShape->getMarginNV (); 431 266 } 432 break;433 267 case CYLINDER_SHAPE_PROXYTYPE: 434 268 { … … 436 270 return cylShape->getMarginNV(); 437 271 } 438 break;439 272 case CAPSULE_SHAPE_PROXYTYPE: 440 273 { … … 442 275 return capsuleShape->getMarginNV(); 443 276 } 444 break;445 277 case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE: 446 278 /* fall through */ … … 450 282 return convexHullShape->getMarginNV(); 451 283 } 452 break;453 284 default: 454 285 #ifndef __SPU__ … … 457 288 btAssert (0); 458 289 #endif 459 break;460 290 } 461 291 … … 484 314 case BOX_SHAPE_PROXYTYPE: 485 315 { 486 bt ConvexInternalShape* convexShape = (btConvexInternalShape*)this;316 btBoxShape* convexShape = (btBoxShape*)this; 487 317 float margin=convexShape->getMarginNonVirtual(); 488 318 btVector3 halfExtents = convexShape->getImplicitShapeDimensions(); 489 319 halfExtents += btVector3(margin,margin,margin); 490 320 btMatrix3x3 abs_b = t.getBasis().absolute(); 491 bt Point3 center = t.getOrigin();321 btVector3 center = t.getOrigin(); 492 322 btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents)); 493 323 … … 496 326 break; 497 327 } 498 break;499 328 case TRIANGLE_SHAPE_PROXYTYPE: 500 329 { … … 524 353 halfExtents += btVector3(capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual()); 525 354 btMatrix3x3 abs_b = t.getBasis().absolute(); 526 bt Point3 center = t.getOrigin();355 btVector3 center = t.getOrigin(); 527 356 btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents)); 528 357 aabbMin = center - extent; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.h
r2192 r2430 25 25 #include "LinearMath/btAlignedAllocator.h" 26 26 27 //todo: get rid of this btConvexCastResult thing!28 struct btConvexCastResult;29 27 #define MAX_PREFERRED_PENETRATION_DIRECTIONS 10 30 28 … … 39 37 BT_DECLARE_ALIGNED_ALLOCATOR(); 40 38 41 btConvexShape () 42 { 43 } 39 btConvexShape (); 44 40 45 virtual ~btConvexShape() 46 { 41 virtual ~btConvexShape(); 47 42 48 }43 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const = 0; 49 44 50 51 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const =0; 52 #ifndef __SPU__ 53 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0; 54 55 //notice that the vectors should be unit length 56 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0; 57 #endif //#ifndef __SPU__ 45 //////// 46 #ifndef __SPU__ 47 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const=0; 48 #endif //#ifndef __SPU__ 58 49 59 50 btVector3 localGetSupportVertexWithoutMarginNonVirtual (const btVector3& vec) const; … … 61 52 btScalar getMarginNonVirtual () const; 62 53 void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const; 54 55 56 //notice that the vectors should be unit length 57 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0; 63 58 64 59 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version … … 78 73 virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0; 79 74 75 76 77 80 78 }; 81 79 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
r2192 r2430 109 109 } 110 110 111 // todo: could do the batch inside the callback!111 ///@todo: could do the batch inside the callback! 112 112 113 113 … … 164 164 } 165 165 166 void btConvexTriangleMeshShape::getEdge(int ,bt Point3& ,btPoint3& ) const166 void btConvexTriangleMeshShape::getEdge(int ,btVector3& ,btVector3& ) const 167 167 { 168 168 btAssert(0); 169 169 } 170 170 171 void btConvexTriangleMeshShape::getVertex(int ,bt Point3& ) const171 void btConvexTriangleMeshShape::getVertex(int ,btVector3& ) const 172 172 { 173 173 btAssert(0); … … 179 179 } 180 180 181 void btConvexTriangleMeshShape::getPlane(btVector3& ,bt Point3& ,int ) const181 void btConvexTriangleMeshShape::getPlane(btVector3& ,btVector3& ,int ) const 182 182 { 183 183 btAssert(0); … … 185 185 186 186 //not yet 187 bool btConvexTriangleMeshShape::isInside(const bt Point3& ,btScalar ) const187 bool btConvexTriangleMeshShape::isInside(const btVector3& ,btScalar ) const 188 188 { 189 189 btAssert(0); … … 270 270 btVector3 b = triangle[1] - center; 271 271 btVector3 c = triangle[2] - center; 272 btVector3 abc = a + b + c;273 272 btScalar volNeg = -btFabs(a.triple(b, c)) * btScalar(1. / 6); 274 273 for (int j = 0; j < 3; j++) … … 276 275 for (int k = 0; k <= j; k++) 277 276 { 278 i[j][k] = i[k][j] = volNeg * (center[j] * center[k] 279 + btScalar(0.25) * (center[j] * abc[k] + center[k] * abc[j]) 280 + btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k]) 277 i[j][k] = i[k][j] = volNeg * (btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k]) 281 278 + btScalar(0.05) * (a[j] * b[k] + a[k] * b[j] + a[j] * c[k] + a[k] * c[j] + b[j] * c[k] + b[k] * c[j])); 282 279 } -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
r2192 r2430 35 35 virtual int getNumVertices() const; 36 36 virtual int getNumEdges() const; 37 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const;38 virtual void getVertex(int i,bt Point3& vtx) const;37 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const; 38 virtual void getVertex(int i,btVector3& vtx) const; 39 39 virtual int getNumPlanes() const; 40 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i ) const;41 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const;40 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const; 41 virtual bool isInside(const btVector3& pt,btScalar tolerance) const; 42 42 43 43 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
r2192 r2430 14 14 */ 15 15 #include "btCylinderShape.h" 16 #include "LinearMath/btPoint3.h"17 16 18 17 btCylinderShape::btCylinderShape (const btVector3& halfExtents) -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btEmptyShape.h
r2192 r2430 57 57 } 58 58 59 virtual void processAllTriangles(btTriangleCallback* ,const btVector3& ,const btVector3& ) const 60 { 61 } 59 62 60 63 protected: -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
r2192 r2430 19 19 20 20 21 22 btHeightfieldTerrainShape::btHeightfieldTerrainShape 23 ( 24 int heightStickWidth, int heightStickLength, void* heightfieldData, 25 btScalar heightScale, btScalar minHeight, btScalar maxHeight,int upAxis, 26 PHY_ScalarType hdt, bool flipQuadEdges 27 ) 28 { 29 initialize(heightStickWidth, heightStickLength, heightfieldData, 30 heightScale, minHeight, maxHeight, upAxis, hdt, 31 flipQuadEdges); 32 } 33 34 35 21 36 btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges) 22 : btConcaveShape (), m_heightStickWidth(heightStickWidth), 23 m_heightStickLength(heightStickLength), 24 m_maxHeight(maxHeight), 25 m_width((btScalar)heightStickWidth-1), 26 m_length((btScalar)heightStickLength-1), 27 m_heightfieldDataUnknown(heightfieldData), 28 m_useFloatData(useFloatData), 29 m_flipQuadEdges(flipQuadEdges), 30 m_useDiamondSubdivision(false), 31 m_upAxis(upAxis), 32 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) 33 { 37 { 38 // legacy constructor: support only float or unsigned char, 39 // and min height is zero 40 PHY_ScalarType hdt = (useFloatData) ? PHY_FLOAT : PHY_UCHAR; 41 btScalar minHeight = 0.0; 42 43 // previously, height = uchar * maxHeight / 65535. 44 // So to preserve legacy behavior, heightScale = maxHeight / 65535 45 btScalar heightScale = maxHeight / 65535; 46 47 initialize(heightStickWidth, heightStickLength, heightfieldData, 48 heightScale, minHeight, maxHeight, upAxis, hdt, 49 flipQuadEdges); 50 } 51 52 53 54 void btHeightfieldTerrainShape::initialize 55 ( 56 int heightStickWidth, int heightStickLength, void* heightfieldData, 57 btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, 58 PHY_ScalarType hdt, bool flipQuadEdges 59 ) 60 { 61 // validation 62 btAssert(heightStickWidth > 1 && "bad width"); 63 btAssert(heightStickLength > 1 && "bad length"); 64 btAssert(heightfieldData && "null heightfield data"); 65 // btAssert(heightScale) -- do we care? Trust caller here 66 btAssert(minHeight <= maxHeight && "bad min/max height"); 67 btAssert(upAxis >= 0 && upAxis < 3 && 68 "bad upAxis--should be in range [0,2]"); 69 btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_SHORT && 70 "Bad height data type enum"); 71 72 // initialize member variables 34 73 m_shapeType = TERRAIN_SHAPE_PROXYTYPE; 35 36 btScalar quantizationMargin = 1.f; 37 38 //enlarge the AABB to avoid division by zero when initializing the quantization values 39 btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin); 40 41 btVector3 halfExtents(0,0,0); 42 74 m_heightStickWidth = heightStickWidth; 75 m_heightStickLength = heightStickLength; 76 m_minHeight = minHeight; 77 m_maxHeight = maxHeight; 78 m_width = (btScalar) (heightStickWidth - 1); 79 m_length = (btScalar) (heightStickLength - 1); 80 m_heightScale = heightScale; 81 m_heightfieldDataUnknown = heightfieldData; 82 m_heightDataType = hdt; 83 m_flipQuadEdges = flipQuadEdges; 84 m_useDiamondSubdivision = false; 85 m_upAxis = upAxis; 86 m_localScaling.setValue(btScalar(1.), btScalar(1.), btScalar(1.)); 87 88 // determine min/max axis-aligned bounding box (aabb) values 43 89 switch (m_upAxis) 44 90 { 45 91 case 0: 46 92 { 47 halfExtents.setValue( 48 btScalar(m_maxHeight), 49 btScalar(m_width), //?? don't know if this should change 50 btScalar(m_length)); 93 m_localAabbMin.setValue(m_minHeight, 0, 0); 94 m_localAabbMax.setValue(m_maxHeight, m_width, m_length); 51 95 break; 52 96 } 53 97 case 1: 54 98 { 55 halfExtents.setValue( 56 btScalar(m_width), 57 btScalar(m_maxHeight), 58 btScalar(m_length)); 99 m_localAabbMin.setValue(0, m_minHeight, 0); 100 m_localAabbMax.setValue(m_width, m_maxHeight, m_length); 59 101 break; 60 102 }; 61 103 case 2: 62 104 { 63 halfExtents.setValue( 64 btScalar(m_width), 65 btScalar(m_length), 66 btScalar(m_maxHeight) 67 ); 105 m_localAabbMin.setValue(0, 0, m_minHeight); 106 m_localAabbMax.setValue(m_width, m_length, m_maxHeight); 68 107 break; 69 108 } … … 71 110 { 72 111 //need to get valid m_upAxis 73 btAssert(0); 74 } 75 } 76 77 halfExtents*= btScalar(0.5); 78 79 m_localAabbMin = -halfExtents - clampValue; 80 m_localAabbMax = halfExtents + clampValue; 81 btVector3 aabbSize = m_localAabbMax - m_localAabbMin; 82 83 } 112 btAssert(0 && "Bad m_upAxis"); 113 } 114 } 115 116 // remember origin (defined as exact middle of aabb) 117 m_localOrigin = btScalar(0.5) * (m_localAabbMin + m_localAabbMax); 118 } 119 84 120 85 121 … … 93 129 { 94 130 btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5); 95 halfExtents += btVector3(getMargin(),getMargin(),getMargin()); 131 132 btVector3 localOrigin(0, 0, 0); 133 localOrigin[m_upAxis] = (m_minHeight + m_maxHeight) * btScalar(0.5); 134 localOrigin *= m_localScaling; 96 135 97 136 btMatrix3x3 abs_b = t.getBasis().absolute(); 98 bt Point3 center = t.getOrigin();137 btVector3 center = t.getOrigin(); 99 138 btVector3 extent = btVector3(abs_b[0].dot(halfExtents), 100 139 abs_b[1].dot(halfExtents), 101 140 abs_b[2].dot(halfExtents)); 102 141 extent += btVector3(getMargin(),getMargin(),getMargin()); 103 142 104 143 aabbMin = center - extent; 105 144 aabbMax = center + extent; 106 107 108 145 } 109 146 … … 111 148 { 112 149 btScalar val = 0.f; 113 if (m_useFloatData)150 switch (m_heightDataType) 114 151 { 115 val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x]; 116 } else 117 { 118 //assume unsigned short int 119 unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x]; 120 val = heightFieldValue* (m_maxHeight/btScalar(65535)); 121 } 152 case PHY_FLOAT: 153 { 154 val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x]; 155 break; 156 } 157 158 case PHY_UCHAR: 159 { 160 unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x]; 161 val = heightFieldValue * m_heightScale; 162 break; 163 } 164 165 case PHY_SHORT: 166 { 167 short hfValue = m_heightfieldDataShort[(y * m_heightStickWidth) + x]; 168 val = hfValue * m_heightScale; 169 break; 170 } 171 172 default: 173 { 174 btAssert(!"Bad m_heightDataType"); 175 } 176 } 177 122 178 return val; 123 179 } … … 179 235 180 236 237 238 static inline int 239 getQuantized 240 ( 241 float x 242 ) 243 { 244 if (x < 0.0) { 245 return (int) (x - 0.5); 246 } 247 return (int) (x + 0.5); 248 } 249 250 251 252 /// given input vector, return quantized version 253 /** 254 This routine is basically determining the gridpoint indices for a given 255 input vector, answering the question: "which gridpoint is closest to the 256 provided point?". 257 258 "with clamp" means that we restrict the point to be in the heightfield's 259 axis-aligned bounding box. 260 */ 181 261 void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point,int /*isMax*/) const 182 262 { … … 185 265 clampedPoint.setMin(m_localAabbMax); 186 266 187 btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;188 189 //TODO: optimization: check out how to removed this btFabs267 out[0] = getQuantized(clampedPoint.getX()); 268 out[1] = getQuantized(clampedPoint.getY()); 269 out[2] = getQuantized(clampedPoint.getZ()); 190 270 191 out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) ); 192 out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) ); 193 out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) ); 194 195 } 196 197 271 } 272 273 274 275 /// process all triangles within the provided axis-aligned bounding box 276 /** 277 basic algorithm: 278 - convert input aabb to local coordinates (scale down and shift for local origin) 279 - convert input aabb to a range of heightfield grid points (quantize) 280 - iterate over all triangles in that subset of the grid 281 */ 198 282 void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const 199 283 { 200 (void)callback; 201 (void)aabbMax; 202 (void)aabbMin; 284 // scale down the input aabb's so they are in local (non-scaled) coordinates 285 btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]); 286 btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]); 287 288 // account for local origin 289 localAabbMin += m_localOrigin; 290 localAabbMax += m_localOrigin; 203 291 204 292 //quantize the aabbMin and aabbMax, and adjust the start/end ranges 205 206 293 int quantizedAabbMin[3]; 207 294 int quantizedAabbMax[3]; 208 209 btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);210 btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);211 212 295 quantizeWithClamp(quantizedAabbMin, localAabbMin,0); 213 296 quantizeWithClamp(quantizedAabbMax, localAabbMax,1); 214 297 215 298 // expand the min/max quantized values 299 // this is to catch the case where the input aabb falls between grid points! 300 for (int i = 0; i < 3; ++i) { 301 quantizedAabbMin[i]--; 302 quantizedAabbMax[i]++; 303 } 216 304 217 305 int startX=0; … … 224 312 case 0: 225 313 { 226 quantizedAabbMin[1]+=m_heightStickWidth/2-1;227 quantizedAabbMax[1]+=m_heightStickWidth/2+1;228 quantizedAabbMin[2]+=m_heightStickLength/2-1;229 quantizedAabbMax[2]+=m_heightStickLength/2+1;230 231 314 if (quantizedAabbMin[1]>startX) 232 315 startX = quantizedAabbMin[1]; … … 241 324 case 1: 242 325 { 243 quantizedAabbMin[0]+=m_heightStickWidth/2-1;244 quantizedAabbMax[0]+=m_heightStickWidth/2+1;245 quantizedAabbMin[2]+=m_heightStickLength/2-1;246 quantizedAabbMax[2]+=m_heightStickLength/2+1;247 248 326 if (quantizedAabbMin[0]>startX) 249 327 startX = quantizedAabbMin[0]; … … 258 336 case 2: 259 337 { 260 quantizedAabbMin[0]+=m_heightStickWidth/2-1;261 quantizedAabbMax[0]+=m_heightStickWidth/2+1;262 quantizedAabbMin[1]+=m_heightStickLength/2-1;263 quantizedAabbMax[1]+=m_heightStickLength/2+1;264 265 338 if (quantizedAabbMin[0]>startX) 266 339 startX = quantizedAabbMin[0]; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
r2192 r2430 19 19 #include "btConcaveShape.h" 20 20 21 ///The btHeightfieldTerrainShape simulates a 2D heightfield terrain collision shape. You can also use the more general btBvhTriangleMeshShape instead. 22 ///An example implementation of btHeightfieldTerrainShape is provided in Demos/VehicleDemo/VehicleDemo.cpp 21 ///btHeightfieldTerrainShape simulates a 2D heightfield terrain 22 /** 23 The caller is responsible for maintaining the heightfield array; this 24 class does not make a copy. 25 26 The heightfield can be dynamic so long as the min/max height values 27 capture the extremes (heights must always be in that range). 28 29 The local origin of the heightfield is assumed to be the exact 30 center (as determined by width and length and height, with each 31 axis multiplied by the localScaling). 32 33 Most (but not all) rendering and heightfield libraries assume upAxis = 1 34 (that is, the y-axis is "up"). This class allows any of the 3 coordinates 35 to be "up". Make sure your choice of axis is consistent with your rendering 36 system. 37 38 The heightfield heights are determined from the data type used for the 39 heightfieldData array. 40 41 - PHY_UCHAR: height at a point is the uchar value at the 42 grid point, multipled by heightScale. uchar isn't recommended 43 because of its inability to deal with negative values, and 44 low resolution (8-bit). 45 46 - PHY_SHORT: height at a point is the short int value at that grid 47 point, multipled by heightScale. 48 49 - PHY_FLOAT: height at a point is the float value at that grid 50 point. heightScale is ignored when using the float heightfield 51 data type. 52 53 Whatever the caller specifies as minHeight and maxHeight will be honored. 54 The class will not inspect the heightfield to discover the actual minimum 55 or maximum heights. These values are used to determine the heightfield's 56 axis-aligned bounding box, multiplied by localScaling. 57 58 For usage and testing see the TerrainDemo. 59 */ 23 60 class btHeightfieldTerrainShape : public btConcaveShape 24 61 { … … 26 63 btVector3 m_localAabbMin; 27 64 btVector3 m_localAabbMax; 28 65 btVector3 m_localOrigin; 66 29 67 ///terrain data 30 68 int m_heightStickWidth; 31 69 int m_heightStickLength; 70 btScalar m_minHeight; 32 71 btScalar m_maxHeight; 33 72 btScalar m_width; 34 73 btScalar m_length; 74 btScalar m_heightScale; 35 75 union 36 76 { 37 77 unsigned char* m_heightfieldDataUnsignedChar; 78 short* m_heightfieldDataShort; 38 79 btScalar* m_heightfieldDataFloat; 39 80 void* m_heightfieldDataUnknown; 40 81 }; 41 42 bool m_useFloatData;82 83 PHY_ScalarType m_heightDataType; 43 84 bool m_flipQuadEdges; 44 85 bool m_useDiamondSubdivision; … … 52 93 void getVertex(int x,int y,btVector3& vertex) const; 53 94 54 inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const int* aabbMin2,const int* aabbMax2) const 55 { 56 bool overlap = true; 57 overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap; 58 overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap; 59 overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap; 60 return overlap; 61 } 95 96 97 /// protected initialization 98 /** 99 Handles the work of constructors so that public constructors can be 100 backwards-compatible without a lot of copy/paste. 101 */ 102 void initialize(int heightStickWidth, int heightStickLength, 103 void* heightfieldData, btScalar heightScale, 104 btScalar minHeight, btScalar maxHeight, int upAxis, 105 PHY_ScalarType heightDataType, bool flipQuadEdges); 62 106 63 107 public: 64 btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges); 108 /// preferred constructor 109 /** 110 This constructor supports a range of heightfield 111 data types, and allows for a non-zero minimum height value. 112 heightScale is needed for any integer-based heightfield data types. 113 */ 114 btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength, 115 void* heightfieldData, btScalar heightScale, 116 btScalar minHeight, btScalar maxHeight, 117 int upAxis, PHY_ScalarType heightDataType, 118 bool flipQuadEdges); 119 120 /// legacy constructor 121 /** 122 The legacy constructor assumes the heightfield has a minimum height 123 of zero. Only unsigned char or floats are supported. For legacy 124 compatibility reasons, heightScale is calculated as maxHeight / 65535 125 (and is only used when useFloatData = false). 126 */ 127 btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges); 65 128 66 129 virtual ~btHeightfieldTerrainShape(); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
r2192 r2430 36 36 void btMinkowskiSumShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const 37 37 { 38 // todo: could make recursive use of batching. probably this shape is not used frequently.38 ///@todo: could make recursive use of batching. probably this shape is not used frequently. 39 39 for (int i=0;i<numVectors;i++) 40 40 { -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
r2192 r2430 320 320 321 321 int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j]; 322 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);323 #ifdef DEBUG_PATCH_COLORS 324 btVector3 mycolor = color[index&3];325 graphicsbase[8] = mycolor.getX();326 graphicsbase[9] = mycolor.getY();327 graphicsbase[10] = mycolor.getZ();328 #endif //DEBUG_PATCH_COLORS 329 330 331 triangleVerts[j] = btVector3(332 graphicsbase[0]*meshScaling.getX(),333 graphicsbase[1]*meshScaling.getY(),334 graphicsbase[2]*meshScaling.getZ());322 if (type == PHY_FLOAT) 323 { 324 float* graphicsbase = (float*)(vertexbase+graphicsindex*stride); 325 triangleVerts[j] = btVector3( 326 graphicsbase[0]*meshScaling.getX(), 327 graphicsbase[1]*meshScaling.getY(), 328 graphicsbase[2]*meshScaling.getZ()); 329 } 330 else 331 { 332 double* graphicsbase = (double*)(vertexbase+graphicsindex*stride); 333 triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*meshScaling.getX()), btScalar(graphicsbase[1]*meshScaling.getY()), btScalar(graphicsbase[2]*meshScaling.getZ())); 334 } 335 335 } 336 336 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
r2192 r2430 16 16 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 17 17 18 btPolyhedralConvexShape::btPolyhedralConvexShape() 19 :btConvexInternalShape(), 18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(), 20 19 m_localAabbMin(1,1,1), 21 20 m_localAabbMax(-1,-1,-1), … … 25 24 26 25 } 27 28 26 29 27 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
r2192 r2430 17 17 #define BU_SHAPE 18 18 19 #include "LinearMath/btPoint3.h"20 19 #include "LinearMath/btMatrix3x3.h" 21 20 #include "LinearMath/btAabbUtil2.h" … … 32 31 bool m_isLocalAabbValid; 33 32 34 btPolyhedralConvexShape();35 33 public: 36 34 37 35 btPolyhedralConvexShape(); 38 36 39 37 //brute force implementations 38 40 39 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; 41 40 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 41 42 42 43 43 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 44 44 45 46 void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax) 47 { 48 m_isLocalAabbValid = true; 49 m_localAabbMin = aabbMin; 50 m_localAabbMax = aabbMax; 51 } 52 53 inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const 54 { 55 btAssert(m_isLocalAabbValid); 56 aabbMin = m_localAabbMin; 57 aabbMax = m_localAabbMax; 58 } 45 59 46 60 inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const … … 61 75 virtual int getNumVertices() const = 0 ; 62 76 virtual int getNumEdges() const = 0; 63 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const = 0;64 virtual void getVertex(int i,bt Point3& vtx) const = 0;77 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0; 78 virtual void getVertex(int i,btVector3& vtx) const = 0; 65 79 virtual int getNumPlanes() const = 0; 66 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i ) const = 0;80 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0; 67 81 // virtual int getIndex(int i) const = 0 ; 68 82 69 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const = 0;83 virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0; 70 84 71 85 /// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
r2192 r2430 16 16 #include "btScaledBvhTriangleMeshShape.h" 17 17 18 btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape, btVector3localScaling)18 btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling) 19 19 :m_localScaling(localScaling),m_bvhTriMeshShape(childShape) 20 20 { … … 35 35 public: 36 36 37 btScaledTriangleCallback(btTriangleCallback* originalCallback, btVector3localScaling)37 btScaledTriangleCallback(btTriangleCallback* originalCallback,const btVector3& localScaling) 38 38 :m_originalCallback(originalCallback), 39 39 m_localScaling(localScaling) … … 94 94 btMatrix3x3 abs_b = trans.getBasis().absolute(); 95 95 96 bt Point3 center = trans(localCenter);96 btVector3 center = trans(localCenter); 97 97 98 98 btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents), -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
r2192 r2430 33 33 34 34 35 btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape, btVector3localScaling);35 btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling); 36 36 37 37 virtual ~btScaledBvhTriangleMeshShape(); -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp
r2192 r2430 18 18 19 19 #include "LinearMath/btQuaternion.h" 20 21 22 btSphereShape ::btSphereShape (btScalar radius) : btConvexInternalShape ()23 {24 m_shapeType = SPHERE_SHAPE_PROXYTYPE;25 m_implicitShapeDimensions.setX(radius);26 m_collisionMargin = radius;27 }28 20 29 21 btVector3 btSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h
r2192 r2430 28 28 BT_DECLARE_ALIGNED_ALLOCATOR(); 29 29 30 btSphereShape (btScalar radius); 31 30 btSphereShape (btScalar radius) : btConvexInternalShape () 31 { 32 m_shapeType = SPHERE_SHAPE_PROXYTYPE; 33 m_implicitShapeDimensions.setX(radius); 34 m_collisionMargin = radius; 35 } 32 36 33 37 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h
r2192 r2430 19 19 #include "LinearMath/btVector3.h" 20 20 #include "btTriangleCallback.h" 21 #include "btConcaveShape.h" 21 22 22 /// PHY_ScalarType enumerates possible scalar types. 23 /// See the btStridingMeshInterface for its use 24 typedef enum PHY_ScalarType { 25 PHY_FLOAT, 26 PHY_DOUBLE, 27 PHY_INTEGER, 28 PHY_SHORT, 29 PHY_FIXEDPOINT88 30 } PHY_ScalarType; 23 31 24 32 25 /// The btStridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with btBvhTriangleMeshShape and some other collision shapes. … … 78 71 79 72 virtual bool hasPremadeAabb() const { return false; } 80 virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const {} 81 virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const {} 73 virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const 74 { 75 (void) aabbMin; 76 (void) aabbMax; 77 } 78 virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const 79 { 80 (void) aabbMin; 81 (void) aabbMax; 82 } 82 83 83 84 const btVector3& getScaling() const { -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp
r2192 r2430 23 23 } 24 24 25 btBU_Simplex1to4::btBU_Simplex1to4(const bt Point3& pt0) : btPolyhedralConvexShape (),26 m_numVertices(0) 27 { 28 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 29 addVertex(pt0); 30 } 31 32 btBU_Simplex1to4::btBU_Simplex1to4(const bt Point3& pt0,const btPoint3& pt1) : btPolyhedralConvexShape (),25 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexShape (), 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) : btPolyhedralConvexShape (), 33 33 m_numVertices(0) 34 34 { … … 38 38 } 39 39 40 btBU_Simplex1to4::btBU_Simplex1to4(const bt Point3& pt0,const btPoint3& pt1,const btPoint3& pt2) : btPolyhedralConvexShape (),40 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexShape (), 41 41 m_numVertices(0) 42 42 { … … 47 47 } 48 48 49 btBU_Simplex1to4::btBU_Simplex1to4(const bt Point3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3) : btPolyhedralConvexShape (),49 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexShape (), 50 50 m_numVertices(0) 51 51 { … … 61 61 62 62 63 void btBU_Simplex1to4::addVertex(const bt Point3& pt)63 void btBU_Simplex1to4::addVertex(const btVector3& pt) 64 64 { 65 65 m_vertices[m_numVertices++] = pt; … … 93 93 } 94 94 95 void btBU_Simplex1to4::getEdge(int i,bt Point3& pa,btPoint3& pb) const95 void btBU_Simplex1to4::getEdge(int i,btVector3& pa,btVector3& pb) const 96 96 { 97 97 … … 157 157 } 158 158 159 void btBU_Simplex1to4::getVertex(int i,bt Point3& vtx) const159 void btBU_Simplex1to4::getVertex(int i,btVector3& vtx) const 160 160 { 161 161 vtx = m_vertices[i]; … … 184 184 185 185 186 void btBU_Simplex1to4::getPlane(btVector3&, bt Point3& ,int ) const186 void btBU_Simplex1to4::getPlane(btVector3&, btVector3& ,int ) const 187 187 { 188 188 … … 194 194 } 195 195 196 bool btBU_Simplex1to4::isInside(const bt Point3& ,btScalar ) const196 bool btBU_Simplex1to4::isInside(const btVector3& ,btScalar ) const 197 197 { 198 198 return false; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h
r2192 r2430 28 28 29 29 int m_numVertices; 30 bt Point3 m_vertices[4];30 btVector3 m_vertices[4]; 31 31 32 32 public: 33 33 btBU_Simplex1to4(); 34 34 35 btBU_Simplex1to4(const bt Point3& pt0);36 btBU_Simplex1to4(const bt Point3& pt0,const btPoint3& pt1);37 btBU_Simplex1to4(const bt Point3& pt0,const btPoint3& pt1,const btPoint3& pt2);38 btBU_Simplex1to4(const bt Point3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3);35 btBU_Simplex1to4(const btVector3& pt0); 36 btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1); 37 btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2); 38 btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3); 39 39 40 40 … … 46 46 47 47 48 void addVertex(const bt Point3& pt);48 void addVertex(const btVector3& pt); 49 49 50 50 //PolyhedralConvexShape interface … … 54 54 virtual int getNumEdges() const; 55 55 56 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const;56 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const; 57 57 58 virtual void getVertex(int i,bt Point3& vtx) const;58 virtual void getVertex(int i,btVector3& vtx) const; 59 59 60 60 virtual int getNumPlanes() const; 61 61 62 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i) const;62 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i) const; 63 63 64 64 virtual int getIndex(int i) const; 65 65 66 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const;66 virtual bool isInside(const btVector3& pt,btScalar tolerance) const; 67 67 68 68 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h
r2192 r2430 29 29 }; 30 30 31 /// btTriangleBuffercan be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles'31 ///The btTriangleBuffer callback can be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles' 32 32 ///Example usage of this class: 33 33 /// btTriangleBuffer triBuf; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
r2192 r2430 75 75 } 76 76 77 int btTriangleMesh::findOrAddVertex(const btVector3& vertex) 77 78 int btTriangleMesh::findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices) 78 79 { 79 80 //return index of new/existing vertex 80 // todo: could use acceleration structure for this81 ///@todo: could use acceleration structure for this 81 82 if (m_use4componentVertices) 82 83 { 83 for (int i=0;i< m_4componentVertices.size();i++) 84 { 85 if ((m_4componentVertices[i]-vertex).length2() <= m_weldingThreshold) 84 if (removeDuplicateVertices) 86 85 { 87 return i; 86 for (int i=0;i< m_4componentVertices.size();i++) 87 { 88 if ((m_4componentVertices[i]-vertex).length2() <= m_weldingThreshold) 89 { 90 return i; 91 } 88 92 } 89 93 } … … 97 101 { 98 102 99 for (int i=0;i< m_3componentVertices.size();i+=3)103 if (removeDuplicateVertices) 100 104 { 101 btVector3 vtx(m_3componentVertices[i],m_3componentVertices[i+1],m_3componentVertices[i+2]); 102 if ((vtx-vertex).length2() <= m_weldingThreshold) 105 for (int i=0;i< m_3componentVertices.size();i+=3) 103 106 { 104 return i/3; 107 btVector3 vtx(m_3componentVertices[i],m_3componentVertices[i+1],m_3componentVertices[i+2]); 108 if ((vtx-vertex).length2() <= m_weldingThreshold) 109 { 110 return i/3; 111 } 105 112 } 106 113 } 107 114 m_3componentVertices.push_back(vertex.getX()); 108 115 m_3componentVertices.push_back(vertex.getY()); … … 115 122 } 116 123 117 void btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2 )124 void btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2,bool removeDuplicateVertices) 118 125 { 119 126 m_indexedMeshes[0].m_numTriangles++; 120 121 addIndex(findOrAddVertex(vertex0)); 122 addIndex(findOrAddVertex(vertex1)); 123 addIndex(findOrAddVertex(vertex2)); 127 addIndex(findOrAddVertex(vertex0,removeDuplicateVertices)); 128 addIndex(findOrAddVertex(vertex1,removeDuplicateVertices)); 129 addIndex(findOrAddVertex(vertex2,removeDuplicateVertices)); 124 130 } 125 131 -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h
r2192 r2430 26 26 ///If you want to share triangle/index data between graphics mesh and collision mesh (btBvhTriangleMeshShape), you can directly use btTriangleIndexVertexArray or derive your own class from btStridingMeshInterface. 27 27 ///Performance of btTriangleMesh and btTriangleIndexVertexArray used in a btBvhTriangleMeshShape is the same. 28 ///It has a brute-force option to weld together closeby vertices.29 28 class btTriangleMesh : public btTriangleIndexVertexArray 30 29 { … … 43 42 btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true); 44 43 45 int findOrAddVertex(const btVector3& vertex );44 int findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices); 46 45 void addIndex(int index); 47 46 … … 55 54 return m_use4componentVertices; 56 55 } 57 58 void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2); 56 ///By default addTriangle won't search for duplicate vertices, because the search is very slow for large triangle meshes. 57 ///In general it is better to directly use btTriangleIndexVertexArray instead. 58 void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2, bool removeDuplicateVertices=false); 59 59 60 60 int getNumTriangles() const; -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
r2192 r2430 54 54 btMatrix3x3 abs_b = trans.getBasis().absolute(); 55 55 56 bt Point3 center = trans(localCenter);56 btVector3 center = trans(localCenter); 57 57 58 58 btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents), -
code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleShape.h
r2192 r2430 47 47 } 48 48 49 virtual void getEdge(int i,bt Point3& pa,btPoint3& pb) const49 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const 50 50 { 51 51 getVertex(i,pa); … … 89 89 90 90 91 virtual void getPlane(btVector3& planeNormal,bt Point3& planeSupport,int i) const91 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i) const 92 92 { 93 93 getPlaneEquation(i,planeNormal,planeSupport); … … 105 105 } 106 106 107 virtual void getPlaneEquation(int i, btVector3& planeNormal,bt Point3& planeSupport) const107 virtual void getPlaneEquation(int i, btVector3& planeNormal,btVector3& planeSupport) const 108 108 { 109 109 (void)i; … … 119 119 } 120 120 121 virtual bool isInside(const bt Point3& pt,btScalar tolerance) const121 virtual bool isInside(const btVector3& pt,btScalar tolerance) const 122 122 { 123 123 btVector3 normal; … … 133 133 for (i=0;i<3;i++) 134 134 { 135 bt Point3 pa,pb;135 btVector3 pa,pb; 136 136 getEdge(i,pa,pb); 137 137 btVector3 edge = pb-pa;
Note: See TracChangeset
for help on using the changeset viewer.