Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Susano Pinto <andresusanopinto@gmail.com>2008-09-15 18:20:31 +0400
committerAndre Susano Pinto <andresusanopinto@gmail.com>2008-09-15 18:20:31 +0400
commita1d611e9bd3379dd2c002cd5a895c788962a19a5 (patch)
tree3c4bedb765464e1f2deadf2b1124c1228cd3d7e7 /extern/bullet2/src/BulletCollision/CollisionShapes
parent039ed9cb7f3edd2cae640065979aed4a7eb31103 (diff)
svn merge -r 16231:16536 https://svn.blender.org/svnroot/bf-blender/trunk/blender
Diffstat (limited to 'extern/bullet2/src/BulletCollision/CollisionShapes')
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp23
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h104
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp221
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h40
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp36
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h78
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp9
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h45
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp169
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h93
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h6
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h12
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h20
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp78
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h98
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp59
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h87
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp115
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h24
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp14
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h20
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.cpp2
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h14
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp115
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h17
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h34
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp6
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h12
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp4
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h13
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp45
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h124
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp657
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h297
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp42
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h38
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp103
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h57
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.cpp164
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h56
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.cpp2
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h20
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp5
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h16
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp6
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h12
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h6
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.cpp9
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.h10
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h4
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp45
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h40
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp86
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h84
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp109
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h62
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp19
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h27
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h18
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp114
-rw-r--r--extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.h88
61 files changed, 2491 insertions, 1442 deletions
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp
index 636b0046c13..8bc2cfa6ffa 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp
@@ -15,35 +15,20 @@ subject to the following restrictions:
#include "btBoxShape.h"
-btVector3 btBoxShape::getHalfExtents() const
-{
- return m_implicitShapeDimensions * m_localScaling;
-}
+
//{
void btBoxShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
{
- btVector3 halfExtents = getHalfExtents();
-
- btMatrix3x3 abs_b = t.getBasis().absolute();
- btPoint3 center = t.getOrigin();
- btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
- abs_b[1].dot(halfExtents),
- abs_b[2].dot(halfExtents));
- extent += btVector3(getMargin(),getMargin(),getMargin());
-
- aabbMin = center - extent;
- aabbMax = center + extent;
-
-
+ btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax);
}
-void btBoxShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btBoxShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
//btScalar margin = btScalar(0.);
- btVector3 halfExtents = getHalfExtents();
+ btVector3 halfExtents = getHalfExtentsWithMargin();
btScalar lx=btScalar(2.)*(halfExtents.x());
btScalar ly=btScalar(2.)*(halfExtents.y());
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h
index bc42f146c7c..4d4fbefea37 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h
@@ -18,11 +18,11 @@ subject to the following restrictions:
#include "btPolyhedralConvexShape.h"
#include "btCollisionMargin.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h"
-#include "../../LinearMath/btPoint3.h"
-#include "../../LinearMath/btSimdMinMax.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "LinearMath/btPoint3.h"
+#include "LinearMath/btMinMax.h"
-///btBoxShape implements both a feature based (vertex/edge/plane) and implicit (getSupportingVertex) Box
+///The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
class btBoxShape: public btPolyhedralConvexShape
{
@@ -31,47 +31,52 @@ class btBoxShape: public btPolyhedralConvexShape
public:
- btVector3 getHalfExtents() const;
-
+ btVector3 getHalfExtentsWithMargin() const
+ {
+ btVector3 halfExtents = getHalfExtentsWithoutMargin();
+ btVector3 margin(getMargin(),getMargin(),getMargin());
+ halfExtents += margin;
+ return halfExtents;
+ }
+
+ const btVector3& getHalfExtentsWithoutMargin() const
+ {
+ return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
+ }
+
+
virtual int getShapeType() const { return BOX_SHAPE_PROXYTYPE;}
virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
{
+ btVector3 halfExtents = getHalfExtentsWithoutMargin();
+ btVector3 margin(getMargin(),getMargin(),getMargin());
+ halfExtents += margin;
- btVector3 halfExtents = getHalfExtents();
-
- btVector3 supVertex;
- supVertex = btPoint3(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(),
- vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(),
- vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z());
-
- return supVertex;
+ return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
+ btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+ btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
}
- virtual inline btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+ SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const
{
- btVector3 halfExtents = getHalfExtents();
- btVector3 margin(getMargin(),getMargin(),getMargin());
- halfExtents -= margin;
-
- return btVector3(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(),
- vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(),
- vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z());
+ const btVector3& halfExtents = getHalfExtentsWithoutMargin();
+
+ return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
+ btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+ btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
}
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
{
- btVector3 halfExtents = getHalfExtents();
- btVector3 margin(getMargin(),getMargin(),getMargin());
- halfExtents -= margin;
-
-
+ const btVector3& halfExtents = getHalfExtentsWithoutMargin();
+
for (int i=0;i<numVectors;i++)
{
const btVector3& vec = vectors[i];
- supportVerticesOut[i].setValue(vec.x() < btScalar(0.0) ? -halfExtents.x() : halfExtents.x(),
- vec.y() < btScalar(0.0) ? -halfExtents.y() : halfExtents.y(),
- vec.z() < btScalar(0.0) ? -halfExtents.z() : halfExtents.z());
+ supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
+ btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+ btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
}
}
@@ -79,14 +84,38 @@ public:
btBoxShape( const btVector3& boxHalfExtents)
{
- m_implicitShapeDimensions = boxHalfExtents;
+ btVector3 margin(getMargin(),getMargin(),getMargin());
+ m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
};
-
+
+ virtual void setMargin(btScalar collisionMargin)
+ {
+ //correct the m_implicitShapeDimensions for the margin
+ btVector3 oldMargin(getMargin(),getMargin(),getMargin());
+ btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
+
+ btConvexInternalShape::setMargin(collisionMargin);
+ btVector3 newMargin(getMargin(),getMargin(),getMargin());
+ m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
+
+ }
+ virtual void setLocalScaling(const btVector3& scaling)
+ {
+ btVector3 oldMargin(getMargin(),getMargin(),getMargin());
+ btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
+ btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
+
+ btConvexInternalShape::setLocalScaling(scaling);
+
+ m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
+
+ }
+
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const
{
@@ -116,7 +145,7 @@ public:
virtual void getVertex(int i,btVector3& vtx) const
{
- btVector3 halfExtents = getHalfExtents();
+ btVector3 halfExtents = getHalfExtentsWithoutMargin();
vtx = btVector3(
halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1),
@@ -127,7 +156,7 @@ public:
virtual void getPlaneEquation(btVector4& plane,int i) const
{
- btVector3 halfExtents = getHalfExtents();
+ btVector3 halfExtents = getHalfExtentsWithoutMargin();
switch (i)
{
@@ -234,7 +263,7 @@ public:
virtual bool isInside(const btPoint3& pt,btScalar tolerance) const
{
- btVector3 halfExtents = getHalfExtents();
+ btVector3 halfExtents = getHalfExtentsWithoutMargin();
//btScalar minDist = 2*tolerance;
@@ -250,7 +279,7 @@ public:
//debugging
- virtual char* getName()const
+ virtual const char* getName()const
{
return "Box";
}
@@ -291,3 +320,4 @@ public:
#endif //OBB_BOX_MINKOWSKI_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
index 8da554ef14d..819f6f7f97d 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
@@ -18,32 +18,56 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
-
///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
-btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression)
-:btTriangleMeshShape(meshInterface),m_useQuantizedAabbCompression(useQuantizedAabbCompression)
+btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh)
+:btTriangleMeshShape(meshInterface),
+m_bvh(0),
+m_useQuantizedAabbCompression(useQuantizedAabbCompression),
+m_ownsBvh(false)
{
//construct bvh from meshInterface
#ifndef DISABLE_BVH
- m_bvh = new btOptimizedBvh();
btVector3 bvhAabbMin,bvhAabbMax;
- meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
- m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
+ if(meshInterface->hasPremadeAabb())
+ {
+ meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);
+ }
+ else
+ {
+ meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
+ }
+
+ if (buildBvh)
+ {
+ void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
+ m_bvh = new (mem) btOptimizedBvh();
+ m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
+ m_ownsBvh = true;
+ }
#endif //DISABLE_BVH
}
-btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax)
-:btTriangleMeshShape(meshInterface),m_useQuantizedAabbCompression(useQuantizedAabbCompression)
+btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,bool buildBvh)
+:btTriangleMeshShape(meshInterface),
+m_bvh(0),
+m_useQuantizedAabbCompression(useQuantizedAabbCompression),
+m_ownsBvh(false)
{
//construct bvh from meshInterface
#ifndef DISABLE_BVH
- m_bvh = new btOptimizedBvh();
- m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
+ if (buildBvh)
+ {
+ void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
+ m_bvh = new (mem) btOptimizedBvh();
+
+ m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
+ m_ownsBvh = true;
+ }
#endif //DISABLE_BVH
@@ -58,16 +82,140 @@ void btBvhTriangleMeshShape::partialRefitTree(const btVector3& aabbMin,const btV
}
-void btBvhTriangleMeshShape::refitTree()
+void btBvhTriangleMeshShape::refitTree(const btVector3& aabbMin,const btVector3& aabbMax)
{
- m_bvh->refit( m_meshInterface );
+ m_bvh->refit( m_meshInterface, aabbMin,aabbMax );
recalcLocalAabb();
}
btBvhTriangleMeshShape::~btBvhTriangleMeshShape()
{
- delete m_bvh;
+ if (m_ownsBvh)
+ {
+ m_bvh->~btOptimizedBvh();
+ btAlignedFree(m_bvh);
+ }
+}
+
+void btBvhTriangleMeshShape::performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget)
+{
+ struct MyNodeOverlapCallback : public btNodeOverlapCallback
+ {
+ btStridingMeshInterface* m_meshInterface;
+ btTriangleCallback* m_callback;
+
+ MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
+ :m_meshInterface(meshInterface),
+ m_callback(callback)
+ {
+ }
+
+ virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
+ {
+ btVector3 m_triangle[3];
+ const unsigned char *vertexbase;
+ int numverts;
+ PHY_ScalarType type;
+ int stride;
+ const unsigned char *indexbase;
+ int indexstride;
+ int numfaces;
+ PHY_ScalarType indicestype;
+
+ m_meshInterface->getLockedReadOnlyVertexIndexBase(
+ &vertexbase,
+ numverts,
+ type,
+ stride,
+ &indexbase,
+ indexstride,
+ numfaces,
+ indicestype,
+ nodeSubPart);
+
+ unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
+ btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
+
+ const btVector3& meshScaling = m_meshInterface->getScaling();
+ for (int j=2;j>=0;j--)
+ {
+ int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
+
+ btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
+
+ m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
+ }
+
+ /* Perform ray vs. triangle collision here */
+ m_callback->processTriangle(m_triangle,nodeSubPart,nodeTriangleIndex);
+ m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
+ }
+ };
+
+ MyNodeOverlapCallback myNodeCallback(callback,m_meshInterface);
+
+ m_bvh->reportRayOverlappingNodex(&myNodeCallback,raySource,rayTarget);
+}
+
+void btBvhTriangleMeshShape::performConvexcast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax)
+{
+ struct MyNodeOverlapCallback : public btNodeOverlapCallback
+ {
+ btStridingMeshInterface* m_meshInterface;
+ btTriangleCallback* m_callback;
+
+ MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
+ :m_meshInterface(meshInterface),
+ m_callback(callback)
+ {
+ }
+
+ virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
+ {
+ btVector3 m_triangle[3];
+ const unsigned char *vertexbase;
+ int numverts;
+ PHY_ScalarType type;
+ int stride;
+ const unsigned char *indexbase;
+ int indexstride;
+ int numfaces;
+ PHY_ScalarType indicestype;
+
+ m_meshInterface->getLockedReadOnlyVertexIndexBase(
+ &vertexbase,
+ numverts,
+ type,
+ stride,
+ &indexbase,
+ indexstride,
+ numfaces,
+ indicestype,
+ nodeSubPart);
+
+ unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
+ btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
+
+ const btVector3& meshScaling = m_meshInterface->getScaling();
+ for (int j=2;j>=0;j--)
+ {
+ int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
+
+ btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
+
+ m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
+ }
+
+ /* Perform ray vs. triangle collision here */
+ m_callback->processTriangle(m_triangle,nodeSubPart,nodeTriangleIndex);
+ m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
+ }
+ };
+
+ MyNodeOverlapCallback myNodeCallback(callback,m_meshInterface);
+
+ m_bvh->reportBoxCastOverlappingNodex (&myNodeCallback, raySource, rayTarget, aabbMin, aabbMax);
}
//perform bvh tree traversal and report overlapping triangles to 'callback'
@@ -118,13 +266,14 @@ void btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
indicestype,
nodeSubPart);
- int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride);
+ unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
+ btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
const btVector3& meshScaling = m_meshInterface->getScaling();
for (int j=2;j>=0;j--)
{
- int graphicsindex = gfxbase[j];
+ int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
#ifdef DEBUG_TRIANGLE_MESH
@@ -157,17 +306,37 @@ void btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
}
-
-void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
+void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
{
- if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
- {
- btTriangleMeshShape::setLocalScaling(scaling);
- delete m_bvh;
- ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
- m_bvh = new btOptimizedBvh();
- //rebuild the bvh...
- m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
+ if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
+ {
+ btTriangleMeshShape::setLocalScaling(scaling);
+ if (m_ownsBvh)
+ {
+ m_bvh->~btOptimizedBvh();
+ btAlignedFree(m_bvh);
+ }
+ ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
+ void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
+ m_bvh = new(mem) btOptimizedBvh();
+ //rebuild the bvh...
+ m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
+ m_ownsBvh = true;
+ }
+}
- }
+void btBvhTriangleMeshShape::setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& scaling)
+{
+ btAssert(!m_bvh);
+ btAssert(!m_ownsBvh);
+
+ m_bvh = bvh;
+ m_ownsBvh = false;
+ // update the scaling without rebuilding the bvh
+ if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
+ {
+ btTriangleMeshShape::setLocalScaling(scaling);
+ }
}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
index 4914d9f959c..6e587340dc1 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
@@ -18,45 +18,55 @@ subject to the following restrictions:
#include "btTriangleMeshShape.h"
#include "btOptimizedBvh.h"
+#include "LinearMath/btAlignedAllocator.h"
-///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
-///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
+
+///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage.
+///It takes a triangle mesh as input, for example a btTriangleMesh or btTriangleIndexVertexArray. The btBvhTriangleMeshShape class allows for triangle mesh deformations by a refit or partialRefit method.
+///Instead of building the bounding volume hierarchy acceleration structure, it is also possible to serialize (save) and deserialize (load) the structure from disk.
+///See Demos\ConcaveDemo\ConcavePhysicsDemo.cpp for an example.
ATTRIBUTE_ALIGNED16(class) btBvhTriangleMeshShape : public btTriangleMeshShape
{
btOptimizedBvh* m_bvh;
bool m_useQuantizedAabbCompression;
- bool m_pad[12];////need padding due to alignment
+ bool m_ownsBvh;
+ bool m_pad[11];////need padding due to alignment
public:
- btBvhTriangleMeshShape() :btTriangleMeshShape(0) {};
- btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression);
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
+ btBvhTriangleMeshShape() :btTriangleMeshShape(0),m_bvh(0),m_ownsBvh(false) {};
+ btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
- btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax);
+ btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true);
virtual ~btBvhTriangleMeshShape();
-
- /*
+ bool getOwnsBvh () const
+ {
+ return m_ownsBvh;
+ }
+
virtual int getShapeType() const
{
return TRIANGLE_MESH_SHAPE_PROXYTYPE;
}
- */
-
-
+
+ void performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget);
+ void performConvexcast (btTriangleCallback* callback, const btVector3& boxSource, const btVector3& boxTarget, const btVector3& boxMin, const btVector3& boxMax);
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
- void refitTree();
+ void refitTree(const btVector3& aabbMin,const btVector3& aabbMax);
///for a fast incremental refit of parts of the tree. Note: the entire AABB of the tree will become more conservative, it never shrinks
void partialRefitTree(const btVector3& aabbMin,const btVector3& aabbMax);
//debugging
- virtual char* getName()const {return "BVHTRIANGLEMESH";}
+ virtual const char* getName()const {return "BVHTRIANGLEMESH";}
virtual void setLocalScaling(const btVector3& scaling);
@@ -65,6 +75,10 @@ public:
{
return m_bvh;
}
+
+
+ void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));
+
bool usesQuantizedAabbCompression() const
{
return m_useQuantizedAabbCompression;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp
index b7e15172da2..26ba276b900 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp
@@ -21,6 +21,7 @@ subject to the following restrictions:
btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
{
+ m_upAxis = 1;
m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
}
@@ -50,7 +51,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
{
- btVector3 pos(0,getHalfHeight(),0);
+ btVector3 pos(0,0,0);
+ pos[getUpAxis()] = getHalfHeight();
+
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@@ -60,7 +63,9 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
}
}
{
- btVector3 pos(0,-getHalfHeight(),0);
+ btVector3 pos(0,0,0);
+ pos[getUpAxis()] = -getHalfHeight();
+
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@@ -88,7 +93,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
btVector3 vtx;
btScalar newDot;
{
- btVector3 pos(0,getHalfHeight(),0);
+ btVector3 pos(0,0,0);
+ pos[getUpAxis()] = getHalfHeight();
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@@ -98,7 +104,8 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
}
}
{
- btVector3 pos(0,-getHalfHeight(),0);
+ btVector3 pos(0,0,0);
+ pos[getUpAxis()] = -getHalfHeight();
vtx = pos +vec*m_localScaling*(radius) - vec * getMargin();
newDot = vec.dot(vtx);
if (newDot > maxDot)
@@ -112,7 +119,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height)
}
-void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
//as an approximation, take the inertia of the box that bounds the spheres
@@ -122,7 +129,8 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
btScalar radius = getRadius();
- btVector3 halfExtents(radius,radius+getHalfHeight(),radius);
+ btVector3 halfExtents(radius,radius,radius);
+ halfExtents[getUpAxis()]+=getHalfHeight();
btScalar margin = CONVEX_DISTANCE_MARGIN;
@@ -140,6 +148,22 @@ void btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
}
+btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height)
+{
+ m_upAxis = 0;
+ m_implicitShapeDimensions.setValue(0.5f*height, radius,radius);
+}
+
+
+
+
+
+
+btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height)
+{
+ m_upAxis = 2;
+ m_implicitShapeDimensions.setValue(radius,radius,0.5f*height);
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h
index 27da8adefa5..d4b046d40c9 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h
@@ -16,20 +16,27 @@ subject to the following restrictions:
#ifndef BT_CAPSULE_SHAPE_H
#define BT_CAPSULE_SHAPE_H
-#include "btConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "btConvexInternalShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
-///btCapsuleShape represents a capsule around the Y axis
-///A more general solution that can represent capsules is the btMultiSphereShape
-class btCapsuleShape : public btConvexShape
+///The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned around the X axis and btCapsuleShapeZ around the Z axis.
+///The total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
+///The btCapsuleShape is a convex hull of two spheres. The btMultiSphereShape is a more general collision shape that takes the convex hull of multiple sphere, so it can also represent a capsule when just using two spheres.
+class btCapsuleShape : public btConvexInternalShape
{
+protected:
+ int m_upAxis;
+
+protected:
+ ///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
+ btCapsuleShape() {};
public:
btCapsuleShape(btScalar radius,btScalar height);
///CollisionShape Interface
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
/// btConvexShape Interface
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
@@ -38,21 +45,74 @@ public:
virtual int getShapeType() const { return CAPSULE_SHAPE_PROXYTYPE; }
- virtual char* getName()const
+ virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
+ {
+ btVector3 halfExtents(getRadius(),getRadius(),getRadius());
+ halfExtents[m_upAxis] = getRadius() + getHalfHeight();
+ halfExtents += btVector3(getMargin(),getMargin(),getMargin());
+ btMatrix3x3 abs_b = t.getBasis().absolute();
+ btPoint3 center = t.getOrigin();
+ btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
+
+ aabbMin = center - extent;
+ aabbMax = center + extent;
+ }
+
+ virtual const char* getName()const
{
return "CapsuleShape";
}
+ int getUpAxis() const
+ {
+ return m_upAxis;
+ }
+
btScalar getRadius() const
{
- return m_implicitShapeDimensions.getX();
+ int radiusAxis = (m_upAxis+2)%3;
+ return m_implicitShapeDimensions[radiusAxis];
}
btScalar getHalfHeight() const
{
- return m_implicitShapeDimensions.getY();
+ return m_implicitShapeDimensions[m_upAxis];
+ }
+
+};
+
+///btCapsuleShapeX represents a capsule around the Z axis
+///the total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
+class btCapsuleShapeX : public btCapsuleShape
+{
+public:
+
+ btCapsuleShapeX(btScalar radius,btScalar height);
+
+ //debugging
+ virtual const char* getName()const
+ {
+ return "CapsuleX";
}
+
+
+};
+
+///btCapsuleShapeZ represents a capsule around the Z axis
+///the total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
+class btCapsuleShapeZ : public btCapsuleShape
+{
+public:
+ btCapsuleShapeZ(btScalar radius,btScalar height);
+
+ //debugging
+ virtual const char* getName()const
+ {
+ return "CapsuleZ";
+ }
+
+
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp
index 81d82428f4c..39e621aa946 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp
@@ -21,7 +21,12 @@ subject to the following restrictions:
can be used by probes that are checking whether the
library is actually installed.
*/
-extern "C" void btBulletCollisionProbe () {}
+extern "C"
+{
+void btBulletCollisionProbe ();
+
+void btBulletCollisionProbe () {}
+}
@@ -46,7 +51,7 @@ btScalar btCollisionShape::getAngularMotionDisc() const
return disc;
}
-void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax)
+void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
{
//start with static aabb
getAabb(curTrans,temporalAabbMin,temporalAabbMax);
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h
index 96268734a83..3a352b90777 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h
@@ -16,18 +16,21 @@ subject to the following restrictions:
#ifndef COLLISION_SHAPE_H
#define COLLISION_SHAPE_H
-#include "../../LinearMath/btTransform.h"
-#include "../../LinearMath/btVector3.h"
-#include "../../LinearMath/btMatrix3x3.h"
-#include "../../LinearMath/btPoint3.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btMatrix3x3.h"
+#include "LinearMath/btPoint3.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
-///btCollisionShape provides interface for collision shapes that can be shared among btCollisionObjects.
+///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
class btCollisionShape
{
+
+ void* m_userPointer;
+
public:
- btCollisionShape()
+ btCollisionShape() : m_userPointer(0)
{
}
virtual ~btCollisionShape()
@@ -45,30 +48,30 @@ public:
///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
///result is conservative
- void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax);
+ void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
#ifndef __SPU__
- inline bool isPolyhedral() const
+ SIMD_FORCE_INLINE bool isPolyhedral() const
{
return btBroadphaseProxy::isPolyhedral(getShapeType());
}
- inline bool isConvex() const
+ SIMD_FORCE_INLINE bool isConvex() const
{
return btBroadphaseProxy::isConvex(getShapeType());
}
- inline bool isConcave() const
+ SIMD_FORCE_INLINE bool isConcave() const
{
return btBroadphaseProxy::isConcave(getShapeType());
}
- inline bool isCompound() const
+ SIMD_FORCE_INLINE bool isCompound() const
{
return btBroadphaseProxy::isCompound(getShapeType());
}
///isInfinite is used to catch simulation error (aabb check)
- inline bool isInfinite() const
+ SIMD_FORCE_INLINE bool isInfinite() const
{
return btBroadphaseProxy::isInfinite(getShapeType());
}
@@ -76,11 +79,11 @@ public:
virtual int getShapeType() const=0;
virtual void setLocalScaling(const btVector3& scaling) =0;
virtual const btVector3& getLocalScaling() const =0;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) = 0;
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const = 0;
//debugging support
- virtual char* getName()const =0 ;
+ virtual const char* getName()const =0 ;
#endif //__SPU__
@@ -88,6 +91,18 @@ public:
virtual void setMargin(btScalar margin) = 0;
virtual btScalar getMargin() const = 0;
+
+ ///optional user data pointer
+ void setUserPointer(void* userPtr)
+ {
+ m_userPointer = userPtr;
+ }
+
+ void* getUserPointer() const
+ {
+ return m_userPointer;
+ }
+
};
#endif //COLLISION_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
index a4712b3e925..f08b810eadb 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
@@ -14,29 +14,42 @@ subject to the following restrictions:
*/
#include "btCompoundShape.h"
-
-
#include "btCollisionShape.h"
-
+#include "BulletCollision/BroadphaseCollision/btDbvt.h"
btCompoundShape::btCompoundShape()
:m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
-m_aabbTree(0),
m_collisionMargin(btScalar(0.)),
-m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
+m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
+m_dynamicAabbTree(0)
{
+ void* mem = btAlignedAlloc(sizeof(btDbvt),16);
+ m_dynamicAabbTree = new(mem) btDbvt();
+ btAssert(mem==m_dynamicAabbTree);
}
btCompoundShape::~btCompoundShape()
{
+ if (m_dynamicAabbTree)
+ {
+ m_dynamicAabbTree->~btDbvt();
+ btAlignedFree(m_dynamicAabbTree);
+ }
}
void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
{
- m_childTransforms.push_back(localTransform);
- m_childShapes.push_back(shape);
+ //m_childTransforms.push_back(localTransform);
+ //m_childShapes.push_back(shape);
+ btCompoundShapeChild child;
+ child.m_transform = localTransform;
+ child.m_childShape = shape;
+ child.m_childShapeType = shape->getShapeType();
+ child.m_childMargin = shape->getMargin();
+
+ m_children.push_back(child);
//extend the local aabbMin/aabbMax
btVector3 localAabbMin,localAabbMax;
@@ -53,39 +66,100 @@ void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio
}
}
+ if (m_dynamicAabbTree)
+ {
+ const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
+ int index = m_children.size()-1;
+ child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
+ }
+
+}
+
+void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
+{
+ btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
+ if (m_dynamicAabbTree)
+ {
+ m_dynamicAabbTree->remove(m_children[childShapeIndex].m_node);
+ }
+ m_children.swap(childShapeIndex,m_children.size()-1);
+ m_children.pop_back();
+
+}
+
+void btCompoundShape::removeChildShape(btCollisionShape* shape)
+{
+ // Find the children containing the shape specified, and remove those children.
+ //note: there might be multiple children using the same shape!
+ for(int i = m_children.size()-1; i >= 0 ; i--)
+ {
+ if(m_children[i].m_childShape == shape)
+ {
+ m_children.swap(i,m_children.size()-1);
+ m_children.pop_back();
+ //remove it from the m_dynamicAabbTree too
+ //m_dynamicAabbTree->remove(m_aabbProxies[i]);
+ //m_aabbProxies.swap(i,m_children.size()-1);
+ //m_aabbProxies.pop_back();
+ }
+ }
+
+
+
+ recalculateLocalAabb();
}
+void btCompoundShape::recalculateLocalAabb()
+{
+ // Recalculate the local aabb
+ // Brute force, it iterates over all the shapes left.
+ m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
+ m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
+ //extend the local aabbMin/aabbMax
+ for (int j = 0; j < m_children.size(); j++)
+ {
+ btVector3 localAabbMin,localAabbMax;
+ m_children[j].m_childShape->getAabb(m_children[j].m_transform, localAabbMin, localAabbMax);
+ for (int i=0;i<3;i++)
+ {
+ if (m_localAabbMin[i] > localAabbMin[i])
+ m_localAabbMin[i] = localAabbMin[i];
+ if (m_localAabbMax[i] < localAabbMax[i])
+ m_localAabbMax[i] = localAabbMax[i];
+ }
+ }
+}
- ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
+///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
{
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
+ localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
-
+
btMatrix3x3 abs_b = trans.getBasis().absolute();
btPoint3 center = trans(localCenter);
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
- abs_b[1].dot(localHalfExtents),
- abs_b[2].dot(localHalfExtents));
- extent += btVector3(getMargin(),getMargin(),getMargin());
+ abs_b[1].dot(localHalfExtents),
+ abs_b[2].dot(localHalfExtents));
+ aabbMin = center-extent;
+ aabbMax = center+extent;
- aabbMin = center - extent;
- aabbMax = center + extent;
}
-void btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
//approximation: take the inertia from the aabb for now
btTransform ident;
ident.setIdentity();
btVector3 aabbMin,aabbMax;
getAabb(ident,aabbMin,aabbMax);
-
+
btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
-
+
btScalar lx=btScalar(2.)*(halfExtents.x());
btScalar ly=btScalar(2.)*(halfExtents.y());
btScalar lz=btScalar(2.)*(halfExtents.z());
@@ -96,5 +170,62 @@ void btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
}
-
-
+
+
+
+void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const
+{
+ int n = m_children.size();
+
+ btScalar totalMass = 0;
+ btVector3 center(0, 0, 0);
+ for (int k = 0; k < n; k++)
+ {
+ center += m_children[k].m_transform.getOrigin() * masses[k];
+ totalMass += masses[k];
+ }
+ center /= totalMass;
+ principal.setOrigin(center);
+
+ btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
+ for (int k = 0; k < n; k++)
+ {
+ btVector3 i;
+ m_children[k].m_childShape->calculateLocalInertia(masses[k], i);
+
+ const btTransform& t = m_children[k].m_transform;
+ btVector3 o = t.getOrigin() - center;
+
+ //compute inertia tensor in coordinate system of compound shape
+ btMatrix3x3 j = t.getBasis().transpose();
+ j[0] *= i[0];
+ j[1] *= i[1];
+ j[2] *= i[2];
+ j = t.getBasis() * j;
+
+ //add inertia tensor
+ tensor[0] += j[0];
+ tensor[1] += j[1];
+ tensor[2] += j[2];
+
+ //compute inertia tensor of pointmass at o
+ btScalar o2 = o.length2();
+ j[0].setValue(o2, 0, 0);
+ j[1].setValue(0, o2, 0);
+ j[2].setValue(0, 0, o2);
+ j[0] += o * -o.x();
+ j[1] += o * -o.y();
+ j[2] += o * -o.z();
+
+ //add inertia tensor of pointmass
+ tensor[0] += masses[k] * j[0];
+ tensor[1] += masses[k] * j[1];
+ tensor[2] += masses[k] * j[2];
+ }
+
+ tensor.diagonalize(principal.getBasis(), btScalar(0.00001), 20);
+ inertia.setValue(tensor[0][0], tensor[1][1], tensor[2][2]);
+}
+
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
index 86dc1f80947..3624749f768 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
@@ -18,58 +18,97 @@ subject to the following restrictions:
#include "btCollisionShape.h"
-#include "../../LinearMath/btVector3.h"
-#include "../../LinearMath/btTransform.h"
-#include "../../LinearMath/btMatrix3x3.h"
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btMatrix3x3.h"
#include "btCollisionMargin.h"
-#include "../../LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btAlignedObjectArray.h"
-class btOptimizedBvh;
+//class btOptimizedBvh;
+struct btDbvt;
+
+ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
+{
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
+ btTransform m_transform;
+ btCollisionShape* m_childShape;
+ int m_childShapeType;
+ btScalar m_childMargin;
+ struct btDbvtNode* m_node;
+};
+
+SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
+{
+ return ( c1.m_transform == c2.m_transform &&
+ c1.m_childShape == c2.m_childShape &&
+ c1.m_childShapeType == c2.m_childShapeType &&
+ c1.m_childMargin == c2.m_childMargin );
+}
/// btCompoundShape allows to store multiple other btCollisionShapes
-/// This allows for concave collision objects. This is more general then the Static Concave btTriangleMeshShape.
-class btCompoundShape : public btCollisionShape
+/// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
+ATTRIBUTE_ALIGNED16(class) btCompoundShape : public btCollisionShape
{
- btAlignedObjectArray<btTransform> m_childTransforms;
- btAlignedObjectArray<btCollisionShape*> m_childShapes;
+ //btAlignedObjectArray<btTransform> m_childTransforms;
+ //btAlignedObjectArray<btCollisionShape*> m_childShapes;
+ btAlignedObjectArray<btCompoundShapeChild> m_children;
btVector3 m_localAabbMin;
btVector3 m_localAabbMax;
- btOptimizedBvh* m_aabbTree;
+ //btOptimizedBvh* m_aabbTree;
+ btDbvt* m_dynamicAabbTree;
public:
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
btCompoundShape();
virtual ~btCompoundShape();
void addChildShape(const btTransform& localTransform,btCollisionShape* shape);
+ /// Remove all children shapes that contain the specified shape
+ virtual void removeChildShape(btCollisionShape* shape);
+
+ void removeChildShapeByIndex(int childShapeindex);
+
+
int getNumChildShapes() const
{
- return int (m_childShapes.size());
+ return int (m_children.size());
}
btCollisionShape* getChildShape(int index)
{
- return m_childShapes[index];
+ return m_children[index].m_childShape;
}
const btCollisionShape* getChildShape(int index) const
{
- return m_childShapes[index];
+ return m_children[index].m_childShape;
}
- btTransform& getChildTransform(int index)
+ btTransform getChildTransform(int index)
+ {
+ return m_children[index].m_transform;
+ }
+ const btTransform getChildTransform(int index) const
{
- return m_childTransforms[index];
+ return m_children[index].m_transform;
}
- const btTransform& getChildTransform(int index) const
+
+
+ btCompoundShapeChild* getChildList()
{
- return m_childTransforms[index];
+ return &m_children[0];
}
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
- void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+ virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+ /** Re-calculate the local Aabb. Is called at the end of removeChildShapes.
+ Use this yourself if you modify the children or their transforms. */
+ virtual void recalculateLocalAabb();
virtual void setLocalScaling(const btVector3& scaling)
{
@@ -80,8 +119,8 @@ public:
return m_localScaling;
}
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
-
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
+
virtual int getShapeType() const { return COMPOUND_SHAPE_PROXYTYPE;}
virtual void setMargin(btScalar margin)
@@ -92,7 +131,7 @@ public:
{
return m_collisionMargin;
}
- virtual char* getName()const
+ virtual const char* getName()const
{
return "Compound";
}
@@ -100,11 +139,19 @@ public:
//this is optional, but should make collision queries faster, by culling non-overlapping nodes
void createAabbTreeFromChildren();
- const btOptimizedBvh* getAabbTree() const
+ btDbvt* getDynamicAabbTree()
{
- return m_aabbTree;
+ return m_dynamicAabbTree;
}
+ ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
+ ///and the center of mass to the current coordinate system. "masses" points to an array of masses of the children. The resulting transform
+ ///"principal" has to be applied inversely to all children transforms in order for the local coordinate system of the compound
+ ///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
+ ///of the collision object by the principal transform.
+ void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
+
+
private:
btScalar m_collisionMargin;
protected:
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h
index 73f974e4ee9..f3f57206ab7 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h
@@ -17,12 +17,12 @@ subject to the following restrictions:
#define CONCAVE_SHAPE_H
#include "btCollisionShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
#include "btTriangleCallback.h"
-///Concave shape proves an interface concave shapes that can produce triangles that overlapping a given AABB.
-///Static triangle mesh, infinite plane, height field/landscapes are example that implement this interface.
+///The btConcaveShape class provides an interface for non-moving (static) concave shapes.
+///It has been implemented by the btStaticPlaneShape, btBvhTriangleMeshShape and btHeightfieldTerrainShape.
class btConcaveShape : public btCollisionShape
{
protected:
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h
index 3ccda5b12c6..685369742e4 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h
@@ -16,11 +16,11 @@ subject to the following restrictions:
#ifndef CONE_MINKOWSKI_H
#define CONE_MINKOWSKI_H
-#include "btConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "btConvexInternalShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
-///btConeShape implements a Cone shape, around the Y axis
-class btConeShape : public btConvexShape
+///The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y axis. The btConeShapeX is aligned around the X axis and btConeShapeZ around the Z axis.
+class btConeShape : public btConvexInternalShape
{
@@ -42,7 +42,7 @@ public:
btScalar getHeight() const { return m_height;}
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia)
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
btTransform identity;
identity.setIdentity();
@@ -72,7 +72,7 @@ public:
virtual int getShapeType() const { return CONE_SHAPE_PROXYTYPE; }
- virtual char* getName()const
+ virtual const char* getName()const
{
return "Cone";
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h
index 3fd5e382525..c029ca19403 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h
@@ -17,18 +17,17 @@ subject to the following restrictions:
#define CONVEX_HULL_SHAPE_H
#include "btPolyhedralConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
-#include "../../LinearMath/btAlignedObjectArray.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "LinearMath/btAlignedObjectArray.h"
-///ConvexHullShape implements an implicit (getSupportingVertex) Convex Hull of a Point Cloud (vertices)
-///No connectivity is needed. localGetSupportingVertex iterates linearly though all vertices.
-///on modern hardware, due to cache coherency this isn't that bad. Complex algorithms tend to trash the cash.
-///(memory is much slower then the cpu)
+///The btConvexHullShape implements an implicit convex hull of an array of vertices.
+///Bullet provides a general and fast collision detector for convex shapes based on GJK and EPA using localGetSupportingVertex.
ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
{
btAlignedObjectArray<btPoint3> m_points;
public:
+ BT_DECLARE_ALIGNED_ALLOCATOR();
///this constructor optionally takes in a pointer to points. Each point is assumed to be 3 consecutive btScalar (x,y,z), the striding defines the number of bytes between each point, in memory.
@@ -43,7 +42,12 @@ public:
return &m_points[0];
}
- int getNumPoints()
+ const btPoint3* getPoints() const
+ {
+ return &m_points[0];
+ }
+
+ int getNumPoints() const
{
return m_points.size();
}
@@ -56,7 +60,7 @@ public:
virtual int getShapeType()const { return CONVEX_HULL_SHAPE_PROXYTYPE; }
//debugging
- virtual char* getName()const {return "Convex";}
+ virtual const char* getName()const {return "Convex";}
virtual int getNumVertices() const;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
new file mode 100644
index 00000000000..f828d28e18c
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
@@ -0,0 +1,78 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+#include "btConvexInternalShape.h"
+
+
+btConvexInternalShape::btConvexInternalShape()
+: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
+m_collisionMargin(CONVEX_DISTANCE_MARGIN)
+{
+}
+
+
+void btConvexInternalShape::setLocalScaling(const btVector3& scaling)
+{
+ m_localScaling = scaling;
+}
+
+
+
+void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const
+{
+
+ btScalar margin = getMargin();
+ for (int i=0;i<3;i++)
+ {
+ btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
+ vec[i] = btScalar(1.);
+
+ btVector3 sv = localGetSupportingVertex(vec*trans.getBasis());
+
+ btVector3 tmp = trans(sv);
+ maxAabb[i] = tmp[i]+margin;
+ vec[i] = btScalar(-1.);
+ tmp = trans(localGetSupportingVertex(vec*trans.getBasis()));
+ minAabb[i] = tmp[i]-margin;
+ }
+};
+
+
+btVector3 btConvexInternalShape::localGetSupportingVertex(const btVector3& vec)const
+{
+#ifndef __SPU__
+
+ btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
+
+ if ( getMargin()!=btScalar(0.) )
+ {
+ btVector3 vecnorm = vec;
+ if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+ {
+ vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
+ }
+ vecnorm.normalize();
+ supVertex+= getMargin() * vecnorm;
+ }
+ return supVertex;
+
+#else
+ return btVector3(0,0,0);
+#endif //__SPU__
+
+ }
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h
new file mode 100644
index 00000000000..9388ccf31f2
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h
@@ -0,0 +1,98 @@
+
+#ifndef BT_CONVEX_INTERNAL_SHAPE_H
+#define BT_CONVEX_INTERNAL_SHAPE_H
+
+#include "btConvexShape.h"
+
+///The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
+class btConvexInternalShape : public btConvexShape
+{
+
+ protected:
+
+ //local scaling. collisionMargin is not scaled !
+ btVector3 m_localScaling;
+
+ btVector3 m_implicitShapeDimensions;
+
+ btScalar m_collisionMargin;
+
+ btScalar m_padding;
+
+public:
+
+ btConvexInternalShape();
+
+ virtual ~btConvexInternalShape()
+ {
+
+ }
+
+
+ virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
+#ifndef __SPU__
+ virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
+
+ //notice that the vectors should be unit length
+ virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
+#endif //#ifndef __SPU__
+
+ const btVector3& getImplicitShapeDimensions() const
+ {
+ return m_implicitShapeDimensions;
+ }
+
+ ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
+ void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+ {
+ getAabbSlow(t,aabbMin,aabbMax);
+ }
+
+
+
+ virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+
+
+ virtual void setLocalScaling(const btVector3& scaling);
+ virtual const btVector3& getLocalScaling() const
+ {
+ return m_localScaling;
+ }
+
+ const btVector3& getLocalScalingNV() const
+ {
+ return m_localScaling;
+ }
+
+ virtual void setMargin(btScalar margin)
+ {
+ m_collisionMargin = margin;
+ }
+ virtual btScalar getMargin() const
+ {
+ return m_collisionMargin;
+ }
+
+ btScalar getMarginNV() const
+ {
+ return m_collisionMargin;
+ }
+
+ virtual int getNumPreferredPenetrationDirections() const
+ {
+ return 0;
+ }
+
+ virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
+ {
+ (void)penetrationVector;
+ (void)index;
+ btAssert(0);
+ }
+
+
+
+};
+
+
+#endif //BT_CONVEX_INTERNAL_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
index 7edf1ea6db8..7afcccf8b03 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
@@ -16,62 +16,3 @@ subject to the following restrictions:
#include "btConvexShape.h"
-btConvexShape::btConvexShape()
-: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
-m_collisionMargin(CONVEX_DISTANCE_MARGIN)
-{
-}
-
-
-void btConvexShape::setLocalScaling(const btVector3& scaling)
-{
- m_localScaling = scaling;
-}
-
-
-
-void btConvexShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const
-{
-
- btScalar margin = getMargin();
- for (int i=0;i<3;i++)
- {
- btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
- vec[i] = btScalar(1.);
-
- btVector3 sv = localGetSupportingVertex(vec*trans.getBasis());
-
- btVector3 tmp = trans(sv);
- maxAabb[i] = tmp[i]+margin;
- vec[i] = btScalar(-1.);
- tmp = trans(localGetSupportingVertex(vec*trans.getBasis()));
- minAabb[i] = tmp[i]-margin;
- }
-};
-
-
-btVector3 btConvexShape::localGetSupportingVertex(const btVector3& vec)const
-{
-#ifndef __SPU__
-
- btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
-
- if ( getMargin()!=btScalar(0.) )
- {
- btVector3 vecnorm = vec;
- if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
- {
- vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
- }
- vecnorm.normalize();
- supVertex+= getMargin() * vecnorm;
- }
- return supVertex;
-
-#else
- return btVector3(0,0,0);
-#endif //__SPU__
-
- }
-
-
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h
index 746f383dfc7..e4eb7f6dbf6 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h
@@ -18,37 +18,25 @@ subject to the following restrictions:
#include "btCollisionShape.h"
-#include "../../LinearMath/btVector3.h"
-#include "../../LinearMath/btTransform.h"
-#include "../../LinearMath/btMatrix3x3.h"
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btMatrix3x3.h"
#include "btCollisionMargin.h"
+#include "LinearMath/btAlignedAllocator.h"
//todo: get rid of this btConvexCastResult thing!
struct btConvexCastResult;
#define MAX_PREFERRED_PENETRATION_DIRECTIONS 10
-/// btConvexShape is an abstract shape interface.
-/// The explicit part provides plane-equations, the implicit part provides GetClosestPoint interface.
-/// used in combination with GJK or btConvexCast
+/// The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape, btConvexHullShape etc.
+/// It describes general convex shapes using the localGetSupportingVertex interface, used by collision detectors such as btGjkPairDetector.
ATTRIBUTE_ALIGNED16(class) btConvexShape : public btCollisionShape
{
-protected:
-
- //local scaling. collisionMargin is not scaled !
- btVector3 m_localScaling;
-
- btVector3 m_implicitShapeDimensions;
-
- btScalar m_collisionMargin;
-
- btScalar m_padding[2];
-
-
-
public:
- btConvexShape();
+
+ BT_DECLARE_ALIGNED_ALLOCATOR();
virtual ~btConvexShape()
{
@@ -56,7 +44,7 @@ public:
}
- virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
+ virtual btVector3 localGetSupportingVertex(const btVector3& vec)const =0;
#ifndef __SPU__
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
@@ -64,63 +52,24 @@ public:
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
#endif //#ifndef __SPU__
- const btVector3& getImplicitShapeDimensions() const
- {
- return m_implicitShapeDimensions;
- }
///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
- void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
- {
- getAabbSlow(t,aabbMin,aabbMax);
- }
-
-
-
- virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
-
+ void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
- virtual void setLocalScaling(const btVector3& scaling);
- virtual const btVector3& getLocalScaling() const
- {
- return m_localScaling;
- }
+ virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
- const btVector3& getLocalScalingNV() const
- {
- return m_localScaling;
- }
+ virtual void setLocalScaling(const btVector3& scaling) =0;
+ virtual const btVector3& getLocalScaling() const =0;
- virtual void setMargin(btScalar margin)
- {
- m_collisionMargin = margin;
- }
- virtual btScalar getMargin() const
- {
- return m_collisionMargin;
- }
+ virtual void setMargin(btScalar margin)=0;
- btScalar getMarginNV() const
- {
- return m_collisionMargin;
- }
+ virtual btScalar getMargin() const=0;
- virtual int getNumPreferredPenetrationDirections() const
- {
- return 0;
- }
+ virtual int getNumPreferredPenetrationDirections() const=0;
- virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
- {
- (void)penetrationVector;
- (void)index;
- btAssert(0);
- }
-
-
+ virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0;
-}
-;
+};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
index 6941030b15f..02a293e82ba 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
@@ -19,10 +19,11 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
-btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface)
+btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface, bool calcAabb)
:m_stridingMesh(meshInterface)
{
- recalcLocalAabb();
+ if ( calcAabb )
+ recalcLocalAabb();
}
@@ -203,3 +204,113 @@ const btVector3& btConvexTriangleMeshShape::getLocalScaling() const
{
return m_stridingMesh->getScaling();
}
+
+void btConvexTriangleMeshShape::calculatePrincipalAxisTransform(btTransform& principal, btVector3& inertia, btScalar& volume) const
+{
+ class CenterCallback: public btInternalTriangleIndexCallback
+ {
+ bool first;
+ btVector3 ref;
+ btVector3 sum;
+ btScalar volume;
+
+ public:
+
+ CenterCallback() : first(true), ref(0, 0, 0), sum(0, 0, 0), volume(0)
+ {
+ }
+
+ virtual void internalProcessTriangleIndex(btVector3* triangle, int partId, int triangleIndex)
+ {
+ (void) triangleIndex;
+ (void) partId;
+ if (first)
+ {
+ ref = triangle[0];
+ first = false;
+ }
+ else
+ {
+ btScalar vol = btFabs((triangle[0] - ref).triple(triangle[1] - ref, triangle[2] - ref));
+ sum += (btScalar(0.25) * vol) * ((triangle[0] + triangle[1] + triangle[2] + ref));
+ volume += vol;
+ }
+ }
+
+ btVector3 getCenter()
+ {
+ return (volume > 0) ? sum / volume : ref;
+ }
+
+ btScalar getVolume()
+ {
+ return volume * btScalar(1. / 6);
+ }
+
+ };
+
+ class InertiaCallback: public btInternalTriangleIndexCallback
+ {
+ btMatrix3x3 sum;
+ btVector3 center;
+
+ public:
+
+ InertiaCallback(btVector3& center) : sum(0, 0, 0, 0, 0, 0, 0, 0, 0), center(center)
+ {
+ }
+
+ virtual void internalProcessTriangleIndex(btVector3* triangle, int partId, int triangleIndex)
+ {
+ (void) triangleIndex;
+ (void) partId;
+ btMatrix3x3 i;
+ btVector3 a = triangle[0] - center;
+ btVector3 b = triangle[1] - center;
+ btVector3 c = triangle[2] - center;
+ btVector3 abc = a + b + c;
+ btScalar volNeg = -btFabs(a.triple(b, c)) * btScalar(1. / 6);
+ for (int j = 0; j < 3; j++)
+ {
+ for (int k = 0; k <= j; k++)
+ {
+ i[j][k] = i[k][j] = volNeg * (center[j] * center[k]
+ + btScalar(0.25) * (center[j] * abc[k] + center[k] * abc[j])
+ + btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k])
+ + 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]));
+ }
+ }
+ btScalar i00 = -i[0][0];
+ btScalar i11 = -i[1][1];
+ btScalar i22 = -i[2][2];
+ i[0][0] = i11 + i22;
+ i[1][1] = i22 + i00;
+ i[2][2] = i00 + i11;
+ sum[0] += i[0];
+ sum[1] += i[1];
+ sum[2] += i[2];
+ }
+
+ btMatrix3x3& getInertia()
+ {
+ return sum;
+ }
+
+ };
+
+ CenterCallback centerCallback;
+ btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
+ m_stridingMesh->InternalProcessAllTriangles(&centerCallback, -aabbMax, aabbMax);
+ btVector3 center = centerCallback.getCenter();
+ principal.setOrigin(center);
+ volume = centerCallback.getVolume();
+
+ InertiaCallback inertiaCallback(center);
+ m_stridingMesh->InternalProcessAllTriangles(&inertiaCallback, -aabbMax, aabbMax);
+
+ btMatrix3x3& i = inertiaCallback.getInertia();
+ i.diagonalize(principal.getBasis(), btScalar(0.00001), 20);
+ inertia.setValue(i[0][0], i[1][1], i[2][2]);
+ inertia /= volume;
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
index 34ee7af744c..6ff0bf5d43b 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
@@ -3,20 +3,24 @@
#include "btPolyhedralConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
-/// btConvexTriangleMeshShape is a convex hull of a triangle mesh. If you just have a point cloud, you can use btConvexHullShape instead.
-/// It uses the btStridingMeshInterface instead of a point cloud. This can avoid the duplication of the triangle mesh data.
+/// The btConvexTriangleMeshShape is a convex hull of a triangle mesh, but the performance is not as good as btConvexHullShape.
+/// A small benefit of this class is that it uses the btStridingMeshInterface, so you can avoid the duplication of the triangle mesh data. Nevertheless, most users should use the much better performing btConvexHullShape instead.
class btConvexTriangleMeshShape : public btPolyhedralConvexShape
{
class btStridingMeshInterface* m_stridingMesh;
public:
- btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface);
+ btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface, bool calcAabb = true);
- class btStridingMeshInterface* getStridingMesh()
+ class btStridingMeshInterface* getMeshInterface()
+ {
+ return m_stridingMesh;
+ }
+ const class btStridingMeshInterface* getMeshInterface() const
{
return m_stridingMesh;
}
@@ -28,7 +32,7 @@ public:
virtual int getShapeType()const { return CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE; }
//debugging
- virtual char* getName()const {return "ConvexTrimesh";}
+ virtual const char* getName()const {return "ConvexTrimesh";}
virtual int getNumVertices() const;
virtual int getNumEdges() const;
@@ -42,6 +46,13 @@ public:
virtual void setLocalScaling(const btVector3& scaling);
virtual const btVector3& getLocalScaling() const;
+ ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
+ ///and the center of mass to the current coordinate system. A mass of 1 is assumed, for other masses just multiply the computed "inertia"
+ ///by the mass. The resulting transform "principal" has to be applied inversely to the mesh in order for the local coordinate system of the
+ ///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
+ ///of the collision object by the principal transform. This method also computes the volume of the convex mesh.
+ void calculatePrincipalAxisTransform(btTransform& principal, btVector3& inertia, btScalar& volume) const;
+
};
@@ -49,3 +60,4 @@ public:
#endif //CONVEX_TRIANGLEMESH_SHAPE_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp
index 1666afb3b88..3afef1c7550 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp
@@ -45,7 +45,7 @@ void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3&
}
-inline btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v)
+SIMD_FORCE_INLINE btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v)
{
const int cylinderUpAxis = 0;
const int XX = 1;
@@ -163,24 +163,24 @@ const int ZZ = 1;
btVector3 btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
{
- return CylinderLocalSupportX(getHalfExtents(),vec);
+ return CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vec);
}
btVector3 btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
{
- return CylinderLocalSupportZ(getHalfExtents(),vec);
+ return CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vec);
}
btVector3 btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
{
- return CylinderLocalSupportY(getHalfExtents(),vec);
+ return CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vec);
}
void btCylinderShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
{
for (int i=0;i<numVectors;i++)
{
- supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtents(),vectors[i]);
+ supportVerticesOut[i] = CylinderLocalSupportY(getHalfExtentsWithoutMargin(),vectors[i]);
}
}
@@ -188,7 +188,7 @@ void btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const b
{
for (int i=0;i<numVectors;i++)
{
- supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtents(),vectors[i]);
+ supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtentsWithoutMargin(),vectors[i]);
}
}
@@ -199,7 +199,7 @@ void btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const b
{
for (int i=0;i<numVectors;i++)
{
- supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtents(),vectors[i]);
+ supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtentsWithoutMargin(),vectors[i]);
}
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h
index c78890c887a..30938acf7c7 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h
@@ -17,10 +17,10 @@ subject to the following restrictions:
#define CYLINDER_MINKOWSKI_H
#include "btBoxShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
-#include "../../LinearMath/btVector3.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "LinearMath/btVector3.h"
-/// implements cylinder shape interface
+/// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis.
class btCylinderShape : public btBoxShape
{
@@ -60,7 +60,7 @@ public:
//use box inertia
- // virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ // virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual int getShapeType() const
{
@@ -74,11 +74,11 @@ public:
virtual btScalar getRadius() const
{
- return getHalfExtents().getX();
+ return getHalfExtentsWithMargin().getX();
}
//debugging
- virtual char* getName()const
+ virtual const char* getName()const
{
return "CylinderY";
}
@@ -96,14 +96,14 @@ public:
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
//debugging
- virtual char* getName()const
+ virtual const char* getName()const
{
return "CylinderX";
}
virtual btScalar getRadius() const
{
- return getHalfExtents().getY();
+ return getHalfExtentsWithMargin().getY();
}
};
@@ -121,14 +121,14 @@ public:
return 2;
}
//debugging
- virtual char* getName()const
+ virtual const char* getName()const
{
return "CylinderZ";
}
virtual btScalar getRadius() const
{
- return getHalfExtents().getX();
+ return getHalfExtentsWithMargin().getX();
}
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.cpp
index dcc486f194b..6954aad7917 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.cpp
@@ -40,7 +40,7 @@ void btEmptyShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aa
}
-void btEmptyShape::calculateLocalInertia(btScalar ,btVector3& )
+void btEmptyShape::calculateLocalInertia(btScalar ,btVector3& ) const
{
btAssert(0);
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h
index 8ec53444976..d7d78407b61 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h
@@ -18,16 +18,16 @@ subject to the following restrictions:
#include "btConcaveShape.h"
-#include "../../LinearMath/btVector3.h"
-#include "../../LinearMath/btTransform.h"
-#include "../../LinearMath/btMatrix3x3.h"
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btMatrix3x3.h"
#include "btCollisionMargin.h"
-/// btEmptyShape is a collision shape without actual collision detection.
-///It can be replaced by another shape during runtime
+/// The btEmptyShape is a collision shape without actual collision detection shape, so most users should ignore this class.
+/// It can be replaced by another shape during runtime, but the inertia tensor should be recomputed.
class btEmptyShape : public btConcaveShape
{
public:
@@ -49,12 +49,12 @@ public:
return m_localScaling;
}
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual int getShapeType() const { return EMPTY_SHAPE_PROXYTYPE;}
- virtual char* getName()const
+ virtual const char* getName()const
{
return "Empty";
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
index 94be43c88e2..a291d6b7ce7 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
@@ -18,16 +18,18 @@ subject to the following restrictions:
#include "LinearMath/btTransformUtil.h"
-btHeightfieldTerrainShape::btHeightfieldTerrainShape(int width,int length,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
-:m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
-m_width(width),
-m_length(length),
-m_heightfieldDataUnknown(heightfieldData),
+btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
+: m_heightStickWidth(heightStickWidth),
+m_heightStickLength(heightStickLength),
m_maxHeight(maxHeight),
-m_upAxis(upAxis),
+m_width((btScalar)heightStickWidth-1),
+m_length((btScalar)heightStickLength-1),
+m_heightfieldDataUnknown(heightfieldData),
m_useFloatData(useFloatData),
m_flipQuadEdges(flipQuadEdges),
-m_useDiamondSubdivision(false)
+m_useDiamondSubdivision(false),
+m_upAxis(upAxis),
+m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
{
@@ -43,25 +45,25 @@ m_useDiamondSubdivision(false)
case 0:
{
halfExtents.setValue(
- m_maxHeight,
- m_width,
- m_length);
+ btScalar(m_maxHeight),
+ btScalar(m_width), //?? don't know if this should change
+ btScalar(m_length));
break;
}
case 1:
{
halfExtents.setValue(
- m_width,
- m_maxHeight,
- m_length);
+ btScalar(m_width),
+ btScalar(m_maxHeight),
+ btScalar(m_length));
break;
};
case 2:
{
halfExtents.setValue(
- m_width,
- m_length,
- m_maxHeight
+ btScalar(m_width),
+ btScalar(m_length),
+ btScalar(m_maxHeight)
);
break;
}
@@ -89,19 +91,15 @@ btHeightfieldTerrainShape::~btHeightfieldTerrainShape()
void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
{
-/*
- aabbMin.setValue(-1e30f,-1e30f,-1e30f);
- aabbMax.setValue(1e30f,1e30f,1e30f);
-*/
-
btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5);
+ halfExtents += btVector3(getMargin(),getMargin(),getMargin());
btMatrix3x3 abs_b = t.getBasis().absolute();
btPoint3 center = t.getOrigin();
btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
abs_b[1].dot(halfExtents),
abs_b[2].dot(halfExtents));
- extent += btVector3(getMargin(),getMargin(),getMargin());
+
aabbMin = center - extent;
aabbMax = center + extent;
@@ -114,11 +112,11 @@ btScalar btHeightfieldTerrainShape::getHeightFieldValue(int x,int y) const
btScalar val = 0.f;
if (m_useFloatData)
{
- val = m_heightfieldDataFloat[(y*m_width)+x];
+ val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x];
} else
{
//assume unsigned short int
- unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_width)+x];
+ unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x];
val = heightFieldValue* (m_maxHeight/btScalar(65535));
}
return val;
@@ -133,8 +131,8 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
btAssert(x>=0);
btAssert(y>=0);
- btAssert(x<m_width);
- btAssert(y<m_length);
+ btAssert(x<m_heightStickWidth);
+ btAssert(y<m_heightStickLength);
btScalar height = getHeightFieldValue(x,y);
@@ -145,25 +143,25 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
{
vertex.setValue(
height,
- (-m_width/2 ) + x,
- (-m_length/2 ) + y
+ (-m_width/btScalar(2.0)) + x,
+ (-m_length/btScalar(2.0) ) + y
);
break;
}
case 1:
{
vertex.setValue(
- (-m_width/2 ) + x,
+ (-m_width/btScalar(2.0)) + x,
height,
- (-m_length/2 ) + y
+ (-m_length/btScalar(2.0)) + y
);
break;
};
case 2:
{
vertex.setValue(
- (-m_width/2 ) + x,
- (-m_length/2 ) + y,
+ (-m_width/btScalar(2.0)) + x,
+ (-m_length/btScalar(2.0)) + y,
height
);
break;
@@ -180,21 +178,20 @@ void btHeightfieldTerrainShape::getVertex(int x,int y,btVector3& vertex) const
}
-void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point) const
+void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point,int /*isMax*/) const
{
-
-
btVector3 clampedPoint(point);
clampedPoint.setMax(m_localAabbMin);
clampedPoint.setMin(m_localAabbMax);
- btVector3 v = (clampedPoint );// * m_quantization;
-
- out[0] = (int)(v.getX());
- out[1] = (int)(v.getY());
- out[2] = (int)(v.getZ());
- //correct for
+ btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;
+ //TODO: optimization: check out how to removed this btFabs
+
+ out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) );
+ out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) );
+ out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) );
+
}
@@ -212,24 +209,24 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
btVector3 localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
btVector3 localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
- quantizeWithClamp(quantizedAabbMin, localAabbMin);
- quantizeWithClamp(quantizedAabbMax, localAabbMax);
+ quantizeWithClamp(quantizedAabbMin, localAabbMin,0);
+ quantizeWithClamp(quantizedAabbMax, localAabbMax,1);
int startX=0;
- int endX=m_width-1;
+ int endX=m_heightStickWidth-1;
int startJ=0;
- int endJ=m_length-1;
+ int endJ=m_heightStickLength-1;
switch (m_upAxis)
{
case 0:
{
- quantizedAabbMin[1]+=m_width/2-1;
- quantizedAabbMax[1]+=m_width/2+1;
- quantizedAabbMin[2]+=m_length/2-1;
- quantizedAabbMax[2]+=m_length/2+1;
+ quantizedAabbMin[1]+=m_heightStickWidth/2-1;
+ quantizedAabbMax[1]+=m_heightStickWidth/2+1;
+ quantizedAabbMin[2]+=m_heightStickLength/2-1;
+ quantizedAabbMax[2]+=m_heightStickLength/2+1;
if (quantizedAabbMin[1]>startX)
startX = quantizedAabbMin[1];
@@ -243,10 +240,10 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
}
case 1:
{
- quantizedAabbMin[0]+=m_width/2-1;
- quantizedAabbMax[0]+=m_width/2+1;
- quantizedAabbMin[2]+=m_length/2-1;
- quantizedAabbMax[2]+=m_length/2+1;
+ quantizedAabbMin[0]+=m_heightStickWidth/2-1;
+ quantizedAabbMax[0]+=m_heightStickWidth/2+1;
+ quantizedAabbMin[2]+=m_heightStickLength/2-1;
+ quantizedAabbMax[2]+=m_heightStickLength/2+1;
if (quantizedAabbMin[0]>startX)
startX = quantizedAabbMin[0];
@@ -260,10 +257,10 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
};
case 2:
{
- quantizedAabbMin[0]+=m_width/2-1;
- quantizedAabbMax[0]+=m_width/2+1;
- quantizedAabbMin[1]+=m_length/2-1;
- quantizedAabbMax[1]+=m_length/2+1;
+ quantizedAabbMin[0]+=m_heightStickWidth/2-1;
+ quantizedAabbMax[0]+=m_heightStickWidth/2+1;
+ quantizedAabbMin[1]+=m_heightStickLength/2-1;
+ quantizedAabbMax[1]+=m_heightStickLength/2+1;
if (quantizedAabbMin[0]>startX)
startX = quantizedAabbMin[0];
@@ -290,7 +287,7 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
for(int x=startX; x<endX; x++)
{
btVector3 vertices[3];
- if (m_flipQuadEdges || (m_useDiamondSubdivision && ((j+x) & 1)))
+ if (m_flipQuadEdges || (m_useDiamondSubdivision && !((j+x) & 1)))
{
//first triangle
getVertex(x,j,vertices[0]);
@@ -322,7 +319,7 @@ void btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
}
-void btHeightfieldTerrainShape::calculateLocalInertia(btScalar ,btVector3& inertia)
+void btHeightfieldTerrainShape::calculateLocalInertia(btScalar ,btVector3& inertia) const
{
//moving concave objects not supported
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
index 49f3e106733..d6890fe6b97 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
@@ -18,7 +18,8 @@ subject to the following restrictions:
#include "btConcaveShape.h"
-///btHeightfieldTerrainShape simulates a 2D heightfield terrain
+///The btHeightfieldTerrainShape simulates a 2D heightfield terrain collision shape. You can also use the more general btBvhTriangleMeshShape instead.
+///An example implementation of btHeightfieldTerrainShape is provided in Demos/VehicleDemo/VehicleDemo.cpp
class btHeightfieldTerrainShape : public btConcaveShape
{
protected:
@@ -26,9 +27,11 @@ protected:
btVector3 m_localAabbMax;
///terrain data
- int m_width;
- int m_length;
+ int m_heightStickWidth;
+ int m_heightStickLength;
btScalar m_maxHeight;
+ btScalar m_width;
+ btScalar m_length;
union
{
unsigned char* m_heightfieldDataUnsignedChar;
@@ -45,7 +48,7 @@ protected:
btVector3 m_localScaling;
virtual btScalar getHeightFieldValue(int x,int y) const;
- void quantizeWithClamp(int* out, const btVector3& point) const;
+ void quantizeWithClamp(int* out, const btVector3& point,int isMax) const;
void getVertex(int x,int y,btVector3& vertex) const;
inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const int* aabbMin2,const int* aabbMax2) const
@@ -58,7 +61,7 @@ protected:
}
public:
- btHeightfieldTerrainShape(int width,int height,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
+ btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
virtual ~btHeightfieldTerrainShape();
@@ -74,14 +77,14 @@ public:
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual void setLocalScaling(const btVector3& scaling);
virtual const btVector3& getLocalScaling() const;
//debugging
- virtual char* getName()const {return "HEIGHTFIELD";}
+ virtual const char* getName()const {return "HEIGHTFIELD";}
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h
new file mode 100644
index 00000000000..7cb6d5ab6fe
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h
@@ -0,0 +1,34 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+/// This file was created by Alex Silverman
+
+#ifndef MATERIAL_H
+#define MATERIAL_H
+
+// Material class to be used by btMultimaterialTriangleMeshShape to store triangle properties
+class btMaterial
+{
+ // public members so that materials can change due to world events
+public:
+ btScalar m_friction;
+ btScalar m_restitution;
+ int pad[2];
+
+ btMaterial(){}
+ btMaterial(btScalar fric, btScalar rest) { m_friction = fric; m_restitution = rest; }
+};
+
+#endif // MATERIAL_H \ No newline at end of file
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
index 015314bc09f..8f893ac98aa 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
@@ -26,9 +26,9 @@ m_shapeB(shapeB)
btVector3 btMinkowskiSumShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
{
- btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(vec*m_transA.getBasis()));
+ btVector3 supVertexA = m_transA(m_shapeA->localGetSupportingVertexWithoutMargin(-vec*m_transA.getBasis()));
btVector3 supVertexB = m_transB(m_shapeB->localGetSupportingVertexWithoutMargin(vec*m_transB.getBasis()));
- return supVertexA + supVertexB;
+ return supVertexA - supVertexB;
}
void btMinkowskiSumShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
@@ -49,7 +49,7 @@ btScalar btMinkowskiSumShape::getMargin() const
}
-void btMinkowskiSumShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btMinkowskiSumShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
(void)mass;
btAssert(0);
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
index 198faaff9f9..f9c8427c2f3 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
@@ -16,11 +16,11 @@ subject to the following restrictions:
#ifndef MINKOWSKI_SUM_SHAPE_H
#define MINKOWSKI_SUM_SHAPE_H
-#include "btConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "btConvexInternalShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
-/// btMinkowskiSumShape represents implicit (getSupportingVertex) based minkowski sum of two convex implicit shapes.
-class btMinkowskiSumShape : public btConvexShape
+/// The btMinkowskiSumShape is only for advanced users. This shape represents implicit based minkowski sum of two convex implicit shapes.
+class btMinkowskiSumShape : public btConvexInternalShape
{
btTransform m_transA;
@@ -37,7 +37,7 @@ public:
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
void setTransformA(const btTransform& transA) { m_transA = transA;}
void setTransformB(const btTransform& transB) { m_transB = transB;}
@@ -53,7 +53,7 @@ public:
const btConvexShape* getShapeA() const { return m_shapeA;}
const btConvexShape* getShapeB() const { return m_shapeB;}
- virtual char* getName()const
+ virtual const char* getName()const
{
return "MinkowskiSum";
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
index 6015a618082..c709205efc2 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
@@ -47,7 +47,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,cons
btVector3 vec = vec0;
btScalar lenSqr = vec.length2();
- if (lenSqr < btScalar(0.0001))
+ if (lenSqr < (SIMD_EPSILON*SIMD_EPSILON))
{
vec.setValue(1,0,0);
} else
@@ -116,7 +116,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,cons
-void btMultiSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btMultiSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
//as an approximation, take the inertia of the box that bounds the spheres
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
index 1897b474057..45968f3947f 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
@@ -16,13 +16,14 @@ subject to the following restrictions:
#ifndef MULTI_SPHERE_MINKOWSKI_H
#define MULTI_SPHERE_MINKOWSKI_H
-#include "btConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "btConvexInternalShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
#define MAX_NUM_SPHERES 5
-///btMultiSphereShape represents implicit convex hull of a collection of spheres (using getSupportingVertex)
-class btMultiSphereShape : public btConvexShape
+///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes.
+///It is possible to animate the spheres for deformation.
+class btMultiSphereShape : public btConvexInternalShape
{
@@ -39,7 +40,7 @@ public:
btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres);
///CollisionShape Interface
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
/// btConvexShape Interface
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
@@ -63,7 +64,7 @@ public:
virtual int getShapeType() const { return MULTI_SPHERE_SHAPE_PROXYTYPE; }
- virtual char* getName()const
+ virtual const char* getName()const
{
return "MultiSphere";
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp
new file mode 100644
index 00000000000..fc47e86411d
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp
@@ -0,0 +1,45 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+/// This file was created by Alex Silverman
+
+#include "BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h"
+//#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
+
+
+///Obtains the material for a specific triangle
+const btMaterial * btMultimaterialTriangleMeshShape::getMaterialProperties(int partID, int triIndex)
+{
+ const unsigned char * materialBase = 0;
+ int numMaterials;
+ PHY_ScalarType materialType;
+ int materialStride;
+ const unsigned char * triangleMaterialBase = 0;
+ int numTriangles;
+ int triangleMaterialStride;
+ PHY_ScalarType triangleType;
+
+ ((btTriangleIndexVertexMaterialArray*)m_meshInterface)->getLockedReadOnlyMaterialBase(&materialBase, numMaterials, materialType, materialStride,
+ &triangleMaterialBase, numTriangles, triangleMaterialStride, triangleType, partID);
+
+ // return the pointer to the place with the friction for the triangle
+ // TODO: This depends on whether it's a moving mesh or not
+ // BUG IN GIMPACT
+ //return (btScalar*)(&materialBase[triangleMaterialBase[(triIndex-1) * triangleMaterialStride] * materialStride]);
+ int * matInd = (int *)(&(triangleMaterialBase[(triIndex * triangleMaterialStride)]));
+ btMaterial *matVal = (btMaterial *)(&(materialBase[*matInd * materialStride]));
+ return (matVal);
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
new file mode 100644
index 00000000000..2f108020cdf
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
@@ -0,0 +1,124 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+/// This file was created by Alex Silverman
+
+#ifndef BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
+#define BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
+
+#include "btBvhTriangleMeshShape.h"
+#include "btMaterial.h"
+
+///The BvhTriangleMaterialMeshShape extends the btBvhTriangleMeshShape. Its main contribution is the interface into a material array, which allows per-triangle friction and restitution.
+ATTRIBUTE_ALIGNED16(class) btMultimaterialTriangleMeshShape : public btBvhTriangleMeshShape
+{
+ btAlignedObjectArray <btMaterial*> m_materialList;
+ int ** m_triangleMaterials;
+
+public:
+
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
+ btMultimaterialTriangleMeshShape(): btBvhTriangleMeshShape() {}
+ btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true):
+ btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
+ {
+ btVector3 m_triangle[3];
+ const unsigned char *vertexbase;
+ int numverts;
+ PHY_ScalarType type;
+ int stride;
+ const unsigned char *indexbase;
+ int indexstride;
+ int numfaces;
+ PHY_ScalarType indicestype;
+
+ //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
+
+ for(int i = 0; i < meshInterface->getNumSubParts(); i++)
+ {
+ m_meshInterface->getLockedReadOnlyVertexIndexBase(
+ &vertexbase,
+ numverts,
+ type,
+ stride,
+ &indexbase,
+ indexstride,
+ numfaces,
+ indicestype,
+ i);
+ //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces, 16));
+ }
+ }
+
+ ///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
+ btMultimaterialTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true):
+ btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax, buildBvh)
+ {
+ btVector3 m_triangle[3];
+ const unsigned char *vertexbase;
+ int numverts;
+ PHY_ScalarType type;
+ int stride;
+ const unsigned char *indexbase;
+ int indexstride;
+ int numfaces;
+ PHY_ScalarType indicestype;
+
+ //m_materialLookup = (int**)(btAlignedAlloc(sizeof(int*) * meshInterface->getNumSubParts(), 16));
+
+ for(int i = 0; i < meshInterface->getNumSubParts(); i++)
+ {
+ m_meshInterface->getLockedReadOnlyVertexIndexBase(
+ &vertexbase,
+ numverts,
+ type,
+ stride,
+ &indexbase,
+ indexstride,
+ numfaces,
+ indicestype,
+ i);
+ //m_materialLookup[i] = (int*)(btAlignedAlloc(sizeof(int) * numfaces * 2, 16));
+ }
+ }
+
+ virtual ~btMultimaterialTriangleMeshShape()
+ {
+/*
+ for(int i = 0; i < m_meshInterface->getNumSubParts(); i++)
+ {
+ btAlignedFree(m_materialValues[i]);
+ m_materialLookup[i] = NULL;
+ }
+ btAlignedFree(m_materialValues);
+ m_materialLookup = NULL;
+*/
+ }
+ virtual int getShapeType() const
+ {
+ return MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
+ }
+
+ //debugging
+ virtual const char* getName()const {return "MULTIMATERIALTRIANGLEMESH";}
+
+ ///Obtains the material for a specific triangle
+ const btMaterial * getMaterialProperties(int partID, int triIndex);
+
+}
+;
+
+#endif //BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
index 44438a24455..a248c55b571 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
@@ -19,13 +19,12 @@ subject to the following restrictions:
#include "LinearMath/btIDebugDraw.h"
-
-btOptimizedBvh::btOptimizedBvh() : m_useQuantization(false),
- m_traversalMode(TRAVERSAL_STACKLESS_CACHE_FRIENDLY)
- //m_traversalMode(TRAVERSAL_STACKLESS)
- //m_traversalMode(TRAVERSAL_RECURSIVE)
+btOptimizedBvh::btOptimizedBvh()
{
+}
+btOptimizedBvh::~btOptimizedBvh()
+{
}
@@ -80,7 +79,7 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized
struct QuantizedNodeTriangleCallback : public btInternalTriangleIndexCallback
{
QuantizedNodeArray& m_triangleNodes;
- const btOptimizedBvh* m_optimizedTree; // for quantization
+ const btQuantizedBvh* m_optimizedTree; // for quantization
QuantizedNodeTriangleCallback& operator=(QuantizedNodeTriangleCallback& other)
{
@@ -89,14 +88,16 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized
return *this;
}
- QuantizedNodeTriangleCallback(QuantizedNodeArray& triangleNodes,const btOptimizedBvh* tree)
+ QuantizedNodeTriangleCallback(QuantizedNodeArray& triangleNodes,const btQuantizedBvh* tree)
:m_triangleNodes(triangleNodes),m_optimizedTree(tree)
{
}
virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)
{
- btAssert(partId==0);
+ // The partId and triangle index must fit in the same (positive) integer
+ btAssert(partId < (1<<MAX_NUM_PARTS_IN_BITS));
+ btAssert(triangleIndex < (1<<(31-MAX_NUM_PARTS_IN_BITS)));
//negative indices are reserved for escapeIndex
btAssert(triangleIndex>=0);
@@ -111,10 +112,29 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized
aabbMin.setMin(triangle[2]);
aabbMax.setMax(triangle[2]);
- m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMin[0],aabbMin);
- m_optimizedTree->quantizeWithClamp(&node.m_quantizedAabbMax[0],aabbMax);
+ //PCK: add these checks for zero dimensions of aabb
+ const btScalar MIN_AABB_DIMENSION = btScalar(0.002);
+ const btScalar MIN_AABB_HALF_DIMENSION = btScalar(0.001);
+ if (aabbMax.x() - aabbMin.x() < MIN_AABB_DIMENSION)
+ {
+ aabbMax.setX(aabbMax.x() + MIN_AABB_HALF_DIMENSION);
+ aabbMin.setX(aabbMin.x() - MIN_AABB_HALF_DIMENSION);
+ }
+ if (aabbMax.y() - aabbMin.y() < MIN_AABB_DIMENSION)
+ {
+ aabbMax.setY(aabbMax.y() + MIN_AABB_HALF_DIMENSION);
+ aabbMin.setY(aabbMin.y() - MIN_AABB_HALF_DIMENSION);
+ }
+ if (aabbMax.z() - aabbMin.z() < MIN_AABB_DIMENSION)
+ {
+ aabbMax.setZ(aabbMax.z() + MIN_AABB_HALF_DIMENSION);
+ aabbMin.setZ(aabbMin.z() - MIN_AABB_HALF_DIMENSION);
+ }
- node.m_escapeIndexOrTriangleIndex = triangleIndex;
+ m_optimizedTree->quantize(&node.m_quantizedAabbMin[0],aabbMin,0);
+ m_optimizedTree->quantize(&node.m_quantizedAabbMax[0],aabbMax,1);
+
+ node.m_escapeIndexOrTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
m_triangleNodes.push_back(node);
}
@@ -170,10 +190,45 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized
subtree.m_rootNodeIndex = 0;
subtree.m_subtreeSize = m_quantizedContiguousNodes[0].isLeafNode() ? 1 : m_quantizedContiguousNodes[0].getEscapeIndex();
}
+
+ //PCK: update the copy of the size
+ m_subtreeHeaderCount = m_SubtreeHeaders.size();
+
+ //PCK: clear m_quantizedLeafNodes and m_leafNodes, they are temporary
+ m_quantizedLeafNodes.clear();
+ m_leafNodes.clear();
+}
+
+
+
+
+void btOptimizedBvh::refit(btStridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax)
+{
+ if (m_useQuantization)
+ {
+
+ setQuantizationValues(aabbMin,aabbMax);
+
+ updateBvhNodes(meshInterface,0,m_curNodeIndex,0);
+
+ ///now update all subtree headers
+
+ int i;
+ for (i=0;i<m_SubtreeHeaders.size();i++)
+ {
+ btBvhSubtreeInfo& subtree = m_SubtreeHeaders[i];
+ subtree.setAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]);
+ }
+
+ } else
+ {
+
+ }
}
+
void btOptimizedBvh::refitPartial(btStridingMeshInterface* meshInterface,const btVector3& aabbMin,const btVector3& aabbMax)
{
//incrementally initialize quantization values
@@ -193,16 +248,17 @@ void btOptimizedBvh::refitPartial(btStridingMeshInterface* meshInterface,const b
unsigned short quantizedQueryAabbMin[3];
unsigned short quantizedQueryAabbMax[3];
- quantizeWithClamp(&quantizedQueryAabbMin[0],aabbMin);
- quantizeWithClamp(&quantizedQueryAabbMax[0],aabbMax);
+ quantize(&quantizedQueryAabbMin[0],aabbMin,0);
+ quantize(&quantizedQueryAabbMax[0],aabbMax,1);
int i;
for (i=0;i<this->m_SubtreeHeaders.size();i++)
{
btBvhSubtreeInfo& subtree = m_SubtreeHeaders[i];
- bool overlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,subtree.m_quantizedAabbMin,subtree.m_quantizedAabbMax);
- if (overlap)
+ //PCK: unsigned instead of bool
+ unsigned overlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,subtree.m_quantizedAabbMin,subtree.m_quantizedAabbMax);
+ if (overlap != 0)
{
updateBvhNodes(meshInterface,subtree.m_rootNodeIndex,subtree.m_rootNodeIndex+subtree.m_subtreeSize,i);
@@ -212,36 +268,23 @@ void btOptimizedBvh::refitPartial(btStridingMeshInterface* meshInterface,const b
}
-///just for debugging, to visualize the individual patches/subtrees
-#ifdef DEBUG_PATCH_COLORS
-btVector3 color[4]=
-{
- btVector3(255,0,0),
- btVector3(0,255,0),
- btVector3(0,0,255),
- btVector3(0,255,255)
-};
-#endif //DEBUG_PATCH_COLORS
-
-
void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int firstNode,int endNode,int index)
{
(void)index;
btAssert(m_useQuantization);
- int nodeSubPart=0;
+ int curNodeSubPart=-1;
//get access info to trianglemesh data
- const unsigned char *vertexbase;
- int numverts;
- PHY_ScalarType type;
- int stride;
- const unsigned char *indexbase;
- int indexstride;
- int numfaces;
- PHY_ScalarType indicestype;
- meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts, type,stride,&indexbase,indexstride,numfaces,indicestype,nodeSubPart);
+ const unsigned char *vertexbase = 0;
+ int numverts = 0;
+ PHY_ScalarType type = PHY_INTEGER;
+ int stride = 0;
+ const unsigned char *indexbase = 0;
+ int indexstride = 0;
+ int numfaces = 0;
+ PHY_ScalarType indicestype = PHY_INTEGER;
btVector3 triangleVerts[3];
btVector3 aabbMin,aabbMax;
@@ -256,16 +299,26 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f
if (curNode.isLeafNode())
{
//recalc aabb from triangle data
+ int nodeSubPart = curNode.getPartId();
int nodeTriangleIndex = curNode.getTriangleIndex();
+ if (nodeSubPart != curNodeSubPart)
+ {
+ if (curNodeSubPart >= 0)
+ meshInterface->unLockReadOnlyVertexBase(curNodeSubPart);
+ meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts, type,stride,&indexbase,indexstride,numfaces,indicestype,nodeSubPart);
+
+ curNodeSubPart = nodeSubPart;
+ btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
+ }
//triangles->getLockedReadOnlyVertexIndexBase(vertexBase,numVerts,
- int* gfxbase = (int*)(indexbase+nodeTriangleIndex*indexstride);
+ unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
for (int j=2;j>=0;j--)
{
- int graphicsindex = gfxbase[j];
+ int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
#ifdef DEBUG_PATCH_COLORS
btVector3 mycolor = color[index&3];
@@ -292,8 +345,8 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f
aabbMin.setMin(triangleVerts[2]);
aabbMax.setMax(triangleVerts[2]);
- quantizeWithClamp(&curNode.m_quantizedAabbMin[0],aabbMin);
- quantizeWithClamp(&curNode.m_quantizedAabbMax[0],aabbMax);
+ quantize(&curNode.m_quantizedAabbMin[0],aabbMin,0);
+ quantize(&curNode.m_quantizedAabbMax[0],aabbMax,1);
} else
{
@@ -321,525 +374,17 @@ void btOptimizedBvh::updateBvhNodes(btStridingMeshInterface* meshInterface,int f
}
- meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
-
-
-}
-
-void btOptimizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin)
-{
- //enlarge the AABB to avoid division by zero when initializing the quantization values
- btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
- m_bvhAabbMin = bvhAabbMin - clampValue;
- m_bvhAabbMax = bvhAabbMax + clampValue;
- btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
- m_bvhQuantization = btVector3(btScalar(65535.0),btScalar(65535.0),btScalar(65535.0)) / aabbSize;
-}
-
-
-void btOptimizedBvh::refit(btStridingMeshInterface* meshInterface)
-{
- if (m_useQuantization)
- {
- //calculate new aabb
- btVector3 aabbMin,aabbMax;
- meshInterface->calculateAabbBruteForce(aabbMin,aabbMax);
-
- setQuantizationValues(aabbMin,aabbMax);
-
- updateBvhNodes(meshInterface,0,m_curNodeIndex,0);
-
- ///now update all subtree headers
-
- int i;
- for (i=0;i<m_SubtreeHeaders.size();i++)
- {
- btBvhSubtreeInfo& subtree = m_SubtreeHeaders[i];
- subtree.setAabbFromQuantizeNode(m_quantizedContiguousNodes[subtree.m_rootNodeIndex]);
- }
-
- } else
- {
-
- }
-}
-
-
-
-btOptimizedBvh::~btOptimizedBvh()
-{
-}
-
-#ifdef DEBUG_TREE_BUILDING
-int gStackDepth = 0;
-int gMaxStackDepth = 0;
-#endif //DEBUG_TREE_BUILDING
-
-void btOptimizedBvh::buildTree (int startIndex,int endIndex)
-{
-#ifdef DEBUG_TREE_BUILDING
- gStackDepth++;
- if (gStackDepth > gMaxStackDepth)
- gMaxStackDepth = gStackDepth;
-#endif //DEBUG_TREE_BUILDING
-
-
- int splitAxis, splitIndex, i;
- int numIndices =endIndex-startIndex;
- int curIndex = m_curNodeIndex;
-
- assert(numIndices>0);
-
- if (numIndices==1)
- {
-#ifdef DEBUG_TREE_BUILDING
- gStackDepth--;
-#endif //DEBUG_TREE_BUILDING
-
- assignInternalNodeFromLeafNode(m_curNodeIndex,startIndex);
-
- m_curNodeIndex++;
- return;
- }
- //calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
-
- splitAxis = calcSplittingAxis(startIndex,endIndex);
-
- splitIndex = sortAndCalcSplittingIndex(startIndex,endIndex,splitAxis);
-
- int internalNodeIndex = m_curNodeIndex;
-
- setInternalNodeAabbMax(m_curNodeIndex,btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)));
- setInternalNodeAabbMin(m_curNodeIndex,btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30)));
-
- for (i=startIndex;i<endIndex;i++)
- {
- mergeInternalNodeAabb(m_curNodeIndex,getAabbMin(i),getAabbMax(i));
- }
-
- m_curNodeIndex++;
-
-
- //internalNode->m_escapeIndex;
-
- int leftChildNodexIndex = m_curNodeIndex;
-
- //build left child tree
- buildTree(startIndex,splitIndex);
-
- int rightChildNodexIndex = m_curNodeIndex;
- //build right child tree
- buildTree(splitIndex,endIndex);
-
-#ifdef DEBUG_TREE_BUILDING
- gStackDepth--;
-#endif //DEBUG_TREE_BUILDING
-
- int escapeIndex = m_curNodeIndex - curIndex;
-
- if (m_useQuantization)
- {
- //escapeIndex is the number of nodes of this subtree
- const int sizeQuantizedNode =sizeof(btQuantizedBvhNode);
- const int treeSizeInBytes = escapeIndex * sizeQuantizedNode;
- if (treeSizeInBytes > MAX_SUBTREE_SIZE_IN_BYTES)
- {
- updateSubtreeHeaders(leftChildNodexIndex,rightChildNodexIndex);
- }
- }
-
- setInternalNodeEscapeIndex(internalNodeIndex,escapeIndex);
-
-}
-
-void btOptimizedBvh::updateSubtreeHeaders(int leftChildNodexIndex,int rightChildNodexIndex)
-{
- btAssert(m_useQuantization);
-
- btQuantizedBvhNode& leftChildNode = m_quantizedContiguousNodes[leftChildNodexIndex];
- int leftSubTreeSize = leftChildNode.isLeafNode() ? 1 : leftChildNode.getEscapeIndex();
- int leftSubTreeSizeInBytes = leftSubTreeSize * sizeof(btQuantizedBvhNode);
-
- btQuantizedBvhNode& rightChildNode = m_quantizedContiguousNodes[rightChildNodexIndex];
- int rightSubTreeSize = rightChildNode.isLeafNode() ? 1 : rightChildNode.getEscapeIndex();
- int rightSubTreeSizeInBytes = rightSubTreeSize * sizeof(btQuantizedBvhNode);
-
- if(leftSubTreeSizeInBytes <= MAX_SUBTREE_SIZE_IN_BYTES)
- {
- btBvhSubtreeInfo& subtree = m_SubtreeHeaders.expand();
- subtree.setAabbFromQuantizeNode(leftChildNode);
- subtree.m_rootNodeIndex = leftChildNodexIndex;
- subtree.m_subtreeSize = leftSubTreeSize;
- }
-
- if(rightSubTreeSizeInBytes <= MAX_SUBTREE_SIZE_IN_BYTES)
- {
- btBvhSubtreeInfo& subtree = m_SubtreeHeaders.expand();
- subtree.setAabbFromQuantizeNode(rightChildNode);
- subtree.m_rootNodeIndex = rightChildNodexIndex;
- subtree.m_subtreeSize = rightSubTreeSize;
- }
-}
-
-
-int btOptimizedBvh::sortAndCalcSplittingIndex(int startIndex,int endIndex,int splitAxis)
-{
- int i;
- int splitIndex =startIndex;
- int numIndices = endIndex - startIndex;
- btScalar splitValue;
-
- btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
- for (i=startIndex;i<endIndex;i++)
- {
- btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
- means+=center;
- }
- means *= (btScalar(1.)/(btScalar)numIndices);
-
- splitValue = means[splitAxis];
-
- //sort leafNodes so all values larger then splitValue comes first, and smaller values start from 'splitIndex'.
- for (i=startIndex;i<endIndex;i++)
- {
- btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
- if (center[splitAxis] > splitValue)
- {
- //swap
- swapLeafNodes(i,splitIndex);
- splitIndex++;
- }
- }
-
- //if the splitIndex causes unbalanced trees, fix this by using the center in between startIndex and endIndex
- //otherwise the tree-building might fail due to stack-overflows in certain cases.
- //unbalanced1 is unsafe: it can cause stack overflows
- //bool unbalanced1 = ((splitIndex==startIndex) || (splitIndex == (endIndex-1)));
-
- //unbalanced2 should work too: always use center (perfect balanced trees)
- //bool unbalanced2 = true;
-
- //this should be safe too:
- int rangeBalancedIndices = numIndices/3;
- bool unbalanced = ((splitIndex<=(startIndex+rangeBalancedIndices)) || (splitIndex >=(endIndex-1-rangeBalancedIndices)));
-
- if (unbalanced)
- {
- splitIndex = startIndex+ (numIndices>>1);
- }
-
- bool unbal = (splitIndex==startIndex) || (splitIndex == (endIndex));
- btAssert(!unbal);
-
- return splitIndex;
-}
-
-
-int btOptimizedBvh::calcSplittingAxis(int startIndex,int endIndex)
-{
- int i;
-
- btVector3 means(btScalar(0.),btScalar(0.),btScalar(0.));
- btVector3 variance(btScalar(0.),btScalar(0.),btScalar(0.));
- int numIndices = endIndex-startIndex;
-
- for (i=startIndex;i<endIndex;i++)
- {
- btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
- means+=center;
- }
- means *= (btScalar(1.)/(btScalar)numIndices);
-
- for (i=startIndex;i<endIndex;i++)
- {
- btVector3 center = btScalar(0.5)*(getAabbMax(i)+getAabbMin(i));
- btVector3 diff2 = center-means;
- diff2 = diff2 * diff2;
- variance += diff2;
- }
- variance *= (btScalar(1.)/ ((btScalar)numIndices-1) );
-
- return variance.maxAxis();
-}
-
-
-
-void btOptimizedBvh::reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
-{
- //either choose recursive traversal (walkTree) or stackless (walkStacklessTree)
-
-
- if (m_useQuantization)
- {
- ///quantize query AABB
- unsigned short int quantizedQueryAabbMin[3];
- unsigned short int quantizedQueryAabbMax[3];
- quantizeWithClamp(quantizedQueryAabbMin,aabbMin);
- quantizeWithClamp(quantizedQueryAabbMax,aabbMax);
-
- switch (m_traversalMode)
- {
- case TRAVERSAL_STACKLESS:
- walkStacklessQuantizedTree(nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax,0,m_curNodeIndex);
- break;
- case TRAVERSAL_STACKLESS_CACHE_FRIENDLY:
- walkStacklessQuantizedTreeCacheFriendly(nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
- break;
- case TRAVERSAL_RECURSIVE:
- {
- const btQuantizedBvhNode* rootNode = &m_quantizedContiguousNodes[0];
- walkRecursiveQuantizedTreeAgainstQueryAabb(rootNode,nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
- }
- break;
- default:
- //unsupported
- btAssert(0);
- }
- } else
- {
- walkStacklessTree(nodeCallback,aabbMin,aabbMax);
- }
-}
-
-
-int maxIterations = 0;
-
-void btOptimizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
-{
- btAssert(!m_useQuantization);
-
- const btOptimizedBvhNode* rootNode = &m_contiguousNodes[0];
- int escapeIndex, curIndex = 0;
- int walkIterations = 0;
- bool aabbOverlap, isLeafNode;
-
- while (curIndex < m_curNodeIndex)
- {
- //catch bugs in tree data
- assert (walkIterations < m_curNodeIndex);
-
- walkIterations++;
- aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg);
- isLeafNode = rootNode->m_escapeIndex == -1;
-
- if (isLeafNode && aabbOverlap)
- {
- nodeCallback->processNode(rootNode->m_subPart,rootNode->m_triangleIndex);
- }
-
- if (aabbOverlap || isLeafNode)
- {
- rootNode++;
- curIndex++;
- } else
- {
- escapeIndex = rootNode->m_escapeIndex;
- rootNode += escapeIndex;
- curIndex += escapeIndex;
- }
- }
- if (maxIterations < walkIterations)
- maxIterations = walkIterations;
-
-}
+ if (curNodeSubPart >= 0)
+ meshInterface->unLockReadOnlyVertexBase(curNodeSubPart);
-/*
-///this was the original recursive traversal, before we optimized towards stackless traversal
-void btOptimizedBvh::walkTree(btOptimizedBvhNode* rootNode,btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
-{
- bool isLeafNode, aabbOverlap = TestAabbAgainstAabb2(aabbMin,aabbMax,rootNode->m_aabbMin,rootNode->m_aabbMax);
- if (aabbOverlap)
- {
- isLeafNode = (!rootNode->m_leftChild && !rootNode->m_rightChild);
- if (isLeafNode)
- {
- nodeCallback->processNode(rootNode);
- } else
- {
- walkTree(rootNode->m_leftChild,nodeCallback,aabbMin,aabbMax);
- walkTree(rootNode->m_rightChild,nodeCallback,aabbMin,aabbMax);
- }
- }
-
-}
-*/
-
-void btOptimizedBvh::walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantizedBvhNode* currentNode,btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const
-{
- btAssert(m_useQuantization);
-
- bool aabbOverlap, isLeafNode;
-
- aabbOverlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,currentNode->m_quantizedAabbMin,currentNode->m_quantizedAabbMax);
- isLeafNode = currentNode->isLeafNode();
- if (aabbOverlap)
- {
- if (isLeafNode)
- {
- nodeCallback->processNode(0,currentNode->getTriangleIndex());
- } else
- {
- //process left and right children
- const btQuantizedBvhNode* leftChildNode = currentNode+1;
- walkRecursiveQuantizedTreeAgainstQueryAabb(leftChildNode,nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
-
- const btQuantizedBvhNode* rightChildNode = leftChildNode->isLeafNode() ? leftChildNode+1:leftChildNode+leftChildNode->getEscapeIndex();
- walkRecursiveQuantizedTreeAgainstQueryAabb(rightChildNode,nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax);
- }
- }
}
-
-
-
-
-
-
-void btOptimizedBvh::walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const
+///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place'
+btOptimizedBvh* btOptimizedBvh::deSerializeInPlace(void *i_alignedDataBuffer, unsigned int i_dataBufferSize, bool i_swapEndian)
{
- btAssert(m_useQuantization);
-
- int curIndex = startNodeIndex;
- int walkIterations = 0;
- int subTreeSize = endNodeIndex - startNodeIndex;
-
- const btQuantizedBvhNode* rootNode = &m_quantizedContiguousNodes[startNodeIndex];
- int escapeIndex;
+ btQuantizedBvh* bvh = btQuantizedBvh::deSerializeInPlace(i_alignedDataBuffer,i_dataBufferSize,i_swapEndian);
- bool aabbOverlap, isLeafNode;
-
- while (curIndex < endNodeIndex)
- {
-
-//#define VISUALLY_ANALYZE_BVH 1
-#ifdef VISUALLY_ANALYZE_BVH
- //some code snippet to debugDraw aabb, to visually analyze bvh structure
- static int drawPatch = 0;
- //need some global access to a debugDrawer
- extern btIDebugDraw* debugDrawerPtr;
- if (curIndex==drawPatch)
- {
- btVector3 aabbMin,aabbMax;
- aabbMin = unQuantize(rootNode->m_quantizedAabbMin);
- aabbMax = unQuantize(rootNode->m_quantizedAabbMax);
- btVector3 color(1,0,0);
- debugDrawerPtr->drawAabb(aabbMin,aabbMax,color);
- }
-#endif//VISUALLY_ANALYZE_BVH
-
- //catch bugs in tree data
- assert (walkIterations < subTreeSize);
-
- walkIterations++;
- aabbOverlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,rootNode->m_quantizedAabbMin,rootNode->m_quantizedAabbMax);
- isLeafNode = rootNode->isLeafNode();
-
- if (isLeafNode && aabbOverlap)
- {
- nodeCallback->processNode(0,rootNode->getTriangleIndex());
- }
-
- if (aabbOverlap || isLeafNode)
- {
- rootNode++;
- curIndex++;
- } else
- {
- escapeIndex = rootNode->getEscapeIndex();
- rootNode += escapeIndex;
- curIndex += escapeIndex;
- }
- }
- if (maxIterations < walkIterations)
- maxIterations = walkIterations;
-
-}
-
-//This traversal can be called from Playstation 3 SPU
-void btOptimizedBvh::walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const
-{
- btAssert(m_useQuantization);
-
- int i;
-
-
- for (i=0;i<this->m_SubtreeHeaders.size();i++)
- {
- const btBvhSubtreeInfo& subtree = m_SubtreeHeaders[i];
-
- bool overlap = testQuantizedAabbAgainstQuantizedAabb(quantizedQueryAabbMin,quantizedQueryAabbMax,subtree.m_quantizedAabbMin,subtree.m_quantizedAabbMax);
- if (overlap)
- {
- walkStacklessQuantizedTree(nodeCallback,quantizedQueryAabbMin,quantizedQueryAabbMax,
- subtree.m_rootNodeIndex,
- subtree.m_rootNodeIndex+subtree.m_subtreeSize);
- }
- }
-}
-
-
-
-
-void btOptimizedBvh::reportSphereOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
-{
- (void)nodeCallback;
- (void)aabbMin;
- (void)aabbMax;
- //not yet, please use aabb
- btAssert(0);
-}
-
-
-void btOptimizedBvh::quantizeWithClamp(unsigned short* out, const btVector3& point) const
-{
-
- btAssert(m_useQuantization);
-
- btVector3 clampedPoint(point);
- clampedPoint.setMax(m_bvhAabbMin);
- clampedPoint.setMin(m_bvhAabbMax);
-
- btVector3 v = (clampedPoint - m_bvhAabbMin) * m_bvhQuantization;
- out[0] = (unsigned short)(v.getX()+0.5f);
- out[1] = (unsigned short)(v.getY()+0.5f);
- out[2] = (unsigned short)(v.getZ()+0.5f);
-}
-
-btVector3 btOptimizedBvh::unQuantize(const unsigned short* vecIn) const
-{
- btVector3 vecOut;
- vecOut.setValue(
- (btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
- (btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
- (btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
- vecOut += m_bvhAabbMin;
- return vecOut;
-}
-
-
-void btOptimizedBvh::swapLeafNodes(int i,int splitIndex)
-{
- if (m_useQuantization)
- {
- btQuantizedBvhNode tmp = m_quantizedLeafNodes[i];
- m_quantizedLeafNodes[i] = m_quantizedLeafNodes[splitIndex];
- m_quantizedLeafNodes[splitIndex] = tmp;
- } else
- {
- btOptimizedBvhNode tmp = m_leafNodes[i];
- m_leafNodes[i] = m_leafNodes[splitIndex];
- m_leafNodes[splitIndex] = tmp;
- }
-}
-
-void btOptimizedBvh::assignInternalNodeFromLeafNode(int internalNode,int leafNodeIndex)
-{
- if (m_useQuantization)
- {
- m_quantizedContiguousNodes[internalNode] = m_quantizedLeafNodes[leafNodeIndex];
- } else
- {
- m_contiguousNodes[internalNode] = m_leafNodes[leafNodeIndex];
- }
+ //we don't add additional data so just do a static upcast
+ return static_cast<btOptimizedBvh*>(bvh);
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h
index d5159586344..d7536417d7e 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h
@@ -16,315 +16,48 @@ subject to the following restrictions:
#ifndef OPTIMIZED_BVH_H
#define OPTIMIZED_BVH_H
-
-#include "../../LinearMath/btVector3.h"
-
-
-//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vclrf__m128.asp
-
-
+#include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h"
class btStridingMeshInterface;
-//Note: currently we have 16 bytes per quantized node
-#define MAX_SUBTREE_SIZE_IN_BYTES 2048
-
-///btQuantizedBvhNode is a compressed aabb node, 16 bytes.
-///Node can be used for leafnode or internal node. Leafnodes can point to 32-bit triangle index (non-negative range).
-ATTRIBUTE_ALIGNED16 (struct) btQuantizedBvhNode
+///The btOptimizedBvh extends the btQuantizedBvh to create AABB tree for triangle meshes, through the btStridingMeshInterface.
+ATTRIBUTE_ALIGNED16(class) btOptimizedBvh : public btQuantizedBvh
{
- //12 bytes
- unsigned short int m_quantizedAabbMin[3];
- unsigned short int m_quantizedAabbMax[3];
- //4 bytes
- int m_escapeIndexOrTriangleIndex;
-
- bool isLeafNode() const
- {
- //skipindex is negative (internal node), triangleindex >=0 (leafnode)
- return (m_escapeIndexOrTriangleIndex >= 0);
- }
- int getEscapeIndex() const
- {
- btAssert(!isLeafNode());
- return -m_escapeIndexOrTriangleIndex;
- }
- int getTriangleIndex() const
- {
- btAssert(isLeafNode());
- return m_escapeIndexOrTriangleIndex;
- }
-}
-;
-
-/// btOptimizedBvhNode contains both internal and leaf node information.
-/// Total node size is 44 bytes / node. You can use the compressed version of 16 bytes.
-ATTRIBUTE_ALIGNED16 (struct) btOptimizedBvhNode
-{
- //32 bytes
- btVector3 m_aabbMinOrg;
- btVector3 m_aabbMaxOrg;
-
- //4
- int m_escapeIndex;
-
- //8
- //for child nodes
- int m_subPart;
- int m_triangleIndex;
- int m_padding[5];//bad, due to alignment
-
-
-};
-
-
-///btBvhSubtreeInfo provides info to gather a subtree of limited size
-ATTRIBUTE_ALIGNED16(class) btBvhSubtreeInfo
-{
public:
- //12 bytes
- unsigned short int m_quantizedAabbMin[3];
- unsigned short int m_quantizedAabbMax[3];
- //4 bytes, points to the root of the subtree
- int m_rootNodeIndex;
- //4 bytes
- int m_subtreeSize;
- int m_padding[3];
-
-
- void setAabbFromQuantizeNode(const btQuantizedBvhNode& quantizedNode)
- {
- m_quantizedAabbMin[0] = quantizedNode.m_quantizedAabbMin[0];
- m_quantizedAabbMin[1] = quantizedNode.m_quantizedAabbMin[1];
- m_quantizedAabbMin[2] = quantizedNode.m_quantizedAabbMin[2];
- m_quantizedAabbMax[0] = quantizedNode.m_quantizedAabbMax[0];
- m_quantizedAabbMax[1] = quantizedNode.m_quantizedAabbMax[1];
- m_quantizedAabbMax[2] = quantizedNode.m_quantizedAabbMax[2];
- }
-}
-;
-
-
-class btNodeOverlapCallback
-{
-public:
- virtual ~btNodeOverlapCallback() {};
-
- virtual void processNode(int subPart, int triangleIndex) = 0;
-};
-
-#include "../../LinearMath/btAlignedAllocator.h"
-#include "../../LinearMath/btAlignedObjectArray.h"
-
-
-
-///for code readability:
-typedef btAlignedObjectArray<btOptimizedBvhNode> NodeArray;
-typedef btAlignedObjectArray<btQuantizedBvhNode> QuantizedNodeArray;
-typedef btAlignedObjectArray<btBvhSubtreeInfo> BvhSubtreeInfoArray;
-
-
-///OptimizedBvh store an AABB tree that can be quickly traversed on CPU (and SPU,GPU in future)
-ATTRIBUTE_ALIGNED16(class) btOptimizedBvh
-{
- NodeArray m_leafNodes;
- NodeArray m_contiguousNodes;
-
- QuantizedNodeArray m_quantizedLeafNodes;
-
- QuantizedNodeArray m_quantizedContiguousNodes;
-
- int m_curNodeIndex;
-
-
- //quantization data
- bool m_useQuantization;
- btVector3 m_bvhAabbMin;
- btVector3 m_bvhAabbMax;
- btVector3 m_bvhQuantization;
-
- enum btTraversalMode
- {
- TRAVERSAL_STACKLESS = 0,
- TRAVERSAL_STACKLESS_CACHE_FRIENDLY,
- TRAVERSAL_RECURSIVE
- };
-
- btTraversalMode m_traversalMode;
-
-
-
-
- BvhSubtreeInfoArray m_SubtreeHeaders;
-
-
- ///two versions, one for quantized and normal nodes. This allows code-reuse while maintaining readability (no template/macro!)
- ///this might be refactored into a virtual, it is usually not calculated at run-time
- void setInternalNodeAabbMin(int nodeIndex, const btVector3& aabbMin)
- {
- if (m_useQuantization)
- {
- quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0] ,aabbMin);
- } else
- {
- m_contiguousNodes[nodeIndex].m_aabbMinOrg = aabbMin;
-
- }
- }
- void setInternalNodeAabbMax(int nodeIndex,const btVector3& aabbMax)
- {
- if (m_useQuantization)
- {
- quantizeWithClamp(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0],aabbMax);
- } else
- {
- m_contiguousNodes[nodeIndex].m_aabbMaxOrg = aabbMax;
- }
- }
-
- btVector3 getAabbMin(int nodeIndex) const
- {
- if (m_useQuantization)
- {
- return unQuantize(&m_quantizedLeafNodes[nodeIndex].m_quantizedAabbMin[0]);
- }
- //non-quantized
- return m_leafNodes[nodeIndex].m_aabbMinOrg;
-
- }
- btVector3 getAabbMax(int nodeIndex) const
- {
- if (m_useQuantization)
- {
- return unQuantize(&m_quantizedLeafNodes[nodeIndex].m_quantizedAabbMax[0]);
- }
- //non-quantized
- return m_leafNodes[nodeIndex].m_aabbMaxOrg;
-
- }
-
- void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.0));
-
- void setInternalNodeEscapeIndex(int nodeIndex, int escapeIndex)
- {
- if (m_useQuantization)
- {
- m_quantizedContiguousNodes[nodeIndex].m_escapeIndexOrTriangleIndex = -escapeIndex;
- }
- else
- {
- m_contiguousNodes[nodeIndex].m_escapeIndex = escapeIndex;
- }
-
- }
-
- void mergeInternalNodeAabb(int nodeIndex,const btVector3& newAabbMin,const btVector3& newAabbMax)
- {
- if (m_useQuantization)
- {
- unsigned short int quantizedAabbMin[3];
- unsigned short int quantizedAabbMax[3];
- quantizeWithClamp(quantizedAabbMin,newAabbMin);
- quantizeWithClamp(quantizedAabbMax,newAabbMax);
- for (int i=0;i<3;i++)
- {
- if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] > quantizedAabbMin[i])
- m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] = quantizedAabbMin[i];
-
- if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[i] < quantizedAabbMax[i])
- m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[i] = quantizedAabbMax[i];
-
- }
- } else
- {
- //non-quantized
- m_contiguousNodes[nodeIndex].m_aabbMinOrg.setMin(newAabbMin);
- m_contiguousNodes[nodeIndex].m_aabbMaxOrg.setMax(newAabbMax);
- }
- }
-
- void swapLeafNodes(int firstIndex,int secondIndex);
-
- void assignInternalNodeFromLeafNode(int internalNode,int leafNodeIndex);
+ BT_DECLARE_ALIGNED_ALLOCATOR();
protected:
-
-
- void buildTree (int startIndex,int endIndex);
-
- int calcSplittingAxis(int startIndex,int endIndex);
-
- int sortAndCalcSplittingIndex(int startIndex,int endIndex,int splitAxis);
-
- void walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
-
- void walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const;
-
- ///tree traversal designed for small-memory processors like PS3 SPU
- void walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
-
- ///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
- void walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantizedBvhNode* currentNode,btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
-
- ///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
- void walkRecursiveQuantizedTreeAgainstQuantizedTree(const btQuantizedBvhNode* treeNodeA,const btQuantizedBvhNode* treeNodeB,btNodeOverlapCallback* nodeCallback) const;
-
-
- inline bool testQuantizedAabbAgainstQuantizedAabb(unsigned short int* aabbMin1,unsigned short int* aabbMax1,const unsigned short int* aabbMin2,const unsigned short int* aabbMax2) const
- {
- bool overlap = true;
- overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
- overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
- overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
- return overlap;
- }
-
- void updateSubtreeHeaders(int leftChildNodexIndex,int rightChildNodexIndex);
-
public:
+
btOptimizedBvh();
virtual ~btOptimizedBvh();
void build(btStridingMeshInterface* triangles,bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax);
- void reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
-
- void reportSphereOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
-
- void quantizeWithClamp(unsigned short* out, const btVector3& point) const;
-
- btVector3 unQuantize(const unsigned short* vecIn) const;
-
- ///setTraversalMode let's you choose between stackless, recursive or stackless cache friendly tree traversal. Note this is only implemented for quantized trees.
- void setTraversalMode(btTraversalMode traversalMode)
- {
- m_traversalMode = traversalMode;
- }
-
- void refit(btStridingMeshInterface* triangles);
+ void refit(btStridingMeshInterface* triangles,const btVector3& aabbMin,const btVector3& aabbMax);
void refitPartial(btStridingMeshInterface* triangles,const btVector3& aabbMin, const btVector3& aabbMax);
void updateBvhNodes(btStridingMeshInterface* meshInterface,int firstNode,int endNode,int index);
+ /// Data buffer MUST be 16 byte aligned
+ virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian)
+ {
+ return btQuantizedBvh::serialize(o_alignedDataBuffer,i_dataBufferSize,i_swapEndian);
- QuantizedNodeArray& getQuantizedNodeArray()
- {
- return m_quantizedContiguousNodes;
}
- BvhSubtreeInfoArray& getSubtreeInfoArray()
- {
- return m_SubtreeHeaders;
- }
+ ///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place'
+ static btOptimizedBvh *deSerializeInPlace(void *i_alignedDataBuffer, unsigned int i_dataBufferSize, bool i_swapEndian);
-}
-;
+
+};
#endif //OPTIMIZED_BVH_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
index bbc4ba62af6..71c3af38a02 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
@@ -13,7 +13,7 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
-#include <BulletCollision/CollisionShapes/btPolyhedralConvexShape.h>
+#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
btPolyhedralConvexShape::btPolyhedralConvexShape()
:m_localAabbMin(1,1,1),
@@ -95,7 +95,7 @@ void btPolyhedralConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin(
-void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
//not yet, return box inertia
@@ -128,10 +128,46 @@ void btPolyhedralConvexShape::getAabb(const btTransform& trans,btVector3& aabbMi
+void btPolyhedralConvexShape::setLocalScaling(const btVector3& scaling)
+{
+ btConvexInternalShape::setLocalScaling(scaling);
+ recalcLocalAabb();
+}
void btPolyhedralConvexShape::recalcLocalAabb()
{
m_isLocalAabbValid = true;
+
+ #if 1
+ static const btVector3 _directions[] =
+ {
+ btVector3( 1., 0., 0.),
+ btVector3( 0., 1., 0.),
+ btVector3( 0., 0., 1.),
+ btVector3( -1., 0., 0.),
+ btVector3( 0., -1., 0.),
+ btVector3( 0., 0., -1.)
+ };
+
+ btVector3 _supporting[] =
+ {
+ btVector3( 0., 0., 0.),
+ btVector3( 0., 0., 0.),
+ btVector3( 0., 0., 0.),
+ btVector3( 0., 0., 0.),
+ btVector3( 0., 0., 0.),
+ btVector3( 0., 0., 0.)
+ };
+
+ batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
+
+ for ( int i = 0; i < 3; ++i )
+ {
+ m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
+ m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
+ }
+
+ #else
for (int i=0;i<3;i++)
{
@@ -143,6 +179,8 @@ void btPolyhedralConvexShape::recalcLocalAabb()
tmp = localGetSupportingVertex(vec);
m_localAabbMin[i] = tmp[i]-m_collisionMargin;
}
+ #endif
}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
index c35f7512663..4c4ce7feaa7 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
@@ -16,13 +16,14 @@ subject to the following restrictions:
#ifndef BU_SHAPE
#define BU_SHAPE
-#include "../../LinearMath/btPoint3.h"
-#include "../../LinearMath/btMatrix3x3.h"
-#include "btConvexShape.h"
+#include "LinearMath/btPoint3.h"
+#include "LinearMath/btMatrix3x3.h"
+#include "LinearMath/btAabbUtil2.h"
+#include "btConvexInternalShape.h"
-///PolyhedralConvexShape is an interface class for feature based (vertex/edge/face) convex shapes.
-class btPolyhedralConvexShape : public btConvexShape
+///The btPolyhedralConvexShape is an internal interface class for polyhedral convex shapes.
+class btPolyhedralConvexShape : public btConvexInternalShape
{
protected:
@@ -38,7 +39,7 @@ public:
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
@@ -46,33 +47,14 @@ public:
//lazy evaluation of local aabb
btAssert(m_isLocalAabbValid);
-
- btAssert(m_localAabbMin.getX() <= m_localAabbMax.getX());
- btAssert(m_localAabbMin.getY() <= m_localAabbMax.getY());
- btAssert(m_localAabbMin.getZ() <= m_localAabbMax.getZ());
-
-
- btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
- btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
-
- btMatrix3x3 abs_b = trans.getBasis().absolute();
-
- btPoint3 center = trans(localCenter);
-
- btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
- abs_b[1].dot(localHalfExtents),
- abs_b[2].dot(localHalfExtents));
- extent += btVector3(margin,margin,margin);
-
- aabbMin = center - extent;
- aabbMax = center + extent;
-
-
+ btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax);
}
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+ virtual void setLocalScaling(const btVector3& scaling);
+
void recalcLocalAabb();
virtual int getNumVertices() const = 0 ;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
new file mode 100644
index 00000000000..5a17b4e2df0
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
@@ -0,0 +1,103 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "btScaledBvhTriangleMeshShape.h"
+
+btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling)
+:m_bvhTriMeshShape(childShape),
+m_localScaling(localScaling)
+{
+
+}
+
+btScaledBvhTriangleMeshShape::~btScaledBvhTriangleMeshShape()
+{
+}
+
+
+class btScaledTriangleCallback : public btTriangleCallback
+{
+ btTriangleCallback* m_originalCallback;
+
+ btVector3 m_localScaling;
+
+public:
+
+ btScaledTriangleCallback(btTriangleCallback* originalCallback,btVector3 localScaling)
+ :m_originalCallback(originalCallback),
+ m_localScaling(localScaling)
+ {
+ }
+
+ virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
+ {
+ btVector3 newTriangle[3];
+ newTriangle[0] = triangle[0]*m_localScaling;
+ newTriangle[1] = triangle[1]*m_localScaling;
+ newTriangle[2] = triangle[2]*m_localScaling;
+ m_originalCallback->processTriangle(&newTriangle[0],partId,triangleIndex);
+ }
+};
+
+void btScaledBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
+{
+ btScaledTriangleCallback scaledCallback(callback,m_localScaling);
+
+ btVector3 invLocalScaling(1.f/m_localScaling.getX(),1.f/m_localScaling.getY(),1.f/m_localScaling.getZ());
+ btVector3 scaledAabbMin = aabbMin * invLocalScaling;
+ btVector3 scaledAabbMax = aabbMax * invLocalScaling;
+ m_bvhTriMeshShape->processAllTriangles(&scaledCallback,scaledAabbMin,scaledAabbMax);
+}
+
+
+void btScaledBvhTriangleMeshShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
+{
+ btVector3 localAabbMin = m_bvhTriMeshShape->getLocalAabbMin();
+ btVector3 localAabbMax = m_bvhTriMeshShape->getLocalAabbMax();
+ localAabbMin *= m_localScaling;
+ localAabbMax *= m_localScaling;
+
+ btVector3 localHalfExtents = btScalar(0.5)*(localAabbMax-localAabbMin);
+ btScalar margin = m_bvhTriMeshShape->getMargin();
+ localHalfExtents += btVector3(margin,margin,margin);
+ btVector3 localCenter = btScalar(0.5)*(localAabbMax+localAabbMin);
+
+ btMatrix3x3 abs_b = trans.getBasis().absolute();
+
+ btPoint3 center = trans(localCenter);
+
+ btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
+ abs_b[1].dot(localHalfExtents),
+ abs_b[2].dot(localHalfExtents));
+ aabbMin = center - extent;
+ aabbMax = center + extent;
+
+}
+
+void btScaledBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
+{
+ m_localScaling = scaling;
+}
+
+const btVector3& btScaledBvhTriangleMeshShape::getLocalScaling() const
+{
+ return m_localScaling;
+}
+
+void btScaledBvhTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
+{
+ ///don't make this a movable object!
+ btAssert(0);
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
new file mode 100644
index 00000000000..8e1d29fc005
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
@@ -0,0 +1,57 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef SCALED_BVH_TRIANGLE_MESH_SHAPE_H
+#define SCALED_BVH_TRIANGLE_MESH_SHAPE_H
+
+#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
+
+
+///The btScaledBvhTriangleMeshShape allows to instance a scaled version of an existing btBvhTriangleMeshShape.
+///Note that each btBvhTriangleMeshShape still can have its own local scaling, independent from this btScaledBvhTriangleMeshShape 'localScaling'
+ATTRIBUTE_ALIGNED16(class) btScaledBvhTriangleMeshShape : public btConcaveShape
+{
+
+
+ btVector3 m_localScaling;
+
+ btBvhTriangleMeshShape* m_bvhTriMeshShape;
+
+public:
+
+
+ btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling);
+
+ virtual ~btScaledBvhTriangleMeshShape();
+
+ virtual int getShapeType() const
+ {
+ //use un-used 'FAST_CONCAVE_MESH_PROXYTYPE' for now, later add SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE to btBroadphaseProxy.h
+ return FAST_CONCAVE_MESH_PROXYTYPE;
+ }
+
+ virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+ virtual void setLocalScaling(const btVector3& scaling);
+ virtual const btVector3& getLocalScaling() const;
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
+
+ virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
+
+ //debugging
+ virtual const char* getName()const {return "SCALEDBVHTRIANGLEMESH";}
+
+};
+
+#endif //BVH_TRIANGLE_MESH_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.cpp
new file mode 100644
index 00000000000..a87b87f1a6f
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.cpp
@@ -0,0 +1,164 @@
+/*
+btbtShapeHull implemented by John McCutchan.
+
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://bulletphysics.com
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "btShapeHull.h"
+#include "LinearMath/btConvexHull.h"
+
+#define NUM_UNITSPHERE_POINTS 42
+
+static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
+{
+ btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
+ btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
+ btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
+ btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
+ btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
+ btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
+ btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
+ btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
+ btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
+ btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
+ btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
+ btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
+ btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
+ btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
+ btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
+ btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
+ btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
+ btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
+ btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
+ btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
+ btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
+ btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
+ btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
+ btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
+ btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
+ btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
+ btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
+ btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
+ btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
+ btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
+ btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
+ btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
+ btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
+ btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
+ btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
+ btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
+ btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
+ btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
+ btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
+ btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
+ btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
+ btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
+};
+
+btShapeHull::btShapeHull (const btConvexShape* shape)
+{
+ m_shape = shape;
+ m_vertices.clear ();
+ m_indices.clear();
+ m_numIndices = 0;
+}
+
+btShapeHull::~btShapeHull ()
+{
+ m_indices.clear();
+ m_vertices.clear ();
+}
+
+bool
+btShapeHull::buildHull (btScalar /*margin*/)
+{
+ int numSampleDirections = NUM_UNITSPHERE_POINTS;
+ {
+ int numPDA = m_shape->getNumPreferredPenetrationDirections();
+ if (numPDA)
+ {
+ for (int i=0;i<numPDA;i++)
+ {
+ btVector3 norm;
+ m_shape->getPreferredPenetrationDirection(i,norm);
+ btUnitSpherePoints[numSampleDirections] = norm;
+ numSampleDirections++;
+ }
+ }
+ }
+
+ btVector3 supportPoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2];
+ int i;
+ for (i = 0; i < numSampleDirections; i++)
+ {
+ supportPoints[i] = m_shape->localGetSupportingVertex(btUnitSpherePoints[i]);
+ }
+
+ HullDesc hd;
+ hd.mFlags = QF_TRIANGLES;
+ hd.mVcount = static_cast<unsigned int>(numSampleDirections);
+
+#ifdef BT_USE_DOUBLE_PRECISION
+ hd.mVertices = &supportPoints[0];
+ hd.mVertexStride = sizeof(btVector3);
+#else
+ hd.mVertices = &supportPoints[0];
+ hd.mVertexStride = sizeof (btVector3);
+#endif
+
+ HullLibrary hl;
+ HullResult hr;
+ if (hl.CreateConvexHull (hd, hr) == QE_FAIL)
+ {
+ return false;
+ }
+
+ m_vertices.resize (static_cast<int>(hr.mNumOutputVertices));
+
+
+ for (i = 0; i < static_cast<int>(hr.mNumOutputVertices); i++)
+ {
+ m_vertices[i] = hr.m_OutputVertices[i];
+ }
+ m_numIndices = hr.mNumIndices;
+ m_indices.resize(static_cast<int>(m_numIndices));
+ for (i = 0; i < static_cast<int>(m_numIndices); i++)
+ {
+ m_indices[i] = hr.m_Indices[i];
+ }
+
+ // free temporary hull result that we just copied
+ hl.ReleaseResult (hr);
+
+ return true;
+}
+
+int
+btShapeHull::numTriangles () const
+{
+ return static_cast<int>(m_numIndices / 3);
+}
+
+int
+btShapeHull::numVertices () const
+{
+ return m_vertices.size ();
+}
+
+int
+btShapeHull::numIndices () const
+{
+ return static_cast<int>(m_numIndices);
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h
new file mode 100644
index 00000000000..583c6b99eb6
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h
@@ -0,0 +1,56 @@
+/*
+btShapeHull implemented by John McCutchan.
+
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2008 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _SHAPE_HULL_H
+#define _SHAPE_HULL_H
+
+#include "LinearMath/btAlignedObjectArray.h"
+#include "BulletCollision/CollisionShapes/btConvexShape.h"
+
+
+///The btShapeHull class takes a btConvexShape, builds a simplified convex hull using btConvexHull and provides triangle indices and vertices.
+///It can be useful for to simplify a complex convex object and for visualization of a non-polyhedral convex object.
+///It approximates the convex hull using the supporting vertex of 42 directions.
+class btShapeHull
+{
+public:
+ btShapeHull (const btConvexShape* shape);
+ ~btShapeHull ();
+
+ bool buildHull (btScalar margin);
+
+ int numTriangles () const;
+ int numVertices () const;
+ int numIndices () const;
+
+ const btVector3* getVertexPointer() const
+ {
+ return &m_vertices[0];
+ }
+ const unsigned int* getIndexPointer() const
+ {
+ return &m_indices[0];
+ }
+
+protected:
+ btAlignedObjectArray<btVector3> m_vertices;
+ btAlignedObjectArray<unsigned int> m_indices;
+ unsigned int m_numIndices;
+ const btConvexShape* m_shape;
+};
+
+#endif //_SHAPE_HULL_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.cpp
index ca65dd03f3e..15cfe432e27 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.cpp
@@ -68,7 +68,7 @@ void btSphereShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& a
-void btSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
btScalar elem = btScalar(0.4) * mass * getMargin()*getMargin();
inertia.setValue(elem,elem,elem);
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h
index 66521664087..83421d69e0d 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h
@@ -16,15 +16,17 @@ subject to the following restrictions:
#ifndef SPHERE_MINKOWSKI_H
#define SPHERE_MINKOWSKI_H
-#include "btConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "btConvexInternalShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
-///btSphereShape implements an implicit (getSupportingVertex) Sphere
-ATTRIBUTE_ALIGNED16(class) btSphereShape : public btConvexShape
+///The btSphereShape implements an implicit sphere, centered around a local origin with radius.
+ATTRIBUTE_ALIGNED16(class) btSphereShape : public btConvexInternalShape
{
public:
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
btSphereShape (btScalar radius);
@@ -34,26 +36,26 @@ public:
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
virtual int getShapeType() const { return SPHERE_SHAPE_PROXYTYPE; }
- btScalar getRadius() const { return m_implicitShapeDimensions.getX();}
+ btScalar getRadius() const { return m_implicitShapeDimensions.getX() * m_localScaling.getX();}
//debugging
- virtual char* getName()const {return "SPHERE";}
+ virtual const char* getName()const {return "SPHERE";}
virtual void setMargin(btScalar margin)
{
- btConvexShape::setMargin(margin);
+ btConvexInternalShape::setMargin(margin);
}
virtual btScalar getMargin() const
{
//to improve gjk behaviour, use radius+margin as the full margin, so never get into the penetration case
//this means, non-uniform scaling is not supported anymore
- return m_localScaling.getX() * getRadius() + btConvexShape::getMargin();
+ return getRadius();
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
index 4fbaafa1b93..3c98ca08ddc 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
@@ -19,10 +19,11 @@ subject to the following restrictions:
btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
-:m_planeNormal(planeNormal),
+:m_planeNormal(planeNormal.normalized()),
m_planeConstant(planeConstant),
m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.))
{
+ // btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );
}
@@ -86,7 +87,7 @@ void btStaticPlaneShape::processAllTriangles(btTriangleCallback* callback,const
}
-void btStaticPlaneShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btStaticPlaneShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
(void)mass;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
index f59cc0c3347..ddebca73dea 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
@@ -19,8 +19,7 @@ subject to the following restrictions:
#include "btConcaveShape.h"
-///StaticPlaneShape simulates an 'infinite' plane by dynamically reporting triangles approximated by intersection of the plane with the AABB.
-///Assumed is that the other objects is not also infinite, so a reasonable sized AABB.
+///The btStaticPlaneShape simulates an infinite non-moving (static) collision plane.
class btStaticPlaneShape : public btConcaveShape
{
protected:
@@ -46,14 +45,23 @@ public:
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual void setLocalScaling(const btVector3& scaling);
virtual const btVector3& getLocalScaling() const;
+ const btVector3& getPlaneNormal() const
+ {
+ return m_planeNormal;
+ }
+
+ const btScalar& getPlaneConstant() const
+ {
+ return m_planeConstant;
+ }
//debugging
- virtual char* getName()const {return "STATICPLANE";}
+ virtual const char* getName()const {return "STATICPLANE";}
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
index 03ca1ae7736..752a5fc1dfa 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
@@ -51,7 +51,7 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
- int* tri_indices= (int*)(indexbase+gfxindex*indexstride);
+ unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
@@ -66,7 +66,7 @@ void btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
- short int* tri_indices= (short int*)(indexbase+gfxindex*indexstride);
+ unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
@@ -121,4 +121,4 @@ void btStridingMeshInterface::calculateAabbBruteForce(btVector3& aabbMin,btVecto
aabbMin = aabbCallback.m_aabbMin;
aabbMax = aabbCallback.m_aabbMax;
-} \ No newline at end of file
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h
index d7b354b7855..85020dd3f58 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h
@@ -16,7 +16,7 @@ subject to the following restrictions:
#ifndef STRIDING_MESHINTERFACE_H
#define STRIDING_MESHINTERFACE_H
-#include "../../LinearMath/btVector3.h"
+#include "LinearMath/btVector3.h"
#include "btTriangleCallback.h"
/// PHY_ScalarType enumerates possible scalar types.
@@ -29,7 +29,8 @@ typedef enum PHY_ScalarType {
PHY_FIXEDPOINT88
} PHY_ScalarType;
-/// btStridingMeshInterface is the interface class for high performance access to triangle meshes
+/// The btStridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with btBvhTriangleMeshShape and some other collision shapes.
+/// Using index striding of 3*sizeof(integer) it can use triangle arrays, using index striding of 1*sizeof(integer) it can handle triangle strips.
/// It allows for sharing graphics and collision meshes. Also it provides locking/unlocking of graphics meshes that are in gpu memory.
class btStridingMeshInterface
{
@@ -47,7 +48,7 @@ class btStridingMeshInterface
- void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
+ virtual void InternalProcessAllTriangles(btInternalTriangleIndexCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
///brute force method to calculate aabb
void calculateAabbBruteForce(btVector3& aabbMin,btVector3& aabbMax);
@@ -75,6 +76,10 @@ class btStridingMeshInterface
virtual void preallocateVertices(int numverts)=0;
virtual void preallocateIndices(int numindices)=0;
+ virtual bool hasPremadeAabb() const { return false; }
+ virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const {}
+ virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const {}
+
const btVector3& getScaling() const {
return m_scaling;
}
@@ -83,6 +88,7 @@ class btStridingMeshInterface
m_scaling = scaling;
}
+
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h
index 94bc4ec0fa5..09272d61dc2 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h
@@ -18,10 +18,10 @@ subject to the following restrictions:
#include "btPolyhedralConvexShape.h"
-#include "../BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
-///BU_Simplex1to4 implements feature based and implicit simplex of up to 4 vertices (tetrahedron, triangle, line, vertex).
+///The btBU_Simplex1to4 implements tetrahedron, triangle, line, vertex collision shapes. In most cases it is better to use btConvexHullShape instead.
class btBU_Simplex1to4 : public btPolyhedralConvexShape
{
protected:
@@ -68,7 +68,7 @@ public:
///getName is for debugging
- virtual char* getName()const { return "btBU_Simplex1to4";}
+ virtual const char* getName()const { return "btBU_Simplex1to4";}
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.cpp
index 54864c32f3a..5194219f256 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.cpp
@@ -16,14 +16,7 @@ subject to the following restrictions:
#include "btTriangleBuffer.h"
-///example usage of this class:
-// btTriangleBuffer triBuf;
-// concaveShape->processAllTriangles(&triBuf,aabbMin, aabbMax);
-// for (int i=0;i<triBuf.getNumTriangles();i++)
-// {
-// const btTriangle& tri = triBuf.getTriangle(i);
-// //do something useful here with the triangle
-// }
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.h
index 3805c519d22..c739fc11e8f 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleBuffer.h
@@ -17,7 +17,7 @@ subject to the following restrictions:
#define BT_TRIANGLE_BUFFER_H
#include "btTriangleCallback.h"
-#include "../../LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btAlignedObjectArray.h"
struct btTriangle
{
@@ -29,6 +29,14 @@ struct btTriangle
};
///btTriangleBuffer can be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles'
+///Example usage of this class:
+/// btTriangleBuffer triBuf;
+/// concaveShape->processAllTriangles(&triBuf,aabbMin, aabbMax);
+/// for (int i=0;i<triBuf.getNumTriangles();i++)
+/// {
+/// const btTriangle& tri = triBuf.getTriangle(i);
+/// //do something useful here with the triangle
+/// }
class btTriangleBuffer : public btTriangleCallback
{
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h
index fbb87bc4fd8..cb760be80ca 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h
@@ -16,9 +16,11 @@ subject to the following restrictions:
#ifndef TRIANGLE_CALLBACK_H
#define TRIANGLE_CALLBACK_H
-#include "../../LinearMath/btVector3.h"
+#include "LinearMath/btVector3.h"
+///The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTriangles.
+///This callback is called by processAllTriangles for all btConcaveShape derived class, such as btBvhTriangleMeshShape, btStaticPlaneShape and btHeightfieldTerrainShape.
class btTriangleCallback
{
public:
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
index 00847861cf1..8d634a67143 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
@@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
@@ -18,34 +18,43 @@ subject to the following restrictions:
btTriangleIndexVertexArray::btTriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride)
{
btIndexedMesh mesh;
-
+
mesh.m_numTriangles = numTriangles;
mesh.m_triangleIndexBase = (const unsigned char *)triangleIndexBase;
mesh.m_triangleIndexStride = triangleIndexStride;
mesh.m_numVertices = numVertices;
mesh.m_vertexBase = (const unsigned char *)vertexBase;
mesh.m_vertexStride = vertexStride;
-
+
addIndexedMesh(mesh);
}
+btTriangleIndexVertexArray::~btTriangleIndexVertexArray()
+{
+
+}
+
void btTriangleIndexVertexArray::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
{
btAssert(subpart< getNumSubParts() );
-
+
btIndexedMesh& mesh = m_indexedMeshes[subpart];
numverts = mesh.m_numVertices;
(*vertexbase) = (unsigned char *) mesh.m_vertexBase;
+ #ifdef BT_USE_DOUBLE_PRECISION
+ type = PHY_DOUBLE;
+ #else
type = PHY_FLOAT;
+ #endif
vertexStride = mesh.m_vertexStride;
numfaces = mesh.m_numTriangles;
(*indexbase) = (unsigned char *)mesh.m_triangleIndexBase;
indexstride = mesh.m_triangleIndexStride;
- indicestype = PHY_INTEGER;
+ indicestype = mesh.m_indexType;
}
void btTriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& vertexStride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
@@ -54,12 +63,34 @@ void btTriangleIndexVertexArray::getLockedReadOnlyVertexIndexBase(const unsigned
numverts = mesh.m_numVertices;
(*vertexbase) = (const unsigned char *)mesh.m_vertexBase;
+ #ifdef BT_USE_DOUBLE_PRECISION
+ type = PHY_DOUBLE;
+ #else
type = PHY_FLOAT;
+ #endif
vertexStride = mesh.m_vertexStride;
numfaces = mesh.m_numTriangles;
(*indexbase) = (const unsigned char *)mesh.m_triangleIndexBase;
indexstride = mesh.m_triangleIndexStride;
- indicestype = PHY_INTEGER;
+ indicestype = mesh.m_indexType;
+}
+
+bool btTriangleIndexVertexArray::hasPremadeAabb() const
+{
+ return (m_hasAabb == 1);
+}
+
+void btTriangleIndexVertexArray::setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax )
+{
+ m_aabbMin = aabbMin;
+ m_aabbMax = aabbMax;
+ m_hasAabb = 1; // this is intentionally an int see notes in header
+}
+
+void btTriangleIndexVertexArray::getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
+{
+ *aabbMin = m_aabbMin;
+ *aabbMax = m_aabbMax;
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
index 6ab6a762b39..e546675f802 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
@@ -17,48 +17,62 @@ subject to the following restrictions:
#define BT_TRIANGLE_INDEX_VERTEX_ARRAY_H
#include "btStridingMeshInterface.h"
-#include "../../LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btScalar.h"
-///IndexedMesh indexes into existing vertex and index arrays, in a similar way OpenGL glDrawElements
-///instead of the number of indices, we pass the number of triangles
-///todo: explain with pictures
+
+///The btIndexedMesh indexes a single vertex and index array. Multiple btIndexedMesh objects can be passed into a btTriangleIndexVertexArray using addIndexedMesh.
+///Instead of the number of indices, we pass the number of triangles.
ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
{
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
int m_numTriangles;
const unsigned char * m_triangleIndexBase;
int m_triangleIndexStride;
int m_numVertices;
const unsigned char * m_vertexBase;
int m_vertexStride;
- int pad[2];
+ // The index type is set when adding an indexed mesh to the
+ // btTriangleIndexVertexArray, do not set it manually
+ PHY_ScalarType m_indexType;
+ int pad;
}
;
typedef btAlignedObjectArray<btIndexedMesh> IndexedMeshArray;
-///TriangleIndexVertexArray allows to use multiple meshes, by indexing into existing triangle/index arrays.
+///The btTriangleIndexVertexArray allows to access multiple triangle meshes, by indexing into existing triangle/index arrays.
///Additional meshes can be added using addIndexedMesh
///No duplcate is made of the vertex/index data, it only indexes into external vertex/index arrays.
///So keep those arrays around during the lifetime of this btTriangleIndexVertexArray.
ATTRIBUTE_ALIGNED16( class) btTriangleIndexVertexArray : public btStridingMeshInterface
{
+protected:
IndexedMeshArray m_indexedMeshes;
- int m_pad[3];
+ int m_pad[2];
+ int m_hasAabb; // using int instead of bool to maintain alignment
+ btVector3 m_aabbMin;
+ btVector3 m_aabbMax;
-
public:
- btTriangleIndexVertexArray()
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
+ btTriangleIndexVertexArray() : m_hasAabb(0)
{
}
+ virtual ~btTriangleIndexVertexArray();
+
//just to be backwards compatible
- btTriangleIndexVertexArray(int numTriangleIndices,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride);
+ btTriangleIndexVertexArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,int numVertices,btScalar* vertexBase,int vertexStride);
- void addIndexedMesh(const btIndexedMesh& mesh)
+ void addIndexedMesh(const btIndexedMesh& mesh, PHY_ScalarType indexType = PHY_INTEGER)
{
m_indexedMeshes.push_back(mesh);
+ m_indexedMeshes[m_indexedMeshes.size()-1].m_indexType = indexType;
}
@@ -91,6 +105,10 @@ public:
virtual void preallocateVertices(int numverts){(void) numverts;}
virtual void preallocateIndices(int numindices){(void) numindices;}
+ virtual bool hasPremadeAabb() const;
+ virtual void setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax );
+ virtual void getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const;
+
}
;
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
new file mode 100644
index 00000000000..492854ff646
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
@@ -0,0 +1,86 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+///This file was created by Alex Silverman
+
+#include "btTriangleIndexVertexMaterialArray.h"
+
+btTriangleIndexVertexMaterialArray::btTriangleIndexVertexMaterialArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,
+ int numVertices,btScalar* vertexBase,int vertexStride,
+ int numMaterials, unsigned char* materialBase, int materialStride,
+ int* triangleMaterialsBase, int materialIndexStride) :
+btTriangleIndexVertexArray(numTriangles, triangleIndexBase, triangleIndexStride, numVertices, vertexBase, vertexStride)
+{
+ btMaterialProperties mat;
+
+ mat.m_numMaterials = numMaterials;
+ mat.m_materialBase = materialBase;
+ mat.m_materialStride = materialStride;
+#ifdef BT_USE_DOUBLE_PRECISION
+ mat.m_materialType = PHY_DOUBLE;
+#else
+ mat.m_materialType = PHY_FLOAT;
+#endif
+
+ mat.m_numTriangles = numTriangles;
+ mat.m_triangleMaterialsBase = (unsigned char *)triangleMaterialsBase;
+ mat.m_triangleMaterialStride = materialIndexStride;
+ mat.m_triangleType = PHY_INTEGER;
+
+ addMaterialProperties(mat);
+}
+
+
+void btTriangleIndexVertexMaterialArray::getLockedMaterialBase(unsigned char **materialBase, int& numMaterials, PHY_ScalarType& materialType, int& materialStride,
+ unsigned char ** triangleMaterialBase, int& numTriangles, int& triangleMaterialStride, PHY_ScalarType& triangleType, int subpart)
+{
+ btAssert(subpart< getNumSubParts() );
+
+ btMaterialProperties& mats = m_materials[subpart];
+
+ numMaterials = mats.m_numMaterials;
+ (*materialBase) = (unsigned char *) mats.m_materialBase;
+#ifdef BT_USE_DOUBLE_PRECISION
+ materialType = PHY_DOUBLE;
+#else
+ materialType = PHY_FLOAT;
+#endif
+ materialStride = mats.m_materialStride;
+
+ numTriangles = mats.m_numTriangles;
+ (*triangleMaterialBase) = (unsigned char *)mats.m_triangleMaterialsBase;
+ triangleMaterialStride = mats.m_triangleMaterialStride;
+ triangleType = mats.m_triangleType;
+}
+
+void btTriangleIndexVertexMaterialArray::getLockedReadOnlyMaterialBase(const unsigned char **materialBase, int& numMaterials, PHY_ScalarType& materialType, int& materialStride,
+ const unsigned char ** triangleMaterialBase, int& numTriangles, int& triangleMaterialStride, PHY_ScalarType& triangleType, int subpart)
+{
+ btMaterialProperties& mats = m_materials[subpart];
+
+ numMaterials = mats.m_numMaterials;
+ (*materialBase) = (const unsigned char *) mats.m_materialBase;
+#ifdef BT_USE_DOUBLE_PRECISION
+ materialType = PHY_DOUBLE;
+#else
+ materialType = PHY_FLOAT;
+#endif
+ materialStride = mats.m_materialStride;
+
+ numTriangles = mats.m_numTriangles;
+ (*triangleMaterialBase) = (const unsigned char *)mats.m_triangleMaterialsBase;
+ triangleMaterialStride = mats.m_triangleMaterialStride;
+ triangleType = mats.m_triangleType;
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h
new file mode 100644
index 00000000000..69a2e631458
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h
@@ -0,0 +1,84 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+///This file was created by Alex Silverman
+
+#ifndef BT_MULTIMATERIAL_TRIANGLE_INDEX_VERTEX_ARRAY_H
+#define BT_MULTIMATERIAL_TRIANGLE_INDEX_VERTEX_ARRAY_H
+
+#include "btTriangleIndexVertexArray.h"
+
+
+ATTRIBUTE_ALIGNED16( struct) btMaterialProperties
+{
+ ///m_materialBase ==========> 2 btScalar values make up one material, friction then restitution
+ int m_numMaterials;
+ const unsigned char * m_materialBase;
+ int m_materialStride;
+ PHY_ScalarType m_materialType;
+ ///m_numTriangles <=========== This exists in the btIndexedMesh object for the same subpart, but since we're
+ /// padding the structure, it can be reproduced at no real cost
+ ///m_triangleMaterials =====> 1 integer value makes up one entry
+ /// eg: m_triangleMaterials[1] = 5; // This will set triangle 2 to use material 5
+ int m_numTriangles;
+ const unsigned char * m_triangleMaterialsBase;
+ int m_triangleMaterialStride;
+ ///m_triangleType <========== Automatically set in addMaterialProperties
+ PHY_ScalarType m_triangleType;
+};
+
+typedef btAlignedObjectArray<btMaterialProperties> MaterialArray;
+
+///Teh btTriangleIndexVertexMaterialArray is built on TriangleIndexVertexArray
+///The addition of a material array allows for the utilization of the partID and
+///triangleIndex that are returned in the ContactAddedCallback. As with
+///TriangleIndexVertexArray, no duplicate is made of the material data, so it
+///is the users responsibility to maintain the array during the lifetime of the
+///TriangleIndexVertexMaterialArray.
+ATTRIBUTE_ALIGNED16(class) btTriangleIndexVertexMaterialArray : public btTriangleIndexVertexArray
+{
+protected:
+ MaterialArray m_materials;
+
+public:
+ BT_DECLARE_ALIGNED_ALLOCATOR();
+
+ btTriangleIndexVertexMaterialArray()
+ {
+ }
+
+ btTriangleIndexVertexMaterialArray(int numTriangles,int* triangleIndexBase,int triangleIndexStride,
+ int numVertices,btScalar* vertexBase,int vertexStride,
+ int numMaterials, unsigned char* materialBase, int materialStride,
+ int* triangleMaterialsBase, int materialIndexStride);
+
+ virtual ~btTriangleIndexVertexMaterialArray() {}
+
+ void addMaterialProperties(const btMaterialProperties& mat, PHY_ScalarType triangleType = PHY_INTEGER)
+ {
+ m_materials.push_back(mat);
+ m_materials[m_materials.size()-1].m_triangleType = triangleType;
+ }
+
+ virtual void getLockedMaterialBase(unsigned char **materialBase, int& numMaterials, PHY_ScalarType& materialType, int& materialStride,
+ unsigned char ** triangleMaterialBase, int& numTriangles, int& triangleMaterialStride, PHY_ScalarType& triangleType ,int subpart = 0);
+
+ virtual void getLockedReadOnlyMaterialBase(const unsigned char **materialBase, int& numMaterials, PHY_ScalarType& materialType, int& materialStride,
+ const unsigned char ** triangleMaterialBase, int& numTriangles, int& triangleMaterialStride, PHY_ScalarType& triangleType, int subpart = 0);
+
+}
+;
+
+#endif //BT_MULTIMATERIAL_TRIANGLE_INDEX_VERTEX_ARRAY_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp
index 98c54ef45f8..bcea97052d6 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp
@@ -14,47 +14,102 @@ subject to the following restrictions:
*/
#include "btTriangleMesh.h"
-#include <assert.h>
-btTriangleMesh::btTriangleMesh ()
+
+btTriangleMesh::btTriangleMesh (bool use32bitIndices,bool use4componentVertices)
+:m_use32bitIndices(use32bitIndices),
+m_use4componentVertices(use4componentVertices)
{
+ btIndexedMesh meshIndex;
+ meshIndex.m_numTriangles = 0;
+ meshIndex.m_numVertices = 0;
+ meshIndex.m_indexType = PHY_INTEGER;
+ meshIndex.m_triangleIndexBase = 0;
+ meshIndex.m_triangleIndexStride = 3*sizeof(int);
+ meshIndex.m_vertexBase = 0;
+ meshIndex.m_vertexStride = sizeof(btVector3);
+ m_indexedMeshes.push_back(meshIndex);
-}
+ if (m_use32bitIndices)
+ {
+ m_indexedMeshes[0].m_numTriangles = m_32bitIndices.size()/3;
+ m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_32bitIndices[0];
+ m_indexedMeshes[0].m_indexType = PHY_INTEGER;
+ m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(int);
+ } else
+ {
+ m_indexedMeshes[0].m_numTriangles = m_16bitIndices.size()/3;
+ m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_16bitIndices[0];
+ m_indexedMeshes[0].m_indexType = PHY_SHORT;
+ m_indexedMeshes[0].m_triangleIndexStride = 3*sizeof(short int);
+ }
-void btTriangleMesh::getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart)
-{
- (void)subpart;
- numverts = m_vertices.size();
- *vertexbase = (unsigned char*)&m_vertices[0];
- type = PHY_FLOAT;
- stride = sizeof(btVector3);
+ if (m_use4componentVertices)
+ {
+ m_indexedMeshes[0].m_numVertices = m_4componentVertices.size();
+ m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_4componentVertices[0];
+ m_indexedMeshes[0].m_vertexStride = sizeof(btVector3);
+ } else
+ {
+ m_indexedMeshes[0].m_numVertices = m_3componentVertices.size()/3;
+ m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0];
+ m_indexedMeshes[0].m_vertexStride = 3*sizeof(btScalar);
+ }
- numfaces = m_indices.size()/3;
- *indexbase = (unsigned char*) &m_indices[0];
- indicestype = PHY_INTEGER;
- indexstride = 3*sizeof(int);
}
-void btTriangleMesh::getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart) const
+
+void btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
{
- (void)subpart;
- numverts = m_vertices.size();
- *vertexbase = (unsigned char*)&m_vertices[0];
- type = PHY_FLOAT;
- stride = sizeof(btVector3);
+ m_indexedMeshes[0].m_numTriangles++;
+ m_indexedMeshes[0].m_numVertices+=3;
- numfaces = m_indices.size()/3;
- *indexbase = (unsigned char*) &m_indices[0];
- indicestype = PHY_INTEGER;
- indexstride = 3*sizeof(int);
+ if (m_use4componentVertices)
+ {
+ m_4componentVertices.push_back(vertex0);
+ m_4componentVertices.push_back(vertex1);
+ m_4componentVertices.push_back(vertex2);
+ m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_4componentVertices[0];
+ } else
+ {
+ m_3componentVertices.push_back(vertex0.getX());
+ m_3componentVertices.push_back(vertex0.getY());
+ m_3componentVertices.push_back(vertex0.getZ());
-}
+ m_3componentVertices.push_back(vertex1.getX());
+ m_3componentVertices.push_back(vertex1.getY());
+ m_3componentVertices.push_back(vertex1.getZ());
+ m_3componentVertices.push_back(vertex2.getX());
+ m_3componentVertices.push_back(vertex2.getY());
+ m_3componentVertices.push_back(vertex2.getZ());
+ m_indexedMeshes[0].m_vertexBase = (unsigned char*)&m_3componentVertices[0];
+ }
+ if (m_use32bitIndices)
+ {
+ int curIndex = m_32bitIndices.size();
+ m_32bitIndices.push_back(curIndex++);
+ m_32bitIndices.push_back(curIndex++);
+ m_32bitIndices.push_back(curIndex++);
+ m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_32bitIndices[0];
+ } else
+ {
+ short curIndex = static_cast<short>(m_16bitIndices.size());
+ m_16bitIndices.push_back(curIndex++);
+ m_16bitIndices.push_back(curIndex++);
+ m_16bitIndices.push_back(curIndex++);
+ m_indexedMeshes[0].m_triangleIndexBase = (unsigned char*) &m_16bitIndices[0];
+ }
+}
-int btTriangleMesh::getNumSubParts() const
+int btTriangleMesh::getNumTriangles() const
{
- return 1;
+ if (m_use32bitIndices)
+ {
+ return m_32bitIndices.size() / 3;
+ }
+ return m_16bitIndices.size() / 3;
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h
index 525f5336b48..e4d41d5ede0 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h
@@ -17,54 +17,42 @@ subject to the following restrictions:
#ifndef TRIANGLE_MESH_H
#define TRIANGLE_MESH_H
-#include "btStridingMeshInterface.h"
-#include "../../LinearMath/btVector3.h"
-#include "../../LinearMath/btAlignedObjectArray.h"
-
-///TriangleMesh provides storage for a concave triangle mesh. It can be used as data for the btTriangleMeshShape.
-class btTriangleMesh : public btStridingMeshInterface
+#include "btTriangleIndexVertexArray.h"
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btAlignedObjectArray.h"
+
+///The btTriangleMesh class is a convenience class derived from btTriangleIndexVertexArray, that provides storage for a concave triangle mesh. It can be used as data for the btBvhTriangleMeshShape.
+///It allows either 32bit or 16bit indices, and 4 (x-y-z-w) or 3 (x-y-z) component vertices.
+///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.
+///Performance of btTriangleMesh and btTriangleIndexVertexArray used in a btBvhTriangleMeshShape is the same.
+class btTriangleMesh : public btTriangleIndexVertexArray
{
- btAlignedObjectArray<btVector3> m_vertices;
- btAlignedObjectArray<int> m_indices;
+ btAlignedObjectArray<btVector3> m_4componentVertices;
+ btAlignedObjectArray<float> m_3componentVertices;
+
+ btAlignedObjectArray<unsigned int> m_32bitIndices;
+ btAlignedObjectArray<unsigned short int> m_16bitIndices;
+ bool m_use32bitIndices;
+ bool m_use4componentVertices;
+
public:
- btTriangleMesh ();
+ btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true);
- void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
+ bool getUse32bitIndices() const
{
- int curIndex = m_indices.size();
- m_vertices.push_back(vertex0);
- m_vertices.push_back(vertex1);
- m_vertices.push_back(vertex2);
-
- m_indices.push_back(curIndex++);
- m_indices.push_back(curIndex++);
- m_indices.push_back(curIndex++);
+ return m_use32bitIndices;
}
- int getNumTriangles() const
+ bool getUse4componentVertices() const
{
- return m_indices.size() / 3;
+ return m_use4componentVertices;
}
-
-
-//StridingMeshInterface interface implementation
-
- virtual void getLockedVertexIndexBase(unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0);
-
- virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,const unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart=0) const;
-
- /// unLockVertexBase finishes the access to a subpart of the triangle mesh
- /// make a call to unLockVertexBase when the read and write access (using getLockedVertexIndexBase) is finished
- virtual void unLockVertexBase(int subpart) {(void) subpart;}
-
- virtual void unLockReadOnlyVertexBase(int subpart) const { (void) subpart;}
-
- /// getNumSubParts returns the number of seperate subparts
- /// each subpart has a continuous array of vertices and indices
- virtual int getNumSubParts() const;
+ void addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2);
+ int getNumTriangles() const;
+
virtual void preallocateVertices(int numverts){(void) numverts;}
virtual void preallocateIndices(int numindices){(void) numindices;}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
index ed81897b515..0a2c77096d1 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
@@ -20,12 +20,18 @@ subject to the following restrictions:
#include "LinearMath/btAabbUtil2.h"
#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
-#include "stdio.h"
btTriangleMeshShape::btTriangleMeshShape(btStridingMeshInterface* meshInterface)
: m_meshInterface(meshInterface)
{
- recalcLocalAabb();
+ if(meshInterface->hasPremadeAabb())
+ {
+ meshInterface->getPremadeAabb(&m_localAabbMin, &m_localAabbMax);
+ }
+ else
+ {
+ recalcLocalAabb();
+ }
}
@@ -41,6 +47,7 @@ void btTriangleMeshShape::getAabb(const btTransform& trans,btVector3& aabbMin,bt
{
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
+ localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
btMatrix3x3 abs_b = trans.getBasis().absolute();
@@ -50,12 +57,10 @@ void btTriangleMeshShape::getAabb(const btTransform& trans,btVector3& aabbMin,bt
btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
abs_b[1].dot(localHalfExtents),
abs_b[2].dot(localHalfExtents));
- extent += btVector3(getMargin(),getMargin(),getMargin());
-
aabbMin = center - extent;
aabbMax = center + extent;
-
+
}
void btTriangleMeshShape::recalcLocalAabb()
@@ -138,6 +143,7 @@ const btVector3& btTriangleMeshShape::getLocalScaling() const
//#define DEBUG_TRIANGLE_MESH
+
void btTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
{
struct FilteredCallback : public btInternalTriangleIndexCallback
@@ -174,8 +180,7 @@ void btTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const
-
-void btTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+void btTriangleMeshShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
(void)mass;
//moving concave objects not supported
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
index e6173e47640..c9eabafe290 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
@@ -20,18 +20,20 @@ subject to the following restrictions:
#include "btStridingMeshInterface.h"
-///Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
+///The btTriangleMeshShape is an internal concave triangle mesh interface. Don't use this class directly, use btBvhTriangleMeshShape instead.
class btTriangleMeshShape : public btConcaveShape
{
protected:
btVector3 m_localAabbMin;
btVector3 m_localAabbMax;
btStridingMeshInterface* m_meshInterface;
-
-public:
+ ///btTriangleMeshShape constructor has been disabled/protected, so that users will not mistakenly use this class.
+ ///Don't use btTriangleMeshShape but use btBvhTriangleMeshShape instead!
btTriangleMeshShape(btStridingMeshInterface* meshInterface);
+public:
+
virtual ~btTriangleMeshShape();
virtual btVector3 localGetSupportingVertex(const btVector3& vec) const;
@@ -44,16 +46,11 @@ public:
void recalcLocalAabb();
- virtual int getShapeType() const
- {
- return TRIANGLE_MESH_SHAPE_PROXYTYPE;
- }
-
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
virtual void processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia);
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
virtual void setLocalScaling(const btVector3& scaling);
virtual const btVector3& getLocalScaling() const;
@@ -68,9 +65,19 @@ public:
return m_meshInterface;
}
+ const btVector3& getLocalAabbMin() const
+ {
+ return m_localAabbMin;
+ }
+ const btVector3& getLocalAabbMax() const
+ {
+ return m_localAabbMax;
+ }
+
+
//debugging
- virtual char* getName()const {return "TRIANGLEMESH";}
+ virtual const char* getName()const {return "TRIANGLEMESH";}
};
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h
index c2e240c051c..ba7aa0c32a0 100644
--- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h
@@ -27,7 +27,6 @@ public:
btVector3 m_vertices1[3];
-
virtual int getNumVertices() const
{
return 3;
@@ -84,14 +83,13 @@ public:
- btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2)
- {
- m_vertices1[0] = p0;
- m_vertices1[1] = p1;
- m_vertices1[2] = p2;
- }
+ btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2)
+ {
+ m_vertices1[0] = p0;
+ m_vertices1[1] = p1;
+ m_vertices1[2] = p2;
+ }
-
virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i) const
{
@@ -116,7 +114,7 @@ public:
planeSupport = m_vertices1[0];
}
- virtual void calculateLocalInertia(btScalar mass,btVector3& inertia)
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
(void)mass;
btAssert(0);
@@ -155,7 +153,7 @@ public:
return false;
}
//debugging
- virtual char* getName()const
+ virtual const char* getName()const
{
return "Triangle";
}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp
new file mode 100644
index 00000000000..ef340286cb0
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp
@@ -0,0 +1,114 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "btUniformScalingShape.h"
+
+btUniformScalingShape::btUniformScalingShape( btConvexShape* convexChildShape,btScalar uniformScalingFactor):
+m_childConvexShape(convexChildShape),
+m_uniformScalingFactor(uniformScalingFactor)
+{
+}
+
+btUniformScalingShape::~btUniformScalingShape()
+{
+}
+
+
+btVector3 btUniformScalingShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+{
+ btVector3 tmpVertex;
+ tmpVertex = m_childConvexShape->localGetSupportingVertexWithoutMargin(vec);
+ return tmpVertex*m_uniformScalingFactor;
+}
+
+void btUniformScalingShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+{
+ m_childConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors);
+ int i;
+ for (i=0;i<numVectors;i++)
+ {
+ supportVerticesOut[i] = supportVerticesOut[i] * m_uniformScalingFactor;
+ }
+}
+
+
+btVector3 btUniformScalingShape::localGetSupportingVertex(const btVector3& vec)const
+{
+ btVector3 tmpVertex;
+ tmpVertex = m_childConvexShape->localGetSupportingVertex(vec);
+ return tmpVertex*m_uniformScalingFactor;
+}
+
+
+void btUniformScalingShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
+{
+
+ ///this linear upscaling is not realistic, but we don't deal with large mass ratios...
+ btVector3 tmpInertia;
+ m_childConvexShape->calculateLocalInertia(mass,tmpInertia);
+ inertia = tmpInertia * m_uniformScalingFactor;
+}
+
+
+ ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
+void btUniformScalingShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+{
+ m_childConvexShape->getAabb(t,aabbMin,aabbMax);
+ btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5);
+ btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor;
+
+ aabbMin = aabbCenter - scaledAabbHalfExtends;
+ aabbMax = aabbCenter + scaledAabbHalfExtends;
+
+}
+
+void btUniformScalingShape::getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+{
+ m_childConvexShape->getAabbSlow(t,aabbMin,aabbMax);
+ btVector3 aabbCenter = (aabbMax+aabbMin)*btScalar(0.5);
+ btVector3 scaledAabbHalfExtends = (aabbMax-aabbMin)*btScalar(0.5)*m_uniformScalingFactor;
+
+ aabbMin = aabbCenter - scaledAabbHalfExtends;
+ aabbMax = aabbCenter + scaledAabbHalfExtends;
+}
+
+void btUniformScalingShape::setLocalScaling(const btVector3& scaling)
+{
+ m_childConvexShape->setLocalScaling(scaling);
+}
+
+const btVector3& btUniformScalingShape::getLocalScaling() const
+{
+ return m_childConvexShape->getLocalScaling();
+}
+
+void btUniformScalingShape::setMargin(btScalar margin)
+{
+ m_childConvexShape->setMargin(margin);
+}
+btScalar btUniformScalingShape::getMargin() const
+{
+ return m_childConvexShape->getMargin() * m_uniformScalingFactor;
+}
+
+int btUniformScalingShape::getNumPreferredPenetrationDirections() const
+{
+ return m_childConvexShape->getNumPreferredPenetrationDirections();
+}
+
+void btUniformScalingShape::getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
+{
+ m_childConvexShape->getPreferredPenetrationDirection(index,penetrationVector);
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.h
new file mode 100644
index 00000000000..1e17fc8e198
--- /dev/null
+++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.h
@@ -0,0 +1,88 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it freely,
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef BT_UNIFORM_SCALING_SHAPE_H
+#define BT_UNIFORM_SCALING_SHAPE_H
+
+#include "btConvexShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+
+///The btUniformScalingShape allows to re-use uniform scaled instances of btConvexShape in a memory efficient way.
+///Istead of using btUniformScalingShape, it is better to use the non-uniform setLocalScaling method on convex shapes that implement it.
+class btUniformScalingShape : public btConvexShape
+{
+ btConvexShape* m_childConvexShape;
+
+ btScalar m_uniformScalingFactor;
+
+ public:
+
+ btUniformScalingShape( btConvexShape* convexChildShape, btScalar uniformScalingFactor);
+
+ virtual ~btUniformScalingShape();
+
+ virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
+
+ virtual btVector3 localGetSupportingVertex(const btVector3& vec)const;
+
+ virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+
+ virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const;
+
+ btScalar getUniformScalingFactor() const
+ {
+ return m_uniformScalingFactor;
+ }
+
+ btConvexShape* getChildShape()
+ {
+ return m_childConvexShape;
+ }
+
+ const btConvexShape* getChildShape() const
+ {
+ return m_childConvexShape;
+ }
+
+ virtual const char* getName()const
+ {
+ return "UniformScalingShape";
+ }
+
+ virtual int getShapeType() const { return UNIFORM_SCALING_SHAPE_PROXYTYPE; }
+
+
+ ///////////////////////////
+
+
+ ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
+ void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+
+ virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+
+ virtual void setLocalScaling(const btVector3& scaling) ;
+ virtual const btVector3& getLocalScaling() const ;
+
+ virtual void setMargin(btScalar margin);
+ virtual btScalar getMargin() const;
+
+ virtual int getNumPreferredPenetrationDirections() const;
+
+ virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const;
+
+
+};
+
+#endif //BT_UNIFORM_SCALING_SHAPE_H