updated to latest Bullet 2.x
authorErwin Coumans <blender@erwincoumans.com>
Wed, 29 Nov 2006 05:24:52 +0000 (05:24 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Wed, 29 Nov 2006 05:24:52 +0000 (05:24 +0000)
41 files changed:
extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp
extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h
extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp
extern/bullet2/src/LinearMath/btScalar.h
extern/bullet2/src/LinearMath/btStackAlloc.h [new file with mode: 0644]

index 7b35df09db6db73db63d15958ca0bea1a928e53d..3ad2467886b28f5085b9fdee23f3ce793c2f64d4 100644 (file)
@@ -44,6 +44,8 @@ CONCAVE_SHAPES_START_HERE,
        TRIANGLE_MESH_SHAPE_PROXYTYPE,
        ///used for demo integration FAST/Swift collision library and Bullet
        FAST_CONCAVE_MESH_PROXYTYPE,
+       //terrain
+       TERRAIN_SHAPE_PROXYTYPE,
 ///Used for GIMPACT Trimesh integration
        GIMPACT_SHAPE_PROXYTYPE,
        
index 415c398a1016cbea4a92366814cc80722fe98962..1a4713986380026ca250ce991737794f148be819 100644 (file)
@@ -29,6 +29,7 @@ enum btCollisionDispatcherId
 };
 
 class btPersistentManifold;
+class btStackAlloc;
 
 struct btDispatcherInfo
 {
@@ -45,7 +46,8 @@ struct btDispatcherInfo
                m_useContinuous(false),
                m_debugDraw(0),
                m_enableSatConvex(false),
-               m_enableSPU(false)
+               m_enableSPU(false),
+               m_stackAllocator(0)
        {
 
        }
@@ -57,6 +59,7 @@ struct btDispatcherInfo
        class btIDebugDraw*     m_debugDraw;
        bool    m_enableSatConvex;
        bool    m_enableSPU;
+       btStackAlloc*   m_stackAllocator;
        
 };
 
index c9d21f2d9a38296a60756fc8eddb930b04408149..e8865a2c45a51b4a3b7c37776d0afc3c0c232399 100644 (file)
@@ -101,7 +101,7 @@ btPersistentManifold*       btCollisionDispatcher::getNewManifold(void* b0,void* b1)
 { 
        gNumManifold++;
        
-       //ASSERT(gNumManifold < 65535);
+       //btAssert(gNumManifold < 65535);
        
 
        btCollisionObject* body0 = (btCollisionObject*)b0;
@@ -145,7 +145,7 @@ void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 
 btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold)
 {
-#define USE_DISPATCH_REGISTRY_ARRAY 1
+
 #ifdef USE_DISPATCH_REGISTRY_ARRAY
        
        btCollisionAlgorithmConstructionInfo ci;
@@ -194,6 +194,7 @@ btCollisionAlgorithmCreateFunc* btCollisionDispatcher::internalFindCreateFunc(in
 }
 
 
+#ifndef USE_DISPATCH_REGISTRY_ARRAY
 
 btCollisionAlgorithm* btCollisionDispatcher::internalFindAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold)
 {
@@ -232,6 +233,7 @@ btCollisionAlgorithm* btCollisionDispatcher::internalFindAlgorithm(btCollisionOb
        return new btEmptyAlgorithm(ci);
        
 }
+#endif //USE_DISPATCH_REGISTRY_ARRAY
 
 bool   btCollisionDispatcher::needsResponse(btCollisionObject* body0,btCollisionObject* body1)
 {
index 4e97bce9d65ce94203d2780b0ebceb4d0a9d079f..41bc98e1dca8cb3f81865a1f7cebace23c8c7cfc 100644 (file)
@@ -30,7 +30,7 @@ class btOverlappingPairCache;
 
 #include "btCollisionCreateFunc.h"
 
-
+#define USE_DISPATCH_REGISTRY_ARRAY 1
 
 
 ///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
@@ -56,7 +56,9 @@ class btCollisionDispatcher : public btDispatcher
        btCollisionAlgorithmCreateFunc* m_swappedCompoundCreateFunc;
        btCollisionAlgorithmCreateFunc*   m_emptyCreateFunc;
 
+#ifndef USE_DISPATCH_REGISTRY_ARRAY
        btCollisionAlgorithm* internalFindAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0);
+#endif //USE_DISPATCH_REGISTRY_ARRAY
 
 public:
 
index 775ed3e13d817ff0d4b8da2fa76d718c6b57c292..9df6d7186ec2e1ad3a10c93d56aec34b70551add 100644 (file)
@@ -25,6 +25,7 @@ subject to the following restrictions:
 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btQuickprof.h"
+#include "LinearMath/btStackAlloc.h"
 
 //When the user doesn't provide dispatcher or broadphase, create basic versions (and delete them in destructor)
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
@@ -32,26 +33,22 @@ subject to the following restrictions:
 
 #include <algorithm>
 
-btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
+btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache, int stackSize)
 :m_dispatcher1(dispatcher),
 m_broadphasePairCache(pairCache),
 m_ownsDispatcher(false),
 m_ownsBroadphasePairCache(false)
 {
-}
-
-
-btCollisionWorld::btCollisionWorld()
-: m_dispatcher1(new    btCollisionDispatcher()),
-m_broadphasePairCache(new btSimpleBroadphase()),
-m_ownsDispatcher(true),
-m_ownsBroadphasePairCache(true)
-{
+       m_stackAlloc = new btStackAlloc(stackSize);
+       m_dispatchInfo.m_stackAllocator = m_stackAlloc;
 }
 
 
 btCollisionWorld::~btCollisionWorld()
 {
+       m_stackAlloc->destroy();
+       delete m_stackAlloc;
+
        //clean up remaining objects
        std::vector<btCollisionObject*>::iterator i;
 
index e212e520bda73849023e024d840351eb33460b2f..9c5487848295bb2145f0f64b2e311a07dc9ccc9b 100644 (file)
@@ -64,7 +64,7 @@ subject to the following restrictions:
 #ifndef COLLISION_WORLD_H
 #define COLLISION_WORLD_H
 
-
+class btStackAlloc;
 class btCollisionShape;
 class btBroadphaseInterface;
 #include "LinearMath/btVector3.h"
@@ -88,6 +88,10 @@ protected:
        
        btDispatcher*   m_dispatcher1;
 
+       btDispatcherInfo        m_dispatchInfo;
+
+       btStackAlloc*   m_stackAlloc;
+
        btOverlappingPairCache* m_broadphasePairCache;
        
        bool    m_ownsDispatcher;
@@ -95,11 +99,8 @@ protected:
 
 public:
 
-       //this constructor will create and own a dispatcher and paircache and delete it at destruction
-       btCollisionWorld();
-
        //this constructor doesn't own the dispatcher and paircache/broadphase
-       btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache);
+       btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache, int stackSize = 2*1024*1024);
 
        virtual ~btCollisionWorld();
 
@@ -237,7 +238,12 @@ public:
        void    removeCollisionObject(btCollisionObject* collisionObject);
 
        virtual void    performDiscreteCollisionDetection(      btDispatcherInfo&       dispatchInfo);
-       
+
+       btDispatcherInfo& getDispatchInfo()
+       {
+               return m_dispatchInfo;
+       }
+
 };
 
 
index 8ad3967bac2f81c9b1962d67d94bb01e60d97b5a..06adb3a04c8311112857ca414e6f809c2b0c83a4 100644 (file)
@@ -172,7 +172,7 @@ void btConvexConcaveCollisionAlgorithm::processCollision (btCollisionObject* bod
 
 
                btCollisionObject*      triOb = triBody;
-               ConcaveShape* concaveShape = static_cast<ConcaveShape*>( triOb->getCollisionShape());
+               btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
                
                if (convexBody->getCollisionShape()->isConvex())
                {
@@ -288,7 +288,7 @@ float btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject
 
                btCollisionObject* concavebody = triBody;
 
-               ConcaveShape* triangleMesh = (ConcaveShape*) concavebody->getCollisionShape();
+               btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape();
                
                if (triangleMesh)
                {
index e896508bdb947c2defd8638bf1a304b24b0789c8..09457aea3e94fd3e95963be57382c2ce08cd9837 100644 (file)
@@ -61,37 +61,28 @@ subject to the following restrictions:
 
 #endif //USE_HULL
 
-bool gUseEpa = true;
-
-
-#ifdef WIN32
-void DrawRasterizerLine(const float* from,const float* to,int color);
-#endif
-
-
-
-
-//#define PROCESS_SINGLE_CONTACT
-#ifdef WIN32
-bool gForceBoxBox = false;//false;//true;
-
-#else
-bool gForceBoxBox = false;//false;//true;
-#endif
-bool gBoxBoxUseGjk = true;//true;//false;
-bool gDisableConvexCollision = false;
 
+btConvexConvexAlgorithm::CreateFunc::CreateFunc()
+{
+       m_ownsSolvers = true;
+       m_simplexSolver = new btVoronoiSimplexSolver();
+       m_pdSolver = new btGjkEpaPenetrationDepthSolver;
+}
 
+btConvexConvexAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*                      simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
+{
+       m_ownsSolvers = false;
+       m_simplexSolver = simplexSolver;
+       m_pdSolver = pdSolver;
+}
 
-btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1)
+btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
 : btCollisionAlgorithm(ci),
-m_gjkPairDetector(0,0,&m_simplexSolver,0),
-m_useEpa(!gUseEpa),
+m_gjkPairDetector(0,0,simplexSolver,pdSolver),
 m_ownManifold (false),
 m_manifoldPtr(mf),
 m_lowLevelOfDetail(false)
 {
-       checkPenetrationDepthSolver();
 
 }
 
@@ -115,27 +106,6 @@ void       btConvexConvexAlgorithm ::setLowLevelOfDetail(bool useLowLevel)
 
 
 
-static btGjkEpaPenetrationDepthSolver  gEpaPenetrationDepthSolver;
-static btMinkowskiPenetrationDepthSolver       gPenetrationDepthSolver;
-
-
-
-void   btConvexConvexAlgorithm::checkPenetrationDepthSolver()
-{
-       if (m_useEpa != gUseEpa)
-       {
-               m_useEpa  = gUseEpa;
-               if (m_useEpa)
-               {
-                       m_gjkPairDetector.setPenetrationDepthSolver(&gEpaPenetrationDepthSolver);
-               } else
-               {
-                       m_gjkPairDetector.setPenetrationDepthSolver(&gPenetrationDepthSolver);
-               }
-       }
-       
-}
-
 
 //
 // Convex-Convex collision algorithm
@@ -164,7 +134,6 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
                resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth);
                }
 #else
-       checkPenetrationDepthSolver();
 
        btConvexShape* min0 = static_cast<btConvexShape*>(body0->getCollisionShape());
        btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape());
@@ -176,7 +145,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
        m_gjkPairDetector.setMinkowskiB(min1);
        input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
        input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
-       
+       input.m_stackAlloc = dispatchInfo.m_stackAllocator;
+
 //     input.m_maximumDistanceSquared = 1e30f;
        
        input.m_transformA = body0->getWorldTransform();
@@ -209,7 +179,6 @@ float       btConvexConvexAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btC
        if (disableCcd)
                return 1.f;
 
-       checkPenetrationDepthSolver();
 
        //An adhoc way of testing the Continuous Collision Detection algorithms
        //One object is approximated as a sphere, to simplify things
index 1cd94408f1fe0c1bb55142ef420d47a6ebd04015..ccfe6d5b8cb1d170647455ccc5a18705698726c7 100644 (file)
@@ -28,23 +28,17 @@ class btConvexPenetrationDepthSolver;
 ///ConvexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations.
 class btConvexConvexAlgorithm : public btCollisionAlgorithm
 {
-       //ConvexPenetrationDepthSolver* m_penetrationDepthSolver;
-       btVoronoiSimplexSolver  m_simplexSolver;
        btGjkPairDetector m_gjkPairDetector;
-       bool    m_useEpa;
 public:
 
        bool    m_ownManifold;
        btPersistentManifold*   m_manifoldPtr;
        bool                    m_lowLevelOfDetail;
-
-       void    checkPenetrationDepthSolver();
-
        
 
 public:
 
-       btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
+       btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
 
        virtual ~btConvexConvexAlgorithm();
 
@@ -62,9 +56,16 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
+               btConvexPenetrationDepthSolver*         m_pdSolver;
+               btSimplexSolverInterface*                       m_simplexSolver;
+               bool    m_ownsSolvers;
+               
+               CreateFunc(btSimplexSolverInterface*                    simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
+               CreateFunc();
+
                virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
                {
-                       return new btConvexConvexAlgorithm(ci.m_manifold,ci,body0,body1);
+                       return new btConvexConvexAlgorithm(ci.m_manifold,ci,body0,body1,m_simplexSolver,m_pdSolver);
                }
        };
 
index e85a36c0b73ff024dd5b26a01fb07a1417875627..ee451a9b6c0dec9e74bce33bcca44af3be7dc32a 100644 (file)
@@ -220,7 +220,7 @@ public:
                        edgeVert1 = 7;
                        break;
                default:
-                       ASSERT(0);
+                       btAssert(0);
 
                }
 
index 338527d58a4c44b119556fb6ec6933dfac50b35a..3bd0a31754522d199086210d69ce60491d9fc911 100644 (file)
@@ -15,7 +15,6 @@ subject to the following restrictions:
 
 //#define DISABLE_BVH
 
-
 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
 #include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
 
index 29f62828d040849dddc96699675e9c84740d9c00..7cd35a9186019d1e448b8cf1a83be7201f5c4c24 100644 (file)
@@ -17,12 +17,12 @@ subject to the following restrictions:
 
 #include "btConcaveShape.h"
 
-ConcaveShape::ConcaveShape() : m_collisionMargin(0.f)
+btConcaveShape::btConcaveShape() : m_collisionMargin(0.f)
 {
 
 }
 
-ConcaveShape::~ConcaveShape()
+btConcaveShape::~btConcaveShape()
 {
 
 }
index 304654531edc2977903fbf138930db9b2cc8d8fb..2bbba88bc44aaf3e935ae6aefe732ba03285a183 100644 (file)
@@ -24,15 +24,15 @@ subject to the following restrictions:
 
 ///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.
-class ConcaveShape : public btCollisionShape
+class btConcaveShape : public btCollisionShape
 {
 protected:
        float m_collisionMargin;
 
 public:
-       ConcaveShape();
+       btConcaveShape();
 
-       virtual ~ConcaveShape();
+       virtual ~btConcaveShape();
 
        virtual void    processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const = 0;
 
index c92f42cdee8e040a42acce6a7e8d554699112f92..c16149e55fbdfd0104ce7eca62139bc22408b0dd 100644 (file)
@@ -29,7 +29,7 @@ subject to the following restrictions:
 
 /// btEmptyShape is a collision shape without actual collision detection. 
 ///It can be replaced by another shape during runtime
-class btEmptyShape     : public ConcaveShape
+class btEmptyShape     : public btConcaveShape
 {
 public:
        btEmptyShape();
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
new file mode 100644 (file)
index 0000000..57132ee
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+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 "btHeightfieldTerrainShape.h"
+
+#include "LinearMath/btTransformUtil.h"
+
+
+btHeightfieldTerrainShape::btHeightfieldTerrainShape()
+:m_localScaling(0.f,0.f,0.f)
+{
+}
+
+
+btHeightfieldTerrainShape::~btHeightfieldTerrainShape()
+{
+}
+
+
+
+void btHeightfieldTerrainShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+{
+       aabbMin.setValue(-1e30f,-1e30f,-1e30f);
+       aabbMax.setValue(1e30f,1e30f,1e30f);
+
+}
+
+
+
+
+void   btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
+{
+
+       btVector3 halfExtents = (aabbMax - aabbMin) * 0.5f;
+       btScalar radius = halfExtents.length();
+       btVector3 center = (aabbMax + aabbMin) * 0.5f;
+       
+       //TODO
+       //this is where the triangles are generated, given AABB and plane equation (normal/constant)
+/*
+       btVector3 tangentDir0,tangentDir1;
+
+       //tangentDir0/tangentDir1 can be precalculated
+       btPlaneSpace1(m_planeNormal,tangentDir0,tangentDir1);
+
+       btVector3 supVertex0,supVertex1;
+
+       btVector3 projectedCenter = center - (m_planeNormal.dot(center) - m_planeConstant)*m_planeNormal;
+       
+       btVector3 triangle[3];
+       triangle[0] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
+       triangle[1] = projectedCenter + tangentDir0*radius - tangentDir1*radius;
+       triangle[2] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
+
+       callback->processTriangle(triangle,0,0);
+
+       triangle[0] = projectedCenter - tangentDir0*radius - tangentDir1*radius;
+       triangle[1] = projectedCenter - tangentDir0*radius + tangentDir1*radius;
+       triangle[2] = projectedCenter + tangentDir0*radius + tangentDir1*radius;
+
+       callback->processTriangle(triangle,0,1);
+*/
+
+}
+
+void   btHeightfieldTerrainShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+{
+       //moving concave objects not supported
+       
+       inertia.setValue(0.f,0.f,0.f);
+}
+
+void   btHeightfieldTerrainShape::setLocalScaling(const btVector3& scaling)
+{
+       m_localScaling = scaling;
+}
+const btVector3& btHeightfieldTerrainShape::getLocalScaling() const
+{
+       return m_localScaling;
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
new file mode 100644 (file)
index 0000000..e4cc9d4
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+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 HEIGHTFIELD_TERRAIN_SHAPE_H
+#define HEIGHTFIELD_TERRAIN_SHAPE_H
+
+#include "BulletCollision/CollisionShapes/btConcaveShape.h"
+
+///btHeightfieldTerrainShape simulates a 2D heightfield terrain 
+class btHeightfieldTerrainShape : public btConcaveShape
+{
+protected:
+       btVector3       m_localAabbMin;
+       btVector3       m_localAabbMax;
+       
+       //todo: terrain data
+
+       btVector3       m_localScaling;
+
+public:
+       btHeightfieldTerrainShape();
+
+       virtual ~btHeightfieldTerrainShape();
+
+
+       virtual int     getShapeType() const
+       {
+               return TERRAIN_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    setLocalScaling(const btVector3& scaling);
+       
+       virtual const btVector3& getLocalScaling() const;
+       
+       //debugging
+       virtual char*   getName()const {return "HEIGHTFIELD";}
+
+};
+
+#endif //HEIGHTFIELD_TERRAIN_SHAPE_H
index 7414d470d7d590c184382d94e872784393172de0..65b30e1ff069370d1ba1c3b09f49d5be1284980d 100644 (file)
@@ -21,7 +21,7 @@ subject to the following restrictions:
 
 ///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.
-class btStaticPlaneShape : public ConcaveShape
+class btStaticPlaneShape : public btConcaveShape
 {
 protected:
        btVector3       m_localAabbMin;
index f7507b293948b1e51cd992ecd9a253fdbfbaea41..76b5859be7edee834f49eff1e8be74ce65703646 100644 (file)
@@ -76,7 +76,7 @@ void  btStridingMeshInterface::InternalProcessAllTriangles(btInternalTriangleInde
                                break;
                        }
                default:
-                       ASSERT((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
+                       btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
                }
 
                unLockReadOnlyVertexBase(part);
index 154b7145e680d1431a7366552f80c836b111e594..7400d372bee2dee4fe9e4a7a29e6c8a692a1ec15 100644 (file)
@@ -32,7 +32,7 @@ btTriangleIndexVertexArray::btTriangleIndexVertexArray(int numTriangles,int* tri
 
 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)
 {
-       ASSERT(subpart< getNumSubParts() );
+       btAssert(subpart< getNumSubParts() );
        
        btIndexedMesh& mesh = m_indexedMeshes[subpart];
 
index 81cb1412db9f159f55188b21e647f1f84a2dfba8..4bf000f0c8d30d25dac78f645f8693e4d715545e 100644 (file)
@@ -21,7 +21,7 @@ subject to the following restrictions:
 
 
 ///Concave triangle mesh. Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
-class btTriangleMeshShape : public ConcaveShape
+class btTriangleMeshShape : public btConcaveShape
 {
 protected:
        btStridingMeshInterface* m_meshInterface;
index 8e6e2daa4fbce745ad932e70fd82db03c00244ae..3284a599ea720643760d032efcd2543e1c411f2b 100644 (file)
@@ -59,7 +59,7 @@ public:
 
        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax)const 
        {
-//             ASSERT(0);
+//             btAssert(0);
                getAabbSlow(t,aabbMin,aabbMax);
        }
 
@@ -116,7 +116,7 @@ public:
 
        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia)
        {
-               ASSERT(0);
+               btAssert(0);
                inertia.setValue(0.f,0.f,0.f);
        }
 
index ba02ea56e834149c3e90c5a52f2af927c2666e94..188c8258c8e42ddeaebbd8d7e315e6c4d02ba34b 100644 (file)
@@ -17,6 +17,7 @@ subject to the following restrictions:
 #ifndef CONVEX_PENETRATION_DEPTH_H
 #define CONVEX_PENETRATION_DEPTH_H
 
+class btStackAlloc;
 class btVector3;
 #include "btSimplexSolverInterface.h"
 class btConvexShape;
@@ -33,7 +34,7 @@ public:
                btConvexShape* convexA,btConvexShape* convexB,
                                        const btTransform& transA,const btTransform& transB,
                                btVector3& v, btPoint3& pa, btPoint3& pb,
-                               class btIDebugDraw* debugDraw
+                               class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
                                ) = 0;
 
 
index ef2b480fa6286f7faff27eb11578cac649c25ca1..e9db97d1b135c5dc17ed161920cec00add50fefc 100644 (file)
@@ -18,7 +18,7 @@ subject to the following restrictions:
 #define DISCRETE_COLLISION_DETECTOR1_INTERFACE_H
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btVector3.h"
-
+class btStackAlloc;
 
 /// This interface is made to be used by an iterative approach to do TimeOfImpact calculations
 /// This interface allows to query for closest points and penetration depth between two (convex) objects
@@ -42,13 +42,15 @@ struct btDiscreteCollisionDetectorInterface
        struct ClosestPointInput
        {
                ClosestPointInput()
-                       :m_maximumDistanceSquared(1e30f)
+                       :m_maximumDistanceSquared(1e30f),
+                       m_stackAlloc(0)
                {
                }
 
                btTransform m_transformA;
                btTransform m_transformB;
                btScalar        m_maximumDistanceSquared;
+               btStackAlloc* m_stackAlloc;
        };
 
        virtual ~btDiscreteCollisionDetectorInterface() {};
index ade4635c57ba6f3ecf084f1d44990fc8c2ec989d..8abdfdbb7e509d691c02ae3a3192e62d7a96bc6c 100644 (file)
@@ -26,6 +26,15 @@ Nov.2006
 
 #include "btGjkEpa.h"
 #include <string.h> //for memset
+#include <LinearMath/btStackAlloc.h>
+
+#if defined(DEBUG) || defined (_DEBUG)
+#include <stdio.h> //for debug printf
+#ifdef __SPU__
+#include <spu_printf.h>
+#define printf spu_printf
+#endif //__SPU__
+#endif
 
 namespace gjkepa_impl
 {
@@ -58,21 +67,18 @@ typedef btMatrix3x3         Rotation;
 // Const
 //
 
-static const U                 chkPrecision            =1/U(sizeof(F)==4);
-
-static const F                 cstInf                          =F(1/sin(0.));
-static const F                 cstPi                           =F(acos(-1.));
-static const F                 cst2Pi                          =cstPi*2;
 
-static const U                 GJK_maxiterations       =128;
-static const U                 GJK_hashsize            =1<<6;
-static const U                 GJK_hashmask            =GJK_hashsize-1;
-static const F                 GJK_insimplex_eps       =F(0.0001);
-static const F                 GJK_sqinsimplex_eps     =GJK_insimplex_eps*GJK_insimplex_eps;
-
-static const U                 EPA_maxiterations       =256;
-static const F                 EPA_inface_eps          =F(0.01);
-static const F                 EPA_accuracy            =F(0.001);
+#define cstInf                         SIMD_INFINITY
+#define cstPi                          SIMD_PI
+#define        cst2Pi                          SIMD_2_PI
+#define GJK_maxiterations      (128)
+#define GJK_hashsize           (1<<6)
+#define GJK_hashmask           (GJK_hashsize-1)
+#define GJK_insimplex_eps      F(0.0001)
+#define GJK_sqinsimplex_eps    (GJK_insimplex_eps*GJK_insimplex_eps)
+#define EPA_maxiterations      256
+#define        EPA_inface_eps          F(0.01)
+#define EPA_accuracy           F(0.001)
 
 //
 // Utils
@@ -95,80 +101,7 @@ throw(object); }
 template <typename T> static inline void       Raise(const T&)                         {}
 #endif
 
-       struct Block
-               {
-               Block*  previous;
-               U1*             address;
-               };
 
-//
-// StackAlloc
-//
-struct StackAlloc
-       {
-       
-
-                               StackAlloc()            { ctor(); }
-                               StackAlloc(U size)      { ctor();Create(size); }
-                               ~StackAlloc()           { Free(); }
-       void            Create(U size)
-               {
-               Free();
-               data            =       new U1[size];
-               totalsize       =       size;
-               }
-       void            Free()
-               {
-               if(usedsize==0)
-                       {
-                       if(!ischild)            delete[] data;
-                       data                            =       0;
-                       usedsize                        =       0;
-                       } else Raise(L"StackAlloc is still in use");
-               }
-               U1*                     Allocate(U size)
-               {
-               const U nus(usedsize+size);
-               if(nus<totalsize)
-                       {
-                       usedsize=nus;
-                       return(data+(usedsize-size));
-                       }
-               Raise(L"Not enough memory");
-               return(0);
-               }
-       Block*          BeginBlock()
-               {
-               Block*  pb = (Block*)Allocate(sizeof(Block));
-               pb->previous    =       current;
-               pb->address             =       data+usedsize;
-               current                 =       pb;
-               return(pb);
-               }
-       void            EndBlock(Block* block)
-               {
-               if(block==current)
-                       {
-                       current         =       block->previous;
-                       usedsize        =       (U)((block->address-data)-sizeof(Block));
-                       } else Raise(L"Unmatched blocks");
-               }
-
-       private:
-       void            ctor()
-               {
-               data            =       0;
-               totalsize       =       0;
-               usedsize        =       0;
-               current         =       0;
-               ischild         =       false;
-               }
-       U1*             data;
-       U               totalsize;
-       U               usedsize;
-       Block*  current;
-       Z               ischild;
-       };
 
 //
 // GJK
@@ -185,8 +118,8 @@ struct      GJK
                Vector3 v;
                He*             n;
                };
-       StackAlloc*                             sa;
-       Block*          sablock;
+       btStackAlloc*                           sa;
+       btBlock*                sablock;
        He*                                             table[GJK_hashsize];
        Rotation                                wrotations[2];
        Vector3                                 positions[2];
@@ -198,7 +131,7 @@ struct      GJK
        F                                               margin;
        Z                                               failed;
        //
-                                       GJK(StackAlloc* psa,
+                                       GJK(btStackAlloc* psa,
                                                const Rotation& wrot0,const Vector3& pos0,const btConvexShape* shape0,
                                                const Rotation& wrot1,const Vector3& pos1,const btConvexShape* shape1,
                                                F pmargin=0)
@@ -206,14 +139,14 @@ struct    GJK
                wrotations[0]=wrot0;positions[0]=pos0;shapes[0]=shape0;
                wrotations[1]=wrot1;positions[1]=pos1;shapes[1]=shape1;
                sa              =psa;
-               sablock =sa->BeginBlock();
+               sablock =sa->beginBlock();
                margin  =pmargin;
                failed  =false;
                }
        //
                                        ~GJK()
                {
-               sa->EndBlock(sablock);
+               sa->endBlock(sablock);
                }
        // vdh : very dumm hash
        static inline U Hash(const Vector3& v)
@@ -243,7 +176,7 @@ struct      GJK
                const U                 h(Hash(ray));
                He*                             e = (He*)(table[h]);
                while(e) { if(e->v==ray) { --order;return(false); } else e=e->n; }
-               e=(He*)sa->Allocate(sizeof(He));e->v=ray;e->n=table[h];table[h]=e;
+               e=(He*)sa->allocate(sizeof(He));e->v=ray;e->n=table[h];table[h]=e;
                Support(ray,simplex[++order]);
                return(ray.dot(SPXW(order))>0);
                }
@@ -401,7 +334,7 @@ struct      EPA
                };
        //
        GJK*                    gjk;
-       StackAlloc*             sa;
+       btStackAlloc*           sa;
        Face*                   root;
        U                               nfaces;
        U                               iterations;
@@ -464,7 +397,7 @@ c) const
        //
        inline Face*    NewFace(const GJK::Mkv* a,const GJK::Mkv* b,const GJK::Mkv* c)
                {
-               Face*   pf = (Face*)sa->Allocate(sizeof(Face));
+               Face*   pf = (Face*)sa->allocate(sizeof(Face));
                if(Set(pf,a,b,c))
                        {
                        if(root) root->prev=pf;
@@ -506,7 +439,7 @@ c) const
        //
        GJK::Mkv*               Support(const Vector3& w) const
                {
-               GJK::Mkv*               v =(GJK::Mkv*)sa->Allocate(sizeof(GJK::Mkv));
+               GJK::Mkv*               v =(GJK::Mkv*)sa->allocate(sizeof(GJK::Mkv));
                gjk->Support(w,*v);
                return(v);
                }
@@ -540,7 +473,7 @@ ff)
        //
        inline F                EvaluatePD(F accuracy=EPA_accuracy)
                {
-               Block*  sablock = sa->BeginBlock();
+               btBlock*        sablock = sa->beginBlock();
                Face*                           bestface = 0;
                U                                       markid(1);
                depth           =       -cstInf;
@@ -579,7 +512,7 @@ U   eidx[9][4]={{0,0,4,0},{0,1,2,1},{0,2,1,2},{1,1,5,2},{1,0,2,0},{2,2,3,2},{3,1,5
                        U i;
 
                        for( i=0;i<=gjk->order;++i)             { 
-basemkv[i]=(GJK::Mkv*)sa->Allocate(sizeof(GJK::Mkv));*basemkv[i]=gjk->simplex[i]; 
+basemkv[i]=(GJK::Mkv*)sa->allocate(sizeof(GJK::Mkv));*basemkv[i]=gjk->simplex[i]; 
 }
                        for( i=0;i<nfidx;++i,pfidx+=3)          { 
 basefaces[i]=NewFace(basemkv[pfidx[0]],basemkv[pfidx[1]],basemkv[pfidx[2]]); 
@@ -589,7 +522,7 @@ Link(basefaces[peidx[0]],peidx[1],basefaces[peidx[2]],peidx[3]); }
                        }
                if(0==nfaces)
                        {
-                       sa->EndBlock(sablock);
+                       sa->endBlock(sablock);
                        return(depth);
                        }
                /* Expand hull          */
@@ -632,7 +565,7 @@ nf+=BuildHorizon(markid,w,*bf->f[i],bf->e[i],cf,ff); }
                        nearest[0]              =       features[0][0]*b.x()+features[0][1]*b.y()+features[0][2]*b.z();
                        nearest[1]              =       features[1][0]*b.x()+features[1][1]*b.y()+features[1][2]*b.z();
                        } else failed=true;
-               sa->EndBlock(sablock);
+               sa->endBlock(sablock);
                return(depth);
                }
        };
@@ -644,17 +577,17 @@ nf+=BuildHorizon(markid,w,*bf->f[i],bf->e[i],cf,ff); }
 
 using namespace        gjkepa_impl;
 
-/* Need some kind of stackalloc , create a static one till bullet provide
-one.   */
-static const U         g_sasize((1024<<10)*2);
-static StackAlloc      g_sa(g_sasize);
+
 
 //
 bool   btGjkEpaSolver::Collide(btConvexShape *shape0,const btTransform &wtrs0,
                                                                btConvexShape *shape1,const btTransform &wtrs1,
                                                                btScalar        radialmargin,
+                                                               btStackAlloc* stackAlloc,
                                                                sResults&       results)
 {
+       
+
 /* Initialize                                  */
 results.witnesses[0]   =
 results.witnesses[1]   =
@@ -664,7 +597,7 @@ results.status                      =       sResults::Separated;
 results.epa_iterations =       0;
 results.gjk_iterations =       0;
 /* Use GJK to locate origin            */
-GJK                    gjk(&g_sa,
+GJK                    gjk(stackAlloc,
                                wtrs0.getBasis(),wtrs0.getOrigin(),shape0,
                                wtrs1.getBasis(),wtrs1.getOrigin(),shape1,
                                radialmargin+EPA_accuracy);
index d26ac9cdfe55e62893ce281f785a110b8acb6689..359829f8f319b5bf8a813358c98255c8bef76fe2 100644 (file)
@@ -23,6 +23,8 @@ Nov.2006
 #define _05E48D53_04E0_49ad_BB0A_D74FE62E7366_
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 
+class btStackAlloc;
+
 ///btGjkEpaSolver contributed under zlib by Nathanael Presson
 struct btGjkEpaSolver
 {
@@ -44,6 +46,7 @@ struct        sResults
 static bool    Collide(btConvexShape* shape0,const btTransform& wtrs0,
                                        btConvexShape* shape1,const btTransform& wtrs1,
                                        btScalar        radialmargin,
+                                       btStackAlloc* stackAlloc,
                                        sResults&       results);
 };
 
index c2958b22b6a245afeb01fcb8189abfa5cccfd1ea..3d252751c9ae3f2b9b5366baf49ae72561457596 100644 (file)
@@ -23,7 +23,7 @@ bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& sim
                                                                                          btConvexShape* pConvexA, btConvexShape* pConvexB,
                                                                                          const btTransform& transformA, const btTransform& transformB,
                                                                                          btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB,
-                                                                                         class btIDebugDraw* debugDraw )
+                                                                                         class btIDebugDraw* debugDraw, btStackAlloc* stackAlloc )
 {
 
 
@@ -32,7 +32,7 @@ bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& sim
        btGjkEpaSolver::sResults        results;
        if(btGjkEpaSolver::Collide(     pConvexA,transformA,
                                                                pConvexB,transformB,
-                                                               radialmargin,results))
+                                                               radialmargin,stackAlloc,results))
                {
        //      debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0));
                //resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth);
index a7332a7a51a4aa4b8ae6353ee72e0fbdeccc10a1..3916ba0776cb15f222231a70b354e6f425d93ba7 100644 (file)
@@ -29,7 +29,7 @@ class btGjkEpaPenetrationDepthSolver : public btConvexPenetrationDepthSolver
                                                                          btConvexShape* pConvexA, btConvexShape* pConvexB,
                                                                          const btTransform& transformA, const btTransform& transformB,
                                                                          btVector3& v, btPoint3& wWitnessOnA, btPoint3& wWitnessOnB,
-                                                                         class btIDebugDraw* debugDraw );
+                                                                         class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc );
 
        private :
 
index 646c07a5d3923b633a8707831a42749a963a9c9e..0ce04dcfad8a742ae1a94cc016f3856a392e1b39 100644 (file)
@@ -20,6 +20,10 @@ subject to the following restrictions:
 
 #if defined(DEBUG) || defined (_DEBUG)
 #include <stdio.h> //for debug printf
+#ifdef __SPU__
+#include <spu_printf.h>
+#define printf spu_printf
+#endif //__SPU__
 #endif
 
 //must be above the machine epsilon
@@ -29,10 +33,7 @@ subject to the following restrictions:
 int gNumDeepPenetrationChecks = 0;
 int gNumGjkChecks = 0;
 
-#ifdef __SPU__
-#include <spu_printf.h>
-#define printf spu_printf
-#endif //__SPU__
+
 
 btGjkPairDetector::btGjkPairDetector(btConvexShape* objectA,btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver*     penetrationDepthSolver)
 :m_cachedSeparatingAxis(0.f,0.f,1.f),
@@ -202,7 +203,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
                                normalInB *= rlen; //normalize
                                btScalar s = btSqrt(squaredDistance);
                        
-                               ASSERT(s > btScalar(0.0));
+                               btAssert(s > btScalar(0.0));
                                pointOnA -= m_cachedSeparatingAxis * (marginA / s);
                                pointOnB += m_cachedSeparatingAxis * (marginB / s);
                                distance = ((1.f/rlen) - margin);
@@ -236,7 +237,7 @@ void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
                                        m_minkowskiA,m_minkowskiB,
                                        localTransA,localTransB,
                                        m_cachedSeparatingAxis, tmpPointOnA, tmpPointOnB,
-                                       debugDraw
+                                       debugDraw,input.m_stackAlloc
                                        );
 
                                if (isValid2)
index 74cf2b7c07169573d3056b1af1d429a9aba45b17..de6749a9b721a6fd7586f80bcf6120b0ef298374 100644 (file)
@@ -74,7 +74,7 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
                                                                                                   btConvexShape* convexA,btConvexShape* convexB,
                                                                                                   const btTransform& transA,const btTransform& transB,
                                                                                                   btVector3& v, btPoint3& pa, btPoint3& pb,
-                                                                                                  class btIDebugDraw* debugDraw
+                                                                                                  class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
                                                                                                   )
 {
 
index c287195317e8a722cf1db9a86e33aa840a443533..b348b21b52a843037c8a214e2d9e441395ca817f 100644 (file)
@@ -28,7 +28,7 @@ public:
        btConvexShape* convexA,btConvexShape* convexB,
                                const btTransform& transA,const btTransform& transB,
                        btVector3& v, btPoint3& pa, btPoint3& pb,
-                       class btIDebugDraw* debugDraw
+                       class btIDebugDraw* debugDraw,btStackAlloc* stackAlloc
                        );
 
 };
index ab0e8767e5d346a40e9c17e812621366cb293d07..c2372b648f62deb18b50ca6ba1bd43130e58cf2d 100644 (file)
@@ -86,13 +86,13 @@ public:
 
        inline const btManifoldPoint& getContactPoint(int index) const
        {
-               ASSERT(index < m_cachedPoints);
+               btAssert(index < m_cachedPoints);
                return m_pointCache[index];
        }
 
        inline btManifoldPoint& getContactPoint(int index)
        {
-               ASSERT(index < m_cachedPoints);
+               btAssert(index < m_cachedPoints);
                return m_pointCache[index];
        }
 
index bb2aecfb6d0996d994edc1416b15ae523140e671..384e4f7bab53d4c814acb8a358eea9829b7c1df5 100644 (file)
@@ -50,7 +50,7 @@ public:
                m_1MinvJt = inertiaInvB * m_bJ;
                m_Adiag = massInvA + m_0MinvJt.dot(m_aJ) + massInvB + m_1MinvJt.dot(m_bJ);
 
-               ASSERT(m_Adiag > 0.0f);
+               btAssert(m_Adiag > 0.0f);
        }
 
        //angular constraint between two different rigidbodies
@@ -67,7 +67,7 @@ public:
                m_1MinvJt = inertiaInvB * m_bJ;
                m_Adiag =  m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ);
 
-               ASSERT(m_Adiag > 0.0f);
+               btAssert(m_Adiag > 0.0f);
        }
 
        //angular constraint between two different rigidbodies
@@ -83,7 +83,7 @@ public:
                m_1MinvJt = inertiaInvB * m_bJ;
                m_Adiag =  m_0MinvJt.dot(m_aJ) + m_1MinvJt.dot(m_bJ);
 
-               ASSERT(m_Adiag > 0.0f);
+               btAssert(m_Adiag > 0.0f);
        }
 
        //constraint on one rigidbody
@@ -101,7 +101,7 @@ public:
                m_1MinvJt = btVector3(0.f,0.f,0.f);
                m_Adiag = massInvA + m_0MinvJt.dot(m_aJ);
 
-               ASSERT(m_Adiag > 0.0f);
+               btAssert(m_Adiag > 0.0f);
        }
 
        btScalar        getDiagonal() const { return m_Adiag; }
index bf92434b69bfc124b6248dfa5a7796ef248008b7..edca6c8fa089e8266a9e3a560557a7cbec4c78db 100644 (file)
@@ -51,7 +51,7 @@ void btSolve2LinearConstraint::resolveUnilateralPairConstraint(
        if (fabs(len) >= SIMD_EPSILON)
                return;
 
-       ASSERT(len < SIMD_EPSILON);
+       btAssert(len < SIMD_EPSILON);
 
 
        //this jacobian entry could be re-used for all iterations
@@ -133,7 +133,7 @@ void btSolve2LinearConstraint::resolveBilateralPairConstraint(
        if (fabs(len) >= SIMD_EPSILON)
                return;
 
-       ASSERT(len < SIMD_EPSILON);
+       btAssert(len < SIMD_EPSILON);
 
 
        //this jacobian entry could be re-used for all iterations
index 0dece6b20e6f240f83799cc27c6eb365dcc7e9ef..f59598f2a5383159e7c061a6bc1e3d4f227292c4 100644 (file)
@@ -57,19 +57,6 @@ subject to the following restrictions:
 #include <algorithm>
 
 
-btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver)
-:btDynamicsWorld(),
-m_constraintSolver(constraintSolver? constraintSolver: new btSequentialImpulseConstraintSolver),
-m_debugDrawer(0),
-m_gravity(0,-10,0),
-m_localTime(1.f/60.f),
-m_profileTimings(0)
-{
-       m_islandManager = new btSimulationIslandManager();
-       m_ownsIslandManager = true;
-       m_ownsConstraintSolver = (constraintSolver==0);
-}
-
 
 btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
 :btDynamicsWorld(dispatcher,pairCache),
@@ -267,27 +254,27 @@ void      btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep)
        ///apply gravity, predict motion
        predictUnconstraintMotion(timeStep);
 
-       btDispatcherInfo        dispatchInfo;
+       btDispatcherInfo& dispatchInfo = getDispatchInfo();
+
        dispatchInfo.m_timeStep = timeStep;
        dispatchInfo.m_stepCount = 0;
        dispatchInfo.m_debugDraw = getDebugDrawer();
 
-
        ///perform collision detection
        performDiscreteCollisionDetection(dispatchInfo);
 
        calculateSimulationIslands();
 
-       btContactSolverInfo infoGlobal;
-       infoGlobal.m_timeStep = timeStep;
+       
+       getSolverInfo().m_timeStep = timeStep;
        
 
 
        ///solve non-contact constraints
-       solveNoncontactConstraints(infoGlobal);
+       solveNoncontactConstraints(getSolverInfo());
        
        ///solve contact constraints
-       solveContactConstraints(infoGlobal);
+       solveContactConstraints(getSolverInfo());
 
        ///CallbackTriggers();
 
index 4aa83683cd547f3211a8592ec7a681135fde2334..72619091c6ff86a3a62a1cc9fb0066170a317efa 100644 (file)
@@ -23,7 +23,8 @@ class btOverlappingPairCache;
 class btConstraintSolver;
 class btSimulationIslandManager;
 class btTypedConstraint;
-struct btContactSolverInfo;
+#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
+
 class btRaycastVehicle;
 class btIDebugDraw;
 
@@ -52,6 +53,9 @@ protected:
        bool    m_ownsIslandManager;
        bool    m_ownsConstraintSolver;
 
+       btContactSolverInfo     m_solverInfo;
+
+
        std::vector<btRaycastVehicle*>  m_vehicles;
 
        int     m_profileTimings;
@@ -83,11 +87,8 @@ public:
 
 
        ///this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete those
-       btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver=0);
+       btDiscreteDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
 
-       ///this btDiscreteDynamicsWorld will create and own dispatcher, pairCache and constraintSolver, and deletes it in the destructor.
-       btDiscreteDynamicsWorld(btConstraintSolver* constraintSolver = 0);
-               
        virtual ~btDiscreteDynamicsWorld();
 
        ///if maxSubSteps > 0, it will interpolate motion between fixedTimeStep's
@@ -144,6 +145,11 @@ public:
 
        virtual const btTypedConstraint* getConstraint(int index) const;
 
+       btContactSolverInfo& getSolverInfo()
+       {
+               return m_solverInfo;
+       }
+
 
 };
 
index a991fdca79d0d9b34e2321adb3c1161337c63ca4..617ed98d2af3230f2b2895baa17156d971fd23aa 100644 (file)
@@ -27,9 +27,6 @@ class btDynamicsWorld : public btCollisionWorld
 {
        public:
                
-               btDynamicsWorld()
-               {
-               }
 
                btDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
                :btCollisionWorld(dispatcher,pairCache)
index fe6a73939a7dfe17c0825fc893f761f7b4b0810d..ce5c76c58e2e8977dc70cff54bd001a693f64413 100644 (file)
@@ -22,13 +22,7 @@ subject to the following restrictions:
 #include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
 
 
-btSimpleDynamicsWorld::btSimpleDynamicsWorld()
-:m_constraintSolver(new btSequentialImpulseConstraintSolver),
-m_ownsConstraintSolver(true),
-m_debugDrawer(0),
-m_gravity(0,0,-10)
-{
-}
+
 
 btSimpleDynamicsWorld::btSimpleDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver)
 :btDynamicsWorld(dispatcher,pairCache),
index f74e2460732f6d6f54b70e75ccae4c1ef798c14c..cdc0c5559f6fcf07b998c6683b9197150d8c4adb 100644 (file)
@@ -46,8 +46,6 @@ protected:
 public:
 
 
-       ///this btSimpleDynamicsWorld constructor creates and owns dispatcher, broadphase pairCache and constraintSolver
-       btSimpleDynamicsWorld();
 
        ///this btSimpleDynamicsWorld constructor creates dispatcher, broadphase pairCache and constraintSolver
        btSimpleDynamicsWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache,btConstraintSolver* constraintSolver);
index 700bdb866cdce31f18854b8453aa11c12fa36f8f..248ecfbce4efbde2363d1a4fcd63ffe4accb4c8e 100644 (file)
@@ -386,21 +386,21 @@ void      btRaycastVehicle::applyEngineForce(btScalar force, int wheel)
 
 const btWheelInfo&     btRaycastVehicle::getWheelInfo(int index) const
 {
-       ASSERT((index >= 0) && (index <         getNumWheels()));
+       btAssert((index >= 0) && (index <       getNumWheels()));
        
        return m_wheelInfo[index];
 }
 
 btWheelInfo&   btRaycastVehicle::getWheelInfo(int index) 
 {
-       ASSERT((index >= 0) && (index <         getNumWheels()));
+       btAssert((index >= 0) && (index <       getNumWheels()));
        
        return m_wheelInfo[index];
 }
 
 void btRaycastVehicle::setBrake(float brake,int wheelIndex)
 {
-       ASSERT((wheelIndex >= 0) && (wheelIndex <       getNumWheels()));
+       btAssert((wheelIndex >= 0) && (wheelIndex <     getNumWheels()));
        getWheelInfo(wheelIndex).m_brake;
 }
 
index aa046b89df03db07b39f80de7e2d78536c0be524..46b8145a76662b1a0bdde017bf40e0fa866d032a 100644 (file)
@@ -37,7 +37,7 @@ subject to the following restrictions:
                //#define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
                #define ATTRIBUTE_ALIGNED16(a) a
                #include <assert.h>
-               #define ASSERT assert
+               #define btAssert assert
 #else
        
        //non-windows systems
@@ -47,7 +47,7 @@ subject to the following restrictions:
                #ifndef assert
                #include <assert.h>
                #endif
-               #define ASSERT assert
+               #define btAssert assert
 #endif
 
 
diff --git a/extern/bullet2/src/LinearMath/btStackAlloc.h b/extern/bullet2/src/LinearMath/btStackAlloc.h
new file mode 100644 (file)
index 0000000..d219b45
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+Copyright (c) 2003-2006 Gino van den Bergen / 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.
+*/
+
+/*
+StackAlloc extracted from GJK-EPA collision solver by Nathanael Presson
+Nov.2006
+*/
+
+#ifndef BT_STACK_ALLOC
+#define BT_STACK_ALLOC
+
+#include "btScalar.h" //for btAssert
+
+struct btBlock
+{
+       btBlock*                        previous;
+       unsigned char*          address;
+};
+
+///StackAlloc provides some fast stack-based memory allocator (LIFO last-in first-out)
+class btStackAlloc
+{
+public:
+
+       btStackAlloc(unsigned int size) { ctor();create(size); }
+       ~btStackAlloc()         { destroy(); }
+       
+       inline void             create(unsigned int size)
+       {
+               destroy();
+               data            =       new unsigned char[size];
+               totalsize       =       size;
+       }
+       inline void             destroy()
+       {
+               btAssert(usedsize==0);
+               //Raise(L"StackAlloc is still in use");
+
+               if(usedsize==0)
+               {
+                       if(!ischild)            delete[] data;
+                       data                            =       0;
+                       usedsize                        =       0;
+               }
+               
+       }
+       unsigned char*                  allocate(unsigned int size)
+       {
+               const unsigned int      nus(usedsize+size);
+               if(nus<totalsize)
+               {
+                       usedsize=nus;
+                       return(data+(usedsize-size));
+               }
+               btAssert(0);
+               //&& (L"Not enough memory"));
+               
+               return(0);
+       }
+       inline btBlock*         beginBlock()
+       {
+               btBlock*        pb = (btBlock*)allocate(sizeof(btBlock));
+               pb->previous    =       current;
+               pb->address             =       data+usedsize;
+               current                 =       pb;
+               return(pb);
+       }
+       inline void             endBlock(btBlock* block)
+       {
+               btAssert(block==current);
+               //Raise(L"Unmatched blocks");
+               if(block==current)
+               {
+                       current         =       block->previous;
+                       usedsize        =       (unsigned int)((block->address-data)-sizeof(btBlock));
+               }
+       }
+
+private:
+       void            ctor()
+       {
+               data            =       0;
+               totalsize       =       0;
+               usedsize        =       0;
+               current         =       0;
+               ischild         =       false;
+       }
+       unsigned char*          data;
+       unsigned int            totalsize;
+       unsigned int            usedsize;
+       btBlock*        current;
+       bool            ischild;
+};
+
+#endif //BT_STACK_ALLOC