Added refactored Bullet 2.x library. Important: these files are not part of the Blend...
authorErwin Coumans <blender@erwincoumans.com>
Mon, 23 Oct 2006 02:54:30 +0000 (02:54 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Mon, 23 Oct 2006 02:54:30 +0000 (02:54 +0000)
The refactoring didn't leave a single file the same, all filenames and classes have bt prefix, methodnames start with lowercase, a single headerfile can be included, and also a single include path.
Plan is to make use of this Bullet 2.x version in extern/bullet2 within the coming weeks, then extern/bullet can be discarded/ignored/content removed.

164 files changed:
extern/bullet2/readme.txt [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CMakeLists.txt [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/Doxyfile [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexCast.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexCast.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPointCollector.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp [new file with mode: 0644]
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/CMakeLists.txt [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btConstraintSolver.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Vehicle/btVehicleRaycaster.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Vehicle/btWheelInfo.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/Vehicle/btWheelInfo.h [new file with mode: 0644]
extern/bullet2/src/CMakeLists.txt [new file with mode: 0644]
extern/bullet2/src/LinearMath/CMakeLists.txt [new file with mode: 0644]
extern/bullet2/src/LinearMath/btAabbUtil2.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btDefaultMotionState.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btIDebugDraw.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btList.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btMatrix3x3.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btMinMax.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btMotionState.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btPoint3.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btQuadWord.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btQuaternion.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btQuickprof.cpp [new file with mode: 0644]
extern/bullet2/src/LinearMath/btQuickprof.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btRandom.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btScalar.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btSimdMinMax.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btTransform.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btTransformUtil.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btVector3.h [new file with mode: 0644]
extern/bullet2/src/btBulletCollisionCommon.h [new file with mode: 0644]
extern/bullet2/src/btBulletDynamicsCommon.h [new file with mode: 0644]

diff --git a/extern/bullet2/readme.txt b/extern/bullet2/readme.txt
new file mode 100644 (file)
index 0000000..4d1a4c1
--- /dev/null
@@ -0,0 +1,12 @@
+
+*** These files in extern/bullet2 are NOT part of the Blender build yet ***
+
+This is the new refactored version of Bullet physics library version 2.x
+
+Soon this will replace the old Bullet version in extern/bullet.
+First the integration in Blender Game Engine needs to be updated.
+Once that is done all build systems can be updated to use/build extern/bullet2 files.
+
+Questions? mail blender at erwincoumans.com, or check the bf-blender mailing list.
+Thanks,
+Erwin
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp
new file mode 100644 (file)
index 0000000..b05285c
--- /dev/null
@@ -0,0 +1,499 @@
+
+//Bullet Continuous Collision Detection and Physics Library
+//Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
+
+
+//
+// btAxisSweep3
+//
+// Copyright (c) 2006 Simon Hobbs
+//
+// 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 "btAxisSweep3.h"
+
+#include <assert.h>
+
+btBroadphaseProxy*     btAxisSweep3::createProxy(  const btVector3& min,  const btVector3& max,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask)
+{
+               unsigned short handleId = addHandle(min,max, userPtr,collisionFilterGroup,collisionFilterMask);
+               
+               Handle* handle = getHandle(handleId);
+                               
+               return handle;
+}
+
+void   btAxisSweep3::destroyProxy(btBroadphaseProxy* proxy)
+{
+       Handle* handle = static_cast<Handle*>(proxy);
+       removeHandle(handle->m_handleId);
+}
+
+void   btAxisSweep3::setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax)
+{
+       Handle* handle = static_cast<Handle*>(proxy);
+       updateHandle(handle->m_handleId,aabbMin,aabbMax);
+}
+
+
+
+
+
+
+btAxisSweep3::btAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, int maxHandles)
+:btOverlappingPairCache()
+{
+       //assert(bounds.HasVolume());
+
+       // 1 handle is reserved as sentinel
+       assert(maxHandles > 1 && maxHandles < 32767);
+
+       // init bounds
+       m_worldAabbMin = worldAabbMin;
+       m_worldAabbMax = worldAabbMax;
+
+       btVector3 aabbSize = m_worldAabbMax - m_worldAabbMin;
+
+       m_quantize = btVector3(65535.0f,65535.0f,65535.0f) / aabbSize;
+
+       // allocate handles buffer and put all handles on free list
+       m_pHandles = new Handle[maxHandles];
+       m_maxHandles = maxHandles;
+       m_numHandles = 0;
+
+       // handle 0 is reserved as the null index, and is also used as the sentinel
+       m_firstFreeHandle = 1;
+       {
+               for (int i = m_firstFreeHandle; i < maxHandles; i++)
+                       m_pHandles[i].SetNextFree(i + 1);
+               m_pHandles[maxHandles - 1].SetNextFree(0);
+       }
+
+       {
+       // allocate edge buffers
+       for (int i = 0; i < 3; i++)
+               m_pEdges[i] = new Edge[maxHandles * 2];
+       }
+       //removed overlap management
+
+       // make boundary sentinels
+       
+       m_pHandles[0].m_clientObject = 0;
+
+       for (int axis = 0; axis < 3; axis++)
+       {
+               m_pHandles[0].m_minEdges[axis] = 0;
+               m_pHandles[0].m_maxEdges[axis] = 1;
+
+               m_pEdges[axis][0].m_pos = 0;
+               m_pEdges[axis][0].m_handle = 0;
+               m_pEdges[axis][1].m_pos = 0xffff;
+               m_pEdges[axis][1].m_handle = 0;
+       }
+}
+
+btAxisSweep3::~btAxisSweep3()
+{
+       
+       for (int i = 2; i >= 0; i--)
+               delete[] m_pEdges[i];
+       delete[] m_pHandles;
+}
+
+void btAxisSweep3::quantize(unsigned short* out, const btPoint3& point, int isMax) const
+{
+       btPoint3 clampedPoint(point);
+       /*
+       if (isMax)
+               clampedPoint += btVector3(10,10,10);
+       else
+       {
+               clampedPoint -= btVector3(10,10,10);
+       }
+       */
+
+
+       clampedPoint.setMax(m_worldAabbMin);
+       clampedPoint.setMin(m_worldAabbMax);
+
+       btVector3 v = (clampedPoint - m_worldAabbMin) * m_quantize;
+       out[0] = (unsigned short)(((int)v.getX() & 0xfffc) | isMax);
+       out[1] = (unsigned short)(((int)v.getY() & 0xfffc) | isMax);
+       out[2] = (unsigned short)(((int)v.getZ() & 0xfffc) | isMax);
+       
+}
+
+
+
+unsigned short btAxisSweep3::allocHandle()
+{
+       assert(m_firstFreeHandle);
+
+       unsigned short handle = m_firstFreeHandle;
+       m_firstFreeHandle = getHandle(handle)->GetNextFree();
+       m_numHandles++;
+
+       return handle;
+}
+
+void btAxisSweep3::freeHandle(unsigned short handle)
+{
+       assert(handle > 0 && handle < m_maxHandles);
+
+       getHandle(handle)->SetNextFree(m_firstFreeHandle);
+       m_firstFreeHandle = handle;
+
+       m_numHandles--;
+}
+
+
+
+unsigned short btAxisSweep3::addHandle(const btPoint3& aabbMin,const btPoint3& aabbMax, void* pOwner,short int collisionFilterGroup,short int collisionFilterMask)
+{
+       // quantize the bounds
+       unsigned short min[3], max[3];
+       quantize(min, aabbMin, 0);
+       quantize(max, aabbMax, 1);
+
+       // allocate a handle
+       unsigned short handle = allocHandle();
+       assert(handle!= 0xcdcd);
+
+       Handle* pHandle = getHandle(handle);
+       
+       pHandle->m_handleId = handle;
+       //pHandle->m_pOverlaps = 0;
+       pHandle->m_clientObject = pOwner;
+       pHandle->m_collisionFilterGroup = collisionFilterGroup;
+       pHandle->m_collisionFilterMask = collisionFilterMask;
+
+       // compute current limit of edge arrays
+       int limit = m_numHandles * 2;
+
+       // insert new edges just inside the max boundary edge
+       for (int axis = 0; axis < 3; axis++)
+       {
+               m_pHandles[0].m_maxEdges[axis] += 2;
+
+               m_pEdges[axis][limit + 1] = m_pEdges[axis][limit - 1];
+
+               m_pEdges[axis][limit - 1].m_pos = min[axis];
+               m_pEdges[axis][limit - 1].m_handle = handle;
+
+               m_pEdges[axis][limit].m_pos = max[axis];
+               m_pEdges[axis][limit].m_handle = handle;
+
+               pHandle->m_minEdges[axis] = limit - 1;
+               pHandle->m_maxEdges[axis] = limit;
+       }
+
+       // now sort the new edges to their correct position
+       sortMinDown(0, pHandle->m_minEdges[0], false);
+       sortMaxDown(0, pHandle->m_maxEdges[0], false);
+       sortMinDown(1, pHandle->m_minEdges[1], false);
+       sortMaxDown(1, pHandle->m_maxEdges[1], false);
+       sortMinDown(2, pHandle->m_minEdges[2], true);
+       sortMaxDown(2, pHandle->m_maxEdges[2], true);
+
+       //PrintAxis(1);
+
+       return handle;
+}
+
+
+void btAxisSweep3::removeHandle(unsigned short handle)
+{
+       Handle* pHandle = getHandle(handle);
+
+       //explicitly remove the pairs containing the proxy
+       //we could do it also in the sortMinUp (passing true)
+       //todo: compare performance
+       removeOverlappingPairsContainingProxy(pHandle);
+
+
+       // compute current limit of edge arrays
+       int limit = m_numHandles * 2;
+       int axis;
+
+       for (axis = 0;axis<3;axis++)
+       {
+               Edge* pEdges = m_pEdges[axis];
+               int maxEdge= pHandle->m_maxEdges[axis];
+               pEdges[maxEdge].m_pos = 0xffff;
+               int minEdge = pHandle->m_minEdges[axis];
+               pEdges[minEdge].m_pos = 0xffff;
+       }
+
+       // remove the edges by sorting them up to the end of the list
+       for ( axis = 0; axis < 3; axis++)
+       {
+               Edge* pEdges = m_pEdges[axis];
+               int max = pHandle->m_maxEdges[axis];
+               pEdges[max].m_pos = 0xffff;
+
+               sortMaxUp(axis,max,false);
+               
+               int i = pHandle->m_minEdges[axis];
+               pEdges[i].m_pos = 0xffff;
+
+               sortMinUp(axis,i,false);
+
+               pEdges[limit-1].m_handle = 0;
+               pEdges[limit-1].m_pos = 0xffff;
+
+       }
+
+       // free the handle
+       freeHandle(handle);
+
+       
+}
+
+bool btAxisSweep3::testOverlap(int ignoreAxis,const Handle* pHandleA, const Handle* pHandleB)
+{
+       //optimization 1: check the array index (memory address), instead of the m_pos
+
+       for (int axis = 0; axis < 3; axis++)
+       { 
+               if (axis != ignoreAxis)
+               {
+                       if (pHandleA->m_maxEdges[axis] < pHandleB->m_minEdges[axis] || 
+                               pHandleB->m_maxEdges[axis] < pHandleA->m_minEdges[axis]) 
+                       { 
+                               return false; 
+                       } 
+               }
+       } 
+
+       //optimization 2: only 2 axis need to be tested
+
+       /*for (int axis = 0; axis < 3; axis++)
+       {
+               if (m_pEdges[axis][pHandleA->m_maxEdges[axis]].m_pos < m_pEdges[axis][pHandleB->m_minEdges[axis]].m_pos ||
+                       m_pEdges[axis][pHandleB->m_maxEdges[axis]].m_pos < m_pEdges[axis][pHandleA->m_minEdges[axis]].m_pos)
+               {
+                       return false;
+               }
+       }
+       */
+
+       return true;
+}
+
+void btAxisSweep3::updateHandle(unsigned short handle, const btPoint3& aabbMin,const btPoint3& aabbMax)
+{
+//     assert(bounds.IsFinite());
+       //assert(bounds.HasVolume());
+
+       Handle* pHandle = getHandle(handle);
+
+       // quantize the new bounds
+       unsigned short min[3], max[3];
+       quantize(min, aabbMin, 0);
+       quantize(max, aabbMax, 1);
+
+       // update changed edges
+       for (int axis = 0; axis < 3; axis++)
+       {
+               unsigned short emin = pHandle->m_minEdges[axis];
+               unsigned short emax = pHandle->m_maxEdges[axis];
+
+               int dmin = (int)min[axis] - (int)m_pEdges[axis][emin].m_pos;
+               int dmax = (int)max[axis] - (int)m_pEdges[axis][emax].m_pos;
+
+               m_pEdges[axis][emin].m_pos = min[axis];
+               m_pEdges[axis][emax].m_pos = max[axis];
+
+               // expand (only adds overlaps)
+               if (dmin < 0)
+                       sortMinDown(axis, emin);
+
+               if (dmax > 0)
+                       sortMaxUp(axis, emax);
+
+               // shrink (only removes overlaps)
+               if (dmin > 0)
+                       sortMinUp(axis, emin);
+
+               if (dmax < 0)
+                       sortMaxDown(axis, emax);
+       }
+
+       //PrintAxis(1);
+}
+
+// sorting a min edge downwards can only ever *add* overlaps
+void btAxisSweep3::sortMinDown(int axis, unsigned short edge, bool updateOverlaps)
+{
+       Edge* pEdge = m_pEdges[axis] + edge;
+       Edge* pPrev = pEdge - 1;
+       Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+       while (pEdge->m_pos < pPrev->m_pos)
+       {
+               Handle* pHandlePrev = getHandle(pPrev->m_handle);
+
+               if (pPrev->IsMax())
+               {
+                       // if previous edge is a maximum check the bounds and add an overlap if necessary
+                       if (updateOverlaps && testOverlap(axis,pHandleEdge, pHandlePrev))
+                       {
+                               addOverlappingPair(pHandleEdge,pHandlePrev);
+
+                               //AddOverlap(pEdge->m_handle, pPrev->m_handle);
+
+                       }
+
+                       // update edge reference in other handle
+                       pHandlePrev->m_maxEdges[axis]++;
+               }
+               else
+                       pHandlePrev->m_minEdges[axis]++;
+
+               pHandleEdge->m_minEdges[axis]--;
+
+               // swap the edges
+               Edge swap = *pEdge;
+               *pEdge = *pPrev;
+               *pPrev = swap;
+
+               // decrement
+               pEdge--;
+               pPrev--;
+       }
+}
+
+// sorting a min edge upwards can only ever *remove* overlaps
+void btAxisSweep3::sortMinUp(int axis, unsigned short edge, bool updateOverlaps)
+{
+       Edge* pEdge = m_pEdges[axis] + edge;
+       Edge* pNext = pEdge + 1;
+       Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+       while (pEdge->m_pos > pNext->m_pos)
+       {
+               Handle* pHandleNext = getHandle(pNext->m_handle);
+
+               if (pNext->IsMax())
+               {
+                       // if next edge is maximum remove any overlap between the two handles
+                       if (updateOverlaps)
+                       {
+                               Handle* handle0 = getHandle(pEdge->m_handle);
+                               Handle* handle1 = getHandle(pNext->m_handle);
+                               btBroadphasePair tmpPair(*handle0,*handle1);
+                               removeOverlappingPair(tmpPair);
+
+                       }
+
+                       // update edge reference in other handle
+                       pHandleNext->m_maxEdges[axis]--;
+               }
+               else
+                       pHandleNext->m_minEdges[axis]--;
+
+               pHandleEdge->m_minEdges[axis]++;
+
+               // swap the edges
+               Edge swap = *pEdge;
+               *pEdge = *pNext;
+               *pNext = swap;
+
+               // increment
+               pEdge++;
+               pNext++;
+       }
+}
+
+// sorting a max edge downwards can only ever *remove* overlaps
+void btAxisSweep3::sortMaxDown(int axis, unsigned short edge, bool updateOverlaps)
+{
+       Edge* pEdge = m_pEdges[axis] + edge;
+       Edge* pPrev = pEdge - 1;
+       Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+       while (pEdge->m_pos < pPrev->m_pos)
+       {
+               Handle* pHandlePrev = getHandle(pPrev->m_handle);
+
+               if (!pPrev->IsMax())
+               {
+                       // if previous edge was a minimum remove any overlap between the two handles
+                       if (updateOverlaps)
+                       {
+                               Handle* handle0 = getHandle(pEdge->m_handle);
+                               Handle* handle1 = getHandle(pPrev->m_handle);
+                               btBroadphasePair* pair = findPair(handle0,handle1);
+                               //assert(pair);
+
+                               if (pair)
+                               {
+                                       removeOverlappingPair(*pair);
+                               }
+                       }
+
+                       // update edge reference in other handle
+                       pHandlePrev->m_minEdges[axis]++;;
+               }
+               else
+                       pHandlePrev->m_maxEdges[axis]++;
+
+               pHandleEdge->m_maxEdges[axis]--;
+
+               // swap the edges
+               Edge swap = *pEdge;
+               *pEdge = *pPrev;
+               *pPrev = swap;
+
+               // decrement
+               pEdge--;
+               pPrev--;
+       }
+}
+
+// sorting a max edge upwards can only ever *add* overlaps
+void btAxisSweep3::sortMaxUp(int axis, unsigned short edge, bool updateOverlaps)
+{
+       Edge* pEdge = m_pEdges[axis] + edge;
+       Edge* pNext = pEdge + 1;
+       Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+       while (pEdge->m_pos > pNext->m_pos)
+       {
+               Handle* pHandleNext = getHandle(pNext->m_handle);
+
+               if (!pNext->IsMax())
+               {
+                       // if next edge is a minimum check the bounds and add an overlap if necessary
+                       if (updateOverlaps && testOverlap(axis, pHandleEdge, pHandleNext))
+                       {
+                               Handle* handle0 = getHandle(pEdge->m_handle);
+                               Handle* handle1 = getHandle(pNext->m_handle);
+                               addOverlappingPair(handle0,handle1);
+                       }
+
+                       // update edge reference in other handle
+                       pHandleNext->m_minEdges[axis]--;
+               }
+               else
+                       pHandleNext->m_maxEdges[axis]--;
+
+               pHandleEdge->m_maxEdges[axis]++;
+
+               // swap the edges
+               Edge swap = *pEdge;
+               *pEdge = *pNext;
+               *pNext = swap;
+
+               // increment
+               pEdge++;
+               pNext++;
+       }
+}
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h
new file mode 100644 (file)
index 0000000..ebbbe01
--- /dev/null
@@ -0,0 +1,115 @@
+//Bullet Continuous Collision Detection and Physics Library
+//Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
+
+//
+// btAxisSweep3.h
+//
+// Copyright (c) 2006 Simon Hobbs
+//
+// 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 AXIS_SWEEP_3_H
+#define AXIS_SWEEP_3_H
+
+#include "LinearMath/btPoint3.h"
+#include "LinearMath/btVector3.h"
+#include "btOverlappingPairCache.h"
+#include "btBroadphaseProxy.h"
+
+/// btAxisSweep3 is an efficient implementation of the 3d axis sweep and prune broadphase.
+/// It uses arrays rather then lists for storage of the 3 axis. Also it operates using integer coordinates instead of floats.
+/// The testOverlap check is optimized to check the array index, rather then the actual AABB coordinates/pos
+class btAxisSweep3 : public btOverlappingPairCache
+{
+
+public:
+       
+
+       class Edge
+       {
+       public:
+               unsigned short m_pos;                   // low bit is min/max
+               unsigned short m_handle;
+
+               unsigned short IsMax() const {return m_pos & 1;}
+       };
+
+public:
+       class Handle : public btBroadphaseProxy
+       {
+       public:
+               
+               // indexes into the edge arrays
+               unsigned short m_minEdges[3], m_maxEdges[3];            // 6 * 2 = 12
+               unsigned short m_handleId;
+               unsigned short m_pad;
+               
+               //void* m_pOwner; this is now in btBroadphaseProxy.m_clientObject
+       
+               inline void SetNextFree(unsigned short next) {m_minEdges[0] = next;}
+               inline unsigned short GetNextFree() const {return m_minEdges[0];}
+       };              // 24 bytes + 24 for Edge structures = 44 bytes total per entry
+
+       
+private:
+       btPoint3 m_worldAabbMin;                                                // overall system bounds
+       btPoint3 m_worldAabbMax;                                                // overall system bounds
+
+       btVector3 m_quantize;                                           // scaling factor for quantization
+
+       int m_numHandles;                                               // number of active handles
+       int m_maxHandles;                                               // max number of handles
+       Handle* m_pHandles;                                             // handles pool
+       unsigned short m_firstFreeHandle;               // free handles list
+
+       Edge* m_pEdges[3];                                              // edge arrays for the 3 axes (each array has m_maxHandles * 2 + 2 sentinel entries)
+
+
+       // allocation/deallocation
+       unsigned short allocHandle();
+       void freeHandle(unsigned short handle);
+       
+
+       bool testOverlap(int ignoreAxis,const Handle* pHandleA, const Handle* pHandleB);
+
+       //Overlap* AddOverlap(unsigned short handleA, unsigned short handleB);
+       //void RemoveOverlap(unsigned short handleA, unsigned short handleB);
+
+       void quantize(unsigned short* out, const btPoint3& point, int isMax) const;
+
+       void sortMinDown(int axis, unsigned short edge, bool updateOverlaps = true);
+       void sortMinUp(int axis, unsigned short edge, bool updateOverlaps = true);
+       void sortMaxDown(int axis, unsigned short edge, bool updateOverlaps = true);
+       void sortMaxUp(int axis, unsigned short edge, bool updateOverlaps = true);
+
+public:
+       btAxisSweep3(const btPoint3& worldAabbMin,const btPoint3& worldAabbMax, int maxHandles = 16384);
+       virtual ~btAxisSweep3();
+
+       virtual void    refreshOverlappingPairs()
+       {
+               //this is replace by sweep and prune
+       }
+       
+       unsigned short addHandle(const btPoint3& aabbMin,const btPoint3& aabbMax, void* pOwner,short int collisionFilterGroup,short int collisionFilterMask);
+       void removeHandle(unsigned short handle);
+       void updateHandle(unsigned short handle, const btPoint3& aabbMin,const btPoint3& aabbMax);
+       inline Handle* getHandle(unsigned short index) const {return m_pHandles + index;}
+
+
+       //Broadphase Interface
+       virtual btBroadphaseProxy*      createProxy(  const btVector3& min,  const btVector3& max,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask);
+       virtual void    destroyProxy(btBroadphaseProxy* proxy);
+       virtual void    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax);
+
+};
+
+#endif //AXIS_SWEEP_3_H
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
new file mode 100644 (file)
index 0000000..0c0bfe4
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+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                BROADPHASE_INTERFACE_H
+#define        BROADPHASE_INTERFACE_H
+
+
+
+struct btDispatcherInfo;
+class btDispatcher;
+struct btBroadphaseProxy;
+#include "LinearMath/btVector3.h"
+
+///BroadphaseInterface for aabb-overlapping object pairs
+class btBroadphaseInterface
+{
+public:
+       virtual ~btBroadphaseInterface() {}
+
+       virtual btBroadphaseProxy*      createProxy(  const btVector3& min,  const btVector3& max,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask) =0;
+       virtual void    destroyProxy(btBroadphaseProxy* proxy)=0;
+       virtual void    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax)=0;
+       virtual void    cleanProxyFromPairs(btBroadphaseProxy* proxy)=0;
+       
+
+};
+
+#endif //BROADPHASE_INTERFACE_H
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp
new file mode 100644 (file)
index 0000000..f4d7341
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+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 "btBroadphaseProxy.h"
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
new file mode 100644 (file)
index 0000000..713d7d1
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+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 BROADPHASE_PROXY_H
+#define BROADPHASE_PROXY_H
+
+
+
+/// btDispatcher uses these types
+/// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
+/// to facilitate type checking
+enum BroadphaseNativeTypes
+{
+// polyhedral convex shapes
+       BOX_SHAPE_PROXYTYPE,
+       TRIANGLE_SHAPE_PROXYTYPE,
+       TETRAHEDRAL_SHAPE_PROXYTYPE,
+       CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
+       CONVEX_HULL_SHAPE_PROXYTYPE,
+//implicit convex shapes
+IMPLICIT_CONVEX_SHAPES_START_HERE,
+       SPHERE_SHAPE_PROXYTYPE,
+       MULTI_SPHERE_SHAPE_PROXYTYPE,
+       CONE_SHAPE_PROXYTYPE,
+       CONVEX_SHAPE_PROXYTYPE,
+       CYLINDER_SHAPE_PROXYTYPE,
+       MINKOWSKI_SUM_SHAPE_PROXYTYPE,
+       MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
+//concave shapes
+CONCAVE_SHAPES_START_HERE,
+       //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
+       TRIANGLE_MESH_SHAPE_PROXYTYPE,
+       ///used for demo integration FAST/Swift collision library and Bullet
+       FAST_CONCAVE_MESH_PROXYTYPE,
+
+       EMPTY_SHAPE_PROXYTYPE,
+       STATIC_PLANE_PROXYTYPE,
+CONCAVE_SHAPES_END_HERE,
+
+       COMPOUND_SHAPE_PROXYTYPE,
+
+       MAX_BROADPHASE_COLLISION_TYPES
+};
+
+
+///btBroadphaseProxy
+struct btBroadphaseProxy
+{
+       
+       ///optional filtering to cull potential collisions
+       enum CollisionFilterGroups
+       {
+               DefaultFilter = 1,
+               StaticFilter = 2,
+               KinematicFilter = 4,
+               DebrisFilter = 8,
+               AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter,
+       };
+
+       //Usually the client btCollisionObject or Rigidbody class
+       void*   m_clientObject;
+       short int m_collisionFilterGroup;
+       short int m_collisionFilterMask;
+
+       //used for memory pools
+       btBroadphaseProxy() :m_clientObject(0){}
+
+       btBroadphaseProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask)
+               :m_clientObject(userPtr),
+               m_collisionFilterGroup(collisionFilterGroup),
+               m_collisionFilterMask(collisionFilterMask)
+       {
+       }
+
+       static inline bool isPolyhedral(int proxyType)
+       {
+               return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
+       }
+
+       static inline bool      isConvex(int proxyType)
+       {
+               return (proxyType < CONCAVE_SHAPES_START_HERE);
+       }
+
+       static inline bool      isConcave(int proxyType)
+       {
+               return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
+                       (proxyType < CONCAVE_SHAPES_END_HERE));
+       }
+       static inline bool      isCompound(int proxyType)
+       {
+               return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
+       }
+       
+};
+
+class btCollisionAlgorithm;
+
+struct btBroadphaseProxy;
+
+//Increase SIMPLE_MAX_ALGORITHMS to allow multiple btDispatchers caching their own algorithms
+#define SIMPLE_MAX_ALGORITHMS 1
+
+/// contains a pair of aabb-overlapping objects
+struct btBroadphasePair
+{
+       btBroadphasePair ()
+               :
+       m_pProxy0(0),
+               m_pProxy1(0)
+       {
+               for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
+               {
+                       m_algorithms[i] = 0;
+               }
+       }
+
+       btBroadphasePair(const btBroadphasePair& other)
+               :               m_pProxy0(other.m_pProxy0),
+                               m_pProxy1(other.m_pProxy1)
+       {
+               for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
+               {
+                       m_algorithms[i] = other.m_algorithms[i];
+               }
+       }
+       btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
+       {
+
+               //keep them sorted, so the std::set operations work
+               if (&proxy0 < &proxy1)
+        { 
+            m_pProxy0 = &proxy0; 
+            m_pProxy1 = &proxy1; 
+        }
+        else 
+        { 
+                       m_pProxy0 = &proxy1; 
+            m_pProxy1 = &proxy0; 
+        }
+
+               for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
+               {
+                       m_algorithms[i] = 0;
+               }
+
+       }
+       
+       btBroadphaseProxy* m_pProxy0;
+       btBroadphaseProxy* m_pProxy1;
+       
+       mutable btCollisionAlgorithm* m_algorithms[SIMPLE_MAX_ALGORITHMS];
+};
+
+
+//comparison for set operation, see Solid DT_Encounter
+inline bool operator<(const btBroadphasePair& a, const btBroadphasePair& b) 
+{ 
+    return a.m_pProxy0 < b.m_pProxy0 || 
+        (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1); 
+}
+
+
+#endif //BROADPHASE_PROXY_H
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp
new file mode 100644 (file)
index 0000000..2ad0c86
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+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 "btCollisionAlgorithm.h"
+#include "btDispatcher.h"
+
+btCollisionAlgorithm::btCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
+{
+       m_dispatcher = ci.m_dispatcher;
+}
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h
new file mode 100644 (file)
index 0000000..a57c761
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+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 COLLISION_ALGORITHM_H
+#define COLLISION_ALGORITHM_H
+
+struct btBroadphaseProxy;
+class btDispatcher;
+class btManifoldResult;
+struct btCollisionObject;
+struct btDispatcherInfo;
+
+struct btCollisionAlgorithmConstructionInfo
+{
+       btCollisionAlgorithmConstructionInfo()
+               :m_dispatcher(0)
+       {
+       }
+       btCollisionAlgorithmConstructionInfo(btDispatcher* dispatcher,int temp)
+               :m_dispatcher(dispatcher)
+       {
+       }
+
+       btDispatcher*   m_dispatcher;
+
+       int     getDispatcherId();
+
+};
+
+
+///btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatcher.
+///It is persistent over frames
+class btCollisionAlgorithm
+{
+
+protected:
+
+       btDispatcher*   m_dispatcher;
+
+protected:
+       int     getDispatcherId();
+       
+public:
+
+       btCollisionAlgorithm() {};
+
+       btCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
+
+       virtual ~btCollisionAlgorithm() {};
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
+
+       virtual float calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
+
+};
+
+
+#endif //COLLISION_ALGORITHM_H
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.cpp
new file mode 100644 (file)
index 0000000..2076822
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+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 "btDispatcher.h"
+
+btDispatcher::~btDispatcher()
+{
+
+}
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h
new file mode 100644 (file)
index 0000000..f87c028
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+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 _DISPATCHER_H
+#define _DISPATCHER_H
+
+class btCollisionAlgorithm;
+struct btBroadphaseProxy;
+class btRigidBody;
+struct btCollisionObject;
+class btOverlappingPairCache;
+
+enum btCollisionDispatcherId
+{
+       RIGIDBODY_DISPATCHER = 0,
+       USERCALLBACK_DISPATCHER
+};
+
+class btPersistentManifold;
+
+struct btDispatcherInfo
+{
+       enum DispatchFunc
+       {
+               DISPATCH_DISCRETE = 1,
+               DISPATCH_CONTINUOUS
+       };
+       btDispatcherInfo()
+               :m_dispatchFunc(DISPATCH_DISCRETE),
+               m_timeOfImpact(1.f),
+               m_useContinuous(false),
+               m_debugDraw(0),
+               m_enableSatConvex(false)
+       {
+
+       }
+       float   m_timeStep;
+       int             m_stepCount;
+       int             m_dispatchFunc;
+       float   m_timeOfImpact;
+       bool    m_useContinuous;
+       class btIDebugDraw*     m_debugDraw;
+       bool    m_enableSatConvex;
+       
+};
+
+/// btDispatcher can be used in combination with broadphase to dispatch overlapping pairs.
+/// For example for pairwise collision detection or user callbacks (game logic).
+class btDispatcher
+{
+
+
+public:
+       virtual ~btDispatcher() ;
+
+       virtual btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1) = 0;
+
+       //
+       // asume dispatchers to have unique id's in the range [0..max dispacher]
+       //
+       virtual int getUniqueId() = 0;
+
+       virtual btPersistentManifold*   getNewManifold(void* body0,void* body1)=0;
+
+       virtual void releaseManifold(btPersistentManifold* manifold)=0;
+
+       virtual void clearManifold(btPersistentManifold* manifold)=0;
+
+       virtual bool    needsCollision(btCollisionObject* body0,btCollisionObject* body1) = 0;
+
+       virtual bool    needsResponse(btCollisionObject* body0,btCollisionObject* body1)=0;
+
+       virtual void    dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,btDispatcherInfo& dispatchInfo)=0;
+
+       virtual int getNumManifolds() const = 0;
+
+       virtual btPersistentManifold* getManifoldByIndexInternal(int index) = 0;
+
+};
+
+
+#endif //_DISPATCHER_H
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
new file mode 100644 (file)
index 0000000..8950d20
--- /dev/null
@@ -0,0 +1,203 @@
+
+/*
+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 "btOverlappingPairCache.h"
+
+#include "btDispatcher.h"
+#include "btCollisionAlgorithm.h"
+
+int    gOverlappingPairs = 0;
+
+btOverlappingPairCache::btOverlappingPairCache():
+m_blockedForChanges(false)
+//m_NumOverlapBroadphasePair(0)
+{
+}
+
+
+btOverlappingPairCache::~btOverlappingPairCache()
+{
+       //todo/test: show we erase/delete data, or is it automatic
+}
+
+
+void   btOverlappingPairCache::removeOverlappingPair(btBroadphasePair& findPair)
+{
+       
+       std::set<btBroadphasePair>::iterator it = m_overlappingPairSet.find(findPair);
+//     assert(it != m_overlappingPairSet.end());
+
+       if (it != m_overlappingPairSet.end())
+       {
+               gOverlappingPairs--;
+               btBroadphasePair* pair = (btBroadphasePair*)(&(*it));
+               cleanOverlappingPair(*pair);    
+               m_overlappingPairSet.erase(it);
+       }
+}
+
+
+void   btOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair)
+{
+       for (int dispatcherId=0;dispatcherId<SIMPLE_MAX_ALGORITHMS;dispatcherId++)
+       {
+               if (pair.m_algorithms[dispatcherId])
+               {
+                       {
+                               delete pair.m_algorithms[dispatcherId];
+                               pair.m_algorithms[dispatcherId]=0;
+                       }
+               }
+       }
+}
+
+
+
+
+
+void   btOverlappingPairCache::addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+{
+       //don't add overlap with own
+       assert(proxy0 != proxy1);
+
+       if (!needsBroadphaseCollision(proxy0,proxy1))
+               return;
+
+
+       btBroadphasePair pair(*proxy0,*proxy1);
+       
+       m_overlappingPairSet.insert(pair);
+       gOverlappingPairs++;
+       
+}
+
+///this findPair becomes really slow. Either sort the list to speedup the query, or
+///use a different solution. It is mainly used for Removing overlapping pairs. Removal could be delayed.
+///we could keep a linked list in each proxy, and store pair in one of the proxies (with lowest memory address)
+///Also we can use a 2D bitmap, which can be useful for a future GPU implementation
+ btBroadphasePair*     btOverlappingPairCache::findPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+{
+       if (!needsBroadphaseCollision(proxy0,proxy1))
+               return 0;
+
+       btBroadphasePair tmpPair(*proxy0,*proxy1);
+       std::set<btBroadphasePair>::iterator it = m_overlappingPairSet.find(tmpPair);
+       if ((it == m_overlappingPairSet.end()))
+               return 0;
+
+       //assert(it != m_overlappingPairSet.end());
+        btBroadphasePair* pair = (btBroadphasePair*)(&(*it));
+       return pair;
+}
+
+
+
+
+
+void   btOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy)
+{
+
+       class   CleanPairCallback : public btOverlapCallback
+       {
+               btBroadphaseProxy* m_cleanProxy;
+               btOverlappingPairCache* m_pairCache;
+
+       public:
+               CleanPairCallback(btBroadphaseProxy* cleanProxy,btOverlappingPairCache* pairCache)
+                       :m_cleanProxy(cleanProxy),
+                       m_pairCache(pairCache)
+               {
+               }
+               virtual bool    processOverlap(btBroadphasePair& pair)
+               {
+                       if ((pair.m_pProxy0 == m_cleanProxy) ||
+                               (pair.m_pProxy1 == m_cleanProxy))
+                       {
+                               m_pairCache->cleanOverlappingPair(pair);
+                       }
+                       return false;
+               }
+               
+       };
+
+       CleanPairCallback cleanPairs(proxy,this);
+
+       processAllOverlappingPairs(&cleanPairs);
+
+}
+
+
+
+void   btOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy)
+{
+
+       class   RemovePairCallback : public btOverlapCallback
+       {
+               btBroadphaseProxy* m_obsoleteProxy;
+
+       public:
+               RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
+                       :m_obsoleteProxy(obsoleteProxy)
+               {
+               }
+               virtual bool    processOverlap(btBroadphasePair& pair)
+               {
+                       return ((pair.m_pProxy0 == m_obsoleteProxy) ||
+                               (pair.m_pProxy1 == m_obsoleteProxy));
+               }
+               
+       };
+
+
+       RemovePairCallback removeCallback(proxy);
+
+       processAllOverlappingPairs(&removeCallback);
+}
+
+
+
+void   btOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback)
+{
+       std::set<btBroadphasePair>::iterator it = m_overlappingPairSet.begin();
+       for (; !(it==m_overlappingPairSet.end());)
+       {
+       
+               btBroadphasePair* pair = (btBroadphasePair*)(&(*it));
+               if (callback->processOverlap(*pair))
+               {
+                       cleanOverlappingPair(*pair);
+
+                       std::set<btBroadphasePair>::iterator it2 = it;
+                       //why does next line not compile under OS X??
+#ifdef MAC_OSX_FIXED_STL_SET
+                       it2++;
+                       it = m_overlappingPairSet.erase(it);
+                       assert(it == it2);
+#else
+                       it++;
+                       m_overlappingPairSet.erase(it2);
+#endif //MAC_OSX_FIXED_STL_SET
+
+                       gOverlappingPairs--;
+               } else
+               {
+                       it++;
+               }
+       }
+}
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
new file mode 100644 (file)
index 0000000..85bb826
--- /dev/null
@@ -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.
+*/
+
+#ifndef OVERLAPPING_PAIR_CACHE_H
+#define OVERLAPPING_PAIR_CACHE_H
+
+
+#include "btBroadphaseInterface.h"
+#include "btBroadphaseProxy.h"
+#include "LinearMath/btPoint3.h"
+#include <set>
+
+
+struct btOverlapCallback
+{
+virtual ~btOverlapCallback()
+{
+}
+       //return true for deletion of the pair
+       virtual bool    processOverlap(btBroadphasePair& pair) = 0;
+};
+
+///btOverlappingPairCache maintains the objects with overlapping AABB
+///Typically managed by the Broadphase, Axis3Sweep or btSimpleBroadphase
+class  btOverlappingPairCache : public btBroadphaseInterface
+{
+       //avoid brute-force finding all the time
+       std::set<btBroadphasePair>      m_overlappingPairSet;
+       
+       //during the dispatch, check that user doesn't destroy/create proxy
+       bool            m_blockedForChanges;
+       
+       public:
+               
+       btOverlappingPairCache();       
+       virtual ~btOverlappingPairCache();
+
+       void    processAllOverlappingPairs(btOverlapCallback*);
+
+       void    removeOverlappingPair(btBroadphasePair& pair);
+
+       void    cleanOverlappingPair(btBroadphasePair& pair);
+       
+       void    addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
+
+       btBroadphasePair*       findPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
+               
+       
+       void    cleanProxyFromPairs(btBroadphaseProxy* proxy);
+
+       void    removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy);
+
+
+       inline bool needsBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
+       {
+               bool collides = proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask;
+               collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
+               
+               return collides;
+       }
+               
+       
+
+       virtual void    refreshOverlappingPairs() =0;
+
+
+
+
+};
+#endif //OVERLAPPING_PAIR_CACHE_H
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
new file mode 100644 (file)
index 0000000..1a24c7a
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+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 "btSimpleBroadphase.h"
+#include <BulletCollision/BroadphaseCollision/btDispatcher.h>
+#include <BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h>
+
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btMatrix3x3.h"
+#include <vector>
+
+
+void   btSimpleBroadphase::validate()
+{
+       for (int i=0;i<m_numProxies;i++)
+       {
+               for (int j=i+1;j<m_numProxies;j++)
+               {
+                       assert(m_pProxies[i] != m_pProxies[j]);
+               }
+       }
+       
+}
+
+btSimpleBroadphase::btSimpleBroadphase(int maxProxies)
+       :btOverlappingPairCache(),
+       m_firstFreeProxy(0),
+       m_numProxies(0),
+       m_maxProxies(maxProxies)
+{
+
+       m_proxies = new btSimpleBroadphaseProxy[maxProxies];
+       m_freeProxies = new int[maxProxies];
+       m_pProxies = new btSimpleBroadphaseProxy*[maxProxies];
+       
+
+       int i;
+       for (i=0;i<m_maxProxies;i++)
+       {
+               m_freeProxies[i] = i;
+       }
+}
+
+btSimpleBroadphase::~btSimpleBroadphase()
+{
+       delete[] m_proxies;
+       delete []m_freeProxies;
+       delete [] m_pProxies;
+
+       /*int i;
+       for (i=m_numProxies-1;i>=0;i--)
+       {
+               BP_Proxy* proxy = m_pProxies[i]; 
+               destroyProxy(proxy);
+       }
+       */
+}
+
+
+btBroadphaseProxy*     btSimpleBroadphase::createProxy(  const btVector3& min,  const btVector3& max,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask)
+{
+       if (m_numProxies >= m_maxProxies)
+       {
+               assert(0);
+               return 0; //should never happen, but don't let the game crash ;-)
+       }
+       assert(min[0]<= max[0] && min[1]<= max[1] && min[2]<= max[2]);
+
+       int freeIndex= m_freeProxies[m_firstFreeProxy];
+       btSimpleBroadphaseProxy* proxy = new (&m_proxies[freeIndex])btSimpleBroadphaseProxy(min,max,shapeType,userPtr,collisionFilterGroup,collisionFilterMask);
+       m_firstFreeProxy++;
+
+       btSimpleBroadphaseProxy* proxy1 = &m_proxies[0];
+               
+       int index = proxy - proxy1;
+       assert(index == freeIndex);
+
+       m_pProxies[m_numProxies] = proxy;
+       m_numProxies++;
+       //validate();
+
+       return proxy;
+}
+
+class  RemovingOverlapCallback : public btOverlapCallback
+{
+protected:
+       virtual bool    processOverlap(btBroadphasePair& pair)
+       {
+               assert(0);
+       }
+};
+
+class RemovePairContainingProxy
+{
+
+       btBroadphaseProxy*      m_targetProxy;
+       public:
+       virtual ~RemovePairContainingProxy()
+       {
+       }
+protected:
+       virtual bool processOverlap(btBroadphasePair& pair)
+       {
+               btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy0);
+               btSimpleBroadphaseProxy* proxy1 = static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy1);
+
+               return ((m_targetProxy == proxy0 || m_targetProxy == proxy1));
+       };
+};
+
+void   btSimpleBroadphase::destroyProxy(btBroadphaseProxy* proxyOrg)
+{
+               
+               int i;
+               
+               btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxyOrg);
+               btSimpleBroadphaseProxy* proxy1 = &m_proxies[0];
+       
+               int index = proxy0 - proxy1;
+               assert (index < m_maxProxies);
+               m_freeProxies[--m_firstFreeProxy] = index;
+
+               removeOverlappingPairsContainingProxy(proxyOrg);
+               
+               for (i=0;i<m_numProxies;i++)
+               {
+                       if (m_pProxies[i] == proxyOrg)
+                       {
+                               m_pProxies[i] = m_pProxies[m_numProxies-1];
+                               break;
+                       }
+               }
+               m_numProxies--;
+               //validate();
+               
+}
+
+void   btSimpleBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax)
+{
+       btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
+       sbp->m_min = aabbMin;
+       sbp->m_max = aabbMax;
+}
+
+
+
+
+
+       
+
+
+
+bool   btSimpleBroadphase::aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1)
+{
+       return proxy0->m_min[0] <= proxy1->m_max[0] && proxy1->m_min[0] <= proxy0->m_max[0] && 
+                  proxy0->m_min[1] <= proxy1->m_max[1] && proxy1->m_min[1] <= proxy0->m_max[1] &&
+                  proxy0->m_min[2] <= proxy1->m_max[2] && proxy1->m_min[2] <= proxy0->m_max[2];
+
+}
+
+
+
+//then remove non-overlapping ones
+class CheckOverlapCallback : public btOverlapCallback
+{
+public:
+       virtual bool processOverlap(btBroadphasePair& pair)
+       {
+               return (!btSimpleBroadphase::aabbOverlap(static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy0),static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy1)));
+       }
+};
+
+void   btSimpleBroadphase::refreshOverlappingPairs()
+{
+       //first check for new overlapping pairs
+       int i,j;
+
+       for (i=0;i<m_numProxies;i++)
+       {
+               btBroadphaseProxy* proxy0 = m_pProxies[i];
+               for (j=i+1;j<m_numProxies;j++)
+               {
+                       btBroadphaseProxy* proxy1 = m_pProxies[j];
+                       btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
+                       btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
+
+                       if (aabbOverlap(p0,p1))
+                       {
+                               if ( !findPair(proxy0,proxy1))
+                               {
+                                       addOverlappingPair(proxy0,proxy1);
+                               }
+                       }
+
+               }
+       }
+
+
+       CheckOverlapCallback    checkOverlap;
+
+       processAllOverlappingPairs(&checkOverlap);
+
+
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
new file mode 100644 (file)
index 0000000..2816770
--- /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.
+*/
+
+#ifndef SIMPLE_BROADPHASE_H
+#define SIMPLE_BROADPHASE_H
+
+
+#include "btOverlappingPairCache.h"
+
+
+struct btSimpleBroadphaseProxy : public btBroadphaseProxy
+{
+       btVector3       m_min;
+       btVector3       m_max;
+       
+       btSimpleBroadphaseProxy() {};
+
+       btSimpleBroadphaseProxy(const btPoint3& minpt,const btPoint3& maxpt,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask)
+       :btBroadphaseProxy(userPtr,collisionFilterGroup,collisionFilterMask),
+       m_min(minpt),m_max(maxpt)               
+       {
+       }
+       
+
+};
+
+///SimpleBroadphase is a brute force aabb culling broadphase based on O(n^2) aabb checks
+class btSimpleBroadphase : public btOverlappingPairCache
+{
+
+       btSimpleBroadphaseProxy*        m_proxies;
+       int*                            m_freeProxies;
+       int                             m_firstFreeProxy;
+
+       btSimpleBroadphaseProxy** m_pProxies;
+       int                             m_numProxies;
+
+       
+
+       int m_maxProxies;
+       
+       
+       inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
+       {
+               btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
+               return proxy0;
+       }
+
+
+       void    validate();
+
+protected:
+
+
+       virtual void    refreshOverlappingPairs();
+public:
+       btSimpleBroadphase(int maxProxies=16384);
+       virtual ~btSimpleBroadphase();
+
+
+               static bool     aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
+
+
+       virtual btBroadphaseProxy*      createProxy(  const btVector3& min,  const btVector3& max,int shapeType,void* userPtr ,short int collisionFilterGroup,short int collisionFilterMask);
+
+
+       virtual void    destroyProxy(btBroadphaseProxy* proxy);
+       virtual void    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax);
+               
+       
+       
+
+
+
+};
+
+
+
+#endif //SIMPLE_BROADPHASE_H
+
diff --git a/extern/bullet2/src/BulletCollision/CMakeLists.txt b/extern/bullet2/src/BulletCollision/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d10bd24
--- /dev/null
@@ -0,0 +1,57 @@
+                       
+INCLUDE_DIRECTORIES(
+${BULLET_PHYSICS_SOURCE_DIR}/src }
+)
+       
+ADD_LIBRARY(LibBulletCollision
+                               BroadphaseCollision/btAxisSweep3.cpp
+                               BroadphaseCollision/btBroadphaseProxy.cpp
+                               BroadphaseCollision/btCollisionAlgorithm.cpp
+                               BroadphaseCollision/btDispatcher.cpp
+                               BroadphaseCollision/btOverlappingPairCache.cpp
+                               BroadphaseCollision/btSimpleBroadphase.cpp
+                               CollisionDispatch/btCollisionDispatcher.cpp
+                               CollisionDispatch/btCollisionObject.cpp
+                               CollisionDispatch/btCollisionWorld.cpp
+                               CollisionDispatch/btCompoundCollisionAlgorithm.cpp
+                               CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
+                               CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
+                               CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
+                               CollisionDispatch/btConvexConvexAlgorithm.cpp
+                               CollisionDispatch/btEmptyCollisionAlgorithm.cpp
+                               CollisionDispatch/btManifoldResult.cpp
+                               CollisionDispatch/btSimulationIslandManager.cpp
+                               CollisionDispatch/btUnionFind.cpp
+                               CollisionShapes/btBoxShape.cpp
+                               CollisionShapes/btBvhTriangleMeshShape.cpp
+                               CollisionShapes/btCollisionShape.cpp
+                               CollisionShapes/btCompoundShape.cpp
+                               CollisionShapes/btConcaveShape.cpp
+                               CollisionShapes/btConeShape.cpp
+                               CollisionShapes/btConvexHullShape.cpp
+                               CollisionShapes/btConvexShape.cpp
+                               CollisionShapes/btConvexTriangleMeshShape.cpp
+                               CollisionShapes/btCylinderShape.cpp
+                               CollisionShapes/btEmptyShape.cpp
+                               CollisionShapes/btMinkowskiSumShape.cpp
+                               CollisionShapes/btMultiSphereShape.cpp
+                               CollisionShapes/btOptimizedBvh.cpp
+                               CollisionShapes/btPolyhedralConvexShape.cpp
+                               CollisionShapes/btTetrahedronShape.cpp
+                               CollisionShapes/btSphereShape.cpp
+                               CollisionShapes/btStaticPlaneShape.cpp
+                               CollisionShapes/btStridingMeshInterface.cpp
+                               CollisionShapes/btTriangleCallback.cpp
+                               CollisionShapes/btTriangleIndexVertexArray.cpp
+                               CollisionShapes/btTriangleMesh.cpp
+                               CollisionShapes/btTriangleMeshShape.cpp
+                               NarrowPhaseCollision/btContinuousConvexCollision.cpp
+                               NarrowPhaseCollision/btConvexCast.cpp
+                               NarrowPhaseCollision/btGjkConvexCast.cpp
+                               NarrowPhaseCollision/btGjkPairDetector.cpp
+                               NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
+                               NarrowPhaseCollision/btPersistentManifold.cpp
+                               NarrowPhaseCollision/btRaycastCallback.cpp
+                               NarrowPhaseCollision/btSubSimplexConvexCast.cpp
+                               NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
+)
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
new file mode 100644 (file)
index 0000000..6d499f5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+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 COLLISION_CREATE_FUNC
+#define COLLISION_CREATE_FUNC
+
+#include <vector>
+
+typedef std::vector<struct btCollisionObject*> btCollisionObjectArray;
+class btCollisionAlgorithm;
+struct btCollisionObject;
+
+struct btCollisionAlgorithmConstructionInfo;
+
+///Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm
+struct btCollisionAlgorithmCreateFunc
+{
+       bool m_swapped;
+       
+       btCollisionAlgorithmCreateFunc()
+               :m_swapped(false)
+       {
+       }
+       virtual ~btCollisionAlgorithmCreateFunc(){};
+
+       virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+       {
+               return 0;
+       }
+};
+#endif //COLLISION_CREATE_FUNC
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
new file mode 100644 (file)
index 0000000..d824f68
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+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 "btCollisionDispatcher.h"
+
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
+#include "BulletCollision/CollisionShapes/btCollisionShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include <algorithm>
+#include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
+
+int gNumManifold = 0;
+
+#include <stdio.h>
+
+       
+btCollisionDispatcher::btCollisionDispatcher(bool noDefaultAlgorithms)
+:m_useIslands(true),
+m_count(0),
+m_convexConvexCreateFunc(0),
+m_convexConcaveCreateFunc(0),
+m_swappedConvexConcaveCreateFunc(0),
+m_compoundCreateFunc(0),
+m_swappedCompoundCreateFunc(0),
+m_emptyCreateFunc(0)
+{
+       int i;
+
+       m_emptyCreateFunc = new btEmptyAlgorithm::CreateFunc;
+       for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
+       {
+               for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
+               {
+                       m_doubleDispatch[i][j] = m_emptyCreateFunc;
+               }
+       }
+}
+
+       
+btCollisionDispatcher::btCollisionDispatcher (): 
+       m_useIslands(true),
+               m_count(0)
+{
+       int i;
+       
+       //default CreationFunctions, filling the m_doubleDispatch table
+       m_convexConvexCreateFunc = new btConvexConvexAlgorithm::CreateFunc;
+       m_convexConcaveCreateFunc = new btConvexConcaveCollisionAlgorithm::CreateFunc;
+       m_swappedConvexConcaveCreateFunc = new btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
+       m_compoundCreateFunc = new btCompoundCollisionAlgorithm::CreateFunc;
+       m_swappedCompoundCreateFunc = new btCompoundCollisionAlgorithm::SwappedCreateFunc;
+       m_emptyCreateFunc = new btEmptyAlgorithm::CreateFunc;
+
+       for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
+       {
+               for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
+               {
+                       m_doubleDispatch[i][j] = internalFindCreateFunc(i,j);
+                       assert(m_doubleDispatch[i][j]);
+               }
+       }
+       
+       
+};
+
+void btCollisionDispatcher::registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
+{
+       m_doubleDispatch[proxyType0][proxyType1] = createFunc;
+}
+
+btCollisionDispatcher::~btCollisionDispatcher()
+{
+       delete m_convexConvexCreateFunc;
+       delete m_convexConcaveCreateFunc;
+       delete m_swappedConvexConcaveCreateFunc;
+       delete m_compoundCreateFunc;
+       delete m_swappedCompoundCreateFunc;
+       delete m_emptyCreateFunc;
+}
+
+btPersistentManifold*  btCollisionDispatcher::getNewManifold(void* b0,void* b1) 
+{ 
+       gNumManifold++;
+       
+       //ASSERT(gNumManifold < 65535);
+       
+
+       btCollisionObject* body0 = (btCollisionObject*)b0;
+       btCollisionObject* body1 = (btCollisionObject*)b1;
+       
+       btPersistentManifold* manifold = new btPersistentManifold (body0,body1);
+       m_manifoldsPtr.push_back(manifold);
+
+       return manifold;
+}
+
+void btCollisionDispatcher::clearManifold(btPersistentManifold* manifold)
+{
+       manifold->clearManifold();
+}
+
+       
+void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
+{
+       
+       gNumManifold--;
+
+       //printf("releaseManifold: gNumManifold %d\n",gNumManifold);
+
+       clearManifold(manifold);
+
+       std::vector<btPersistentManifold*>::iterator i =
+               std::find(m_manifoldsPtr.begin(), m_manifoldsPtr.end(), manifold);
+       if (!(i == m_manifoldsPtr.end()))
+       {
+               std::swap(*i, m_manifoldsPtr.back());
+               m_manifoldsPtr.pop_back();
+               delete manifold;
+
+       }
+       
+       
+}
+
+       
+
+btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
+{
+#define USE_DISPATCH_REGISTRY_ARRAY 1
+#ifdef USE_DISPATCH_REGISTRY_ARRAY
+       
+       btCollisionAlgorithmConstructionInfo ci;
+       ci.m_dispatcher = this;
+       btCollisionAlgorithm* algo = m_doubleDispatch[body0->m_collisionShape->getShapeType()][body1->m_collisionShape->getShapeType()]
+       ->CreateCollisionAlgorithm(ci,body0,body1);
+#else
+       btCollisionAlgorithm* algo = internalFindAlgorithm(body0,body1);
+#endif //USE_DISPATCH_REGISTRY_ARRAY
+       return algo;
+}
+
+
+btCollisionAlgorithmCreateFunc* btCollisionDispatcher::internalFindCreateFunc(int proxyType0,int proxyType1)
+{
+       
+       if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
+       {
+               return m_convexConvexCreateFunc;
+       }
+
+       if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1))
+       {
+               return m_convexConcaveCreateFunc;
+       }
+
+       if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0))
+       {
+               return m_swappedConvexConcaveCreateFunc;
+       }
+
+       if (btBroadphaseProxy::isCompound(proxyType0))
+       {
+               return m_compoundCreateFunc;
+       } else
+       {
+               if (btBroadphaseProxy::isCompound(proxyType1))
+               {
+                       return m_swappedCompoundCreateFunc;
+               }
+       }
+
+       //failed to find an algorithm
+       return m_emptyCreateFunc;
+}
+
+
+
+btCollisionAlgorithm* btCollisionDispatcher::internalFindAlgorithm(btCollisionObject* body0,btCollisionObject* body1)
+{
+       m_count++;
+       
+       btCollisionAlgorithmConstructionInfo ci;
+       ci.m_dispatcher = this;
+       
+       if (body0->m_collisionShape->isConvex() && body1->m_collisionShape->isConvex() )
+       {
+               return new btConvexConvexAlgorithm(0,ci,body0,body1);
+       }
+
+       if (body0->m_collisionShape->isConvex() && body1->m_collisionShape->isConcave())
+       {
+               return new btConvexConcaveCollisionAlgorithm(ci,body0,body1,false);
+       }
+
+       if (body1->m_collisionShape->isConvex() && body0->m_collisionShape->isConcave())
+       {
+               return new btConvexConcaveCollisionAlgorithm(ci,body0,body1,true);
+       }
+
+       if (body0->m_collisionShape->isCompound())
+       {
+               return new btCompoundCollisionAlgorithm(ci,body0,body1,false);
+       } else
+       {
+               if (body1->m_collisionShape->isCompound())
+               {
+                       return new btCompoundCollisionAlgorithm(ci,body0,body1,true);
+               }
+       }
+
+       //failed to find an algorithm
+       return new btEmptyAlgorithm(ci);
+       
+}
+
+bool   btCollisionDispatcher::needsResponse(btCollisionObject* body0,btCollisionObject* body1)
+{
+       //here you can do filtering
+       bool hasResponse = 
+               (body0->hasContactResponse() && body1->hasContactResponse());
+       //no response between two static/kinematic bodies:
+       hasResponse = hasResponse &&
+               ((!body0->isStaticOrKinematicObject()) ||(! body1->isStaticOrKinematicObject()));
+       return hasResponse;
+}
+
+bool   btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionObject* body1)
+{
+       assert(body0);
+       assert(body1);
+
+       bool needsCollision = true;
+
+       //broadphase filtering already deals with this
+       if ((body0->isStaticObject() || body0->isKinematicObject()) &&
+               (body1->isStaticObject() || body1->isKinematicObject()))
+       {
+               printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
+       }
+               
+       if ((!body0->IsActive()) && (!body1->IsActive()))
+               needsCollision = false;
+       
+       return needsCollision ;
+
+}
+
+
+
+///interface for iterating all overlapping collision pairs, no matter how those pairs are stored (array, set, map etc)
+///this is useful for the collision dispatcher.
+class btCollisionPairCallback : public btOverlapCallback
+{
+       btDispatcherInfo& m_dispatchInfo;
+       btCollisionDispatcher*  m_dispatcher;
+       int             m_dispatcherId;
+public:
+
+       btCollisionPairCallback(btDispatcherInfo& dispatchInfo,btCollisionDispatcher*   dispatcher,int          dispatcherId)
+       :m_dispatchInfo(dispatchInfo),
+       m_dispatcher(dispatcher),
+       m_dispatcherId(dispatcherId)
+       {
+       }
+
+       virtual bool    processOverlap(btBroadphasePair& pair)
+       {
+               btCollisionObject* body0 = (btCollisionObject*)pair.m_pProxy0->m_clientObject;
+               btCollisionObject* body1 = (btCollisionObject*)pair.m_pProxy1->m_clientObject;
+
+               if (!m_dispatcher->needsCollision(body0,body1))
+                       return false;
+
+               //dispatcher will keep algorithms persistent in the collision pair
+               if (!pair.m_algorithms[m_dispatcherId])
+               {
+                       pair.m_algorithms[m_dispatcherId] = m_dispatcher->findAlgorithm(
+                               body0,
+                               body1);
+               }
+
+               if (pair.m_algorithms[m_dispatcherId])
+               {
+                       btManifoldResult* resultOut = m_dispatcher->internalGetNewManifoldResult(body0,body1);
+                       if (m_dispatchInfo.m_dispatchFunc ==            btDispatcherInfo::DISPATCH_DISCRETE)
+                       {
+                               
+                               pair.m_algorithms[m_dispatcherId]->processCollision(body0,body1,m_dispatchInfo,resultOut);
+                       } else
+                       {
+                               float toi = pair.m_algorithms[m_dispatcherId]->calculateTimeOfImpact(body0,body1,m_dispatchInfo,resultOut);
+                               if (m_dispatchInfo.m_timeOfImpact > toi)
+                                       m_dispatchInfo.m_timeOfImpact = toi;
+
+                       }
+                       m_dispatcher->internalReleaseManifoldResult(resultOut);
+               }
+               return false;
+
+       }
+};
+
+
+void   btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,btDispatcherInfo& dispatchInfo)
+{
+       //m_blockedForChanges = true;
+
+       int dispatcherId = getUniqueId();
+
+       btCollisionPairCallback collisionCallback(dispatchInfo,this,dispatcherId);
+
+       pairCache->processAllOverlappingPairs(&collisionCallback);
+
+       //m_blockedForChanges = false;
+
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
new file mode 100644 (file)
index 0000000..def5965
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+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 COLLISION__DISPATCHER_H
+#define COLLISION__DISPATCHER_H
+
+#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+
+#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
+
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+
+
+class btIDebugDraw;
+class btOverlappingPairCache;
+
+
+#include "btCollisionCreateFunc.h"
+
+
+
+
+///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
+///Time of Impact, Closest Points and Penetration Depth.
+class btCollisionDispatcher : public btDispatcher
+{
+       
+       std::vector<btPersistentManifold*>      m_manifoldsPtr;
+
+       bool m_useIslands;
+       
+       btManifoldResult        m_defaultManifoldResult;
+       
+       btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
+       
+       btCollisionAlgorithmCreateFunc* internalFindCreateFunc(int proxyType0,int proxyType1);
+
+       //default CreationFunctions, filling the m_doubleDispatch table
+       btCollisionAlgorithmCreateFunc* m_convexConvexCreateFunc;
+       btCollisionAlgorithmCreateFunc* m_convexConcaveCreateFunc;
+       btCollisionAlgorithmCreateFunc* m_swappedConvexConcaveCreateFunc;
+       btCollisionAlgorithmCreateFunc* m_compoundCreateFunc;
+       btCollisionAlgorithmCreateFunc* m_swappedCompoundCreateFunc;
+       btCollisionAlgorithmCreateFunc*   m_emptyCreateFunc;
+
+       btCollisionAlgorithm* internalFindAlgorithm(btCollisionObject* body0,btCollisionObject* body1);
+
+public:
+
+       ///allows the user to get contact point callbacks 
+       inline btManifoldResult*        internalGetNewManifoldResult(btCollisionObject* obj0,btCollisionObject* obj1)
+       {
+               //in-place, this prevents parallel dispatching, but just adding a list would fix that.
+               btManifoldResult* manifoldResult = new (&m_defaultManifoldResult)       btManifoldResult(obj0,obj1);
+               return manifoldResult;
+       }
+               
+       ///allows the user to get contact point callbacks 
+       inline void     internalReleaseManifoldResult(btManifoldResult*)
+       {
+       }
+
+       ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
+       void    registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
+
+       int     getNumManifolds() const
+       { 
+               return m_manifoldsPtr.size();
+       }
+
+       btPersistentManifold**  getInternalManifoldPointer()
+       {
+               return &m_manifoldsPtr[0];
+       }
+
+        btPersistentManifold* getManifoldByIndexInternal(int index)
+       {
+               return m_manifoldsPtr[index];
+       }
+
+        const btPersistentManifold* getManifoldByIndexInternal(int index) const
+       {
+               return m_manifoldsPtr[index];
+       }
+
+       int m_count;
+       
+       ///the default constructor creates/register default collision algorithms, for convex, compound and concave shape support
+       btCollisionDispatcher ();
+
+       ///a special constructor that doesn't create/register the default collision algorithms
+       btCollisionDispatcher(bool noDefaultAlgorithms);
+
+       virtual ~btCollisionDispatcher();
+
+       virtual btPersistentManifold*   getNewManifold(void* b0,void* b1);
+       
+       virtual void releaseManifold(btPersistentManifold* manifold);
+
+
+       virtual void clearManifold(btPersistentManifold* manifold);
+
+                       
+       btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1);
+               
+       virtual bool    needsCollision(btCollisionObject* body0,btCollisionObject* body1);
+       
+       virtual bool    needsResponse(btCollisionObject* body0,btCollisionObject* body1);
+
+       virtual int getUniqueId() { return RIGIDBODY_DISPATCHER;}
+       
+       virtual void    dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,btDispatcherInfo& dispatchInfo);
+
+       
+
+};
+
+#endif //COLLISION__DISPATCHER_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
new file mode 100644 (file)
index 0000000..881a8c0
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+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 "btCollisionObject.h"
+
+btCollisionObject::btCollisionObject()
+       :       m_broadphaseHandle(0),
+               m_collisionShape(0),
+               m_collisionFlags(0),
+               m_activationState1(1),
+               m_deactivationTime(0.f),
+               m_userObjectPointer(0),
+               m_hitFraction(1.f),
+               m_ccdSweptSphereRadius(0.f),
+               m_ccdSquareMotionTreshold(0.f)
+{
+       
+}
+
+
+void btCollisionObject::SetActivationState(int newState) 
+{ 
+       if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
+               m_activationState1 = newState;
+}
+
+void btCollisionObject::ForceActivationState(int newState)
+{
+       m_activationState1 = newState;
+}
+
+void btCollisionObject::activate()
+{
+       if (!(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OJBECT)))
+       {
+               SetActivationState(ACTIVE_TAG);
+               m_deactivationTime = 0.f;
+       }
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h
new file mode 100644 (file)
index 0000000..3838fc9
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+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 COLLISION_OBJECT_H
+#define COLLISION_OBJECT_H
+
+#include "LinearMath/btTransform.h"
+
+//island management, m_activationState1
+#define ACTIVE_TAG 1
+#define ISLAND_SLEEPING 2
+#define WANTS_DEACTIVATION 3
+#define DISABLE_DEACTIVATION 4
+#define DISABLE_SIMULATION 5
+
+struct btBroadphaseProxy;
+class  btCollisionShape;
+#include "LinearMath/btMotionState.h"
+
+
+
+/// btCollisionObject can be used to manage collision detection objects. 
+/// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy.
+/// They can be added to the btCollisionWorld.
+struct btCollisionObject
+{
+       btTransform     m_worldTransform;
+       btBroadphaseProxy*      m_broadphaseHandle;
+       btCollisionShape*               m_collisionShape;
+
+       ///m_interpolationWorldTransform is used for CCD and interpolation
+       ///it can be either previous or future (predicted) transform
+       btTransform     m_interpolationWorldTransform;
+
+       enum CollisionFlags
+       {
+               CF_STATIC_OBJECT= 1,
+               CF_KINEMATIC_OJBECT= 2,
+               CF_NO_CONTACT_RESPONSE = 4,
+               CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
+       };
+
+       int                             m_collisionFlags;
+
+       int                             m_islandTag1;
+       int                             m_activationState1;
+       float                   m_deactivationTime;
+
+       btScalar                m_friction;
+       btScalar                m_restitution;
+
+       ///users can point to their objects, m_userPointer is not used by Bullet
+       void*                   m_userObjectPointer;
+
+       ///m_internalOwner is reserved to point to Bullet's btRigidBody. Don't use this, use m_userObjectPointer instead.
+       void*                   m_internalOwner;
+
+       ///time of impact calculation
+       float                   m_hitFraction; 
+       
+       ///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
+       float                   m_ccdSweptSphereRadius;
+
+       /// Don't do continuous collision detection if square motion (in one step) is less then m_ccdSquareMotionTreshold
+       float                   m_ccdSquareMotionTreshold;
+
+       inline bool mergesSimulationIslands() const
+       {
+               ///static objects, kinematic and object without contact response don't merge islands
+               return  !(m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OJBECT | CF_NO_CONTACT_RESPONSE) );
+       }
+
+
+       inline bool             isStaticObject() const {
+               return m_collisionFlags & CF_STATIC_OBJECT;
+       }
+
+       inline bool             isKinematicObject() const
+       {
+               return m_collisionFlags & CF_KINEMATIC_OJBECT;
+       }
+
+       inline bool             isStaticOrKinematicObject() const
+       {
+               return m_collisionFlags & (CF_KINEMATIC_OJBECT | CF_STATIC_OBJECT);
+       }
+
+       inline bool             hasContactResponse() const {
+               return !(m_collisionFlags & CF_NO_CONTACT_RESPONSE);
+       }
+
+       
+
+
+       btCollisionObject();
+
+
+       void    SetCollisionShape(btCollisionShape* collisionShape)
+       {
+               m_collisionShape = collisionShape;
+       }
+
+       int     GetActivationState() const { return m_activationState1;}
+       
+       void SetActivationState(int newState);
+
+       void ForceActivationState(int newState);
+
+       void    activate();
+
+       inline bool IsActive() const
+       {
+               return ((GetActivationState() != ISLAND_SLEEPING) && (GetActivationState() != DISABLE_SIMULATION));
+       }
+
+               void    setRestitution(float rest)
+       {
+               m_restitution = rest;
+       }
+       float   getRestitution() const
+       {
+               return m_restitution;
+       }
+       void    setFriction(float frict)
+       {
+               m_friction = frict;
+       }
+       float   getFriction() const
+       {
+               return m_friction;
+       }
+
+
+};
+
+#endif //COLLISION_OBJECT_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
new file mode 100644 (file)
index 0000000..e24a5c6
--- /dev/null
@@ -0,0 +1,356 @@
+/*
+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 "btCollisionWorld.h"
+#include "btCollisionDispatcher.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionShapes/btCollisionShape.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h" //for raycasting
+#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" //for raycasting
+#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
+#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+#include "LinearMath/btAabbUtil2.h"
+#include "LinearMath/btQuickprof.h"
+
+//When the user doesn't provide dispatcher or broadphase, create basic versions (and delete them in destructor)
+#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
+#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h"
+
+#include <algorithm>
+
+btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
+: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)
+{
+}
+
+
+btCollisionWorld::~btCollisionWorld()
+{
+       //clean up remaining objects
+       std::vector<btCollisionObject*>::iterator i;
+
+       for (i=m_collisionObjects.begin();
+       !(i==m_collisionObjects.end()); i++)
+
+       {
+               btCollisionObject* collisionObject= (*i);
+               
+               btBroadphaseProxy* bp = collisionObject->m_broadphaseHandle;
+               if (bp)
+               {
+                       //
+                       // only clear the cached algorithms
+                       //
+                       getBroadphase()->cleanProxyFromPairs(bp);
+                       getBroadphase()->destroyProxy(bp);
+               }
+       }
+
+       if (m_ownsDispatcher)
+               delete m_dispatcher1;
+       if (m_ownsBroadphasePairCache)
+               delete m_broadphasePairCache;
+
+}
+
+
+
+
+
+
+
+
+
+
+void   btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup,short int collisionFilterMask)
+{
+
+       //check that the object isn't already added
+       std::vector<btCollisionObject*>::iterator i =   std::find(m_collisionObjects.begin(), m_collisionObjects.end(), collisionObject);
+       assert(i == m_collisionObjects.end());
+
+
+               m_collisionObjects.push_back(collisionObject);
+
+               //calculate new AABB
+               btTransform trans = collisionObject->m_worldTransform;
+
+               btVector3       minAabb;
+               btVector3       maxAabb;
+               collisionObject->m_collisionShape->getAabb(trans,minAabb,maxAabb);
+
+               int type = collisionObject->m_collisionShape->getShapeType();
+               collisionObject->m_broadphaseHandle = getBroadphase()->createProxy(
+                       minAabb,
+                       maxAabb,
+                       type,
+                       collisionObject,
+                       collisionFilterGroup,
+                       collisionFilterMask
+                       );
+               
+
+
+
+}
+
+void   btCollisionWorld::performDiscreteCollisionDetection()
+{
+       BEGIN_PROFILE("performDiscreteCollisionDetection");
+
+       btDispatcherInfo        dispatchInfo;
+       dispatchInfo.m_timeStep = 0.f;
+       dispatchInfo.m_stepCount = 0;
+
+       //update aabb (of all moved objects)
+
+       btVector3 aabbMin,aabbMax;
+       for (size_t i=0;i<m_collisionObjects.size();i++)
+       {
+               m_collisionObjects[i]->m_collisionShape->getAabb(m_collisionObjects[i]->m_worldTransform,aabbMin,aabbMax);
+               m_broadphasePairCache->setAabb(m_collisionObjects[i]->m_broadphaseHandle,aabbMin,aabbMax);
+       }
+
+       m_broadphasePairCache->refreshOverlappingPairs();
+
+       btDispatcher* dispatcher = getDispatcher();
+       if (dispatcher)
+               dispatcher->dispatchAllCollisionPairs(m_broadphasePairCache,dispatchInfo);
+
+       END_PROFILE("performDiscreteCollisionDetection");
+
+}
+
+
+void   btCollisionWorld::removeCollisionObject(btCollisionObject* collisionObject)
+{
+       
+       
+       //bool removeFromBroadphase = false;
+       
+       {
+               
+               btBroadphaseProxy* bp = collisionObject->m_broadphaseHandle;
+               if (bp)
+               {
+                       //
+                       // only clear the cached algorithms
+                       //
+                       getBroadphase()->cleanProxyFromPairs(bp);
+                       getBroadphase()->destroyProxy(bp);
+                       collisionObject->m_broadphaseHandle = 0;
+               }
+       }
+
+
+       std::vector<btCollisionObject*>::iterator i =   std::find(m_collisionObjects.begin(), m_collisionObjects.end(), collisionObject);
+               
+       if (!(i == m_collisionObjects.end()))
+               {
+                       std::swap(*i, m_collisionObjects.back());
+                       m_collisionObjects.pop_back();
+               }
+}
+
+void   btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
+                                         btCollisionObject* collisionObject,
+                                         const btCollisionShape* collisionShape,
+                                         const btTransform& colObjWorldTransform,
+                                         RayResultCallback& resultCallback)
+{
+       
+       btSphereShape pointShape(0.0f);
+
+       if (collisionShape->isConvex())
+                       {
+                               btConvexCast::CastResult castResult;
+                               castResult.m_fraction = 1.f;//??
+
+                               btConvexShape* convexShape = (btConvexShape*) collisionShape;
+                               btVoronoiSimplexSolver  simplexSolver;
+                               btSubsimplexConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
+                               //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
+                               //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
+                               
+                               if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
+                               {
+                                       //add hit
+                                       if (castResult.m_normal.length2() > 0.0001f)
+                                       {
+                                               castResult.m_normal.normalize();
+                                               if (castResult.m_fraction < resultCallback.m_closestHitFraction)
+                                               {
+
+                                                       btCollisionWorld::LocalRayResult localRayResult
+                                                               (
+                                                                       collisionObject, 
+                                                                       0,
+                                                                       castResult.m_normal,
+                                                                       castResult.m_fraction
+                                                               );
+
+                                                       resultCallback.AddSingleResult(localRayResult);
+
+                                               }
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               
+                               if (collisionShape->isConcave())
+                                       {
+
+                                               btTriangleMeshShape* triangleMesh = (btTriangleMeshShape*)collisionShape;
+                                               
+                                               btTransform worldTocollisionObject = colObjWorldTransform.inverse();
+
+                                               btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
+                                               btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();
+
+                                               //ConvexCast::CastResult
+
+                                               struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback 
+                                               {
+                                                       btCollisionWorld::RayResultCallback* m_resultCallback;
+                                                       btCollisionObject*      m_collisionObject;
+                                                       btTriangleMeshShape*    m_triangleMesh;
+
+                                                       BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
+                                                               btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*    triangleMesh):
+                                                               btTriangleRaycastCallback(from,to),
+                                                                       m_resultCallback(resultCallback),
+                                                                       m_collisionObject(collisionObject),
+                                                                       m_triangleMesh(triangleMesh)
+                                                               {
+                                                               }
+
+
+                                                       virtual float reportHit(const btVector3& hitNormalLocal, float hitFraction, int partId, int triangleIndex )
+                                                       {
+                                                               btCollisionWorld::LocalShapeInfo        shapeInfo;
+                                                               shapeInfo.m_shapePart = partId;
+                                                               shapeInfo.m_triangleIndex = triangleIndex;
+                                                               
+                                                               btCollisionWorld::LocalRayResult rayResult
+                                                               (m_collisionObject, 
+                                                                       &shapeInfo,
+                                                                       hitNormalLocal,
+                                                                       hitFraction);
+                                                               
+                                                               return m_resultCallback->AddSingleResult(rayResult);
+                                                               
+                                                               
+                                                       }
+       
+                                               };
+
+
+                                               BridgeTriangleRaycastCallback   rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh);
+                                               rcb.m_hitFraction = resultCallback.m_closestHitFraction;
+
+                                               btVector3 rayAabbMinLocal = rayFromLocal;
+                                               rayAabbMinLocal.setMin(rayToLocal);
+                                               btVector3 rayAabbMaxLocal = rayFromLocal;
+                                               rayAabbMaxLocal.setMax(rayToLocal);
+
+                                               triangleMesh->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
+                                                                                       
+                                       } else
+                                       {
+                                               //todo: use AABB tree or other BVH acceleration structure!
+                                               if (collisionShape->isCompound())
+                                               {
+                                                       const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
+                                                       int i=0;
+                                                       for (i=0;i<compoundShape->getNumChildShapes();i++)
+                                                       {
+                                                               btTransform childTrans = compoundShape->getChildTransform(i);
+                                                               const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
+                                                               btTransform childWorldTrans = colObjWorldTransform * childTrans;
+                                                               rayTestSingle(rayFromTrans,rayToTrans,
+                                                                       collisionObject,
+                                                                       childCollisionShape,
+                                                                       childWorldTrans,
+                                                                       resultCallback);
+
+                                                       }
+
+
+                                               }
+                                       }
+                       }
+}
+
+void   btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback)
+{
+
+       
+       btTransform     rayFromTrans,rayToTrans;
+       rayFromTrans.setIdentity();
+       rayFromTrans.setOrigin(rayFromWorld);
+       rayToTrans.setIdentity();
+       
+       rayToTrans.setOrigin(rayToWorld);
+
+       //do culling based on aabb (rayFrom/rayTo)
+       btVector3 rayAabbMin = rayFromWorld;
+       btVector3 rayAabbMax = rayFromWorld;
+       rayAabbMin.setMin(rayToWorld);
+       rayAabbMax.setMax(rayToWorld);
+
+
+       /// brute force go over all objects. Once there is a broadphase, use that, or
+       /// add a raycast against aabb first.
+       
+       std::vector<btCollisionObject*>::iterator iter;
+       
+       for (iter=m_collisionObjects.begin();
+       !(iter==m_collisionObjects.end()); iter++)
+       {
+               
+               btCollisionObject*      collisionObject= (*iter);
+
+               //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
+               btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
+               collisionObject->m_collisionShape->getAabb(collisionObject->m_worldTransform,collisionObjectAabbMin,collisionObjectAabbMax);
+
+               //check aabb overlap
+
+               if (TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,collisionObjectAabbMin,collisionObjectAabbMax))
+               {
+                       rayTestSingle(rayFromTrans,rayToTrans,
+                               collisionObject,
+                                        collisionObject->m_collisionShape,
+                                         collisionObject->m_worldTransform,
+                                         resultCallback);
+                       
+               }
+       }
+
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
new file mode 100644 (file)
index 0000000..2280399
--- /dev/null
@@ -0,0 +1,244 @@
+/*
+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.
+*/
+
+
+/**
+ * @mainpage Bullet Documentation
+ *
+ * @section intro_sec Introduction
+ * Bullet Collision Detection & Physics SDK
+ *
+ * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ).
+ *
+ * There is the Physics Forum for Feedback and bteral Collision Detection and Physics discussions.
+ * Please visit http://www.continuousphysics.com/Bullet/phpBB2/index.php
+ *
+ * @section install_sec Installation
+ *
+ * @subsection step1 Step 1: Download
+ * You can download the Bullet Physics Library from our website: http://www.continuousphysics.com/Bullet/
+ * @subsection step2 Step 2: Building
+ * Bullet comes with autogenerated Project Files for Microsoft Visual Studio 6, 7, 7.1 and 8.
+ * The main Workspace/Solution is located in Bullet/msvc/8/wksbullet.sln (replace 8 with your version).
+ * 
+ * Under other platforms, like Linux or Mac OS-X, Bullet can be build using either using cmake, http://www.cmake.org, or jam, http://www.perforce.com/jam/jam.html . cmake can autogenerate Xcode, KDevelop, MSVC and other build systems. just run cmake . in the root of Bullet.
+ * Jam is a build system that can build the library, demos and also autogenerate the MSVC Project Files.
+ * So if you are not using MSVC, you can run configure and jam .
+ * If you don't have jam installed, you can make jam from the included jam-2.5 sources, or download jam from ftp://ftp.perforce.com/pub/jam/
+ * 
+ * @subsection step3 Step 3: Testing demos
+ * Try to run and experiment with CcdPhysicsDemo executable as a starting point.
+ * Bullet can be used in several ways, as Full Rigid Body simulation, as Collision Detector Library or Low Level / Snippets like the GJK Closest Point calculation.
+ * The Dependencies can be seen in this documentation under Directories
+ * 
+ * @subsection step4 Step 4: Integrating in your application, Full Rigid Body Simulation
+ * Check out CcdPhysicsDemo how to create a btDynamicsWorld, btRigidBody and btCollisionShape, Stepping the simulation and synchronizing your graphics object transform.
+ * PLEASE NOTE THE CcdPhysicsEnvironment and CcdPhysicsController is obsolete and will be removed. It has been replaced by classes derived frmo btDynamicsWorld and btRididBody
+ * @subsection step5 Step 5 : Integrate the Collision Detection Library (without Dynamics and other Extras)
+ * Bullet Collision Detection can also be used without the Dynamics/Extras.
+ * Check out btCollisionWorld and btCollisionObject, and the CollisionInterfaceDemo. Also in Extras/test_BulletOde.cpp there is a sample Collision Detection integration with Open Dynamics Engine, ODE, http://www.ode.org
+ * @subsection step6 Step 6 : Use Snippets like the GJK Closest Point calculation.
+ * Bullet has been designed in a modular way keeping dependencies to a minimum. The ConvexHullDistance demo demonstrates direct use of btGjkPairDetector.
+ *
+ * @section copyright Copyright
+ * Copyright (C) 2005-2006 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon
+ * Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky,
+ * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren.
+ * 
+ */
+
+#ifndef COLLISION_WORLD_H
+#define COLLISION_WORLD_H
+
+
+class btCollisionShape;
+class btBroadphaseInterface;
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "btCollisionObject.h"
+#include "btCollisionDispatcher.h" //for definition of btCollisionObjectArray
+#include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
+
+#include <vector>
+
+
+
+///CollisionWorld is interface and container for the collision detection
+class btCollisionWorld
+{
+
+       
+protected:
+
+       std::vector<btCollisionObject*> m_collisionObjects;
+       
+       btDispatcher*   m_dispatcher1;
+
+       btOverlappingPairCache* m_broadphasePairCache;
+       
+       bool    m_ownsDispatcher;
+       bool    m_ownsBroadphasePairCache;
+
+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);
+
+       virtual ~btCollisionWorld();
+
+
+       btBroadphaseInterface*  getBroadphase()
+       {
+               return m_broadphasePairCache;
+       }
+
+       btOverlappingPairCache* getPairCache()
+       {
+               return m_broadphasePairCache;
+       }
+
+
+       btDispatcher*   getDispatcher()
+       {
+               return m_dispatcher1;
+       }
+
+       ///LocalShapeInfo gives extra information for complex shapes
+       ///Currently, only btTriangleMeshShape is available, so it just contains triangleIndex and subpart
+       struct  LocalShapeInfo
+       {
+               int     m_shapePart;
+               int     m_triangleIndex;
+               
+               //const btCollisionShape*       m_shapeTemp;
+               //const btTransform*    m_shapeLocalTransform;
+       };
+
+       struct  LocalRayResult
+       {
+               LocalRayResult(btCollisionObject*       collisionObject, 
+                       LocalShapeInfo* localShapeInfo,
+                       const btVector3&                hitNormalLocal,
+                       float hitFraction)
+               :m_collisionObject(collisionObject),
+               m_localShapeInfo(m_localShapeInfo),
+               m_hitNormalLocal(hitNormalLocal),
+               m_hitFraction(hitFraction)
+               {
+               }
+
+               btCollisionObject*      m_collisionObject;
+               LocalShapeInfo*                 m_localShapeInfo;
+               const btVector3&                m_hitNormalLocal;
+               float                                   m_hitFraction;
+
+       };
+
+       ///RayResultCallback is used to report new raycast results
+       struct  RayResultCallback
+       {
+               virtual ~RayResultCallback()
+               {
+               }
+               float   m_closestHitFraction;
+               bool    HasHit()
+               {
+                       return (m_closestHitFraction < 1.f);
+               }
+
+               RayResultCallback()
+                       :m_closestHitFraction(1.f)
+               {
+               }
+               virtual float   AddSingleResult(LocalRayResult& rayResult) = 0;
+       };
+
+       struct  ClosestRayResultCallback : public RayResultCallback
+       {
+               ClosestRayResultCallback(btVector3      rayFromWorld,btVector3  rayToWorld)
+               :m_rayFromWorld(rayFromWorld),
+               m_rayToWorld(rayToWorld),
+               m_collisionObject(0)
+               {
+               }
+
+               btVector3       m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
+               btVector3       m_rayToWorld;
+
+               btVector3       m_hitNormalWorld;
+               btVector3       m_hitPointWorld;
+               btCollisionObject*      m_collisionObject;
+               
+               virtual float   AddSingleResult(LocalRayResult& rayResult)
+               {
+
+//caller already does the filter on the m_closestHitFraction
+                       assert(rayResult.m_hitFraction <= m_closestHitFraction);
+                       
+                       m_closestHitFraction = rayResult.m_hitFraction;
+                       m_collisionObject = rayResult.m_collisionObject;
+                       m_hitNormalWorld = m_collisionObject->m_worldTransform.getBasis()*rayResult.m_hitNormalLocal;
+                       m_hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);
+                       return rayResult.m_hitFraction;
+               }
+       };
+
+
+       
+
+       int     getNumCollisionObjects() const
+       {
+               return m_collisionObjects.size();
+       }
+
+       /// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback
+       /// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
+       void    rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback);
+
+       /// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
+       /// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.
+       /// This allows more customization.
+       void    rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
+                                         btCollisionObject* collisionObject,
+                                         const btCollisionShape* collisionShape,
+                                         const btTransform& colObjWorldTransform,
+                                         RayResultCallback& resultCallback);
+
+       void    addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=1,short int collisionFilterMask=1);
+
+       btCollisionObjectArray& getCollisionObjectArray()
+       {
+               return m_collisionObjects;
+       }
+
+       const btCollisionObjectArray& getCollisionObjectArray() const
+       {
+               return m_collisionObjects;
+       }
+
+
+       void    removeCollisionObject(btCollisionObject* collisionObject);
+
+       virtual void    performDiscreteCollisionDetection();
+
+};
+
+
+#endif //COLLISION_WORLD_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
new file mode 100644 (file)
index 0000000..febd726
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+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 "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
+
+
+btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
+:m_isSwapped(isSwapped)
+{
+       btCollisionObject* colObj = m_isSwapped? body1 : body0;
+       btCollisionObject* otherObj = m_isSwapped? body0 : body1;
+       assert (colObj->m_collisionShape->isCompound());
+       
+       btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->m_collisionShape);
+       int numChildren = compoundShape->getNumChildShapes();
+       int i;
+       
+       m_childCollisionAlgorithms.resize(numChildren);
+       for (i=0;i<numChildren;i++)
+       {
+               btCollisionShape* childShape = compoundShape->getChildShape(i);
+               btCollisionShape* orgShape = colObj->m_collisionShape;
+               colObj->m_collisionShape = childShape;
+               m_childCollisionAlgorithms[i] = ci.m_dispatcher->findAlgorithm(colObj,otherObj);
+               colObj->m_collisionShape =orgShape;
+       }
+}
+
+
+btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
+{
+       int numChildren = m_childCollisionAlgorithms.size();
+       int i;
+       for (i=0;i<numChildren;i++)
+       {
+               delete m_childCollisionAlgorithms[i];
+       }
+}
+
+void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       btCollisionObject* colObj = m_isSwapped? body1 : body0;
+       btCollisionObject* otherObj = m_isSwapped? body0 : body1;
+
+       assert (colObj->m_collisionShape->isCompound());
+       btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->m_collisionShape);
+
+       //We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
+       //If both proxies are Compound, we will deal with that directly, by performing sequential/parallel tree traversals
+       //given Proxy0 and Proxy1, if both have a tree, Tree0 and Tree1, this means:
+       //determine overlapping nodes of Proxy1 using Proxy0 AABB against Tree1
+       //then use each overlapping node AABB against Tree0
+       //and vise versa.
+
+       int numChildren = m_childCollisionAlgorithms.size();
+       int i;
+       for (i=0;i<numChildren;i++)
+       {
+               //temporarily exchange parent btCollisionShape with childShape, and recurse
+               btCollisionShape* childShape = compoundShape->getChildShape(i);
+
+               //backup
+               btTransform     orgTrans = colObj->m_worldTransform;
+               btCollisionShape* orgShape = colObj->m_collisionShape;
+
+               btTransform childTrans = compoundShape->getChildTransform(i);
+               btTransform     newChildWorldTrans = orgTrans*childTrans ;
+               colObj->m_worldTransform = newChildWorldTrans;
+               //the contactpoint is still projected back using the original inverted worldtrans
+               colObj->m_collisionShape = childShape;
+               m_childCollisionAlgorithms[i]->processCollision(colObj,otherObj,dispatchInfo,resultOut);
+               //revert back
+               colObj->m_collisionShape =orgShape;
+               colObj->m_worldTransform = orgTrans;
+       }
+}
+
+float  btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+
+       btCollisionObject* colObj = m_isSwapped? body1 : body0;
+       btCollisionObject* otherObj = m_isSwapped? body0 : body1;
+
+       assert (colObj->m_collisionShape->isCompound());
+       
+       btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->m_collisionShape);
+
+       //We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
+       //If both proxies are Compound, we will deal with that directly, by performing sequential/parallel tree traversals
+       //given Proxy0 and Proxy1, if both have a tree, Tree0 and Tree1, this means:
+       //determine overlapping nodes of Proxy1 using Proxy0 AABB against Tree1
+       //then use each overlapping node AABB against Tree0
+       //and vise versa.
+
+       float hitFraction = 1.f;
+
+       int numChildren = m_childCollisionAlgorithms.size();
+       int i;
+       for (i=0;i<numChildren;i++)
+       {
+               //temporarily exchange parent btCollisionShape with childShape, and recurse
+               btCollisionShape* childShape = compoundShape->getChildShape(i);
+
+               //backup
+               btTransform     orgTrans = colObj->m_worldTransform;
+               btCollisionShape* orgShape = colObj->m_collisionShape;
+
+               btTransform childTrans = compoundShape->getChildTransform(i);
+               btTransform     newChildWorldTrans = orgTrans*childTrans ;
+               colObj->m_worldTransform = newChildWorldTrans;
+
+               colObj->m_collisionShape = childShape;
+               float frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
+               if (frac<hitFraction)
+               {
+                       hitFraction = frac;
+               }
+               //revert back
+               colObj->m_collisionShape =orgShape;
+               colObj->m_worldTransform = orgTrans;
+       }
+       return hitFraction;
+
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
new file mode 100644 (file)
index 0000000..fe2d862
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+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 COMPOUND_COLLISION_ALGORITHM_H
+#define COMPOUND_COLLISION_ALGORITHM_H
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+class btDispatcher;
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include <vector>
+#include "btCollisionCreateFunc.h"
+
+/// btCompoundCollisionAlgorithm  supports collision between CompoundCollisionShapes and other collision shapes
+/// Place holder, not fully implemented yet
+class btCompoundCollisionAlgorithm  : public btCollisionAlgorithm
+{
+       std::vector<btCollisionAlgorithm*> m_childCollisionAlgorithms;
+       bool m_isSwapped;
+       
+public:
+
+       btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+
+       virtual ~btCompoundCollisionAlgorithm();
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       float   calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       struct CreateFunc :public       btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btCompoundCollisionAlgorithm(ci,body0,body1,false);
+               }
+       };
+
+       struct SwappedCreateFunc :public        btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btCompoundCollisionAlgorithm(ci,body0,body1,true);
+               }
+       };
+
+};
+
+#endif //COMPOUND_COLLISION_ALGORITHM_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
new file mode 100644 (file)
index 0000000..d7d0055
--- /dev/null
@@ -0,0 +1,303 @@
+/*
+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 "btConvexConcaveCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
+#include "btConvexConvexAlgorithm.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/CollisionShapes/btConcaveShape.h"
+#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
+#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
+#include "BulletCollision/CollisionShapes/btTriangleShape.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h"
+#include "LinearMath/btIDebugDraw.h"
+#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
+
+btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
+: btCollisionAlgorithm(ci),
+m_isSwapped(isSwapped),
+m_btConvexTriangleCallback(ci.m_dispatcher,body0,body1,isSwapped)
+{
+}
+
+btConvexConcaveCollisionAlgorithm::~btConvexConcaveCollisionAlgorithm()
+{
+}
+
+
+
+btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher*  dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped):
+         m_dispatcher(dispatcher),
+       m_dispatchInfoPtr(0)
+{
+       m_convexBody = isSwapped? body1:body0;
+       m_triBody = isSwapped? body0:body1;
+       
+         //
+         // create the manifold from the dispatcher 'manifold pool'
+         //
+         m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
+
+         clearCache();
+}
+
+btConvexTriangleCallback::~btConvexTriangleCallback()
+{
+       clearCache();
+       m_dispatcher->releaseManifold( m_manifoldPtr );
+  
+}
+  
+
+void   btConvexTriangleCallback::clearCache()
+{
+       m_dispatcher->clearManifold(m_manifoldPtr);
+};
+
+
+
+void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex)
+{
+       //just for debugging purposes
+       //printf("triangle %d",m_triangleCount++);
+
+
+       //aabb filter is already applied!       
+
+       btCollisionAlgorithmConstructionInfo ci;
+       ci.m_dispatcher = m_dispatcher;
+
+       btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
+
+
+       
+       ///debug drawing of the overlapping triangles
+       if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() > 0)
+       {
+               btVector3 color(255,255,0);
+               btTransform& tr = ob->m_worldTransform;
+               m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
+               m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(triangle[2]),color);
+               m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
+
+               //btVector3 center = triangle[0] + triangle[1]+triangle[2];
+               //center *= 0.333333f;
+               //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(center),color);
+               //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(center),color);
+               //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(center),color);
+
+       }
+
+
+       //btCollisionObject* colObj = static_cast<btCollisionObject*>(m_convexProxy->m_clientObject);
+       
+       if (m_convexBody->m_collisionShape->isConvex())
+       {
+               btTriangleShape tm(triangle[0],triangle[1],triangle[2]);        
+               tm.setMargin(m_collisionMarginTriangle);
+       
+               
+               btCollisionShape* tmpShape = ob->m_collisionShape;
+               ob->m_collisionShape = &tm;
+               
+               ///this should use the btDispatcher, so the actual registered algorithm is used
+               btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
+               cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
+               cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
+               ob->m_collisionShape = tmpShape;
+
+       }
+
+       
+
+}
+
+
+
+void   btConvexTriangleCallback::setTimeStepAndCounters(float collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       m_dispatchInfoPtr = &dispatchInfo;
+       m_collisionMarginTriangle = collisionMarginTriangle;
+       m_resultOut = resultOut;
+
+       //recalc aabbs
+       btTransform convexInTriangleSpace;
+       convexInTriangleSpace = m_triBody->m_worldTransform.inverse() * m_convexBody->m_worldTransform;
+       btCollisionShape* convexShape = static_cast<btCollisionShape*>(m_convexBody->m_collisionShape);
+       //CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
+       convexShape->getAabb(convexInTriangleSpace,m_aabbMin,m_aabbMax);
+       float extraMargin = collisionMarginTriangle;
+       btVector3 extra(extraMargin,extraMargin,extraMargin);
+
+       m_aabbMax += extra;
+       m_aabbMin -= extra;
+       
+}
+
+void btConvexConcaveCollisionAlgorithm::clearCache()
+{
+       m_btConvexTriangleCallback.clearCache();
+
+}
+
+void btConvexConcaveCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       
+       
+       btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
+       btCollisionObject* triBody = m_isSwapped ? body0 : body1;
+
+       if (triBody->m_collisionShape->isConcave())
+       {
+
+
+               btCollisionObject*      triOb = triBody;
+               ConcaveShape* concaveShape = static_cast<ConcaveShape*>( triOb->m_collisionShape);
+               
+               if (convexBody->m_collisionShape->isConvex())
+               {
+                       float collisionMarginTriangle = concaveShape->getMargin();
+                                       
+                       resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
+                       m_btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,resultOut);
+
+                       //Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
+                       //m_dispatcher->clearManifold(m_btConvexTriangleCallback.m_manifoldPtr);
+
+                       m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
+
+                       concaveShape->processAllTriangles( &m_btConvexTriangleCallback,m_btConvexTriangleCallback.getAabbMin(),m_btConvexTriangleCallback.getAabbMax());
+                       
+       
+               }
+
+       }
+
+}
+
+
+float btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+
+       btCollisionObject* convexbody = m_isSwapped ? body1 : body0;
+       btCollisionObject* triBody = m_isSwapped ? body0 : body1;
+
+
+       //quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)
+
+       //only perform CCD above a certain treshold, this prevents blocking on the long run
+       //because object in a blocked ccd state (hitfraction<1) get their linear velocity halved each frame...
+       float squareMot0 = (convexbody->m_interpolationWorldTransform.getOrigin() - convexbody->m_worldTransform.getOrigin()).length2();
+       if (squareMot0 < convexbody->m_ccdSquareMotionTreshold)
+       {
+               return 1.f;
+       }
+
+       //const btVector3& from = convexbody->m_worldTransform.getOrigin();
+       //btVector3 to = convexbody->m_interpolationWorldTransform.getOrigin();
+       //todo: only do if the motion exceeds the 'radius'
+
+       btTransform triInv = triBody->m_worldTransform.inverse();
+       btTransform convexFromLocal = triInv * convexbody->m_worldTransform;
+       btTransform convexToLocal = triInv * convexbody->m_interpolationWorldTransform;
+
+       struct LocalTriangleSphereCastCallback  : public btTriangleCallback
+       {
+               btTransform m_ccdSphereFromTrans;
+               btTransform m_ccdSphereToTrans;
+               btTransform     m_meshTransform;
+
+               float   m_ccdSphereRadius;
+               float   m_hitFraction;
+       
+
+               LocalTriangleSphereCastCallback(const btTransform& from,const btTransform& to,float ccdSphereRadius,float hitFraction)
+                       :m_ccdSphereFromTrans(from),
+                       m_ccdSphereToTrans(to),
+                       m_ccdSphereRadius(ccdSphereRadius),
+                       m_hitFraction(hitFraction)
+               {                       
+               }
+               
+               
+               virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
+               {
+                       //do a swept sphere for now
+                       btTransform ident;
+                       ident.setIdentity();
+                       btConvexCast::CastResult castResult;
+                       castResult.m_fraction = m_hitFraction;
+                       btSphereShape   pointShape(m_ccdSphereRadius);
+                       btTriangleShape triShape(triangle[0],triangle[1],triangle[2]);
+                       btVoronoiSimplexSolver  simplexSolver;
+                       btSubsimplexConvexCast convexCaster(&pointShape,&triShape,&simplexSolver);
+                       //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
+                       //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
+                       //local space?
+
+                       if (convexCaster.calcTimeOfImpact(m_ccdSphereFromTrans,m_ccdSphereToTrans,
+                               ident,ident,castResult))
+                       {
+                               if (m_hitFraction > castResult.m_fraction)
+                                       m_hitFraction = castResult.m_fraction;
+                       }
+
+               }
+
+       };
+
+
+       
+
+       
+       if (triBody->m_collisionShape->isConcave())
+       {
+               btVector3 rayAabbMin = convexFromLocal.getOrigin();
+               rayAabbMin.setMin(convexToLocal.getOrigin());
+               btVector3 rayAabbMax = convexFromLocal.getOrigin();
+               rayAabbMax.setMax(convexToLocal.getOrigin());
+               rayAabbMin -= btVector3(convexbody->m_ccdSweptSphereRadius,convexbody->m_ccdSweptSphereRadius,convexbody->m_ccdSweptSphereRadius);
+               rayAabbMax += btVector3(convexbody->m_ccdSweptSphereRadius,convexbody->m_ccdSweptSphereRadius,convexbody->m_ccdSweptSphereRadius);
+
+               float curHitFraction = 1.f; //is this available?
+               LocalTriangleSphereCastCallback raycastCallback(convexFromLocal,convexToLocal,
+               convexbody->m_ccdSweptSphereRadius,curHitFraction);
+
+               raycastCallback.m_hitFraction = convexbody->m_hitFraction;
+
+               btCollisionObject* concavebody = triBody;
+
+               ConcaveShape* triangleMesh = (ConcaveShape*) concavebody->m_collisionShape;
+               
+               if (triangleMesh)
+               {
+                       triangleMesh->processAllTriangles(&raycastCallback,rayAabbMin,rayAabbMax);
+               }
+       
+
+
+               if (raycastCallback.m_hitFraction < convexbody->m_hitFraction)
+               {
+                       convexbody->m_hitFraction = raycastCallback.m_hitFraction;
+                       return raycastCallback.m_hitFraction;
+               }
+       }
+
+       return 1.f;
+
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
new file mode 100644 (file)
index 0000000..afcb38c
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+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 CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#define CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+#include "BulletCollision/CollisionShapes/btTriangleCallback.h"
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+class btDispatcher;
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "btCollisionCreateFunc.h"
+
+///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), processTriangle is called.
+class btConvexTriangleCallback : public btTriangleCallback
+{
+       btCollisionObject* m_convexBody;
+       btCollisionObject* m_triBody;
+
+       btVector3       m_aabbMin;
+       btVector3       m_aabbMax ;
+
+       btManifoldResult* m_resultOut;
+
+       btDispatcher*   m_dispatcher;
+       const btDispatcherInfo* m_dispatchInfoPtr;
+       float m_collisionMarginTriangle;
+       
+public:
+int    m_triangleCount;
+       
+       btPersistentManifold*   m_manifoldPtr;
+
+       btConvexTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+
+       void    setTimeStepAndCounters(float collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       virtual ~btConvexTriangleCallback();
+
+       virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
+       
+       void clearCache();
+
+       inline const btVector3& getAabbMin() const
+       {
+               return m_aabbMin;
+       }
+       inline const btVector3& getAabbMax() const
+       {
+               return m_aabbMax;
+       }
+
+};
+
+
+
+
+/// btConvexConcaveCollisionAlgorithm  supports collision between convex shapes and (concave) trianges meshes.
+class btConvexConcaveCollisionAlgorithm  : public btCollisionAlgorithm
+{
+
+       bool    m_isSwapped;
+
+       btConvexTriangleCallback m_btConvexTriangleCallback;
+
+
+public:
+
+       btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+
+       virtual ~btConvexConcaveCollisionAlgorithm();
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       float   calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       void    clearCache();
+
+       struct CreateFunc :public       btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btConvexConcaveCollisionAlgorithm(ci,body0,body1,false);
+               }
+       };
+
+       struct SwappedCreateFunc :public        btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btConvexConcaveCollisionAlgorithm(ci,body0,body1,true);
+               }
+       };
+
+};
+
+#endif //CONVEX_CONCAVE_COLLISION_ALGORITHM_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
new file mode 100644 (file)
index 0000000..54b8bc0
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+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 "btConvexConvexAlgorithm.h"
+
+#include <stdio.h>
+#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionShapes/btConvexShape.h"
+#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
+#include "BulletCollision/CollisionShapes/btBoxShape.h"
+#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
+
+#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
+#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
+#include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
+#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
+
+
+
+#include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h"
+#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h"
+
+#include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
+
+//#include "NarrowPhaseCollision/EpaPenetrationDepthSolver.h"
+
+#ifdef WIN32
+#if _MSC_VER >= 1310
+//only use SIMD Hull code under Win32
+#ifdef TEST_HULL
+#define USE_HULL 1
+#endif //TEST_HULL
+#endif //_MSC_VER 
+#endif //WIN32
+
+
+#ifdef USE_HULL
+
+#include "NarrowPhaseCollision/Hull.h"
+#include "NarrowPhaseCollision/HullContactCollector.h"
+
+
+#endif //USE_HULL
+
+bool gUseEpa = false;
+
+
+#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::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1)
+: btCollisionAlgorithm(ci),
+m_gjkPairDetector(0,0,&m_simplexSolver,0),
+m_useEpa(!gUseEpa),
+m_ownManifold (false),
+m_manifoldPtr(mf),
+m_lowLevelOfDetail(false)
+{
+       checkPenetrationDepthSolver();
+
+}
+
+
+
+
+btConvexConvexAlgorithm::~btConvexConvexAlgorithm()
+{
+       if (m_ownManifold)
+       {
+               if (m_manifoldPtr)
+                       m_dispatcher->releaseManifold(m_manifoldPtr);
+       }
+}
+
+void   btConvexConvexAlgorithm ::setLowLevelOfDetail(bool useLowLevel)
+{
+       m_lowLevelOfDetail = useLowLevel;
+}
+
+
+
+
+static btMinkowskiPenetrationDepthSolver       gPenetrationDepthSolver;
+
+//static EpaPenetrationDepthSolver     gEpaPenetrationDepthSolver;
+
+#ifdef USE_EPA
+Solid3EpaPenetrationDepth      gSolidEpaPenetrationSolver;
+#endif //USE_EPA
+
+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
+//
+void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+
+       if (!m_manifoldPtr)
+       {
+               //swapped?
+               m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
+               m_ownManifold = true;
+       }
+
+
+       checkPenetrationDepthSolver();
+
+       btConvexShape* min0 = static_cast<btConvexShape*>(body0->m_collisionShape);
+       btConvexShape* min1 = static_cast<btConvexShape*>(body1->m_collisionShape);
+       
+       btGjkPairDetector::ClosestPointInput input;
+
+       //TODO: if (dispatchInfo.m_useContinuous)
+       m_gjkPairDetector.setMinkowskiA(min0);
+       m_gjkPairDetector.setMinkowskiB(min1);
+       input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingTreshold();
+       input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
+       
+//     input.m_maximumDistanceSquared = 1e30f;
+       
+       input.m_transformA = body0->m_worldTransform;
+       input.m_transformB = body1->m_worldTransform;
+    
+       resultOut->setPersistentManifold(m_manifoldPtr);
+       m_gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+
+}
+
+
+
+bool disableCcd = false;
+float  btConvexConvexAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       ///Rather then checking ALL pairs, only calculate TOI when motion exceeds treshold
+    
+       ///Linear motion for one of objects needs to exceed m_ccdSquareMotionTreshold
+       ///col0->m_worldTransform,
+       float resultFraction = 1.f;
+
+
+       float squareMot0 = (col0->m_interpolationWorldTransform.getOrigin() - col0->m_worldTransform.getOrigin()).length2();
+    
+       if (squareMot0 < col0->m_ccdSquareMotionTreshold &&
+               squareMot0 < col0->m_ccdSquareMotionTreshold)
+               return resultFraction;
+
+
+
+       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
+       //Starting in penetration should report no time of impact
+       //For proper CCD, better accuracy and handling of 'allowed' penetration should be added
+       //also the mainloop of the physics should have a kind of toi queue (something like Brian Mirtich's application of Timewarp for Rigidbodies)
+
+               
+       /// Convex0 against sphere for Convex1
+       {
+               btConvexShape* convex0 = static_cast<btConvexShape*>(col0->m_collisionShape);
+
+               btSphereShape   sphere1(col1->m_ccdSweptSphereRadius); //todo: allow non-zero sphere sizes, for better approximation
+               btConvexCast::CastResult result;
+               btVoronoiSimplexSolver voronoiSimplex;
+               //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
+               ///Simplification, one object is simplified as a sphere
+               btGjkConvexCast ccd1( convex0 ,&sphere1,&voronoiSimplex);
+               //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
+               if (ccd1.calcTimeOfImpact(col0->m_worldTransform,col0->m_interpolationWorldTransform,
+                       col1->m_worldTransform,col1->m_interpolationWorldTransform,result))
+               {
+               
+                       //store result.m_fraction in both bodies
+               
+                       if (col0->m_hitFraction > result.m_fraction)
+                               col0->m_hitFraction  = result.m_fraction;
+
+                       if (col1->m_hitFraction > result.m_fraction)
+                               col1->m_hitFraction  = result.m_fraction;
+
+                       if (resultFraction > result.m_fraction)
+                               resultFraction = result.m_fraction;
+
+               }
+               
+               
+
+
+       }
+
+       /// Sphere (for convex0) against Convex1
+       {
+               btConvexShape* convex1 = static_cast<btConvexShape*>(col1->m_collisionShape);
+
+               btSphereShape   sphere0(col0->m_ccdSweptSphereRadius); //todo: allow non-zero sphere sizes, for better approximation
+               btConvexCast::CastResult result;
+               btVoronoiSimplexSolver voronoiSimplex;
+               //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
+               ///Simplification, one object is simplified as a sphere
+               btGjkConvexCast ccd1(&sphere0,convex1,&voronoiSimplex);
+               //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
+               if (ccd1.calcTimeOfImpact(col0->m_worldTransform,col0->m_interpolationWorldTransform,
+                       col1->m_worldTransform,col1->m_interpolationWorldTransform,result))
+               {
+               
+                       //store result.m_fraction in both bodies
+               
+                       if (col0->m_hitFraction > result.m_fraction)
+                               col0->m_hitFraction  = result.m_fraction;
+
+                       if (col1->m_hitFraction > result.m_fraction)
+                               col1->m_hitFraction  = result.m_fraction;
+
+                       if (resultFraction > result.m_fraction)
+                               resultFraction = result.m_fraction;
+
+               }
+       }
+       
+       return resultFraction;
+
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
new file mode 100644 (file)
index 0000000..b8e1217
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+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 CONVEX_CONVEX_ALGORITHM_H
+#define CONVEX_CONVEX_ALGORITHM_H
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
+#include "btCollisionCreateFunc.h"
+
+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);
+
+       virtual ~btConvexConvexAlgorithm();
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       virtual float calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       void    setLowLevelOfDetail(bool useLowLevel);
+
+       virtual void setShapeIdentifiers(int partId0,int index0,        int partId1,int index1)
+       {
+                       m_gjkPairDetector.m_partId0=partId0;
+                       m_gjkPairDetector.m_partId1=partId1;
+                       m_gjkPairDetector.m_index0=index0;
+                       m_gjkPairDetector.m_index1=index1;              
+       }
+
+       const btPersistentManifold*     getManifold()
+       {
+               return m_manifoldPtr;
+       }
+
+       struct CreateFunc :public       btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btConvexConvexAlgorithm(0,ci,body0,body1);
+               }
+       };
+
+
+};
+
+#endif //CONVEX_CONVEX_ALGORITHM_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp
new file mode 100644 (file)
index 0000000..9bc1065
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+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 "btEmptyCollisionAlgorithm.h"
+
+
+
+btEmptyAlgorithm::btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
+       : btCollisionAlgorithm(ci)
+{
+}
+
+void btEmptyAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+
+}
+
+float btEmptyAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       return 1.f;
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h
new file mode 100644 (file)
index 0000000..e0e1362
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+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 EMPTY_ALGORITH
+#define EMPTY_ALGORITH
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "btCollisionCreateFunc.h"
+
+#define ATTRIBUTE_ALIGNED(a)
+
+///EmptyAlgorithm is a stub for unsupported collision pairs.
+///The dispatcher can dispatch a persistent btEmptyAlgorithm to avoid a search every frame.
+class btEmptyAlgorithm : public btCollisionAlgorithm
+{
+
+public:
+       
+       btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       virtual float calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       struct CreateFunc :public       btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btEmptyAlgorithm(ci);
+               }
+       };
+
+} ATTRIBUTE_ALIGNED(16);
+
+#endif //EMPTY_ALGORITH
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp
new file mode 100644 (file)
index 0000000..7031521
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+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 "btManifoldResult.h"
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+
+
+///This is to allow MaterialCombiner/Custom Friction/Restitution values
+ContactAddedCallback           gContactAddedCallback=0;
+
+///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
+inline btScalar        calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+{
+       btScalar friction = body0->getFriction() * body1->getFriction();
+
+       const btScalar MAX_FRICTION  = 10.f;
+       if (friction < -MAX_FRICTION)
+               friction = -MAX_FRICTION;
+       if (friction > MAX_FRICTION)
+               friction = MAX_FRICTION;
+       return friction;
+
+}
+
+inline btScalar        calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1)
+{
+       return body0->getRestitution() * body1->getRestitution();
+}
+
+
+
+btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* body1)
+               :m_manifoldPtr(0),
+               m_body0(body0),
+               m_body1(body1)
+{
+       m_rootTransA = body0->m_worldTransform;
+       m_rootTransB = body1->m_worldTransform;
+}
+
+
+void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,float depth)
+{
+       assert(m_manifoldPtr);
+       //order in manifold needs to match
+       
+       if (depth > m_manifoldPtr->getContactBreakingTreshold())
+               return;
+
+       bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
+
+       btTransform transAInv = isSwapped? m_rootTransB.inverse() : m_rootTransA.inverse();
+       btTransform transBInv = isSwapped? m_rootTransA.inverse() : m_rootTransB.inverse();
+
+       btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
+       btVector3 localA = transAInv(pointA );
+       btVector3 localB = transBInv(pointInWorld);
+       btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
+
+       
+
+       int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
+       if (insertIndex >= 0)
+       {
+
+// This is not needed, just use the old info!
+//             const btManifoldPoint& oldPoint = m_manifoldPtr->getContactPoint(insertIndex);
+//             newPt.CopyPersistentInformation(oldPoint);
+//             m_manifoldPtr->replaceContactPoint(newPt,insertIndex);
+
+
+       } else
+       {
+
+               newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
+               newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
+
+               //User can override friction and/or restitution
+               if (gContactAddedCallback &&
+                       //and if either of the two bodies requires custom material
+                        ((m_body0->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
+                          (m_body1->m_collisionFlags & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
+               {
+                       //experimental feature info, for per-triangle material etc.
+                       btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
+                       btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
+                       (*gContactAddedCallback)(newPt,obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);
+               }
+
+               m_manifoldPtr->AddManifoldPoint(newPt);
+       }
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h
new file mode 100644 (file)
index 0000000..f9aae4e
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+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 MANIFOLD_RESULT_H
+#define MANIFOLD_RESULT_H
+
+#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
+struct btCollisionObject;
+class btPersistentManifold;
+class btManifoldPoint;
+#include "LinearMath/btTransform.h"
+
+typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,      const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);
+extern ContactAddedCallback            gContactAddedCallback;
+
+
+
+///btManifoldResult is a helper class to manage  contact results.
+class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
+{
+       btPersistentManifold* m_manifoldPtr;
+
+       //we need this for compounds
+       btTransform     m_rootTransA;
+       btTransform     m_rootTransB;
+
+       btCollisionObject* m_body0;
+       btCollisionObject* m_body1;
+       int     m_partId0;
+       int m_partId1;
+       int m_index0;
+       int m_index1;
+public:
+
+       btManifoldResult()
+       {
+       }
+
+       btManifoldResult(btCollisionObject* body0,btCollisionObject* body1);
+
+       virtual ~btManifoldResult() {};
+
+       void    setPersistentManifold(btPersistentManifold* manifoldPtr)
+       {
+               m_manifoldPtr = manifoldPtr;
+       }
+
+       virtual void setShapeIdentifiers(int partId0,int index0,        int partId1,int index1)
+       {
+                       m_partId0=partId0;
+                       m_partId1=partId1;
+                       m_index0=index0;
+                       m_index1=index1;                
+       }
+
+       virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,float depth);
+
+
+
+};
+
+#endif //MANIFOLD_RESULT_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
new file mode 100644 (file)
index 0000000..fa52d7e
--- /dev/null
@@ -0,0 +1,280 @@
+
+#include "btSimulationIslandManager.h"
+#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionDispatch/btCollisionWorld.h"
+
+#include <stdio.h>
+#include <algorithm>
+
+
+btSimulationIslandManager::btSimulationIslandManager()
+{
+}
+
+btSimulationIslandManager::~btSimulationIslandManager()
+{
+}
+
+
+void btSimulationIslandManager::initUnionFind(int n)
+{
+               m_unionFind.reset(n);
+}
+               
+
+void btSimulationIslandManager::findUnions(btDispatcher* dispatcher)
+{
+       
+       {
+               for (int i=0;i<dispatcher->getNumManifolds();i++)
+               {
+                       const btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
+                       //static objects (invmass 0.f) don't merge !
+
+                        const  btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
+                        const  btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
+
+                       if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
+                               ((colObj1) && ((colObj1)->mergesSimulationIslands())))
+                       {
+
+                               m_unionFind.unite((colObj0)->m_islandTag1,
+                                       (colObj1)->m_islandTag1);
+                       }
+               }
+       }
+}
+
+
+void   btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
+{
+       
+       initUnionFind(colWorld->getCollisionObjectArray().size());
+       
+       // put the index into m_controllers into m_tag  
+       {
+               std::vector<btCollisionObject*>::iterator i;
+               
+               int index = 0;
+               for (i=colWorld->getCollisionObjectArray().begin();
+               !(i==colWorld->getCollisionObjectArray().end()); i++)
+               {
+                       
+                       btCollisionObject*      collisionObject= (*i);
+                       collisionObject->m_islandTag1 = index;
+                       collisionObject->m_hitFraction = 1.f;
+                       index++;
+                       
+               }
+       }
+       // do the union find
+       
+       findUnions(dispatcher);
+       
+
+       
+}
+
+
+
+
+void   btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
+{
+       // put the islandId ('find' value) into m_tag   
+       {
+               
+               
+               std::vector<btCollisionObject*>::iterator i;
+               
+               int index = 0;
+               for (i=colWorld->getCollisionObjectArray().begin();
+               !(i==colWorld->getCollisionObjectArray().end()); i++)
+               {
+                       btCollisionObject* collisionObject= (*i);
+                       
+                       if (collisionObject->mergesSimulationIslands())
+                       {
+                               collisionObject->m_islandTag1 = m_unionFind.find(index);
+                       } else
+                       {
+                               collisionObject->m_islandTag1 = -1;
+                       }
+                       index++;
+               }
+       }
+}
+
+inline int     getIslandId(const btPersistentManifold* lhs)
+{
+       int islandId;
+       const btCollisionObject* rcolObj0 = static_cast<const btCollisionObject*>(lhs->getBody0());
+       const btCollisionObject* rcolObj1 = static_cast<const btCollisionObject*>(lhs->getBody1());
+       islandId= rcolObj0->m_islandTag1>=0?rcolObj0->m_islandTag1:rcolObj1->m_islandTag1;
+       return islandId;
+
+}
+
+bool btPersistentManifoldSortPredicate(const btPersistentManifold* lhs, const btPersistentManifold* rhs)
+{
+       int rIslandId0,lIslandId0;
+       rIslandId0 = getIslandId(rhs);
+       lIslandId0 = getIslandId(lhs);
+       return lIslandId0 < rIslandId0;
+}
+
+
+//
+// todo: this is random access, it can be walked 'cache friendly'!
+//
+void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback)
+{
+       //we are going to sort the unionfind array, and store the element id in the size
+       //afterwards, we clean unionfind, to make sure no-one uses it anymore
+       
+       getUnionFind().sortIslands();
+       int numElem = getUnionFind().getNumElements();
+
+       int endIslandIndex=1;
+
+       //update the sleeping state for bodies, if all are sleeping
+       for (int startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex)
+       {
+               int islandId = getUnionFind().getElement(startIslandIndex).m_id;
+               for (endIslandIndex = startIslandIndex+1;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++)
+               {
+               }
+
+               //int numSleeping = 0;
+
+               bool allSleeping = true;
+
+               int idx;
+               for (idx=startIslandIndex;idx<endIslandIndex;idx++)
+               {
+                       int i = getUnionFind().getElement(idx).m_sz;
+
+                       btCollisionObject* colObj0 = collisionObjects[i];
+                       if ((colObj0->m_islandTag1 != islandId) && (colObj0->m_islandTag1 != -1))
+                       {
+                               printf("error in island management\n");
+                       }
+
+                       assert((colObj0->m_islandTag1 == islandId) || (colObj0->m_islandTag1 == -1));
+                       if (colObj0->m_islandTag1 == islandId)
+                       {
+                               if (colObj0->GetActivationState()== ACTIVE_TAG)
+                               {
+                                       allSleeping = false;
+                               }
+                               if (colObj0->GetActivationState()== DISABLE_DEACTIVATION)
+                               {
+                                       allSleeping = false;
+                               }
+                       }
+               }
+               
+               if (allSleeping)
+               {
+                       int idx;
+                       for (idx=startIslandIndex;idx<endIslandIndex;idx++)
+                       {
+                               int i = getUnionFind().getElement(idx).m_sz;
+                               btCollisionObject* colObj0 = collisionObjects[i];
+                               if ((colObj0->m_islandTag1 != islandId) && (colObj0->m_islandTag1 != -1))
+                               {
+                                       printf("error in island management\n");
+                               }
+
+                               assert((colObj0->m_islandTag1 == islandId) || (colObj0->m_islandTag1 == -1));
+
+                               if (colObj0->m_islandTag1 == islandId)
+                               {
+                                       colObj0->SetActivationState( ISLAND_SLEEPING );
+                               }
+                       }
+               } else
+               {
+
+                       int idx;
+                       for (idx=startIslandIndex;idx<endIslandIndex;idx++)
+                       {
+                               int i = getUnionFind().getElement(idx).m_sz;
+
+                               btCollisionObject* colObj0 = collisionObjects[i];
+                               if ((colObj0->m_islandTag1 != islandId) && (colObj0->m_islandTag1 != -1))
+                               {
+                                       printf("error in island management\n");
+                               }
+
+                               assert((colObj0->m_islandTag1 == islandId) || (colObj0->m_islandTag1 == -1));
+
+                               if (colObj0->m_islandTag1 == islandId)
+                               {
+                                       if ( colObj0->GetActivationState() == ISLAND_SLEEPING)
+                                       {
+                                               colObj0->SetActivationState( WANTS_DEACTIVATION);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       std::vector<btPersistentManifold*>  islandmanifold;
+       int i;
+       int maxNumManifolds = dispatcher->getNumManifolds();
+       islandmanifold.reserve(maxNumManifolds);
+
+       for (i=0;i<maxNumManifolds ;i++)
+       {
+                btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
+                
+                btCollisionObject* colObj0 = static_cast<btCollisionObject*>(manifold->getBody0());
+                btCollisionObject* colObj1 = static_cast<btCollisionObject*>(manifold->getBody1());
+               
+                //todo: check sleeping conditions!
+                if (((colObj0) && colObj0->GetActivationState() != ISLAND_SLEEPING) ||
+                       ((colObj1) && colObj1->GetActivationState() != ISLAND_SLEEPING))
+               {
+                       //kinematic objects don't merge islands, but wake up all connected objects
+                       if (colObj0->isKinematicObject() && colObj0->GetActivationState() != ISLAND_SLEEPING)
+                       {
+                               colObj1->SetActivationState(ACTIVE_TAG);
+                       }
+                       if (colObj1->isKinematicObject() && colObj1->GetActivationState() != ISLAND_SLEEPING)
+                       {
+                               colObj0->SetActivationState(ACTIVE_TAG);
+                       }
+
+                       //filtering for response
+                       if (dispatcher->needsResponse(colObj0,colObj1))
+                               islandmanifold.push_back(manifold);
+               }
+       }
+
+       int numManifolds = islandmanifold.size();
+
+       // Sort manifolds, based on islands
+       // Sort the vector using predicate and std::sort
+       std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
+
+       //now process all active islands (sets of manifolds for now)
+
+       int startManifoldIndex = 0;
+       int endManifoldIndex = 1;
+
+       for (startManifoldIndex=0;startManifoldIndex<numManifolds;startManifoldIndex = endManifoldIndex)
+       {
+               int islandId = getIslandId(islandmanifold[startManifoldIndex]);
+               for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(islandmanifold[endManifoldIndex]));endManifoldIndex++)
+               {
+               }
+               /// Process the actual simulation, only if not sleeping/deactivated
+               int numIslandManifolds = endManifoldIndex-startManifoldIndex;
+               if (numIslandManifolds)
+               {
+                       callback->ProcessIsland(&islandmanifold[startManifoldIndex],numIslandManifolds);
+               }
+       }
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h
new file mode 100644 (file)
index 0000000..36c5100
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+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 SIMULATION_ISLAND_MANAGER_H
+#define SIMULATION_ISLAND_MANAGER_H
+
+#include "BulletCollision/CollisionDispatch/btUnionFind.h"
+#include "btCollisionCreateFunc.h"
+
+class btCollisionWorld;
+class btDispatcher;
+
+///SimulationIslandManager creates and handles simulation islands, using btUnionFind
+class btSimulationIslandManager
+{
+       btUnionFind m_unionFind;
+
+public:
+       btSimulationIslandManager();
+       virtual ~btSimulationIslandManager();
+
+
+       void initUnionFind(int n);      
+       
+               
+       btUnionFind& getUnionFind() { return m_unionFind;}
+
+       virtual void    updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher);
+       virtual void    storeIslandActivationState(btCollisionWorld* world);
+
+
+       void    findUnions(btDispatcher* dispatcher);
+
+       
+
+       struct  IslandCallback
+       {
+               virtual ~IslandCallback() {};
+
+               virtual void    ProcessIsland(class btPersistentManifold**      manifolds,int numManifolds) = 0;
+       };
+
+       void    buildAndProcessIslands(btDispatcher* dispatcher,btCollisionObjectArray& collisionObjects, IslandCallback* callback);
+
+};
+
+#endif //SIMULATION_ISLAND_MANAGER_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
new file mode 100644 (file)
index 0000000..d328184
--- /dev/null
@@ -0,0 +1,242 @@
+/*
+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 "btSphereBoxCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h"
+#include "BulletCollision/CollisionShapes/btBoxShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+//#include <stdio.h>
+
+btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped)
+: btCollisionAlgorithm(ci),
+m_ownManifold(false),
+m_manifoldPtr(mf),
+m_isSwapped(isSwapped)
+{
+       btCollisionObject* sphereObj = m_isSwapped? col1 : col0;
+       btCollisionObject* boxObj = m_isSwapped? col0 : col1;
+       
+       if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObj,boxObj))
+       {
+               m_manifoldPtr = m_dispatcher->getNewManifold(sphereObj,boxObj);
+               m_ownManifold = true;
+       }
+}
+
+
+btSphereBoxCollisionAlgorithm::~btSphereBoxCollisionAlgorithm()
+{
+       if (m_ownManifold)
+       {
+               if (m_manifoldPtr)
+                       m_dispatcher->releaseManifold(m_manifoldPtr);
+       }
+}
+
+
+
+void btSphereBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       if (!m_manifoldPtr)
+               return;
+
+       btCollisionObject* sphereObj = m_isSwapped? body1 : body0;
+       btCollisionObject* boxObj = m_isSwapped? body0 : body1;
+
+
+       btSphereShape* sphere0 = (btSphereShape*)sphereObj ->m_collisionShape;
+
+       btVector3 normalOnSurfaceB;
+       btVector3 pOnBox,pOnSphere;
+       btVector3 sphereCenter = sphereObj->m_worldTransform.getOrigin();
+       btScalar radius = sphere0->getRadius();
+       
+       float dist = getSphereDistance(boxObj,pOnBox,pOnSphere,sphereCenter,radius);
+
+       if (dist < SIMD_EPSILON)
+       {
+               btVector3 normalOnSurfaceB = (pOnBox- pOnSphere).normalize();
+
+               /// report a contact. internally this will be kept persistent, and contact reduction is done
+
+               resultOut->setPersistentManifold(m_manifoldPtr);
+               resultOut->addContactPoint(normalOnSurfaceB,pOnBox,dist);
+               
+       }
+
+       
+
+}
+
+float btSphereBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       //not yet
+       return 1.f;
+}
+
+
+btScalar btSphereBoxCollisionAlgorithm::getSphereDistance(btCollisionObject* boxObj, btVector3& pointOnBox, btVector3& v3PointOnSphere, const btVector3& sphereCenter, btScalar fRadius ) 
+{
+
+       btScalar margins;
+       btVector3 bounds[2];
+       btBoxShape* boxShape= (btBoxShape*)boxObj->m_collisionShape;
+       
+       bounds[0] = -boxShape->getHalfExtents();
+       bounds[1] = boxShape->getHalfExtents();
+
+       margins = boxShape->getMargin();//also add sphereShape margin?
+
+       const btTransform&      m44T = boxObj->m_worldTransform;
+
+       btVector3       boundsVec[2];
+       btScalar        fPenetration;
+
+       boundsVec[0] = bounds[0];
+       boundsVec[1] = bounds[1];
+
+       btVector3       marginsVec( margins, margins, margins );
+
+       // add margins
+       bounds[0] += marginsVec;
+       bounds[1] -= marginsVec;
+
+       /////////////////////////////////////////////////
+
+       btVector3       tmp, prel, n[6], normal, v3P;
+       btScalar   fSep = 10000000.0f, fSepThis;
+
+       n[0].setValue( -1.0f,  0.0f,  0.0f );
+       n[1].setValue(  0.0f, -1.0f,  0.0f );
+       n[2].setValue(  0.0f,  0.0f, -1.0f );
+       n[3].setValue(  1.0f,  0.0f,  0.0f );
+       n[4].setValue(  0.0f,  1.0f,  0.0f );
+       n[5].setValue(  0.0f,  0.0f,  1.0f );
+
+       // convert  point in local space
+       prel = m44T.invXform( sphereCenter);
+       
+       bool    bFound = false;
+
+       v3P = prel;
+
+       for (int i=0;i<6;i++)
+       {
+               int j = i<3? 0:1;
+               if ( (fSepThis = ((v3P-bounds[j]) .dot(n[i]))) > 0.0f )
+               {
+                       v3P = v3P - n[i]*fSepThis;              
+                       bFound = true;
+               }
+       }
+       
+       //
+
+       if ( bFound )
+       {
+               bounds[0] = boundsVec[0];
+               bounds[1] = boundsVec[1];
+
+               normal = (prel - v3P).normalize();
+               pointOnBox = v3P + normal*margins;
+               v3PointOnSphere = prel - normal*fRadius;
+
+               if ( ((v3PointOnSphere - pointOnBox) .dot (normal)) > 0.0f )
+               {
+                       return 1.0f;
+               }
+
+               // transform back in world space
+               tmp = m44T( pointOnBox);
+               pointOnBox    = tmp;
+               tmp  = m44T( v3PointOnSphere);          
+               v3PointOnSphere = tmp;
+               btScalar fSeps2 = (pointOnBox-v3PointOnSphere).length2();
+               
+               //if this fails, fallback into deeper penetration case, below
+               if (fSeps2 > SIMD_EPSILON)
+               {
+                       fSep = - btSqrt(fSeps2);
+                       normal = (pointOnBox-v3PointOnSphere);
+                       normal *= 1.f/fSep;
+               }
+
+               return fSep;
+       }
+
+       //////////////////////////////////////////////////
+       // Deep penetration case
+
+       fPenetration = getSpherePenetration( boxObj,pointOnBox, v3PointOnSphere, sphereCenter, fRadius,bounds[0],bounds[1] );
+
+       bounds[0] = boundsVec[0];
+       bounds[1] = boundsVec[1];
+
+       if ( fPenetration <= 0.0f )
+               return (fPenetration-margins);
+       else
+               return 1.0f;
+}
+
+btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btCollisionObject* boxObj,btVector3& pointOnBox, btVector3& v3PointOnSphere, const btVector3& sphereCenter, btScalar fRadius, const btVector3& aabbMin, const btVector3& aabbMax) 
+{
+
+       btVector3 bounds[2];
+
+       bounds[0] = aabbMin;
+       bounds[1] = aabbMax;
+
+       btVector3       p0, tmp, prel, n[6], normal;
+       btScalar   fSep = -10000000.0f, fSepThis;
+
+       n[0].setValue( -1.0f,  0.0f,  0.0f );
+       n[1].setValue(  0.0f, -1.0f,  0.0f );
+       n[2].setValue(  0.0f,  0.0f, -1.0f );
+       n[3].setValue(  1.0f,  0.0f,  0.0f );
+       n[4].setValue(  0.0f,  1.0f,  0.0f );
+       n[5].setValue(  0.0f,  0.0f,  1.0f );
+
+       const btTransform&      m44T = boxObj->m_worldTransform;
+
+       // convert  point in local space
+       prel = m44T.invXform( sphereCenter);
+
+       ///////////
+
+       for (int i=0;i<6;i++)
+       {
+               int j = i<3 ? 0:1;
+               if ( (fSepThis = ((prel-bounds[j]) .dot( n[i]))-fRadius) > 0.0f )       return 1.0f;
+               if ( fSepThis > fSep )
+               {
+                       p0 = bounds[j]; normal = (btVector3&)n[i];
+                       fSep = fSepThis;
+               }
+       }
+
+       pointOnBox = prel - normal*(normal.dot((prel-p0)));
+       v3PointOnSphere = pointOnBox + normal*fSep;
+
+       // transform back in world space
+       tmp  = m44T( pointOnBox);               
+       pointOnBox    = tmp;
+       tmp  = m44T( v3PointOnSphere);          v3PointOnSphere = tmp;
+       normal = (pointOnBox-v3PointOnSphere).normalize();
+
+       return fSep;
+
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h
new file mode 100644 (file)
index 0000000..68915a4
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+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 SPHERE_BOX_COLLISION_ALGORITHM_H
+#define SPHERE_BOX_COLLISION_ALGORITHM_H
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
+class btPersistentManifold;
+#include "LinearMath/btVector3.h"
+
+/// btSphereBoxCollisionAlgorithm  provides sphere-box collision detection.
+/// Other features are frame-coherency (persistent data) and collision response.
+class btSphereBoxCollisionAlgorithm : public btCollisionAlgorithm
+{
+       bool    m_ownManifold;
+       btPersistentManifold*   m_manifoldPtr;
+       bool    m_isSwapped;
+       
+public:
+
+       btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped);
+
+       virtual ~btSphereBoxCollisionAlgorithm();
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       virtual float calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       btScalar getSphereDistance( btCollisionObject* boxObj,btVector3& v3PointOnBox, btVector3& v3PointOnSphere, const btVector3& v3SphereCenter, btScalar fRadius );
+
+       btScalar getSpherePenetration( btCollisionObject* boxObj, btVector3& v3PointOnBox, btVector3& v3PointOnSphere, const btVector3& v3SphereCenter, btScalar fRadius, const btVector3& aabbMin, const btVector3& aabbMax);
+       
+       struct CreateFunc :public       btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       if (!m_swapped)
+                       {
+                               return new btSphereBoxCollisionAlgorithm(0,ci,body0,body1,false);
+                       } else
+                       {
+                               return new btSphereBoxCollisionAlgorithm(0,ci,body0,body1,true);
+                       }
+               }
+       };
+
+};
+
+#endif //SPHERE_BOX_COLLISION_ALGORITHM_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
new file mode 100644 (file)
index 0000000..bb04833
--- /dev/null
@@ -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 "btSphereSphereCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+
+btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1)
+: btCollisionAlgorithm(ci),
+m_ownManifold(false),
+m_manifoldPtr(mf)
+{
+       if (!m_manifoldPtr)
+       {
+               m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1);
+               m_ownManifold = true;
+       }
+}
+
+btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
+{
+       if (m_ownManifold)
+       {
+               if (m_manifoldPtr)
+                       m_dispatcher->releaseManifold(m_manifoldPtr);
+       }
+}
+
+void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       if (!m_manifoldPtr)
+               return;
+
+       btSphereShape* sphere0 = (btSphereShape*)col0->m_collisionShape;
+       btSphereShape* sphere1 = (btSphereShape*)col1->m_collisionShape;
+
+       btVector3 diff = col0->m_worldTransform.getOrigin()-  col1->m_worldTransform.getOrigin();
+       float len = diff.length();
+       btScalar radius0 = sphere0->getRadius();
+       btScalar radius1 = sphere1->getRadius();
+
+       ///iff distance positive, don't generate a new contact
+       if ( len > (radius0+radius1))
+               return;
+
+       ///distance (negative means penetration)
+       btScalar dist = len - (radius0+radius1);
+
+       btVector3 normalOnSurfaceB = diff / len;
+       ///point on A (worldspace)
+       btVector3 pos0 = col0->m_worldTransform.getOrigin() - radius0 * normalOnSurfaceB;
+       ///point on B (worldspace)
+       btVector3 pos1 = col1->m_worldTransform.getOrigin() + radius1* normalOnSurfaceB;
+
+       /// report a contact. internally this will be kept persistent, and contact reduction is done
+       resultOut->setPersistentManifold(m_manifoldPtr);
+       resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
+
+}
+
+float btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+       //not yet
+       return 1.f;
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h
new file mode 100644 (file)
index 0000000..8b08d01
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+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 SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#define SPHERE_SPHERE_COLLISION_ALGORITHM_H
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
+class btPersistentManifold;
+
+/// btSphereSphereCollisionAlgorithm  provides sphere-sphere collision detection.
+/// Other features are frame-coherency (persistent data) and collision response.
+/// Also provides the most basic sample for custom/user btCollisionAlgorithm
+class btSphereSphereCollisionAlgorithm : public btCollisionAlgorithm
+{
+       bool    m_ownManifold;
+       btPersistentManifold*   m_manifoldPtr;
+       
+public:
+       btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
+
+       btSphereSphereCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
+               : btCollisionAlgorithm(ci) {}
+
+       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       virtual float calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+
+       
+       virtual ~btSphereSphereCollisionAlgorithm();
+
+       struct CreateFunc :public       btCollisionAlgorithmCreateFunc
+       {
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               {
+                       return new btSphereSphereCollisionAlgorithm(0,ci,body0,body1);
+               }
+       };
+
+};
+
+#endif //SPHERE_SPHERE_COLLISION_ALGORITHM_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp
new file mode 100644 (file)
index 0000000..046f348
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+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 "btUnionFind.h"
+#include <assert.h>
+#include <algorithm>
+
+
+
+btUnionFind::~btUnionFind()
+{
+       Free();
+
+}
+
+btUnionFind::btUnionFind()
+{ 
+
+}
+
+void   btUnionFind::allocate(int N)
+{
+       m_elements.resize(N);
+}
+void   btUnionFind::Free()
+{
+       m_elements.clear();
+}
+
+
+void   btUnionFind::reset(int N)
+{
+       allocate(N);
+
+       for (int i = 0; i < N; i++) 
+       { 
+               m_elements[i].m_id = i; m_elements[i].m_sz = 1; 
+       } 
+}
+
+bool btUnionFindElementSortPredicate(const btElement& lhs, const btElement& rhs)
+{
+       return lhs.m_id < rhs.m_id;
+}
+
+
+///this is a special operation, destroying the content of btUnionFind.
+///it sorts the elements, based on island id, in order to make it easy to iterate over islands
+void   btUnionFind::sortIslands()
+{
+
+       //first store the original body index, and islandId
+       int numElements = m_elements.size();
+       
+       for (int i=0;i<numElements;i++)
+       {
+               m_elements[i].m_id = find(i);
+               m_elements[i].m_sz = i;
+       }
+       
+        // Sort the vector using predicate and std::sort
+         std::sort(m_elements.begin(), m_elements.end(), btUnionFindElementSortPredicate);
+
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h
new file mode 100644 (file)
index 0000000..8db1580
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+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 UNION_FIND_H
+#define UNION_FIND_H
+
+#include <vector>
+struct btElement
+{
+       int     m_id;
+       int     m_sz;
+};
+
+///UnionFind calculates connected subsets
+// Implements weighted Quick Union with path compression
+// optimization: could use short ints instead of ints (halving memory, would limit the number of rigid bodies to 64k, sounds reasonable)
+class btUnionFind
+  {
+    private:
+               std::vector<btElement>  m_elements;
+
+    public:
+         
+               btUnionFind();
+               ~btUnionFind();
+
+       
+               //this is a special operation, destroying the content of btUnionFind.
+               //it sorts the elements, based on island id, in order to make it easy to iterate over islands
+               void    sortIslands();
+
+         void  reset(int N);
+
+         inline int    getNumElements() const
+         {
+                 return m_elements.size();
+         }
+         inline bool  isRoot(int x) const
+         {
+                 return (x == m_elements[x].m_id);
+         }
+
+         btElement&    getElement(int index)
+         {
+                 return m_elements[index];
+         }
+         const btElement& getElement(int index) const
+         {
+                 return m_elements[index];
+         }
+   
+         void  allocate(int N);
+         void  Free();
+
+
+
+
+         int find(int p, int q)
+               { 
+                       return (find(p) == find(q)); 
+               }
+
+               void unite(int p, int q)
+               {
+                       int i = find(p), j = find(q);
+                       if (i == j) 
+                               return;
+
+                       //weighted quick union, this keeps the 'trees' balanced, and keeps performance of unite O( log(n) )
+                       if (m_elements[i].m_sz < m_elements[j].m_sz)
+                       { 
+                               m_elements[i].m_id = j; m_elements[j].m_sz += m_elements[i].m_sz; 
+                       }
+                       else 
+                       { 
+                               m_elements[j].m_id = i; m_elements[i].m_sz += m_elements[j].m_sz; 
+                       }
+               }
+
+               int find(int x)
+               { 
+                       //assert(x < m_N);
+                       //assert(x >= 0);
+
+                       while (x != m_elements[x].m_id) 
+                       {
+               //not really a reason not to use path compression, and it flattens the trees/improves find performance dramatically
+               #define USE_PATH_COMPRESSION 1
+               #ifdef USE_PATH_COMPRESSION
+                               //
+                               m_elements[x].m_id = m_elements[m_elements[x].m_id].m_id;
+               #endif //
+                               x = m_elements[x].m_id;
+                               //assert(x < m_N);
+                               //assert(x >= 0);
+
+                       }
+                       return x; 
+               }
+
+
+  };
+
+
+#endif //UNION_FIND_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp
new file mode 100644 (file)
index 0000000..b5f80de
--- /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.
+*/
+
+#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;
+
+
+}
+
+
+void   btBoxShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+{
+       //float margin = 0.f;
+       btVector3 halfExtents = getHalfExtents();
+
+       btScalar lx=2.f*(halfExtents.x());
+       btScalar ly=2.f*(halfExtents.y());
+       btScalar lz=2.f*(halfExtents.z());
+
+       inertia[0] = mass/(12.0f) * (ly*ly + lz*lz);
+       inertia[1] = mass/(12.0f) * (lx*lx + lz*lz);
+       inertia[2] = mass/(12.0f) * (lx*lx + ly*ly);
+
+
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h
new file mode 100644 (file)
index 0000000..b137eb1
--- /dev/null
@@ -0,0 +1,262 @@
+/*
+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 OBB_BOX_MINKOWSKI_H
+#define OBB_BOX_MINKOWSKI_H
+
+#include "btPolyhedralConvexShape.h"
+#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "LinearMath/btPoint3.h"
+#include "LinearMath/btSimdMinMax.h"
+
+///btBoxShape implements both a feature based (vertex/edge/plane) and implicit (getSupportingVertex) Box
+class btBoxShape: public btPolyhedralConvexShape
+{
+
+       //btVector3     m_boxHalfExtents1; //use m_implicitShapeDimensions instead
+
+
+public:
+
+       btVector3 getHalfExtents() const;
+               
+       virtual int     getShapeType() const { return BOX_SHAPE_PROXYTYPE;}
+
+       virtual btVector3       localGetSupportingVertex(const btVector3& vec) const
+       {
+               
+               btVector3 halfExtents = getHalfExtents();
+               
+               btVector3 supVertex;
+               supVertex = btPoint3(vec.x() < btScalar(0.0f) ? -halfExtents.x() : halfExtents.x(),
+                     vec.y() < btScalar(0.0f) ? -halfExtents.y() : halfExtents.y(),
+                     vec.z() < btScalar(0.0f) ? -halfExtents.z() : halfExtents.z()); 
+  
+               return supVertex;
+       }
+
+       virtual inline btVector3        localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+       {
+               btVector3 halfExtents = getHalfExtents();
+               btVector3 margin(getMargin(),getMargin(),getMargin());
+               halfExtents -= margin;
+
+               return btVector3(vec.x() < btScalar(0.0f) ? -halfExtents.x() : halfExtents.x(),
+                    vec.y() < btScalar(0.0f) ? -halfExtents.y() : halfExtents.y(),
+                    vec.z() < btScalar(0.0f) ? -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;
+
+
+               for (int i=0;i<numVectors;i++)
+               {
+                       const btVector3& vec = vectors[i];
+                       supportVerticesOut[i].setValue(vec.x() < btScalar(0.0f) ? -halfExtents.x() : halfExtents.x(),
+                    vec.y() < btScalar(0.0f) ? -halfExtents.y() : halfExtents.y(),
+                    vec.z() < btScalar(0.0f) ? -halfExtents.z() : halfExtents.z()); 
+               }
+
+       }
+
+
+       btBoxShape( const btVector3& boxHalfExtents)
+       {
+               m_implicitShapeDimensions = boxHalfExtents;
+       };
+       
+       virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+
+       
+
+       virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia);
+
+       virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const
+       {
+               //this plane might not be aligned...
+               btVector4 plane ;
+               getPlaneEquation(plane,i);
+               planeNormal = btVector3(plane.getX(),plane.getY(),plane.getZ());
+               planeSupport = localGetSupportingVertex(-planeNormal);
+       }
+
+       
+       virtual int getNumPlanes() const
+       {
+               return 6;
+       }       
+       
+       virtual int     getNumVertices() const 
+       {
+               return 8;
+       }
+
+       virtual int getNumEdges() const
+       {
+               return 12;
+       }
+
+
+       virtual void getVertex(int i,btVector3& vtx) const
+       {
+               btVector3 halfExtents = getHalfExtents();
+
+               vtx = btVector3(
+                               halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1),
+                               halfExtents.y() * (1-((i&2)>>1)) - halfExtents.y() * ((i&2)>>1),
+                               halfExtents.z() * (1-((i&4)>>2)) - halfExtents.z() * ((i&4)>>2));
+       }
+       
+
+       virtual void    getPlaneEquation(btVector4& plane,int i) const
+       {
+               btVector3 halfExtents = getHalfExtents();
+
+               switch (i)
+               {
+               case 0:
+                       plane.setValue(1.f,0.f,0.f);
+                       plane[3] = -halfExtents.x();
+                       break;
+               case 1:
+                       plane.setValue(-1.f,0.f,0.f);
+                       plane[3] = -halfExtents.x();
+                       break;
+               case 2:
+                       plane.setValue(0.f,1.f,0.f);
+                       plane[3] = -halfExtents.y();
+                       break;
+               case 3:
+                       plane.setValue(0.f,-1.f,0.f);
+                       plane[3] = -halfExtents.y();
+                       break;
+               case 4:
+                       plane.setValue(0.f,0.f,1.f);
+                       plane[3] = -halfExtents.z();
+                       break;
+               case 5:
+                       plane.setValue(0.f,0.f,-1.f);
+                       plane[3] = -halfExtents.z();
+                       break;
+               default:
+                       assert(0);
+               }
+       }
+
+       
+       virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const
+       //virtual void getEdge(int i,Edge& edge) const
+       {
+               int edgeVert0 = 0;
+               int edgeVert1 = 0;
+
+               switch (i)
+               {
+               case 0:
+                               edgeVert0 = 0;
+                               edgeVert1 = 1;
+                       break;
+               case 1:
+                               edgeVert0 = 0;
+                               edgeVert1 = 2;
+                       break;
+               case 2:
+                       edgeVert0 = 1;
+                       edgeVert1 = 3;
+
+                       break;
+               case 3:
+                       edgeVert0 = 2;
+                       edgeVert1 = 3;
+                       break;
+               case 4:
+                       edgeVert0 = 0;
+                       edgeVert1 = 4;
+                       break;
+               case 5:
+                       edgeVert0 = 1;
+                       edgeVert1 = 5;
+
+                       break;
+               case 6:
+                       edgeVert0 = 2;
+                       edgeVert1 = 6;
+                       break;
+               case 7:
+                       edgeVert0 = 3;
+                       edgeVert1 = 7;
+                       break;
+               case 8:
+                       edgeVert0 = 4;
+                       edgeVert1 = 5;
+                       break;
+               case 9:
+                       edgeVert0 = 4;
+                       edgeVert1 = 6;
+                       break;
+               case 10:
+                       edgeVert0 = 5;
+                       edgeVert1 = 7;
+                       break;
+               case 11:
+                       edgeVert0 = 6;
+                       edgeVert1 = 7;
+                       break;
+               default:
+                       ASSERT(0);
+
+               }
+
+               getVertex(edgeVert0,pa );
+               getVertex(edgeVert1,pb );
+       }
+
+
+
+
+       
+       virtual bool isInside(const btPoint3& pt,btScalar tolerance) const
+       {
+               btVector3 halfExtents = getHalfExtents();
+
+               //btScalar minDist = 2*tolerance;
+               
+               bool result =   (pt.x() <= (halfExtents.x()+tolerance)) &&
+                                               (pt.x() >= (-halfExtents.x()-tolerance)) &&
+                                               (pt.y() <= (halfExtents.y()+tolerance)) &&
+                                               (pt.y() >= (-halfExtents.y()-tolerance)) &&
+                                               (pt.z() <= (halfExtents.z()+tolerance)) &&
+                                               (pt.z() >= (-halfExtents.z()-tolerance));
+               
+               return result;
+       }
+
+
+       //debugging
+       virtual char*   getName()const
+       {
+               return "Box";
+       }
+
+
+};
+
+#endif //OBB_BOX_MINKOWSKI_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
new file mode 100644 (file)
index 0000000..338527d
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+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.
+*/
+
+//#define DISABLE_BVH
+
+
+#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)
+:btTriangleMeshShape(meshInterface)
+{
+       //construct bvh from meshInterface
+#ifndef DISABLE_BVH
+
+       m_bvh = new btOptimizedBvh();
+       m_bvh->build(meshInterface);
+
+#endif //DISABLE_BVH
+
+}
+
+btBvhTriangleMeshShape::~btBvhTriangleMeshShape()
+{
+       delete m_bvh;
+}
+
+//perform bvh tree traversal and report overlapping triangles to 'callback'
+void   btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
+{
+
+#ifdef DISABLE_BVH
+       //brute force traverse all triangles
+       btTriangleMeshShape::processAllTriangles(callback,aabbMin,aabbMax);
+#else
+
+       //first get all the nodes
+
+       
+       struct  MyNodeOverlapCallback : public btNodeOverlapCallback
+       {
+               btStridingMeshInterface*        m_meshInterface;
+               btTriangleCallback*             m_callback;
+               btVector3                               m_triangle[3];
+
+
+               MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
+                       :m_meshInterface(meshInterface),
+                       m_callback(callback)
+               {
+               }
+                               
+               virtual void processNode(const btOptimizedBvhNode* node)
+               {
+                       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,
+                               node->m_subPart);
+
+                       int* gfxbase = (int*)(indexbase+node->m_triangleIndex*indexstride);
+                       
+                       const btVector3& meshScaling = m_meshInterface->getScaling();
+                       for (int j=2;j>=0;j--)
+                       {
+                               
+                               int graphicsindex = gfxbase[j];
+#ifdef DEBUG_TRIANGLE_MESH
+                               printf("%d ,",graphicsindex);
+#endif //DEBUG_TRIANGLE_MESH
+                               float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+
+                               m_triangle[j] = btVector3(
+                                       graphicsbase[0]*meshScaling.getX(),
+                                       graphicsbase[1]*meshScaling.getY(),
+                                       graphicsbase[2]*meshScaling.getZ());
+#ifdef DEBUG_TRIANGLE_MESH
+                               printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
+#endif //DEBUG_TRIANGLE_MESH
+                       }
+
+                       m_callback->processTriangle(m_triangle,node->m_subPart,node->m_triangleIndex);
+                       m_meshInterface->unLockReadOnlyVertexBase(node->m_subPart);
+               }
+
+       };
+
+       MyNodeOverlapCallback   myNodeCallback(callback,m_meshInterface);
+
+       m_bvh->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
+
+
+#endif//DISABLE_BVH
+
+
+}
+
+
+void   btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
+{
+       if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
+       {
+               btTriangleMeshShape::setLocalScaling(scaling);
+               delete m_bvh;
+               m_bvh = new btOptimizedBvh();
+               m_bvh->build(m_meshInterface);
+               //rebuild the bvh...
+       }
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
new file mode 100644 (file)
index 0000000..59a27e8
--- /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 BVH_TRIANGLE_MESH_SHAPE_H
+#define BVH_TRIANGLE_MESH_SHAPE_H
+
+#include "BulletCollision/CollisionShapes/btTriangleMeshShape.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.
+class btBvhTriangleMeshShape : public btTriangleMeshShape
+{
+
+       btOptimizedBvh* m_bvh;
+       
+       
+public:
+       btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface);
+
+       virtual ~btBvhTriangleMeshShape();
+
+       
+       /*
+       virtual int     getShapeType() const
+       {
+               return TRIANGLE_MESH_SHAPE_PROXYTYPE;
+       }
+       */
+
+
+
+       virtual void    processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
+
+
+       //debugging
+       virtual char*   getName()const {return "BVHTRIANGLEMESH";}
+
+
+       virtual void    setLocalScaling(const btVector3& scaling);
+       
+
+
+};
+
+#endif //BVH_TRIANGLE_MESH_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h
new file mode 100644 (file)
index 0000000..377f0e5
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+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 COLLISION_MARGIN_H
+#define COLLISION_MARGIN_H
+
+//used by Gjk and some other algorithms
+
+#define CONVEX_DISTANCE_MARGIN 0.04f// 0.1f//;//0.01f
+
+
+
+#endif //COLLISION_MARGIN_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.cpp
new file mode 100644 (file)
index 0000000..5474a20
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+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 "BulletCollision/CollisionShapes/btCollisionShape.h"
+
+void   btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) const
+{
+       btTransform tr;
+       tr.setIdentity();
+       btVector3 aabbMin,aabbMax;
+
+       getAabb(tr,aabbMin,aabbMax);
+
+       radius = (aabbMax-aabbMin).length()*0.5f;
+       center = (aabbMin+aabbMax)*0.5f;
+}
+
+float  btCollisionShape::getAngularMotionDisc() const
+{
+       btVector3       center;
+       float disc;
+       getBoundingSphere(center,disc);
+       disc += (center).length();
+       return disc;
+}
+
+void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax)
+{
+       //start with static aabb
+       getAabb(curTrans,temporalAabbMin,temporalAabbMax);
+
+       float temporalAabbMaxx = temporalAabbMax.getX();
+       float temporalAabbMaxy = temporalAabbMax.getY();
+       float temporalAabbMaxz = temporalAabbMax.getZ();
+       float temporalAabbMinx = temporalAabbMin.getX();
+       float temporalAabbMiny = temporalAabbMin.getY();
+       float temporalAabbMinz = temporalAabbMin.getZ();
+
+       // add linear motion
+       btVector3 linMotion = linvel*timeStep;
+       //todo: simd would have a vector max/min operation, instead of per-element access
+       if (linMotion.x() > 0.f)
+               temporalAabbMaxx += linMotion.x(); 
+       else
+               temporalAabbMinx += linMotion.x();
+       if (linMotion.y() > 0.f)
+               temporalAabbMaxy += linMotion.y(); 
+       else
+               temporalAabbMiny += linMotion.y();
+       if (linMotion.z() > 0.f)
+               temporalAabbMaxz += linMotion.z(); 
+       else
+               temporalAabbMinz += linMotion.z();
+
+       //add conservative angular motion
+       btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
+       btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
+       temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
+       temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);
+
+       temporalAabbMin -= angularMotion3d;
+       temporalAabbMax += angularMotion3d;
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h
new file mode 100644 (file)
index 0000000..d015fb2
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+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 COLLISION_SHAPE_H
+#define COLLISION_SHAPE_H
+
+#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.
+class btCollisionShape
+{
+public:
+
+       btCollisionShape() :m_tempDebug(0)
+       {
+       }
+       virtual ~btCollisionShape()
+       {
+       }
+
+       ///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
+       virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
+
+       virtual void    getBoundingSphere(btVector3& center,btScalar& radius) const;
+
+       ///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
+       virtual float   getAngularMotionDisc() const;
+
+       virtual int             getShapeType() const=0;
+
+       ///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);
+
+       inline bool     isPolyhedral() const
+       {
+               return btBroadphaseProxy::isPolyhedral(getShapeType());
+       }
+
+       inline bool     isConvex() const
+       {
+               return btBroadphaseProxy::isConvex(getShapeType());
+       }
+       inline bool     isConcave() const
+       {
+               return btBroadphaseProxy::isConcave(getShapeType());
+       }
+       inline bool     isCompound() const
+       {
+               return btBroadphaseProxy::isCompound(getShapeType());
+       }
+
+       virtual void    setLocalScaling(const btVector3& scaling) =0;
+       virtual const btVector3& getLocalScaling() const =0;
+
+       virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) = 0;
+
+//debugging support
+       virtual char*   getName()const =0 ;
+       const char* getExtraDebugInfo() const { return m_tempDebug;}
+       void  setExtraDebugInfo(const char* extraDebugInfo) { m_tempDebug = extraDebugInfo;}
+       const char * m_tempDebug;
+//endif debugging support
+
+       virtual void    setMargin(float margin) = 0;
+       virtual float   getMargin() const = 0;
+
+};     
+
+#endif //COLLISION_SHAPE_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
new file mode 100644 (file)
index 0000000..88ae8c7
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+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 "btCompoundShape.h"
+
+
+#include "btCollisionShape.h"
+
+
+btCompoundShape::btCompoundShape()
+:m_localAabbMin(1e30f,1e30f,1e30f),
+m_localAabbMax(-1e30f,-1e30f,-1e30f),
+m_aabbTree(0),
+m_collisionMargin(0.f),
+m_localScaling(1.f,1.f,1.f)
+{
+}
+
+
+btCompoundShape::~btCompoundShape()
+{
+}
+
+void   btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
+{
+       m_childTransforms.push_back(localTransform);
+       m_childShapes.push_back(shape);
+
+       //extend the local aabbMin/aabbMax
+       btVector3 localAabbMin,localAabbMax;
+       shape->getAabb(localTransform,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
+void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
+{
+       btVector3 localHalfExtents = 0.5f*(m_localAabbMax-m_localAabbMin);
+       btVector3 localCenter = 0.5f*(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());
+
+       aabbMin = center - extent;
+       aabbMax = center + extent;
+}
+
+void   btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia)
+{
+       //approximation: take the inertia from the aabb for now
+       btTransform ident;
+       ident.setIdentity();
+       btVector3 aabbMin,aabbMax;
+       getAabb(ident,aabbMin,aabbMax);
+       
+       btVector3 halfExtents = (aabbMax-aabbMin)*0.5f;
+       
+       btScalar lx=2.f*(halfExtents.x());
+       btScalar ly=2.f*(halfExtents.y());
+       btScalar lz=2.f*(halfExtents.z());
+
+       inertia[0] = mass/(12.0f) * (ly*ly + lz*lz);
+       inertia[1] = mass/(12.0f) * (lx*lx + lz*lz);
+       inertia[2] = mass/(12.0f) * (lx*lx + ly*ly);
+
+}
+
+       
+       
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h
new file mode 100644 (file)
index 0000000..65a6809
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+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 COMPOUND_SHAPE_H
+#define COMPOUND_SHAPE_H
+
+#include "btCollisionShape.h"
+
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btMatrix3x3.h"
+#include <vector>
+#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
+
+class btOptimizedBvh;
+
+/// 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
+{
+       std::vector<btTransform>                m_childTransforms;
+       std::vector<btCollisionShape*>  m_childShapes;
+       btVector3                                               m_localAabbMin;
+       btVector3                                               m_localAabbMax;
+
+       btOptimizedBvh*                                 m_aabbTree;
+
+public:
+       btCompoundShape();
+
+       virtual ~btCompoundShape();
+
+       void    addChildShape(const btTransform& localTransform,btCollisionShape* shape);
+
+       int             getNumChildShapes() const
+       {
+               return m_childShapes.size();
+       }
+
+       btCollisionShape* getChildShape(int index)
+       {
+               return m_childShapes[index];
+       }
+       const btCollisionShape* getChildShape(int index) const
+       {
+               return m_childShapes[index];
+       }
+
+       btTransform     getChildTransform(int index)
+       {
+               return m_childTransforms[index];
+       }
+       const btTransform       getChildTransform(int index) const
+       {
+               return m_childTransforms[index];
+       }
+
+       ///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    setLocalScaling(const btVector3& scaling)
+       {
+               m_localScaling = scaling;
+       }
+       virtual const btVector3& getLocalScaling() const 
+       {
+               return m_localScaling;
+       }
+
+       virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia);
+       
+       virtual int     getShapeType() const { return COMPOUND_SHAPE_PROXYTYPE;}
+
+       virtual void    setMargin(float margin)
+       {
+               m_collisionMargin = margin;
+       }
+       virtual float   getMargin() const
+       {
+               return m_collisionMargin;
+       }
+       virtual char*   getName()const
+       {
+               return "Compound";
+       }
+
+       //this is optional, but should make collision queries faster, by culling non-overlapping nodes
+       void    createAabbTreeFromChildren();
+
+       const btOptimizedBvh*                                   getAabbTree() const
+       {
+               return m_aabbTree;
+       }
+
+private:
+       btScalar        m_collisionMargin;
+protected:
+       btVector3       m_localScaling;
+
+};
+
+
+
+#endif //COMPOUND_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.cpp
new file mode 100644 (file)
index 0000000..29f6282
--- /dev/null
@@ -0,0 +1,28 @@
+
+/*
+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 "btConcaveShape.h"
+
+ConcaveShape::ConcaveShape() : m_collisionMargin(0.f)
+{
+
+}
+
+ConcaveShape::~ConcaveShape()
+{
+
+}
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h
new file mode 100644 (file)
index 0000000..3046545
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+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 CONCAVE_SHAPE_H
+#define CONCAVE_SHAPE_H
+
+#include "BulletCollision/CollisionShapes/btCollisionShape.h"
+#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.
+class ConcaveShape : public btCollisionShape
+{
+protected:
+       float m_collisionMargin;
+
+public:
+       ConcaveShape();
+
+       virtual ~ConcaveShape();
+
+       virtual void    processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const = 0;
+
+       virtual float getMargin() const {
+               return m_collisionMargin;
+       }
+       virtual void setMargin(float collisionMargin)
+       {
+               m_collisionMargin = collisionMargin;
+       }
+
+
+
+};
+
+#endif //CONCAVE_SHAPE_H
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.cpp
new file mode 100644 (file)
index 0000000..13875fc
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+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 "btConeShape.h"
+#include "LinearMath/btPoint3.h"
+
+#ifdef WIN32
+static int coneindices[3] = {1,2,0};
+#else
+static int coneindices[3] = {2,1,0};
+#endif
+
+btConeShape::btConeShape (btScalar radius,btScalar height):
+m_radius (radius),
+m_height(height)
+{
+       btVector3 halfExtents;
+       m_sinAngle = (m_radius / sqrt(m_radius * m_radius + m_height * m_height));
+}
+
+
+btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
+{
+       
+       float halfHeight = m_height * 0.5f;
+
+ if (v[coneindices[1]] > v.length() * m_sinAngle)
+ {
+       btVector3 tmp;
+
+       tmp[coneindices[0]] = 0.f;
+       tmp[coneindices[1]] = halfHeight;
+       tmp[coneindices[2]] = 0.f;
+       return tmp;
+ }
+  else {
+    btScalar s = btSqrt(v[coneindices[0]] * v[coneindices[0]] + v[coneindices[2]] * v[coneindices[2]]);
+    if (s > SIMD_EPSILON) {
+      btScalar d = m_radius / s;
+         btVector3 tmp;
+         tmp[coneindices[0]] = v[coneindices[0]] * d;
+         tmp[coneindices[1]] = -halfHeight;
+         tmp[coneindices[2]] = v[coneindices[2]] * d;
+         return tmp;
+    }
+    else  {
+               btVector3 tmp;
+               tmp[coneindices[0]] = 0.f;
+               tmp[coneindices[1]] = -halfHeight;
+               tmp[coneindices[2]] = 0.f;
+               return tmp;
+       }
+  }
+
+}
+
+btVector3      btConeShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
+{
+               return coneLocalSupport(vec);
+}
+
+void   btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+{
+       for (int i=0;i<numVectors;i++)
+       {
+               const btVector3& vec = vectors[i];
+               supportVerticesOut[i] = coneLocalSupport(vec);
+       }
+}
+
+
+btVector3      btConeShape::localGetSupportingVertex(const btVector3& vec)  const
+{
+       btVector3 supVertex = coneLocalSupport(vec);
+       if ( getMargin()!=0.f )
+       {
+               btVector3 vecnorm = vec;
+               if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+               {
+                       vecnorm.setValue(-1.f,-1.f,-1.f);
+               } 
+               vecnorm.normalize();
+               supVertex+= getMargin() * vecnorm;
+       }
+       return supVertex;
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h
new file mode 100644 (file)
index 0000000..0fd3ce1
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+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 CONE_MINKOWSKI_H
+#define CONE_MINKOWSKI_H
+
+#include "btConvexShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+
+/// implements cone shape interface
+class btConeShape : public btConvexShape
+
+{
+
+       float m_sinAngle;
+       float m_radius;
+       float m_height;
+       
+       btVector3 coneLocalSupport(const btVector3& v) const;
+
+
+public:
+       btConeShape (btScalar radius,btScalar height);
+       
+       virtual btVector3       localGetSupportingVertex(const btVector3& vec) const;
+       virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
+       virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+
+       float getRadius() const { return m_radius;}
+       float getHeight() const { return m_height;}
+
+
+       virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia)
+       {
+               btTransform identity;
+               identity.setIdentity();
+               btVector3 aabbMin,aabbMax;
+               getAabb(identity,aabbMin,aabbMax);
+
+               btVector3 halfExtents = (aabbMax-aabbMin)*0.5f;
+
+               float margin = getMargin();
+
+               btScalar lx=2.f*(halfExtents.x()+margin);
+               btScalar ly=2.f*(halfExtents.y()+margin);
+               btScalar lz=2.f*(halfExtents.z()+margin);
+               const btScalar x2 = lx*lx;
+               const btScalar y2 = ly*ly;
+               const btScalar z2 = lz*lz;
+               const btScalar scaledmass = mass * 0.08333333f;
+
+               inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
+
+//             inertia.x() = scaledmass * (y2+z2);
+//             inertia.y() = scaledmass * (x2+z2);
+//             inertia.z() = scaledmass * (x2+y2);
+       }
+
+
+
+               virtual int     getShapeType() const { return CONE_SHAPE_PROXYTYPE; }
+
+               virtual char*   getName()const 
+               {
+                       return "Cone";
+               }
+};
+
+
+#endif //CONE_MINKOWSKI_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
new file mode 100644 (file)
index 0000000..7a4c7eb
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+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 "btConvexHullShape.h"
+#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
+
+#include "LinearMath/btQuaternion.h"
+
+
+
+btConvexHullShape ::btConvexHullShape (const float* points,int numPoints,int stride)
+{
+       m_points.resize(numPoints);
+       unsigned char* pointsBaseAddress = (unsigned char*)points;
+
+       for (int i=0;i<numPoints;i++)
+       {
+               btPoint3* point = (btPoint3*)(pointsBaseAddress + i*stride);
+               m_points[i] = point[0];
+       }
+}
+
+btVector3      btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
+{
+       btVector3 supVec(0.f,0.f,0.f);
+       btScalar newDot,maxDot = -1e30f;
+
+       btVector3 vec = vec0;
+       btScalar lenSqr = vec.length2();
+       if (lenSqr < 0.0001f)
+       {
+               vec.setValue(1,0,0);
+       } else
+       {
+               float rlen = 1.f / btSqrt(lenSqr );
+               vec *= rlen;
+       }
+
+
+       for (size_t i=0;i<m_points.size();i++)
+       {
+               btPoint3 vtx = m_points[i] * m_localScaling;
+
+               newDot = vec.dot(vtx);
+               if (newDot > maxDot)
+               {
+                       maxDot = newDot;
+                       supVec = vtx;
+               }
+       }
+       return supVec;
+}
+
+void   btConvexHullShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+{
+       btScalar newDot;
+       //use 'w' component of supportVerticesOut?
+       {
+               for (int i=0;i<numVectors;i++)
+               {
+                       supportVerticesOut[i][3] = -1e30f;
+               }
+       }
+       for (size_t i=0;i<m_points.size();i++)
+       {
+               btPoint3 vtx = m_points[i] * m_localScaling;
+
+               for (int j=0;j<numVectors;j++)
+               {
+                       const btVector3& vec = vectors[j];
+                       
+                       newDot = vec.dot(vtx);
+                       if (newDot > supportVerticesOut[j][3])
+                       {
+                               //WARNING: don't swap next lines, the w component would get overwritten!
+                               supportVerticesOut[j] = vtx;
+                               supportVerticesOut[j][3] = newDot;
+                       }
+               }
+       }
+
+
+
+}
+       
+
+
+btVector3      btConvexHullShape::localGetSupportingVertex(const btVector3& vec)const
+{
+       btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
+
+       if ( getMargin()!=0.f )
+       {
+               btVector3 vecnorm = vec;
+               if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+               {
+                       vecnorm.setValue(-1.f,-1.f,-1.f);
+               } 
+               vecnorm.normalize();
+               supVertex+= getMargin() * vecnorm;
+       }
+       return supVertex;
+}
+
+
+
+
+
+
+
+
+
+//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
+//Please note that you can debug-draw btConvexHullShape with the Raytracer Demo
+int    btConvexHullShape::getNumVertices() const
+{
+       return m_points.size();
+}
+
+int btConvexHullShape::getNumEdges() const
+{
+       return m_points.size();
+}
+
+void btConvexHullShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
+{
+
+       int index0 = i%m_points.size();
+       int index1 = (i+1)%m_points.size();
+       pa = m_points[index0]*m_localScaling;
+       pb = m_points[index1]*m_localScaling;
+}
+
+void btConvexHullShape::getVertex(int i,btPoint3& vtx) const
+{
+       vtx = m_points[i]*m_localScaling;
+}
+
+int    btConvexHullShape::getNumPlanes() const
+{
+       return 0;
+}
+
+void btConvexHullShape::getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const
+{
+       assert(0);
+}
+
+//not yet
+bool btConvexHullShape::isInside(const btPoint3& pt,btScalar tolerance) const
+{
+       assert(0);
+       return false;
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h
new file mode 100644 (file)
index 0000000..afe7dd8
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+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 CONVEX_HULL_SHAPE_H
+#define CONVEX_HULL_SHAPE_H
+
+#include "btPolyhedralConvexShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+
+#include <vector>
+
+///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)
+class btConvexHullShape : public btPolyhedralConvexShape
+{
+       std::vector<btPoint3>   m_points;
+
+public:
+       ///this constructor optionally takes in a pointer to points. Each point is assumed to be 3 consecutive float (x,y,z), the striding defines the number of bytes between each point, in memory.
+       ///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint.
+       ///btConvexHullShape make an internal copy of the points.
+       btConvexHullShape(const float* points=0,int numPoints=0, int stride=sizeof(btPoint3));
+
+       void addPoint(const btPoint3& point)
+       {
+               m_points.push_back(point);
+       }
+       virtual btVector3       localGetSupportingVertex(const btVector3& vec)const;
+       virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
+       virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+       
+
+       virtual int     getShapeType()const { return CONVEX_HULL_SHAPE_PROXYTYPE; }
+
+       //debugging
+       virtual char*   getName()const {return "Convex";}
+
+       
+       virtual int     getNumVertices() const;
+       virtual int getNumEdges() const;
+       virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
+       virtual void getVertex(int i,btPoint3& vtx) const;
+       virtual int     getNumPlanes() const;
+       virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
+       virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
+
+
+
+};
+
+
+#endif //CONVEX_HULL_SHAPE_H
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
new file mode 100644 (file)
index 0000000..9537235
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+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 "btConvexShape.h"
+
+btConvexShape::btConvexShape()
+: m_localScaling(1.f,1.f,1.f),
+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(0.f,0.f,0.f);
+               vec[i] = 1.f;
+
+               btVector3 sv = localGetSupportingVertex(vec*trans.getBasis());
+
+               btVector3 tmp = trans(sv);
+               maxAabb[i] = tmp[i]+margin;
+               vec[i] = -1.f;
+               tmp = trans(localGetSupportingVertex(vec*trans.getBasis()));
+               minAabb[i] = tmp[i]-margin;
+       }
+};
+
+btVector3      btConvexShape::localGetSupportingVertex(const btVector3& vec)const
+ {
+        btVector3      supVertex = localGetSupportingVertexWithoutMargin(vec);
+
+       if ( getMargin()!=0.f )
+       {
+               btVector3 vecnorm = vec;
+               if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+               {
+                       vecnorm.setValue(-1.f,-1.f,-1.f);
+               } 
+               vecnorm.normalize();
+               supVertex+= getMargin() * vecnorm;
+       }
+       return supVertex;
+
+ }
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h
new file mode 100644 (file)
index 0000000..3ffde1b
--- /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.
+*/
+
+#ifndef CONVEX_SHAPE_INTERFACE1
+#define CONVEX_SHAPE_INTERFACE1
+
+#include "btCollisionShape.h"
+
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btMatrix3x3.h"
+#include <vector>
+#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
+
+//todo: get rid of this btConvexCastResult thing!
+struct btConvexCastResult;
+
+
+/// 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
+class btConvexShape : public btCollisionShape
+{
+       
+protected:
+
+       //local scaling. collisionMargin is not scaled !
+       btVector3       m_localScaling;
+
+       btVector3       m_implicitShapeDimensions;
+       
+       btScalar        m_collisionMargin;
+
+public:
+       btConvexShape();
+
+       virtual btVector3       localGetSupportingVertex(const btVector3& vec)const;
+       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;
+
+       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;
+       }
+
+
+       virtual void    setMargin(float margin)
+       {
+               m_collisionMargin = margin;
+       }
+       virtual float   getMargin() const
+       {
+               return m_collisionMargin;
+       }
+
+
+};
+
+
+
+#endif //CONVEX_SHAPE_INTERFACE1
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
new file mode 100644 (file)
index 0000000..9d8e7e1
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+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 "btConvexTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
+
+#include "LinearMath/btQuaternion.h"
+#include "BulletCollision/CollisionShapes/btStridingMeshInterface.h"
+
+
+btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface)
+:m_stridingMesh(meshInterface)
+{
+}
+
+
+
+
+///It's not nice to have all this virtual function overhead, so perhaps we can also gather the points once
+///but then we are duplicating
+class LocalSupportVertexCallback: public btInternalTriangleIndexCallback
+{
+
+       btVector3 m_supportVertexLocal;
+public:
+
+       btScalar m_maxDot;
+       btVector3 m_supportVecLocal;
+
+       LocalSupportVertexCallback(const btVector3& supportVecLocal)
+               : m_supportVertexLocal(0.f,0.f,0.f),
+               m_maxDot(-1e30f),
+                m_supportVecLocal(supportVecLocal)
+       {
+       }
+
+       virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int  triangleIndex)
+       {
+               for (int i=0;i<3;i++)
+               {
+                       btScalar dot = m_supportVecLocal.dot(triangle[i]);
+                       if (dot > m_maxDot)
+                       {
+                               m_maxDot = dot;
+                               m_supportVertexLocal = triangle[i];
+                       }
+               }
+       }
+       
+       btVector3       GetSupportVertexLocal()
+       {
+               return m_supportVertexLocal;
+       }
+
+};
+
+
+
+
+
+btVector3      btConvexTriangleMeshShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
+{
+       btVector3 supVec(0.f,0.f,0.f);
+
+       btVector3 vec = vec0;
+       btScalar lenSqr = vec.length2();
+       if (lenSqr < 0.0001f)
+       {
+               vec.setValue(1,0,0);
+       } else
+       {
+               float rlen = 1.f / btSqrt(lenSqr );
+               vec *= rlen;
+       }
+
+       LocalSupportVertexCallback      supportCallback(vec);
+       btVector3 aabbMax(1e30f,1e30f,1e30f);
+       m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
+       supVec = supportCallback.GetSupportVertexLocal();
+
+       return supVec;
+}
+
+void   btConvexTriangleMeshShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+{
+       //use 'w' component of supportVerticesOut?
+       {
+               for (int i=0;i<numVectors;i++)
+               {
+                       supportVerticesOut[i][3] = -1e30f;
+               }
+       }
+       
+       //todo: could do the batch inside the callback!
+
+
+       for (int j=0;j<numVectors;j++)
+       {
+               const btVector3& vec = vectors[j];
+               LocalSupportVertexCallback      supportCallback(vec);
+               btVector3 aabbMax(1e30f,1e30f,1e30f);
+               m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
+               supportVerticesOut[j] = supportCallback.GetSupportVertexLocal();
+       }
+       
+}
+       
+
+
+btVector3      btConvexTriangleMeshShape::localGetSupportingVertex(const btVector3& vec)const
+{
+       btVector3 supVertex = localGetSupportingVertexWithoutMargin(vec);
+
+       if ( getMargin()!=0.f )
+       {
+               btVector3 vecnorm = vec;
+               if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+               {
+                       vecnorm.setValue(-1.f,-1.f,-1.f);
+               } 
+               vecnorm.normalize();
+               supVertex+= getMargin() * vecnorm;
+       }
+       return supVertex;
+}
+
+
+
+
+
+
+
+
+
+//currently just for debugging (drawing), perhaps future support for algebraic continuous collision detection
+//Please note that you can debug-draw btConvexTriangleMeshShape with the Raytracer Demo
+int    btConvexTriangleMeshShape::getNumVertices() const
+{
+       //cache this?
+       return 0;
+       
+}
+
+int btConvexTriangleMeshShape::getNumEdges() const
+{
+       return 0;
+}
+
+void btConvexTriangleMeshShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
+{
+       assert(0);      
+}
+
+void btConvexTriangleMeshShape::getVertex(int i,btPoint3& vtx) const
+{
+       assert(0);
+}
+
+int    btConvexTriangleMeshShape::getNumPlanes() const
+{
+       return 0;
+}
+
+void btConvexTriangleMeshShape::getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const
+{
+       assert(0);
+}
+
+//not yet
+bool btConvexTriangleMeshShape::isInside(const btPoint3& pt,btScalar tolerance) const
+{
+       assert(0);
+       return false;
+}
+
+
+
+void   btConvexTriangleMeshShape::setLocalScaling(const btVector3& scaling)
+{
+       m_stridingMesh->setScaling(scaling);
+}
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
new file mode 100644 (file)
index 0000000..86e871c
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef CONVEX_TRIANGLEMESH_SHAPE_H
+#define CONVEX_TRIANGLEMESH_SHAPE_H
+
+
+#include "btPolyhedralConvexShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+
+#include <vector>
+
+/// 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.
+class btConvexTriangleMeshShape : public btPolyhedralConvexShape
+{
+
+       class btStridingMeshInterface*  m_stridingMesh;
+
+public:
+       btConvexTriangleMeshShape(btStridingMeshInterface* meshInterface);
+
+       class btStridingMeshInterface*  getStridingMesh()
+       {
+               return m_stridingMesh;
+       }
+       
+       virtual btVector3       localGetSupportingVertex(const btVector3& vec)const;
+       virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
+       virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+       
+       virtual int     getShapeType()const { return CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE; }
+
+       //debugging
+       virtual char*   getName()const {return "ConvexTrimesh";}
+       
+       virtual int     getNumVertices() const;
+       virtual int getNumEdges() const;
+       virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
+       virtual void getVertex(int i,btPoint3& vtx) const;
+       virtual int     getNumPlanes() const;
+       virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
+       virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
+
+       
+       void    setLocalScaling(const btVector3& scaling);
+
+};
+
+
+
+#endif //CONVEX_TRIANGLEMESH_SHAPE_H
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp
new file mode 100644 (file)
index 0000000..16b2634
--- /dev/null
@@ -0,0 +1,196 @@
+/*
+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 "btCylinderShape.h"
+#include "LinearMath/btPoint3.h"
+
+btCylinderShape::btCylinderShape (const btVector3& halfExtents)
+:btBoxShape(halfExtents)
+{
+
+}
+
+
+btCylinderShapeX::btCylinderShapeX (const btVector3& halfExtents)
+:btCylinderShape(halfExtents)
+{
+}
+
+
+btCylinderShapeZ::btCylinderShapeZ (const btVector3& halfExtents)
+:btCylinderShape(halfExtents)
+{
+}
+
+
+
+inline btVector3 CylinderLocalSupportX(const btVector3& halfExtents,const btVector3& v) 
+{
+const int cylinderUpAxis = 0;
+const int XX = 1;
+const int YY = 0;
+const int ZZ = 2;
+
+       //mapping depends on how cylinder local orientation is
+       // extents of the cylinder is: X,Y is for radius, and Z for height
+
+
+       float radius = halfExtents[XX];
+       float halfHeight = halfExtents[cylinderUpAxis];
+
+
+    btVector3 tmp;
+       btScalar d ;
+
+    btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
+    if (s != btScalar(0.0))
+       {
+        d = radius / s;  
+               tmp[XX] = v[XX] * d;
+               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
+               tmp[ZZ] = v[ZZ] * d;
+               return tmp;
+       }
+    else
+       {
+           tmp[XX] = radius;
+               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
+               tmp[ZZ] = btScalar(0.0);
+               return tmp;
+    }
+
+
+}
+
+
+
+
+
+
+inline  btVector3 CylinderLocalSupportY(const btVector3& halfExtents,const btVector3& v) 
+{
+
+const int cylinderUpAxis = 1;
+const int XX = 0;
+const int YY = 1;
+const int ZZ = 2;
+
+
+       float radius = halfExtents[XX];
+       float halfHeight = halfExtents[cylinderUpAxis];
+
+
+    btVector3 tmp;
+       btScalar d ;
+
+    btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
+    if (s != btScalar(0.0))
+       {
+        d = radius / s;  
+               tmp[XX] = v[XX] * d;
+               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
+               tmp[ZZ] = v[ZZ] * d;
+               return tmp;
+       }
+    else
+       {
+           tmp[XX] = radius;
+               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
+               tmp[ZZ] = btScalar(0.0);
+               return tmp;
+    }
+
+}
+
+inline btVector3 CylinderLocalSupportZ(const btVector3& halfExtents,const btVector3& v) 
+{
+const int cylinderUpAxis = 2;
+const int XX = 0;
+const int YY = 2;
+const int ZZ = 1;
+
+       //mapping depends on how cylinder local orientation is
+       // extents of the cylinder is: X,Y is for radius, and Z for height
+
+
+       float radius = halfExtents[XX];
+       float halfHeight = halfExtents[cylinderUpAxis];
+
+
+    btVector3 tmp;
+       btScalar d ;
+
+    btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
+    if (s != btScalar(0.0))
+       {
+        d = radius / s;  
+               tmp[XX] = v[XX] * d;
+               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
+               tmp[ZZ] = v[ZZ] * d;
+               return tmp;
+       }
+    else
+       {
+           tmp[XX] = radius;
+               tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
+               tmp[ZZ] = btScalar(0.0);
+               return tmp;
+    }
+
+
+}
+
+btVector3      btCylinderShapeX::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+{
+       return CylinderLocalSupportX(getHalfExtents(),vec);
+}
+
+
+btVector3      btCylinderShapeZ::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+{
+       return CylinderLocalSupportZ(getHalfExtents(),vec);
+}
+btVector3      btCylinderShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+{
+       return CylinderLocalSupportY(getHalfExtents(),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]);
+       }
+}
+
+void   btCylinderShapeZ::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+{
+       for (int i=0;i<numVectors;i++)
+       {
+               supportVerticesOut[i] = CylinderLocalSupportZ(getHalfExtents(),vectors[i]);
+       }
+}
+
+
+
+
+void   btCylinderShapeX::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+{
+       for (int i=0;i<numVectors;i++)
+       {
+               supportVerticesOut[i] = CylinderLocalSupportX(getHalfExtents(),vectors[i]);
+       }
+}
+
+
diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h
new file mode 100644 (file)
index 0000000..bb0e429
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+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 CYLINDER_MINKOWSKI_H
+#define CYLINDER_MINKOWSKI_H
+
+#include "btBoxShape.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "LinearMath/btVector3.h"
+
+/// implements cylinder shape interface
+class btCylinderShape : public btBoxShape
+
+{
+
+public:
+       btCylinderShape (const btVector3& halfExtents);
+       
+       ///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 btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
+
+       virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
+
+       virtual btVector3       localGetSupportingVertex(const btVector3& vec) const
+       {
+
+               btVector3 supVertex;
+               supVertex = localGetSupportingVertexWithoutMargin(vec);
+               
+               if ( getMargin()!=0.f )
+               {
+                       btVector3 vecnorm = vec;
+                       if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+                       {
+