bullet: Update to current svn, r2636
authorSergej Reich <sergej.reich@googlemail.com>
Thu, 7 Mar 2013 17:53:16 +0000 (17:53 +0000)
committerSergej Reich <sergej.reich@googlemail.com>
Thu, 7 Mar 2013 17:53:16 +0000 (17:53 +0000)
Apply patches in patches directory, remove patches that were applied
upstream.
If you made changes without adding a patch, please check.

Fixes [#32233] exporting bullet format results in corrupt files.

175 files changed:
extern/bullet2/CMakeLists.txt
extern/bullet2/patches/make_id.patch [deleted file]
extern/bullet2/patches/pvs_warning_fixes.patch [deleted file]
extern/bullet2/readme.txt
extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h [new file with mode: 0644]
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/CollisionShapes/btBox2dShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConvex2dShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.h
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h
extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h
extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleInfoMap.h
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h
extern/bullet2/src/BulletCollision/CollisionShapes/btUniformScalingShape.h
extern/bullet2/src/BulletCollision/Gimpact/btBoxCollision.h
extern/bullet2/src/BulletCollision/Gimpact/btCompoundFromGimpact.h
extern/bullet2/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp
extern/bullet2/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h
extern/bullet2/src/BulletCollision/Gimpact/gim_array.h
extern/bullet2/src/BulletCollision/Gimpact/gim_box_collision.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp
extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h
extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.cpp
extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGearConstraint.cpp [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGearConstraint.h [new file with mode: 0644]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSliderConstraint.cpp [changed mode: 0644->0755]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSliderConstraint.h [changed mode: 0644->0755]
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverBody.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp
extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h
extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h
extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h
extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp
extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h
extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp
extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.cpp
extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.h
extern/bullet2/src/BulletSoftBody/btSoftBody.cpp
extern/bullet2/src/BulletSoftBody/btSoftBody.h
extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp
extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h
extern/bullet2/src/BulletSoftBody/btSoftBodyData.h
extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h
extern/bullet2/src/BulletSoftBody/btSoftBodySolvers.h
extern/bullet2/src/BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp
extern/bullet2/src/BulletSoftBody/btSoftRigidCollisionAlgorithm.h
extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp
extern/bullet2/src/BulletSoftBody/btSoftSoftCollisionAlgorithm.cpp
extern/bullet2/src/BulletSoftBody/btSoftSoftCollisionAlgorithm.h
extern/bullet2/src/BulletSoftBody/btSparseSDF.h
extern/bullet2/src/LinearMath/btAabbUtil2.h
extern/bullet2/src/LinearMath/btAlignedAllocator.cpp
extern/bullet2/src/LinearMath/btAlignedObjectArray.h
extern/bullet2/src/LinearMath/btConvexHull.cpp
extern/bullet2/src/LinearMath/btConvexHullComputer.cpp
extern/bullet2/src/LinearMath/btDefaultMotionState.h
extern/bullet2/src/LinearMath/btGrahamScan2dConvexHull.h
extern/bullet2/src/LinearMath/btIDebugDraw.h
extern/bullet2/src/LinearMath/btMatrix3x3.h
extern/bullet2/src/LinearMath/btPolarDecomposition.cpp [new file with mode: 0644]
extern/bullet2/src/LinearMath/btPolarDecomposition.h [new file with mode: 0644]
extern/bullet2/src/LinearMath/btQuadWord.h
extern/bullet2/src/LinearMath/btQuaternion.h
extern/bullet2/src/LinearMath/btScalar.h
extern/bullet2/src/LinearMath/btSerializer.cpp
extern/bullet2/src/LinearMath/btSerializer.h
extern/bullet2/src/LinearMath/btTransform.h
extern/bullet2/src/LinearMath/btVector3.cpp [new file with mode: 0644]
extern/bullet2/src/LinearMath/btVector3.h
extern/bullet2/src/btBulletCollisionCommon.h
extern/bullet2/src/btBulletDynamicsCommon.h
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp

index 3d75794..02ca2cd 100644 (file)
@@ -139,6 +139,7 @@ set(SRC
        src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp
        src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp
        src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp
+       src/BulletDynamics/ConstraintSolver/btGearConstraint.cpp
        src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
        src/BulletDynamics/Dynamics/btRigidBody.cpp
        src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
@@ -162,6 +163,8 @@ set(SRC
        src/LinearMath/btGeometryUtil.cpp
        src/LinearMath/btQuickprof.cpp
        src/LinearMath/btSerializer.cpp
+       src/LinearMath/btVector3.cpp
+       src/LinearMath/btPolarDecomposition.cpp
        
        
        src/BulletCollision/BroadphaseCollision/btAxisSweep3.h
@@ -183,6 +186,7 @@ set(SRC
        src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h
        src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
        src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
+       src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h
        src/BulletCollision/CollisionDispatch/btCollisionObject.h
        src/BulletCollision/CollisionDispatch/btCollisionWorld.h
        src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
@@ -303,6 +307,7 @@ set(SRC
        src/BulletDynamics/ConstraintSolver/btSolverConstraint.h
        src/BulletDynamics/ConstraintSolver/btTypedConstraint.h
        src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h
+       src/BulletDynamics/ConstraintSolver/btGearConstraint.h
        src/BulletDynamics/Dynamics/btActionInterface.h
        src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
        src/BulletDynamics/Dynamics/btDynamicsWorld.h
@@ -353,6 +358,7 @@ set(SRC
        src/LinearMath/btTransform.h
        src/LinearMath/btTransformUtil.h
        src/LinearMath/btVector3.h
+       src/LinearMath/btPolarDecomposition.h
        
        
        src/btBulletCollisionCommon.h
diff --git a/extern/bullet2/patches/make_id.patch b/extern/bullet2/patches/make_id.patch
deleted file mode 100644 (file)
index 959e578..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-Index: src/LinearMath/btSerializer.h
-===================================================================
---- src/LinearMath/btSerializer.h      (revision 46625)
-+++ src/LinearMath/btSerializer.h      (working copy)
-@@ -106,23 +106,23 @@
- #define BT_HEADER_LENGTH 12
- #if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__)
--#     define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
-+#     define BT_MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) )
- #else
--#     define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
-+#     define BT_MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) )
- #endif
--#define BT_SOFTBODY_CODE              MAKE_ID('S','B','D','Y')
--#define BT_COLLISIONOBJECT_CODE MAKE_ID('C','O','B','J')
--#define BT_RIGIDBODY_CODE             MAKE_ID('R','B','D','Y')
--#define BT_CONSTRAINT_CODE            MAKE_ID('C','O','N','S')
--#define BT_BOXSHAPE_CODE              MAKE_ID('B','O','X','S')
--#define BT_QUANTIZED_BVH_CODE MAKE_ID('Q','B','V','H')
--#define BT_TRIANLGE_INFO_MAP  MAKE_ID('T','M','A','P')
--#define BT_SHAPE_CODE                 MAKE_ID('S','H','A','P')
--#define BT_ARRAY_CODE                 MAKE_ID('A','R','A','Y')
--#define BT_SBMATERIAL_CODE            MAKE_ID('S','B','M','T')
--#define BT_SBNODE_CODE                        MAKE_ID('S','B','N','D')
--#define BT_DNA_CODE                           MAKE_ID('D','N','A','1')
-+#define BT_SOFTBODY_CODE              BT_MAKE_ID('S','B','D','Y')
-+#define BT_COLLISIONOBJECT_CODE BT_MAKE_ID('C','O','B','J')
-+#define BT_RIGIDBODY_CODE             BT_MAKE_ID('R','B','D','Y')
-+#define BT_CONSTRAINT_CODE            BT_MAKE_ID('C','O','N','S')
-+#define BT_BOXSHAPE_CODE              BT_MAKE_ID('B','O','X','S')
-+#define BT_QUANTIZED_BVH_CODE BT_MAKE_ID('Q','B','V','H')
-+#define BT_TRIANLGE_INFO_MAP  BT_MAKE_ID('T','M','A','P')
-+#define BT_SHAPE_CODE                 BT_MAKE_ID('S','H','A','P')
-+#define BT_ARRAY_CODE                 BT_MAKE_ID('A','R','A','Y')
-+#define BT_SBMATERIAL_CODE            BT_MAKE_ID('S','B','M','T')
-+#define BT_SBNODE_CODE                        BT_MAKE_ID('S','B','N','D')
-+#define BT_DNA_CODE                           BT_MAKE_ID('D','N','A','1')
- struct        btPointerUid
diff --git a/extern/bullet2/patches/pvs_warning_fixes.patch b/extern/bullet2/patches/pvs_warning_fixes.patch
deleted file mode 100644 (file)
index 5a3fe14..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-Index: extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h
-===================================================================
---- extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h    (Revision 45907)
-+++ extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h    (Revision 45908)
-@@ -45,7 +45,9 @@
-       int     getTriangleIndex() const
-       {
-               // Get only the lower bits where the triangle index is stored
--              return (m_PartIdTriangleIndex&~((~0)<<(31-MAX_NUM_PARTS_IN_BITS)));
-+              unsigned int x = 0;
-+              unsigned int y = (~(x&0))<<(31-MAX_NUM_PARTS_IN_BITS);
-+              return (m_PartIdTriangleIndex&~(y));
-       }
-       int     getPartId() const
-       {
-Index: extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
-===================================================================
---- extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h    (Revision 45907)
-+++ extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h    (Revision 45908)
-@@ -78,8 +78,10 @@
-       int     getTriangleIndex() const
-       {
-               btAssert(isLeafNode());
-+              unsigned int x=0;
-+              unsigned int y = (~(x&0))<<(31-MAX_NUM_PARTS_IN_BITS);
-               // Get only the lower bits where the triangle index is stored
--              return (m_escapeIndexOrTriangleIndex&~((~0)<<(31-MAX_NUM_PARTS_IN_BITS)));
-+              return (m_escapeIndexOrTriangleIndex&~(y));
-       }
-       int     getPartId() const
-       {
index 7f5a7f1..dd806d4 100644 (file)
@@ -7,13 +7,6 @@ Erwin
 Apply patches/ghost_softbody.patch to prevent softbodies being hit by ghost objects.
 Originally committed in blender svn revision: 43905.
 
-Apply patches/pvs_warning_fixes.patch to fix warnings reported by PVS-Studio.
-Originally committed in blender svn revision: 45908.
-
-Apply patches/make_id.patch to prevent duplicated define of MAKE_ID macro in blender
-side and bullet side.
-Sergey
-
 Apply patches/ghost_character.patch to prevent characters from colliding with ghost objects.
 Mitchell
 
index 4f4d94b..cd6e1a8 100644 (file)
@@ -615,7 +615,7 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::removeHandle(BP_FP_INT_TYPE handle,bt
 }
 
 template <typename BP_FP_INT_TYPE>
-void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool(btDispatcher* dispatcher)
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool(btDispatcher* /*dispatcher*/)
 {
        if (m_numHandles == 0)
        {
index 36eec97..4056562 100644 (file)
@@ -23,6 +23,7 @@ struct btBroadphaseProxy;
 class btDispatcher;
 class btManifoldResult;
 class btCollisionObject;
+struct btCollisionObjectWrapper;
 struct btDispatcherInfo;
 class  btPersistentManifold;
 
@@ -69,7 +70,7 @@ public:
 
        virtual ~btCollisionAlgorithm() {};
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
 
index 409da80..b649368 100644 (file)
@@ -57,7 +57,7 @@ subject to the following restrictions:
 // Specific methods implementation
 
 //SSE gives errors on a MSVC 7.1
-#if defined (BT_USE_SSE) && defined (_WIN32)
+#if defined (BT_USE_SSE) //&& defined (_WIN32)
 #define DBVT_SELECT_IMPL               DBVT_IMPL_SSE
 #define DBVT_MERGE_IMPL                        DBVT_IMPL_SSE
 #define DBVT_INT0_IMPL                 DBVT_IMPL_SSE
@@ -160,6 +160,10 @@ struct     btDbvtAabbMm
                btDbvtAabbMm& r);
        DBVT_INLINE friend bool                 NotEqual(       const btDbvtAabbMm& a,
                const btDbvtAabbMm& b);
+    
+    DBVT_INLINE btVector3&     tMins() { return(mi); }
+       DBVT_INLINE btVector3&  tMaxs() { return(mx); }
+    
 private:
        DBVT_INLINE void                                AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
 private:
@@ -320,7 +324,7 @@ struct      btDbvt
        DBVT_PREFIX
                void            collideTV(      const btDbvtNode* root,
                const btDbvtVolume& volume,
-               DBVT_IPOLICY);
+               DBVT_IPOLICY) const;
        ///rayTest is a re-entrant ray test, and can be called in parallel as long as the btAlignedAlloc is thread-safe (uses locking etc)
        ///rayTest is slower than rayTestInternal, because it builds a local stack, using memory allocations, and it recomputes signs/rayDirectionInverses each time
        DBVT_PREFIX
@@ -519,7 +523,11 @@ DBVT_INLINE bool           Intersect(      const btDbvtAabbMm& a,
 #if    DBVT_INT0_IMPL == DBVT_IMPL_SSE
        const __m128    rt(_mm_or_ps(   _mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
                _mm_cmplt_ps(_mm_load_ps(a.mx),_mm_load_ps(b.mi))));
+#if defined (_WIN32)
        const __int32*  pu((const __int32*)&rt);
+#else
+    const int* pu((const int*)&rt);
+#endif
        return((pu[0]|pu[1]|pu[2])==0);
 #else
        return( (a.mi.x()<=b.mx.x())&&
@@ -568,7 +576,12 @@ DBVT_INLINE int                    Select( const btDbvtAabbMm& o,
                                                           const btDbvtAabbMm& b)
 {
 #if    DBVT_SELECT_IMPL == DBVT_IMPL_SSE
+    
+#if defined (_WIN32)
        static ATTRIBUTE_ALIGNED16(const unsigned __int32)      mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
+#else
+    static ATTRIBUTE_ALIGNED16(const unsigned int)     mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x00000000 /*0x7fffffff*/};
+#endif
        ///@todo: the intrinsic version is 11% slower
 #if DBVT_USE_INTRINSIC_SSE
 
@@ -908,7 +921,7 @@ inline void         btDbvt::collideTT(      const btDbvtNode* root0,
 DBVT_PREFIX
 inline void            btDbvt::collideTV(      const btDbvtNode* root,
                                                                  const btDbvtVolume& vol,
-                                                                 DBVT_IPOLICY)
+                                                                 DBVT_IPOLICY) const
 {
        DBVT_CHECKTYPE
                if(root)
index a79cf94..1ebb377 100644 (file)
@@ -22,7 +22,7 @@ struct btBroadphaseProxy;
 class btRigidBody;
 class  btCollisionObject;
 class btOverlappingPairCache;
-
+struct btCollisionObjectWrapper;
 
 class btPersistentManifold;
 class btStackAlloc;
@@ -76,17 +76,17 @@ class btDispatcher
 public:
        virtual ~btDispatcher() ;
 
-       virtual btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold=0) = 0;
+       virtual btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold=0) = 0;
 
-       virtual btPersistentManifold*   getNewManifold(void* body0,void* body1)=0;
+       virtual btPersistentManifold*   getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1)=0;
 
        virtual void releaseManifold(btPersistentManifold* manifold)=0;
 
        virtual void clearManifold(btPersistentManifold* manifold)=0;
 
-       virtual bool    needsCollision(btCollisionObject* body0,btCollisionObject* body1) = 0;
+       virtual bool    needsCollision(const btCollisionObject* body0,const btCollisionObject* body1) = 0;
 
-       virtual bool    needsResponse(btCollisionObject* body0,btCollisionObject* body1)=0;
+       virtual bool    needsResponse(const btCollisionObject* body0,const btCollisionObject* body1)=0;
 
        virtual void    dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher)  =0;
 
index c911435..889216d 100644 (file)
@@ -96,7 +96,25 @@ void btQuantizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btV
        m_bvhAabbMax = bvhAabbMax + clampValue;
        btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
        m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
+
        m_useQuantization = true;
+
+       {
+               unsigned short vecIn[3];
+               btVector3 v;
+               {
+                       quantize(vecIn,m_bvhAabbMin,false);
+                       v = unQuantize(vecIn);
+                       m_bvhAabbMin.setMin(v-clampValue);
+               }
+               {
+                       quantize(vecIn,m_bvhAabbMax,true);
+                       v = unQuantize(vecIn);
+                       m_bvhAabbMax.setMax(v+clampValue);
+               }
+               aabbSize = m_bvhAabbMax - m_bvhAabbMin;
+               m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
+       }
 }
 
 
index 23a5c75..6340178 100644 (file)
@@ -158,7 +158,6 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
                                depth = -(radius-distance);
                        } else
                        {
-                               btScalar distance = 0.f;
                                resultNormal = normal;
                                point = contactPoint;
                                depth = -radius;
index 7e5da6c..57f1464 100644 (file)
@@ -24,7 +24,7 @@ btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisio
 //m_colObj1(0)
 {
 }
-btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* colObj0,btCollisionObject* colObj1)
+btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* )
 :btCollisionAlgorithm(ci)
 //,
 //m_colObj0(0),
index 25fe088..489812b 100644 (file)
@@ -28,7 +28,7 @@ public:
 
        btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci);
 
-       btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* colObj0,btCollisionObject* colObj1);
+       btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
        virtual ~btActivatingCollisionAlgorithm();
 
index 2182d0d..2c36277 100644 (file)
@@ -22,17 +22,18 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btBoxBoxDetector.h"
 #include "BulletCollision/CollisionShapes/btBox2dShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 #define USE_PERSISTENT_CONTACTS 1
 
-btBox2dBox2dCollisionAlgorithm::btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* obj0,btCollisionObject* obj1)
-: btActivatingCollisionAlgorithm(ci,obj0,obj1),
+btBox2dBox2dCollisionAlgorithm::btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* obj0Wrap,const btCollisionObjectWrapper* obj1Wrap)
+: btActivatingCollisionAlgorithm(ci,obj0Wrap,obj1Wrap),
 m_ownManifold(false),
 m_manifoldPtr(mf)
 {
-       if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0,obj1))
+       if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0Wrap->getCollisionObject(),obj1Wrap->getCollisionObject()))
        {
-               m_manifoldPtr = m_dispatcher->getNewManifold(obj0,obj1);
+               m_manifoldPtr = m_dispatcher->getNewManifold(obj0Wrap->getCollisionObject(),obj1Wrap->getCollisionObject());
                m_ownManifold = true;
        }
 }
@@ -52,19 +53,18 @@ btBox2dBox2dCollisionAlgorithm::~btBox2dBox2dCollisionAlgorithm()
 void b2CollidePolygons(btManifoldResult* manifold,  const btBox2dShape* polyA, const btTransform& xfA, const btBox2dShape* polyB, const btTransform& xfB);
 
 //#include <stdio.h>
-void btBox2dBox2dCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btBox2dBox2dCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        if (!m_manifoldPtr)
                return;
 
-       btCollisionObject*      col0 = body0;
-       btCollisionObject*      col1 = body1;
-       btBox2dShape* box0 = (btBox2dShape*)col0->getCollisionShape();
-       btBox2dShape* box1 = (btBox2dShape*)col1->getCollisionShape();
+       
+       const btBox2dShape* box0 = (const btBox2dShape*)body0Wrap->getCollisionShape();
+       const btBox2dShape* box1 = (const btBox2dShape*)body1Wrap->getCollisionShape();
 
        resultOut->setPersistentManifold(m_manifoldPtr);
 
-       b2CollidePolygons(resultOut,box0,col0->getWorldTransform(),box1,col1->getWorldTransform());
+       b2CollidePolygons(resultOut,box0,body0Wrap->getWorldTransform(),box1,body1Wrap->getWorldTransform());
 
        //  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
        if (m_ownManifold)
@@ -151,15 +151,8 @@ static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1
        int index = 0;
        btScalar minDot = BT_LARGE_FLOAT;
 
-       for (int i = 0; i < count2; ++i)
-       {
-               btScalar dot = b2Dot(vertices2[i], normal1);
-               if (dot < minDot)
-               {
-                       minDot = dot;
-                       index = i;
-               }
-       }
+    if( count2 > 0 )
+        index = (int) normal1.minDot( vertices2, count2, minDot);
 
        btVector3 v1 = b2Mul(xf1, vertices1[edge1]);
        btVector3 v2 = b2Mul(xf2, vertices2[index]);
@@ -181,16 +174,9 @@ static btScalar FindMaxSeparation(int* edgeIndex,
 
        // Find edge normal on poly1 that has the largest projection onto d.
        int edge = 0;
-       btScalar maxDot = -BT_LARGE_FLOAT;
-       for (int i = 0; i < count1; ++i)
-       {
-               btScalar dot = b2Dot(normals1[i], dLocal1);
-               if (dot > maxDot)
-               {
-                       maxDot = dot;
-                       edge = i;
-               }
-       }
+    btScalar maxDot;
+    if( count1 > 0 )
+        edge = (int) dLocal1.maxDot( normals1, count1, maxDot);
 
        // Get the separation for the edge normal.
        btScalar s = EdgeSeparation(poly1, xf1, edge, poly2, xf2);
@@ -368,7 +354,7 @@ void b2CollidePolygons(btManifoldResult* manifold,
        btVector3 v11 = vertices1[edge1];
        btVector3 v12 = edge1 + 1 < count1 ? vertices1[edge1+1] : vertices1[0];
 
-       btVector3 dv = v12 - v11;
+       //btVector3 dv = v12 - v11;
        btVector3 sideNormal = b2Mul(xf1.getBasis(), v12 - v11);
        sideNormal.normalize();
        btVector3 frontNormal = btCrossS(sideNormal, 1.0f);
index 97c5be7..6ea6e89 100644 (file)
@@ -33,11 +33,11 @@ public:
        btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
                : btActivatingCollisionAlgorithm(ci) {}
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
-       btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
+       btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
        virtual ~btBox2dBox2dCollisionAlgorithm();
 
@@ -52,11 +52,11 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        int bbsize = sizeof(btBox2dBox2dCollisionAlgorithm);
                        void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
-                       return new(ptr) btBox2dBox2dCollisionAlgorithm(0,ci,body0,body1);
+                       return new(ptr) btBox2dBox2dCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
                }
        };
 
index 4962885..ac68968 100644 (file)
@@ -18,17 +18,17 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btBoxShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "btBoxBoxDetector.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #define USE_PERSISTENT_CONTACTS 1
 
-btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* obj0,btCollisionObject* obj1)
-: btActivatingCollisionAlgorithm(ci,obj0,obj1),
+btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_ownManifold(false),
 m_manifoldPtr(mf)
 {
-       if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0,obj1))
+       if (!m_manifoldPtr && m_dispatcher->needsCollision(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject()))
        {
-               m_manifoldPtr = m_dispatcher->getNewManifold(obj0,obj1);
+               m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
                m_ownManifold = true;
        }
 }
@@ -42,15 +42,14 @@ btBoxBoxCollisionAlgorithm::~btBoxBoxCollisionAlgorithm()
        }
 }
 
-void btBoxBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btBoxBoxCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        if (!m_manifoldPtr)
                return;
 
-       btCollisionObject*      col0 = body0;
-       btCollisionObject*      col1 = body1;
-       btBoxShape* box0 = (btBoxShape*)col0->getCollisionShape();
-       btBoxShape* box1 = (btBoxShape*)col1->getCollisionShape();
+       
+       const btBoxShape* box0 = (btBoxShape*)body0Wrap->getCollisionShape();
+       const btBoxShape* box1 = (btBoxShape*)body1Wrap->getCollisionShape();
 
 
 
@@ -62,8 +61,8 @@ void btBoxBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCo
 
        btDiscreteCollisionDetectorInterface::ClosestPointInput input;
        input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
-       input.m_transformA = body0->getWorldTransform();
-       input.m_transformB = body1->getWorldTransform();
+       input.m_transformA = body0Wrap->getWorldTransform();
+       input.m_transformB = body1Wrap->getWorldTransform();
 
        btBoxBoxDetector detector(box0,box1);
        detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
index f0bbae6..59808df 100644 (file)
@@ -33,11 +33,11 @@ public:
        btBoxBoxCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
                : btActivatingCollisionAlgorithm(ci) {}
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
-       btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
+       btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
        virtual ~btBoxBoxCollisionAlgorithm();
 
@@ -52,11 +52,11 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        int bbsize = sizeof(btBoxBoxCollisionAlgorithm);
                        void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
-                       return new(ptr) btBoxBoxCollisionAlgorithm(0,ci,body0,body1);
+                       return new(ptr) btBoxBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
                }
        };
 
index a7c8cf1..7043bde 100644 (file)
@@ -24,7 +24,7 @@ subject to the following restrictions:
 #include <float.h>
 #include <string.h>
 
-btBoxBoxDetector::btBoxBoxDetector(btBoxShape* box1,btBoxShape* box2)
+btBoxBoxDetector::btBoxBoxDetector(const btBoxShape* box1,const btBoxShape* box2)
 : m_box1(box1),
 m_box2(box2)
 {
index 3c941f7..3924377 100644 (file)
@@ -28,12 +28,12 @@ class btBoxShape;
 /// re-distributed under the Zlib license with permission from Russell L. Smith
 struct btBoxBoxDetector : public btDiscreteCollisionDetectorInterface
 {
-       btBoxShape* m_box1;
-       btBoxShape* m_box2;
+       const btBoxShape* m_box1;
+       const btBoxShape* m_box2;
 
 public:
 
-       btBoxBoxDetector(btBoxShape* box1,btBoxShape* box2);
+       btBoxBoxDetector(const btBoxShape* box1,const btBoxShape* box2);
 
        virtual ~btBoxBoxDetector() {};
 
index 1d7e744..62ee66c 100644 (file)
@@ -19,7 +19,7 @@ subject to the following restrictions:
 #include "LinearMath/btAlignedObjectArray.h"
 class btCollisionAlgorithm;
 class btCollisionObject;
-
+struct btCollisionObjectWrapper;
 struct btCollisionAlgorithmConstructionInfo;
 
 ///Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm
@@ -33,11 +33,11 @@ struct btCollisionAlgorithmCreateFunc
        }
        virtual ~btCollisionAlgorithmCreateFunc(){};
 
-       virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& , btCollisionObject* body0,btCollisionObject* body1)
+       virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& , const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
        {
                
-               (void)body0;
-               (void)body1;
+               (void)body0Wrap;
+               (void)body1Wrap;
                return 0;
        }
 };
index 29674f3..669d0b6 100644 (file)
@@ -25,6 +25,7 @@ subject to the following restrictions:
 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
 #include "LinearMath/btPoolAllocator.h"
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 int gNumManifold = 0;
 
@@ -67,15 +68,13 @@ btCollisionDispatcher::~btCollisionDispatcher()
 {
 }
 
-btPersistentManifold*  btCollisionDispatcher::getNewManifold(void* b0,void* b1) 
+btPersistentManifold*  btCollisionDispatcher::getNewManifold(const btCollisionObject* body0,const btCollisionObject* body1) 
 { 
        gNumManifold++;
        
        //btAssert(gNumManifold < 65535);
        
 
-       btCollisionObject* body0 = (btCollisionObject*)b0;
-       btCollisionObject* body1 = (btCollisionObject*)b1;
 
        //optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
        
@@ -85,7 +84,7 @@ btPersistentManifold* btCollisionDispatcher::getNewManifold(void* b0,void* b1)
 
        btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold());
                
-       void* mem = 0;
+       void* mem = 0;
        
        if (m_persistentManifoldPoolAllocator->getFreeCount())
        {
@@ -143,14 +142,14 @@ void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 
        
 
-btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold)
+btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold)
 {
        
        btCollisionAlgorithmConstructionInfo ci;
 
        ci.m_dispatcher1 = this;
        ci.m_manifold = sharedManifold;
-       btCollisionAlgorithm* algo = m_doubleDispatch[body0->getCollisionShape()->getShapeType()][body1->getCollisionShape()->getShapeType()]->CreateCollisionAlgorithm(ci,body0,body1);
+       btCollisionAlgorithm* algo = m_doubleDispatch[body0Wrap->getCollisionShape()->getShapeType()][body1Wrap->getCollisionShape()->getShapeType()]->CreateCollisionAlgorithm(ci,body0Wrap,body1Wrap);
 
        return algo;
 }
@@ -158,7 +157,7 @@ btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* bo
 
 
 
-bool   btCollisionDispatcher::needsResponse(btCollisionObject* body0,btCollisionObject* body1)
+bool   btCollisionDispatcher::needsResponse(const btCollisionObject* body0,const btCollisionObject* body1)
 {
        //here you can do filtering
        bool hasResponse = 
@@ -169,7 +168,7 @@ bool        btCollisionDispatcher::needsResponse(btCollisionObject* body0,btCollisionOb
        return hasResponse;
 }
 
-bool   btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionObject* body1)
+bool   btCollisionDispatcher::needsCollision(const btCollisionObject* body0,const btCollisionObject* body1)
 {
        btAssert(body0);
        btAssert(body1);
@@ -259,20 +258,25 @@ void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair,
 
                if (dispatcher.needsCollision(colObj0,colObj1))
                {
+                       btCollisionObjectWrapper obj0Wrap(0,colObj0->getCollisionShape(),colObj0,colObj0->getWorldTransform(),-1,-1);
+                       btCollisionObjectWrapper obj1Wrap(0,colObj1->getCollisionShape(),colObj1,colObj1->getWorldTransform(),-1,-1);
+
+
                        //dispatcher will keep algorithms persistent in the collision pair
                        if (!collisionPair.m_algorithm)
                        {
-                               collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
+                               collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap);
                        }
 
                        if (collisionPair.m_algorithm)
                        {
-                               btManifoldResult contactPointResult(colObj0,colObj1);
+                               btManifoldResult contactPointResult(&obj0Wrap,&obj1Wrap);
                                
                                if (dispatchInfo.m_dispatchFunc ==              btDispatcherInfo::DISPATCH_DISCRETE)
                                {
                                        //discrete collision detection query
-                                       collisionPair.m_algorithm->processCollision(colObj0,colObj1,dispatchInfo,&contactPointResult);
+                                       
+                                       collisionPair.m_algorithm->processCollision(&obj0Wrap,&obj1Wrap,dispatchInfo,&contactPointResult);
                                } else
                                {
                                        //continuous collision detection query, time of impact (toi)
index 5accad9..92696ee 100644 (file)
@@ -108,19 +108,18 @@ public:
 
        virtual ~btCollisionDispatcher();
 
-       virtual btPersistentManifold*   getNewManifold(void* b0,void* b1);
+       virtual btPersistentManifold*   getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1);
        
        virtual void releaseManifold(btPersistentManifold* manifold);
 
 
        virtual void clearManifold(btPersistentManifold* manifold);
 
-                       
-       btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0);
+       btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold = 0);
                
-       virtual bool    needsCollision(btCollisionObject* body0,btCollisionObject* body1);
+       virtual bool    needsCollision(const btCollisionObject* body0,const btCollisionObject* body1);
        
-       virtual bool    needsResponse(btCollisionObject* body0,btCollisionObject* body1);
+       virtual bool    needsResponse(const btCollisionObject* body0,const btCollisionObject* body1);
        
        virtual void    dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) ;
 
index 580ea34..cf8ed59 100644 (file)
@@ -31,6 +31,7 @@ btCollisionObject::btCollisionObject()
                m_activationState1(1),
                m_deactivationTime(btScalar(0.)),
                m_friction(btScalar(0.5)),
+               m_rollingFriction(0.0f),
                m_restitution(btScalar(0.)),
                m_internalType(CO_COLLISION_OBJECT),
                m_userObjectPointer(0),
@@ -46,18 +47,18 @@ btCollisionObject::~btCollisionObject()
 {
 }
 
-void btCollisionObject::setActivationState(int newState) 
+void btCollisionObject::setActivationState(int newState) const
 { 
        if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
                m_activationState1 = newState;
 }
 
-void btCollisionObject::forceActivationState(int newState)
+void btCollisionObject::forceActivationState(int newState) const
 {
        m_activationState1 = newState;
 }
 
-void btCollisionObject::activate(bool forceActivation)
+void btCollisionObject::activate(bool forceActivation) const
 {
        if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT)))
        {
@@ -85,9 +86,9 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali
        dataOut->m_islandTag1 = m_islandTag1;
        dataOut->m_companionId = m_companionId;
        dataOut->m_activationState1 = m_activationState1;
-       dataOut->m_activationState1 = m_activationState1;
        dataOut->m_deactivationTime = m_deactivationTime;
        dataOut->m_friction = m_friction;
+       dataOut->m_rollingFriction = m_rollingFriction;
        dataOut->m_restitution = m_restitution;
        dataOut->m_internalType = m_internalType;
        
@@ -100,7 +101,6 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali
        dataOut->m_hitFraction = m_hitFraction;
        dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
        dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
-       dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
        dataOut->m_checkCollideWith = m_checkCollideWith;
 
        return btCollisionObjectDataName;
index 3a11c96..2f17967 100644 (file)
@@ -80,11 +80,12 @@ protected:
        int                             m_islandTag1;
        int                             m_companionId;
 
-       int                             m_activationState1;
-       btScalar                        m_deactivationTime;
+       mutable int                             m_activationState1;
+       mutable btScalar                        m_deactivationTime;
 
        btScalar                m_friction;
        btScalar                m_restitution;
+       btScalar                m_rollingFriction;
 
        ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
        ///do not assign your own m_internalType unless you write a new dynamics object class.
@@ -105,7 +106,7 @@ protected:
        /// If some object should have elaborate collision filtering by sub-classes
        int                     m_checkCollideWith;
 
-       virtual bool    checkCollideWithOverride(btCollisionObject* /* co */)
+       virtual bool    checkCollideWithOverride(const btCollisionObject* /* co */) const
        {
                return true;
        }
@@ -137,6 +138,13 @@ public:
                CO_USER_TYPE=32
        };
 
+       enum AnisotropicFrictionFlags
+       {
+               CF_ANISOTROPIC_FRICTION_DISABLED=0,
+               CF_ANISOTROPIC_FRICTION = 1,
+               CF_ANISOTROPIC_ROLLING_FRICTION = 2
+       };
+
        SIMD_FORCE_INLINE bool mergesSimulationIslands() const
        {
                ///static objects, kinematic and object without contact response don't merge islands
@@ -147,14 +155,15 @@ public:
        {
                return m_anisotropicFriction;
        }
-       void    setAnisotropicFriction(const btVector3& anisotropicFriction)
+       void    setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
        {
                m_anisotropicFriction = anisotropicFriction;
-               m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
+               bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
+               m_hasAnisotropicFriction = isUnity?frictionMode : 0;
        }
-       bool    hasAnisotropicFriction() const
+       bool    hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
        {
-               return m_hasAnisotropicFriction!=0;
+               return (m_hasAnisotropicFriction&frictionMode)!=0;
        }
 
        ///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default.
@@ -207,22 +216,9 @@ public:
                return m_collisionShape;
        }
 
-       SIMD_FORCE_INLINE const btCollisionShape*       getRootCollisionShape() const
-       {
-               return m_rootCollisionShape;
-       }
-
-       SIMD_FORCE_INLINE btCollisionShape*     getRootCollisionShape()
-       {
-               return m_rootCollisionShape;
-       }
+       
 
-       ///Avoid using this internal API call
-       ///internalSetTemporaryCollisionShape is used to temporary replace the actual collision shape by a child collision shape.
-       void    internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
-       {
-               m_collisionShape = collisionShape;
-       }
+       
 
        ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions. 
        ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
@@ -239,7 +235,7 @@ public:
 
        SIMD_FORCE_INLINE       int     getActivationState() const { return m_activationState1;}
        
-       void setActivationState(int newState);
+       void setActivationState(int newState) const;
 
        void    setDeactivationTime(btScalar time)
        {
@@ -250,9 +246,9 @@ public:
                return m_deactivationTime;
        }
 
-       void forceActivationState(int newState);
+       void forceActivationState(int newState) const;
 
-       void    activate(bool forceActivation = false);
+       void    activate(bool forceActivation = false) const;
 
        SIMD_FORCE_INLINE bool isActive() const
        {
@@ -276,6 +272,16 @@ public:
                return m_friction;
        }
 
+       void    setRollingFriction(btScalar frict)
+       {
+               m_rollingFriction = frict;
+       }
+       btScalar        getRollingFriction() const
+       {
+               return m_rollingFriction;
+       }
+
+
        ///reserved for Bullet internal usage
        int     getInternalType() const
        {
@@ -433,7 +439,7 @@ public:
        }
 
 
-       inline bool checkCollideWith(btCollisionObject* co)
+       inline bool checkCollideWith(const btCollisionObject* co) const
        {
                if (m_checkCollideWith)
                        return checkCollideWithOverride(co);
@@ -466,6 +472,7 @@ struct      btCollisionObjectDoubleData
        double                                  m_contactProcessingThreshold;   
        double                                  m_deactivationTime;
        double                                  m_friction;
+       double                                  m_rollingFriction;
        double                                  m_restitution;
        double                                  m_hitFraction; 
        double                                  m_ccdSweptSphereRadius;
@@ -498,6 +505,8 @@ struct      btCollisionObjectFloatData
        float                                   m_contactProcessingThreshold;   
        float                                   m_deactivationTime;
        float                                   m_friction;
+       float                                   m_rollingFriction;
+
        float                                   m_restitution;
        float                                   m_hitFraction; 
        float                                   m_ccdSweptSphereRadius;
@@ -510,6 +519,7 @@ struct      btCollisionObjectFloatData
        int                                             m_activationState1;
        int                                             m_internalType;
        int                                             m_checkCollideWith;
+       char                                    m_padding[4];
 };
 
 
diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h
new file mode 100644 (file)
index 0000000..952440b
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef BT_COLLISION_OBJECT_WRAPPER_H
+#define BT_COLLISION_OBJECT_WRAPPER_H
+
+///btCollisionObjectWrapperis an internal data structure. 
+///Most users can ignore this and use btCollisionObject and btCollisionShape instead
+class btCollisionShape;
+class btCollisionObject;
+class btTransform;
+#include "LinearMath/btScalar.h" // for SIMD_FORCE_INLINE definition
+
+#define BT_DECLARE_STACK_ONLY_OBJECT \
+       private: \
+               void* operator new(size_t size); \
+               void operator delete(void*);
+
+struct btCollisionObjectWrapper;
+struct btCollisionObjectWrapper
+{
+BT_DECLARE_STACK_ONLY_OBJECT
+
+private:
+       btCollisionObjectWrapper(const btCollisionObjectWrapper&); // not implemented. Not allowed.
+       btCollisionObjectWrapper* operator=(const btCollisionObjectWrapper&);
+
+public:
+       const btCollisionObjectWrapper* m_parent;
+       const btCollisionShape* m_shape;
+       const btCollisionObject* m_collisionObject;
+       const btTransform& m_worldTransform;
+       int             m_partId;
+       int             m_index;
+
+       btCollisionObjectWrapper(const btCollisionObjectWrapper* parent, const btCollisionShape* shape, const btCollisionObject* collisionObject, const btTransform& worldTransform, int partId, int index)
+       : m_parent(parent), m_shape(shape), m_collisionObject(collisionObject), m_worldTransform(worldTransform),
+       m_partId(partId), m_index(index)
+       {}
+
+       SIMD_FORCE_INLINE const btTransform& getWorldTransform() const { return m_worldTransform; }
+       SIMD_FORCE_INLINE const btCollisionObject* getCollisionObject() const { return m_collisionObject; }
+       SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const { return m_shape; }
+};
+
+#endif //BT_COLLISION_OBJECT_WRAPPER_H
index 66b93b8..4c09291 100644 (file)
@@ -34,6 +34,7 @@ subject to the following restrictions:
 #include "LinearMath/btStackAlloc.h"
 #include "LinearMath/btSerializer.h"
 #include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 //#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
 
@@ -207,6 +208,11 @@ void       btCollisionWorld::updateAabbs()
 }
 
 
+void   btCollisionWorld::computeOverlappingPairs()
+{
+       BT_PROFILE("calculateOverlappingPairs");
+       m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
+}
 
 void   btCollisionWorld::performDiscreteCollisionDetection()
 {
@@ -216,11 +222,7 @@ void       btCollisionWorld::performDiscreteCollisionDetection()
 
        updateAabbs();
 
-       {
-               BT_PROFILE("calculateOverlappingPairs");
-               m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
-       }
-
+       computeOverlappingPairs();
 
        btDispatcher* dispatcher = getDispatcher();
        {
@@ -260,16 +262,25 @@ void      btCollisionWorld::removeCollisionObject(btCollisionObject* collisionObject)
 }
 
 
-
 void   btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
                                                                                btCollisionObject* collisionObject,
                                                                                const btCollisionShape* collisionShape,
                                                                                const btTransform& colObjWorldTransform,
                                                                                RayResultCallback& resultCallback)
+{
+       btCollisionObjectWrapper colObWrap(0,collisionShape,collisionObject,colObjWorldTransform,-1,-1);
+       btCollisionWorld::rayTestSingleInternal(rayFromTrans,rayToTrans,&colObWrap,resultCallback);
+}
+
+void   btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,const btTransform& rayToTrans,
+                                                                               const btCollisionObjectWrapper* collisionObjectWrap,
+                                                                               RayResultCallback& resultCallback)
 {
        btSphereShape pointShape(btScalar(0.0));
        pointShape.setMargin(0.f);
        const btConvexShape* castShape = &pointShape;
+       const btCollisionShape* collisionShape = collisionObjectWrap->getCollisionShape();
+       const btTransform& colObjWorldTransform = collisionObjectWrap->getWorldTransform();
 
        if (collisionShape->isConvex())
        {
@@ -302,7 +313,7 @@ void        btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                        castResult.m_normal.normalize();
                                        btCollisionWorld::LocalRayResult localRayResult
                                                (
-                                               collisionObject,
+                                               collisionObjectWrap->getCollisionObject(),
                                                0,
                                                castResult.m_normal,
                                                castResult.m_fraction
@@ -330,13 +341,13 @@ void      btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
                                {
                                        btCollisionWorld::RayResultCallback* m_resultCallback;
-                                       btCollisionObject*      m_collisionObject;
+                                       const btCollisionObject*        m_collisionObject;
                                        btTriangleMeshShape*    m_triangleMesh;
 
                                        btTransform m_colObjWorldTransform;
 
                                        BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
-                                               btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*    triangleMesh,const btTransform& colObjWorldTransform):
+                                               btCollisionWorld::RayResultCallback* resultCallback, const btCollisionObject* collisionObject,btTriangleMeshShape*      triangleMesh,const btTransform& colObjWorldTransform):
                                        //@BP Mod
                                        btTriangleRaycastCallback(from,to, resultCallback->m_flags),
                                                m_resultCallback(resultCallback),
@@ -367,7 +378,7 @@ void        btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 
                                };
 
-                               BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh,colObjWorldTransform);
+                               BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),triangleMesh,colObjWorldTransform);
                                rcb.m_hitFraction = resultCallback.m_closestHitFraction;
                                triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
                        } else
@@ -385,13 +396,13 @@ void      btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
                                {
                                        btCollisionWorld::RayResultCallback* m_resultCallback;
-                                       btCollisionObject*      m_collisionObject;
+                                       const btCollisionObject*        m_collisionObject;
                                        btConcaveShape* m_triangleMesh;
 
                                        btTransform m_colObjWorldTransform;
 
                                        BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
-                                               btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& colObjWorldTransform):
+                                               btCollisionWorld::RayResultCallback* resultCallback, const btCollisionObject* collisionObject,btConcaveShape*   triangleMesh, const btTransform& colObjWorldTransform):
                                        //@BP Mod
                                        btTriangleRaycastCallback(from,to, resultCallback->m_flags),
                                                m_resultCallback(resultCallback),
@@ -423,7 +434,7 @@ void        btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                };
 
 
-                               BridgeTriangleRaycastCallback   rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
+                               BridgeTriangleRaycastCallback   rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
                                rcb.m_hitFraction = resultCallback.m_closestHitFraction;
 
                                btVector3 rayAabbMinLocal = rayFromLocal;
@@ -446,6 +457,7 @@ void        btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                                : m_userCallback(user), m_i(i)
                                        { 
                                                m_closestHitFraction = m_userCallback->m_closestHitFraction;
+                                               m_flags = m_userCallback->m_flags;
                                        }
                                        virtual bool needsCollision(btBroadphaseProxy* p) const
                                        {
@@ -468,14 +480,14 @@ void      btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                
                                struct RayTester : btDbvt::ICollide
                                {
-                                       btCollisionObject* m_collisionObject;
+                                       const btCollisionObject* m_collisionObject;
                                        const btCompoundShape* m_compoundShape;
                                        const btTransform& m_colObjWorldTransform;
                                        const btTransform& m_rayFromTrans;
                                        const btTransform& m_rayToTrans;
                                        RayResultCallback& m_resultCallback;
                                        
-                                       RayTester(btCollisionObject* collisionObject,
+                                       RayTester(const btCollisionObject* collisionObject,
                                                        const btCompoundShape* compoundShape,
                                                        const btTransform& colObjWorldTransform,
                                                        const btTransform& rayFromTrans,
@@ -491,33 +503,30 @@ void      btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                                
                                        }
                                        
-                                       void Process(int i)
+                                       void ProcessLeaf(int i)
                                        {
                                                const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(i);
                                                const btTransform& childTrans = m_compoundShape->getChildTransform(i);
                                                btTransform childWorldTrans = m_colObjWorldTransform * childTrans;
                                                
+                                               btCollisionObjectWrapper tmpOb(0,childCollisionShape,m_collisionObject,childWorldTrans,-1,i);
                                                // replace collision shape so that callback can determine the triangle
-                                               btCollisionShape* saveCollisionShape = m_collisionObject->getCollisionShape();
-                                               m_collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
+
+                                               
 
                                                LocalInfoAdder2 my_cb(i, &m_resultCallback);
 
-                                               rayTestSingle(
+                                               rayTestSingleInternal(
                                                        m_rayFromTrans,
                                                        m_rayToTrans,
-                                                       m_collisionObject,
-                                                       childCollisionShape,
-                                                       childWorldTrans,
+                                                       &tmpOb,
                                                        my_cb);
                                                
-                                               // restore
-                                               m_collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
                                        }
-                                       
+                               
                                        void Process(const btDbvtNode* leaf)
                                        {
-                                               Process(leaf->dataAsInt);
+                                               ProcessLeaf(leaf->dataAsInt);
                                        }
                                };
                                
@@ -526,7 +535,7 @@ void        btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 
 
                                RayTester rayCB(
-                                       collisionObject,
+                                       collisionObjectWrap->getCollisionObject(),
                                        compoundShape,
                                        colObjWorldTransform,
                                        rayFromTrans,
@@ -544,7 +553,7 @@ void        btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
                                {
                                        for (int i = 0, n = compoundShape->getNumChildShapes(); i < n; ++i)
                                        {
-                                               rayCB.Process(i);
+                                               rayCB.ProcessLeaf(i);
                                        }       
                                }
                        }
@@ -558,6 +567,17 @@ void       btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
                                                                                        const btTransform& colObjWorldTransform,
                                                                                        ConvexResultCallback& resultCallback, btScalar allowedPenetration)
 {
+       btCollisionObjectWrapper tmpOb(0,collisionShape,collisionObject,colObjWorldTransform,-1,-1);
+       btCollisionWorld::objectQuerySingleInternal(castShape,convexFromTrans,convexToTrans,&tmpOb,resultCallback,allowedPenetration);
+}
+
+void   btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
+                                                                                       const btCollisionObjectWrapper* colObjWrap,
+                                                                                       ConvexResultCallback& resultCallback, btScalar allowedPenetration)
+{
+       const btCollisionShape* collisionShape = colObjWrap->getCollisionShape();
+       const btTransform& colObjWorldTransform = colObjWrap->getWorldTransform();
+
        if (collisionShape->isConvex())
        {
                //BT_PROFILE("convexSweepConvex");
@@ -587,7 +607,7 @@ void        btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
                                        castResult.m_normal.normalize();
                                        btCollisionWorld::LocalConvexResult localConvexResult
                                                (
-                                               collisionObject,
+                                               colObjWrap->getCollisionObject(),
                                                0,
                                                castResult.m_normal,
                                                castResult.m_hitPoint,
@@ -617,11 +637,11 @@ void      btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
                                struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
                                {
                                        btCollisionWorld::ConvexResultCallback* m_resultCallback;
-                                       btCollisionObject*      m_collisionObject;
+                                       const btCollisionObject*        m_collisionObject;
                                        btTriangleMeshShape*    m_triangleMesh;
 
                                        BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
-                                               btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld):
+                                               btCollisionWorld::ConvexResultCallback* resultCallback, const btCollisionObject* collisionObject,btTriangleMeshShape*   triangleMesh, const btTransform& triangleToWorld):
                                        btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
                                                m_resultCallback(resultCallback),
                                                m_collisionObject(collisionObject),
@@ -655,7 +675,7 @@ void        btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 
                                };
 
-                               BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,triangleMesh, colObjWorldTransform);
+                               BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,colObjWrap->getCollisionObject(),triangleMesh, colObjWorldTransform);
                                tccb.m_hitFraction = resultCallback.m_closestHitFraction;
                                tccb.m_allowedPenetration = allowedPenetration;
                                btVector3 boxMinLocal, boxMaxLocal;
@@ -682,7 +702,7 @@ void        btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
                                                                castResult.m_normal.normalize();
                                                                btCollisionWorld::LocalConvexResult localConvexResult
                                                                        (
-                                                                       collisionObject,
+                                                                       colObjWrap->getCollisionObject(),
                                                                        0,
                                                                        castResult.m_normal,
                                                                        castResult.m_hitPoint,
@@ -709,11 +729,11 @@ void      btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
                                        struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
                                        {
                                                btCollisionWorld::ConvexResultCallback* m_resultCallback;
-                                               btCollisionObject*      m_collisionObject;
+                                               const btCollisionObject*        m_collisionObject;
                                                btConcaveShape* m_triangleMesh;
 
                                                BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
-                                                       btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape*      triangleMesh, const btTransform& triangleToWorld):
+                                                       btCollisionWorld::ConvexResultCallback* resultCallback, const btCollisionObject* collisionObject,btConcaveShape*        triangleMesh, const btTransform& triangleToWorld):
                                                btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
                                                        m_resultCallback(resultCallback),
                                                        m_collisionObject(collisionObject),
@@ -746,7 +766,7 @@ void        btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 
                                        };
 
-                                       BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
+                                       BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,colObjWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
                                        tccb.m_hitFraction = resultCallback.m_closestHitFraction;
                                        tccb.m_allowedPenetration = allowedPenetration;
                                        btVector3 boxMinLocal, boxMaxLocal;
@@ -773,9 +793,7 @@ void        btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
                                        btTransform childTrans = compoundShape->getChildTransform(i);
                                        const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
                                        btTransform childWorldTrans = colObjWorldTransform * childTrans;
-                                       // replace collision shape so that callback can determine the triangle
-                                       btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape();
-                                       collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
+                                       
                     struct     LocalInfoAdder : public ConvexResultCallback {
                             ConvexResultCallback* m_userCallback;
                                                        int m_i;
@@ -805,14 +823,11 @@ void      btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 
                     LocalInfoAdder my_cb(i, &resultCallback);
                                        
+                                       btCollisionObjectWrapper tmpObj(colObjWrap,childCollisionShape,colObjWrap->getCollisionObject(),childWorldTrans,-1,i);
 
-                                       objectQuerySingle(castShape, convexFromTrans,convexToTrans,
-                                               collisionObject,
-                                               childCollisionShape,
-                                               childWorldTrans,
-                                               my_cb, allowedPenetration);
-                                       // restore
-                                       collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
+                                       objectQuerySingleInternal(castShape, convexFromTrans,convexToTrans,
+                                               &tmpObj,my_cb, allowedPenetration);
+                                       
                                }
                        }
                }
@@ -993,13 +1008,13 @@ void     btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btT
        /* Compute AABB that encompasses angular movement */
        {
                btVector3 linVel, angVel;
-               btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
+               btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0f, linVel, angVel);
                btVector3 zeroLinVel;
                zeroLinVel.setValue(0,0,0);
                btTransform R;
                R.setIdentity ();
                R.setRotation (convexFromTrans.getRotation());
-               castShape->calculateTemporalAabb (R, zeroLinVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
+               castShape->calculateTemporalAabb (R, zeroLinVel, angVel, 1.0f, castShapeAabbMin, castShapeAabbMax);
        }
 
 #ifndef USE_BRUTEFORCE_RAYBROADPHASE
@@ -1044,26 +1059,26 @@ struct btBridgedManifoldResult : public btManifoldResult
 
        btCollisionWorld::ContactResultCallback&        m_resultCallback;
 
-       btBridgedManifoldResult( btCollisionObject* obj0,btCollisionObject* obj1,btCollisionWorld::ContactResultCallback& resultCallback )
-               :btManifoldResult(obj0,obj1),
+       btBridgedManifoldResult( const btCollisionObjectWrapper* obj0Wrap,const btCollisionObjectWrapper* obj1Wrap,btCollisionWorld::ContactResultCallback& resultCallback )
+               :btManifoldResult(obj0Wrap,obj1Wrap),
                m_resultCallback(resultCallback)
        {
        }
 
        virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
        {
-               bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
+               bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
                btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
                btVector3 localA;
                btVector3 localB;
                if (isSwapped)
                {
-                       localA = m_rootTransB.invXform(pointA );
-                       localB = m_rootTransA.invXform(pointInWorld);
+                       localA = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+                       localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
                } else
                {
-                       localA = m_rootTransA.invXform(pointA );
-                       localB = m_rootTransB.invXform(pointInWorld);
+                       localA = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+                       localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
                }
                
                btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
@@ -1086,9 +1101,9 @@ struct btBridgedManifoldResult : public btManifoldResult
                }
 
                //experimental feature info, for per-triangle material etc.
-               btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
-               btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
-               m_resultCallback.addSingleResult(newPt,obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1);
+               const btCollisionObjectWrapper* obj0Wrap = isSwapped? m_body1Wrap : m_body0Wrap;
+               const btCollisionObjectWrapper* obj1Wrap = isSwapped? m_body0Wrap : m_body1Wrap;
+               m_resultCallback.addSingleResult(newPt,obj0Wrap,newPt.m_partId0,newPt.m_index0,obj1Wrap,newPt.m_partId1,newPt.m_index1);
 
        }
        
@@ -1120,12 +1135,16 @@ struct btSingleContactCallback : public btBroadphaseAabbCallback
                //only perform raycast if filterMask matches
                if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 
                {
-                       btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(m_collisionObject,collisionObject);
+                       btCollisionObjectWrapper ob0(0,m_collisionObject->getCollisionShape(),m_collisionObject,m_collisionObject->getWorldTransform(),-1,-1);
+                       btCollisionObjectWrapper ob1(0,collisionObject->getCollisionShape(),collisionObject,collisionObject->getWorldTransform(),-1,-1);
+
+                       btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(&ob0,&ob1);
                        if (algorithm)
                        {
-                               btBridgedManifoldResult contactPointResult(m_collisionObject,collisionObject, m_resultCallback);
+                               btBridgedManifoldResult contactPointResult(&ob0,&ob1, m_resultCallback);
                                //discrete collision detection query
-                               algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult);
+                               
+                               algorithm->processCollision(&ob0,&ob1, m_world->getDispatchInfo(),&contactPointResult);
 
                                algorithm->~btCollisionAlgorithm();
                                m_world->getDispatcher()->freeCollisionAlgorithm(algorithm);
@@ -1152,12 +1171,15 @@ void    btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCall
 ///it reports one or more contact points (including the one with deepest penetration)
 void   btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback)
 {
-       btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(colObjA,colObjB);
+       btCollisionObjectWrapper obA(0,colObjA->getCollisionShape(),colObjA,colObjA->getWorldTransform(),-1,-1);
+       btCollisionObjectWrapper obB(0,colObjB->getCollisionShape(),colObjB,colObjB->getWorldTransform(),-1,-1);
+
+       btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(&obA,&obB);
        if (algorithm)
        {
-               btBridgedManifoldResult contactPointResult(colObjA,colObjB, resultCallback);
+               btBridgedManifoldResult contactPointResult(&obA,&obB, resultCallback);
                //discrete collision detection query
-               algorithm->processCollision(colObjA,colObjB, getDispatchInfo(),&contactPointResult);
+               algorithm->processCollision(&obA,&obB, getDispatchInfo(),&contactPointResult);
 
                algorithm->~btCollisionAlgorithm();
                getDispatcher()->freeCollisionAlgorithm(algorithm);
@@ -1231,163 +1253,162 @@ void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const
        } else
        {
 
-               /// for polyhedral shapes
-               if (shape->isPolyhedral())
-               {
-                       btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
-
-                       int i;
-                       if (polyshape->getConvexPolyhedron())
-                       {
-                               const btConvexPolyhedron* poly = polyshape->getConvexPolyhedron();
-                               for (i=0;i<poly->m_faces.size();i++)
-                               {
-                                       btVector3 centroid(0,0,0);
-                                       int numVerts = poly->m_faces[i].m_indices.size();
-                                       if (numVerts)
-                                       {
-                                               int lastV = poly->m_faces[i].m_indices[numVerts-1];
-                                               for (int v=0;v<poly->m_faces[i].m_indices.size();v++)
-                                               {
-                                                       int curVert = poly->m_faces[i].m_indices[v];
-                                                       centroid+=poly->m_vertices[curVert];
-                                                       getDebugDrawer()->drawLine(worldTransform*poly->m_vertices[lastV],worldTransform*poly->m_vertices[curVert],color);
-                                                       lastV = curVert;
-                                               }
-                                       }
-                                       centroid*= btScalar(1.f)/btScalar(numVerts);
-                    if (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawNormals)
+        switch (shape->getShapeType())
+        {
+
+        case BOX_SHAPE_PROXYTYPE:
+            {
+                const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
+                btVector3 halfExtents = boxShape->getHalfExtentsWithMargin();
+                getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color);
+                break;
+            }
+
+        case SPHERE_SHAPE_PROXYTYPE:
+            {
+                const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
+                btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
+
+                getDebugDrawer()->drawSphere(radius, worldTransform, color);
+                break;
+            }
+        case MULTI_SPHERE_SHAPE_PROXYTYPE:
+            {
+                const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
+
+                btTransform childTransform;
+                childTransform.setIdentity();
+
+                for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
+                {
+                    childTransform.setOrigin(multiSphereShape->getSpherePosition(i));
+                    getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color);
+                }
+
+                break;
+            }
+        case CAPSULE_SHAPE_PROXYTYPE:
+            {
+                const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
+
+                btScalar radius = capsuleShape->getRadius();
+                btScalar halfHeight = capsuleShape->getHalfHeight();
+
+                int upAxis = capsuleShape->getUpAxis();
+                getDebugDrawer()->drawCapsule(radius, halfHeight, upAxis, worldTransform, color);
+                break;
+            }
+        case CONE_SHAPE_PROXYTYPE:
+            {
+                const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
+                btScalar radius = coneShape->getRadius();//+coneShape->getMargin();
+                btScalar height = coneShape->getHeight();//+coneShape->getMargin();
+
+                int upAxis= coneShape->getConeUpIndex();
+                getDebugDrawer()->drawCone(radius, height, upAxis, worldTransform, color);
+                break;
+
+            }
+        case CYLINDER_SHAPE_PROXYTYPE:
+            {
+                const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
+                int upAxis = cylinder->getUpAxis();
+                btScalar radius = cylinder->getRadius();
+                btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
+                getDebugDrawer()->drawCylinder(radius, halfHeight, upAxis, worldTransform, color);
+                break;
+            }
+
+        case STATIC_PLANE_PROXYTYPE:
+            {
+                const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
+                btScalar planeConst = staticPlaneShape->getPlaneConstant();
+                const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
+                getDebugDrawer()->drawPlane(planeNormal, planeConst,worldTransform, color);
+                break;
+
+            }
+        default:
+            {
+
+                /// for polyhedral shapes
+                if (shape->isPolyhedral())
+                {
+                    btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
+                    
+                    int i;
+                    if (polyshape->getConvexPolyhedron())
+                    {
+                        const btConvexPolyhedron* poly = polyshape->getConvexPolyhedron();
+                        for (i=0;i<poly->m_faces.size();i++)
+                        {
+                            btVector3 centroid(0,0,0);
+                            int numVerts = poly->m_faces[i].m_indices.size();
+                            if (numVerts)
+                            {
+                                int lastV = poly->m_faces[i].m_indices[numVerts-1];
+                                for (int v=0;v<poly->m_faces[i].m_indices.size();v++)
+                                {
+                                    int curVert = poly->m_faces[i].m_indices[v];
+                                    centroid+=poly->m_vertices[curVert];
+                                    getDebugDrawer()->drawLine(worldTransform*poly->m_vertices[lastV],worldTransform*poly->m_vertices[curVert],color);
+                                    lastV = curVert;
+                                }
+                            }
+                            centroid*= btScalar(1.f)/btScalar(numVerts);
+                            if (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawNormals)
+                            {
+                                btVector3 normalColor(1,1,0);
+                                btVector3 faceNormal(poly->m_faces[i].m_plane[0],poly->m_faces[i].m_plane[1],poly->m_faces[i].m_plane[2]);
+                                getDebugDrawer()->drawLine(worldTransform*centroid,worldTransform*(centroid+faceNormal),normalColor);
+                            }
+                            
+                        }
+                        
+                        
+                    } else
                     {
-                                         btVector3 normalColor(1,1,0);
-                                         btVector3 faceNormal(poly->m_faces[i].m_plane[0],poly->m_faces[i].m_plane[1],poly->m_faces[i].m_plane[2]);
-                                         getDebugDrawer()->drawLine(worldTransform*centroid,worldTransform*(centroid+faceNormal),normalColor);
+                        for (i=0;i<polyshape->getNumEdges();i++)
+                        {
+                            btVector3 a,b;
+                            polyshape->getEdge(i,a,b);
+                            btVector3 wa = worldTransform * a;
+                            btVector3 wb = worldTransform * b;
+                            getDebugDrawer()->drawLine(wa,wb,color);
+                        }
                     }
-                                       
-                               }
-
-                               
-                       } else
-                       {
-                               for (i=0;i<polyshape->getNumEdges();i++)
-                               {
-                                       btVector3 a,b;
-                                       polyshape->getEdge(i,a,b);
-                                       btVector3 wa = worldTransform * a;
-                                       btVector3 wb = worldTransform * b;
-                                       getDebugDrawer()->drawLine(wa,wb,color);
-                               }
-                       }
-
-
-               }
-               else
-               {
-                       switch (shape->getShapeType())
-                       {
-
-                       case BOX_SHAPE_PROXYTYPE:
-                               {
-                                       const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
-                                       btVector3 halfExtents = boxShape->getHalfExtentsWithMargin();
-                                       getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color);
-                                       break;
-                               }
-
-                       case SPHERE_SHAPE_PROXYTYPE:
-                               {
-                                       const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
-                                       btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
-
-                                       getDebugDrawer()->drawSphere(radius, worldTransform, color);
-                                       break;
-                               }
-                       case MULTI_SPHERE_SHAPE_PROXYTYPE:
-                               {
-                                       const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
-
-                                       btTransform childTransform;
-                                       childTransform.setIdentity();
-
-                                       for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
-                                       {
-                                               childTransform.setOrigin(multiSphereShape->getSpherePosition(i));
-                                               getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color);
-                                       }
-
-                                       break;
-                               }
-                       case CAPSULE_SHAPE_PROXYTYPE:
-                               {
-                                       const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
-
-                                       btScalar radius = capsuleShape->getRadius();
-                                       btScalar halfHeight = capsuleShape->getHalfHeight();
-
-                                       int upAxis = capsuleShape->getUpAxis();
-                                       getDebugDrawer()->drawCapsule(radius, halfHeight, upAxis, worldTransform, color);
-                                       break;
-                               }
-                       case CONE_SHAPE_PROXYTYPE:
-                               {
-                                       const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
-                                       btScalar radius = coneShape->getRadius();//+coneShape->getMargin();
-                                       btScalar height = coneShape->getHeight();//+coneShape->getMargin();
-
-                                       int upAxis= coneShape->getConeUpIndex();
-                                       getDebugDrawer()->drawCone(radius, height, upAxis, worldTransform, color);
-                                       break;
-
-                               }
-                       case CYLINDER_SHAPE_PROXYTYPE:
-                               {
-                                       const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
-                                       int upAxis = cylinder->getUpAxis();
-                                       btScalar radius = cylinder->getRadius();
-                                       btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
-                                       getDebugDrawer()->drawCylinder(radius, halfHeight, upAxis, worldTransform, color);
-                                       break;
-                               }
-
-                       case STATIC_PLANE_PROXYTYPE:
-                               {
-                                       const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
-                                       btScalar planeConst = staticPlaneShape->getPlaneConstant();
-                                       const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
-                                       getDebugDrawer()->drawPlane(planeNormal, planeConst,worldTransform, color);
-                                       break;
-
-                               }
-                       default:
-                               {
-
-                                       if (shape->isConcave())
-                                       {
-                                               btConcaveShape* concaveMesh = (btConcaveShape*) shape;
-
-                                               ///@todo pass camera, for some culling? no -> we are not a graphics lib
-                                               btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
-                                               btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
-
-                                               DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
-                                               concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
-
-                                       }
-
-                                       if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
-                                       {
-                                               btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
-                                               //todo: pass camera for some culling                    
-                                               btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
-                                               btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
-                                               //DebugDrawcallback drawCallback;
-                                               DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
-                                               convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
-                                       }
-
-
-                                       
-                               }
-                       }
+                    
+                    
+                }
+                    
+                if (shape->isConcave())
+                {
+                    btConcaveShape* concaveMesh = (btConcaveShape*) shape;
+
+                    ///@todo pass camera, for some culling? no -> we are not a graphics lib
+                    btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
+                    btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
+
+                    DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
+                    concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
+
+                }
+
+                if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
+                {
+                    btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
+                    //todo: pass camera for some culling                       
+                    btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
+                    btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
+                    //DebugDrawcallback drawCallback;
+                    DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
+                    convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
+                }
+
+
+                
+            }
+       
                }
        }
 }
@@ -1398,7 +1419,7 @@ void      btCollisionWorld::debugDrawWorld()
        if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
        {
                int numManifolds = getDispatcher()->getNumManifolds();
-               btVector3 color(1,0.65,0);
+               btVector3 color(1,1,0);
                for (int i=0;i<numManifolds;i++)
                {
                        btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
index 0a92d2d..9412242 100644 (file)
@@ -144,6 +144,11 @@ public:
        void    updateSingleAabb(btCollisionObject* colObj);
 
        virtual void    updateAabbs();
+
+       ///the computeOverlappingPairs is usually already called by performDiscreteCollisionDetection (or stepSimulation)
+       ///it can be useful to use if you perform ray tests without collision detection/simulation
+       virtual void    computeOverlappingPairs();
+
        
        virtual void    setDebugDrawer(btIDebugDraw*    debugDrawer)
        {
@@ -173,7 +178,7 @@ public:
 
        struct  LocalRayResult
        {
-               LocalRayResult(btCollisionObject*       collisionObject, 
+               LocalRayResult(const btCollisionObject* collisionObject, 
                        LocalShapeInfo* localShapeInfo,
                        const btVector3&                hitNormalLocal,
                        btScalar hitFraction)
@@ -184,7 +189,7 @@ public:
                {
                }
 
-               btCollisionObject*              m_collisionObject;
+               const btCollisionObject*                m_collisionObject;
                LocalShapeInfo*                 m_localShapeInfo;
                btVector3                               m_hitNormalLocal;
                btScalar                                m_hitFraction;
@@ -195,11 +200,11 @@ public:
        struct  RayResultCallback
        {
                btScalar        m_closestHitFraction;
-               btCollisionObject*              m_collisionObject;
+               const btCollisionObject*                m_collisionObject;
                short int       m_collisionFilterGroup;
                short int       m_collisionFilterMask;
-      //@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback
-      unsigned int m_flags;
+               //@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback.h. Apply any of the EFlags defined there on m_flags here to invoke.
+               unsigned int m_flags;
 
                virtual ~RayResultCallback()
                {
@@ -214,8 +219,8 @@ public:
                        m_collisionObject(0),
                        m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
                        m_collisionFilterMask(btBroadphaseProxy::AllFilter),
-         //@BP Mod
-         m_flags(0)
+                       //@BP Mod
+                       m_flags(0)
                {
                }
 
@@ -272,7 +277,7 @@ public:
                {
                }
 
-               btAlignedObjectArray<btCollisionObject*>                m_collisionObjects;
+               btAlignedObjectArray<const btCollisionObject*>          m_collisionObjects;
 
                btVector3       m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
                btVector3       m_rayToWorld;
@@ -306,7 +311,7 @@ public:
 
        struct LocalConvexResult
        {
-               LocalConvexResult(btCollisionObject*    hitCollisionObject, 
+               LocalConvexResult(const btCollisionObject*      hitCollisionObject, 
                        LocalShapeInfo* localShapeInfo,
                        const btVector3&                hitNormalLocal,
                        const btVector3&                hitPointLocal,
@@ -320,7 +325,7 @@ public:
                {
                }
 
-               btCollisionObject*              m_hitCollisionObject;
+               const btCollisionObject*                m_hitCollisionObject;
                LocalShapeInfo*                 m_localShapeInfo;
                btVector3                               m_hitNormalLocal;
                btVector3                               m_hitPointLocal;
@@ -376,7 +381,7 @@ public:
 
                btVector3       m_hitNormalWorld;
                btVector3       m_hitPointWorld;
-               btCollisionObject*      m_hitCollisionObject;
+               const btCollisionObject*        m_hitCollisionObject;
                
                virtual btScalar        addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace)
                {
@@ -421,7 +426,7 @@ public:
                        return collides;
                }
 
-               virtual btScalar        addSingleResult(btManifoldPoint& cp,    const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) = 0;
+               virtual btScalar        addSingleResult(btManifoldPoint& cp,    const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1) = 0;
        };
 
 
@@ -457,6 +462,10 @@ public:
                                          const btTransform& colObjWorldTransform,
                                          RayResultCallback& resultCallback);
 
+       static void     rayTestSingleInternal(const btTransform& rayFromTrans,const btTransform& rayToTrans,
+                                         const btCollisionObjectWrapper* collisionObjectWrap,
+                                         RayResultCallback& resultCallback);
+
        /// objectQuerySingle performs a collision detection query and calls the resultCallback. It is used internally by rayTest.
        static void     objectQuerySingle(const btConvexShape* castShape, const btTransform& rayFromTrans,const btTransform& rayToTrans,
                                          btCollisionObject* collisionObject,
@@ -464,6 +473,10 @@ public:
                                          const btTransform& colObjWorldTransform,
                                          ConvexResultCallback& resultCallback, btScalar        allowedPenetration);
 
+       static void     objectQuerySingleInternal(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
+                                                                                       const btCollisionObjectWrapper* colObjWrap,
+                                                                                       ConvexResultCallback& resultCallback, btScalar allowedPenetration);
+
        virtual void    addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);
 
        btCollisionObjectArray& getCollisionObjectArray()
index 54889a6..39b86a2 100644 (file)
@@ -20,30 +20,32 @@ subject to the following restrictions:
 #include "LinearMath/btIDebugDraw.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "btManifoldResult.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
-btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
-:btActivatingCollisionAlgorithm(ci,body0,body1),
+btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
+:btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_isSwapped(isSwapped),
 m_sharedManifold(ci.m_manifold)
 {
        m_ownsManifold = false;
 
-       btCollisionObject* colObj = m_isSwapped? body1 : body0;
-       btAssert (colObj->getCollisionShape()->isCompound());
+       const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+       btAssert (colObjWrap->getCollisionShape()->isCompound());
        
-       btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
+       const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
        m_compoundShapeRevision = compoundShape->getUpdateRevision();
        
-       preallocateChildAlgorithms(body0,body1);
+       
+       preallocateChildAlgorithms(body0Wrap,body1Wrap);
 }
 
-void   btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1)
+void   btCompoundCollisionAlgorithm::preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
 {
-       btCollisionObject* colObj = m_isSwapped? body1 : body0;
-       btCollisionObject* otherObj = m_isSwapped? body0 : body1;
-       btAssert (colObj->getCollisionShape()->isCompound());
+       const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+       const btCollisionObjectWrapper* otherObjWrap = m_isSwapped? body0Wrap : body1Wrap;
+       btAssert (colObjWrap->getCollisionShape()->isCompound());
        
-       btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
+       const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 
        int numChildren = compoundShape->getNumChildShapes();
        int i;
@@ -56,11 +58,11 @@ void        btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject*
                        m_childCollisionAlgorithms[i] = 0;
                } else
                {
-                       btCollisionShape* tmpShape = colObj->getCollisionShape();
-                       btCollisionShape* childShape = compoundShape->getChildShape(i);
-                       colObj->internalSetTemporaryCollisionShape( childShape );
-                       m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(colObj,otherObj,m_sharedManifold);
-                       colObj->internalSetTemporaryCollisionShape( tmpShape );
+                       
+                       const btCollisionShape* childShape = compoundShape->getChildShape(i);
+
+                       btCollisionObjectWrapper childWrap(colObjWrap,childShape,colObjWrap->getCollisionObject(),colObjWrap->getWorldTransform(),-1,i);//wrong child trans, but unused (hopefully)
+                       m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(&childWrap,otherObjWrap,m_sharedManifold);
                }
        }
 }
@@ -92,19 +94,16 @@ struct      btCompoundLeafCallback : btDbvt::ICollide
 
 public:
 
-       btCollisionObject* m_compoundColObj;
-       btCollisionObject* m_otherObj;
+       const btCollisionObjectWrapper* m_compoundColObjWrap;
+       const btCollisionObjectWrapper* m_otherObjWrap;
        btDispatcher* m_dispatcher;
        const btDispatcherInfo& m_dispatchInfo;
        btManifoldResult*       m_resultOut;
        btCollisionAlgorithm**  m_childCollisionAlgorithms;
        btPersistentManifold*   m_sharedManifold;
-
-
-
-
-       btCompoundLeafCallback (btCollisionObject* compoundObj,btCollisionObject* otherObj,btDispatcher* dispatcher,const btDispatcherInfo& dispatchInfo,btManifoldResult*      resultOut,btCollisionAlgorithm**        childCollisionAlgorithms,btPersistentManifold*  sharedManifold)
-               :m_compoundColObj(compoundObj),m_otherObj(otherObj),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
+       
+       btCompoundLeafCallback (const btCollisionObjectWrapper* compoundObjWrap,const btCollisionObjectWrapper* otherObjWrap,btDispatcher* dispatcher,const btDispatcherInfo& dispatchInfo,btManifoldResult*    resultOut,btCollisionAlgorithm**        childCollisionAlgorithms,btPersistentManifold*  sharedManifold)
+               :m_compoundColObjWrap(compoundObjWrap),m_otherObjWrap(otherObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
                m_childCollisionAlgorithms(childCollisionAlgorithms),
                m_sharedManifold(sharedManifold)
        {
@@ -112,73 +111,89 @@ public:
        }
 
 
-       void    ProcessChildShape(btCollisionShape* childShape,int index)
+       void    ProcessChildShape(const btCollisionShape* childShape,int index)
        {
                btAssert(index>=0);
-               btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
+               const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
                btAssert(index<compoundShape->getNumChildShapes());
 
 
                //backup
-               btTransform     orgTrans = m_compoundColObj->getWorldTransform();
-               btTransform     orgInterpolationTrans = m_compoundColObj->getInterpolationWorldTransform();
+               btTransform     orgTrans = m_compoundColObjWrap->getWorldTransform();
+               btTransform     orgInterpolationTrans = m_compoundColObjWrap->getWorldTransform();
                const btTransform& childTrans = compoundShape->getChildTransform(index);
                btTransform     newChildWorldTrans = orgTrans*childTrans ;
 
                //perform an AABB check first
                btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
                childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
-               m_otherObj->getCollisionShape()->getAabb(m_otherObj->getWorldTransform(),aabbMin1,aabbMax1);
+               m_otherObjWrap->getCollisionShape()->getAabb(m_otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
 
                if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
                {
 
-                       m_compoundColObj->setWorldTransform( newChildWorldTrans);
-                       m_compoundColObj->setInterpolationWorldTransform(newChildWorldTrans);
+                       btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap,childShape,m_compoundColObjWrap->getCollisionObject(),newChildWorldTrans,-1,index);
 
-                       //the contactpoint is still projected back using the original inverted worldtrans
-                       btCollisionShape* tmpShape = m_compoundColObj->getCollisionShape();
-                       m_compoundColObj->internalSetTemporaryCollisionShape( childShape );
 
+                       //the contactpoint is still projected back using the original inverted worldtrans
                        if (!m_childCollisionAlgorithms[index])
-                               m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold);
+                               m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(&compoundWrap,m_otherObjWrap,m_sharedManifold);
+
+                       
+                       const btCollisionObjectWrapper* tmpWrap = 0;
 
                        ///detect swapping case
-                       if (m_resultOut->getBody0Internal() == m_compoundColObj)
+                       if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
                        {
+                               tmpWrap = m_resultOut->getBody0Wrap();
+                               m_resultOut->setBody0Wrap(&compoundWrap);
                                m_resultOut->setShapeIdentifiersA(-1,index);
                        } else
                        {
+                               tmpWrap = m_resultOut->getBody1Wrap();
+                               m_resultOut->setBody1Wrap(&compoundWrap);
                                m_resultOut->setShapeIdentifiersB(-1,index);
                        }
 
-                       m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut);
+
+                       m_childCollisionAlgorithms[index]->processCollision(&compoundWrap,m_otherObjWrap,m_dispatchInfo,m_resultOut);
+
+#if 0
                        if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
                        {
                                btVector3 worldAabbMin,worldAabbMax;
                                m_dispatchInfo.m_debugDraw->drawAabb(aabbMin0,aabbMax0,btVector3(1,1,1));
                                m_dispatchInfo.m_debugDraw->drawAabb(aabbMin1,aabbMax1,btVector3(1,1,1));
                        }
+#endif
+
+                       if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
+                       {
+                               m_resultOut->setBody0Wrap(tmpWrap);
+                       } else
+                       {
+                               m_resultOut->setBody1Wrap(tmpWrap);
+                       }
                        
-                       //revert back transform
-                       m_compoundColObj->internalSetTemporaryCollisionShape( tmpShape);
-                       m_compoundColObj->setWorldTransform(  orgTrans );
-                       m_compoundColObj->setInterpolationWorldTransform(orgInterpolationTrans);
                }
        }
        void            Process(const btDbvtNode* leaf)
        {
                int index = leaf->dataAsInt;
 
-               btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
-               btCollisionShape* childShape = compoundShape->getChildShape(index);
+               const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
+               const btCollisionShape* childShape = compoundShape->getChildShape(index);
+
+#if 0
                if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
                {
                        btVector3 worldAabbMin,worldAabbMax;
-                       btTransform     orgTrans = m_compoundColObj->getWorldTransform();
+                       btTransform     orgTrans = m_compoundColObjWrap->getWorldTransform();
                        btTransformAabb(leaf->volume.Mins(),leaf->volume.Maxs(),0.,orgTrans,worldAabbMin,worldAabbMax);
                        m_dispatchInfo.m_debugDraw->drawAabb(worldAabbMin,worldAabbMax,btVector3(1,0,0));
                }
+#endif
+
                ProcessChildShape(childShape,index);
 
        }
@@ -189,15 +204,13 @@ public:
 
 
 
-void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
-       btCollisionObject* colObj = m_isSwapped? body1 : body0;
-       btCollisionObject* otherObj = m_isSwapped? body0 : body1;
-
-       
+       const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+       const btCollisionObjectWrapper* otherObjWrap = m_isSwapped? body0Wrap : body1Wrap;
 
-       btAssert (colObj->getCollisionShape()->isCompound());
-       btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
+       btAssert (colObjWrap->getCollisionShape()->isCompound());
+       const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 
        ///btCompoundShape might have changed:
        ////make sure the internal child collision algorithm caches are still valid
@@ -206,13 +219,13 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
                ///clear and update all
                removeChildAlgorithms();
                
-               preallocateChildAlgorithms(body0,body1);
+               preallocateChildAlgorithms(body0Wrap,body1Wrap);
        }
 
 
-       btDbvt* tree = compoundShape->getDynamicAabbTree();
+       const btDbvt* tree = compoundShape->getDynamicAabbTree();
        //use a dynamic aabb tree to cull potential child-overlaps
-       btCompoundLeafCallback  callback(colObj,otherObj,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
+       btCompoundLeafCallback  callback(colObjWrap,otherObjWrap,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
 
        ///we need to refresh all contact manifolds
        ///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
@@ -244,8 +257,8 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 
                btVector3 localAabbMin,localAabbMax;
                btTransform otherInCompoundSpace;
-               otherInCompoundSpace = colObj->getWorldTransform().inverse() * otherObj->getWorldTransform();
-               otherObj->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);
+               otherInCompoundSpace = colObjWrap->getWorldTransform().inverse() * otherObjWrap->getWorldTransform();
+               otherObjWrap->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);
 
                const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
                //process all children, that overlap with  the given AABB bounds
@@ -267,7 +280,7 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
                int numChildren = m_childCollisionAlgorithms.size();
                int i;
                btManifoldArray manifoldArray;
-        btCollisionShape* childShape = 0;
+        const btCollisionShape* childShape = 0;
         btTransform    orgTrans;
         btTransform    orgInterpolationTrans;
         btTransform    newChildWorldTrans;
@@ -279,14 +292,14 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
                        {
                                childShape = compoundShape->getChildShape(i);
                        //if not longer overlapping, remove the algorithm
-                orgTrans = colObj->getWorldTransform();
-                orgInterpolationTrans = colObj->getInterpolationWorldTransform();
+                orgTrans = colObjWrap->getWorldTransform();
+                orgInterpolationTrans = colObjWrap->getWorldTransform();
                                const btTransform& childTrans = compoundShape->getChildTransform(i);
                 newChildWorldTrans = orgTrans*childTrans ;
 
                                //perform an AABB check first
                                childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
-                               otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1);
+                               otherObjWrap->getCollisionShape()->getAabb(otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
 
                                if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
                                {
@@ -301,7 +314,8 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 
 btScalar       btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
-
+       btAssert(0);
+       //needs to be fixed, using btCollisionObjectWrapper and NOT modifying internal data structures
        btCollisionObject* colObj = m_isSwapped? body1 : body0;
        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
 
@@ -324,8 +338,7 @@ btScalar    btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
     btScalar frac;
        for (i=0;i<numChildren;i++)
        {
-               //temporarily exchange parent btCollisionShape with childShape, and recurse
-               btCollisionShape* childShape = compoundShape->getChildShape(i);
+               //btCollisionShape* childShape = compoundShape->getChildShape(i);
 
                //backup
         orgTrans = colObj->getWorldTransform();
@@ -334,15 +347,15 @@ btScalar  btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
                //btTransform   newChildWorldTrans = orgTrans*childTrans ;
                colObj->setWorldTransform( orgTrans*childTrans );
 
-               btCollisionShape* tmpShape = colObj->getCollisionShape();
-               colObj->internalSetTemporaryCollisionShape( childShape );
+               //btCollisionShape* tmpShape = colObj->getCollisionShape();
+               //colObj->internalSetTemporaryCollisionShape( childShape );
         frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
                if (frac<hitFraction)
                {
                        hitFraction = frac;
                }
                //revert back
-               colObj->internalSetTemporaryCollisionShape( tmpShape);
+               //colObj->internalSetTemporaryCollisionShape( tmpShape);
                colObj->setWorldTransform( orgTrans);
        }
        return hitFraction;
index 4045749..b16fc52 100644 (file)
@@ -41,15 +41,15 @@ class btCompoundCollisionAlgorithm  : public btActivatingCollisionAlgorithm
        
        void    removeChildAlgorithms();
        
-       void    preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1);
+       void    preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 public:
 
-       btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+       btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
        virtual ~btCompoundCollisionAlgorithm();
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        btScalar        calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -65,19 +65,19 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
-                       return new(mem) btCompoundCollisionAlgorithm(ci,body0,body1,false);
+                       return new(mem) btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
                }
        };
 
        struct SwappedCreateFunc :public        btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
-                       return new(mem) btCompoundCollisionAlgorithm(ci,body0,body1,true);
+                       return new(mem) btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
                }
        };
 
index db7f884..3e1afed 100644 (file)
@@ -43,7 +43,7 @@ subject to the following restrictions:
 
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 btConvex2dConvex2dAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*                  simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
 {
@@ -57,8 +57,8 @@ btConvex2dConvex2dAlgorithm::CreateFunc::~CreateFunc()
 { 
 }
 
-btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
-: btActivatingCollisionAlgorithm(ci,body0,body1),
+btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_simplexSolver(simplexSolver),
 m_pdSolver(pdSolver),
 m_ownManifold (false),
@@ -67,8 +67,8 @@ m_lowLevelOfDetail(false),
  m_numPerturbationIterations(numPerturbationIterations),
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 {
-       (void)body0;
-       (void)body1;
+       (void)body0Wrap;
+       (void)body1Wrap;
 }
 
 
@@ -96,13 +96,13 @@ extern btScalar gContactBreakingThreshold;
 //
 // Convex-Convex collision algorithm
 //
-void btConvex2dConvex2dAlgorithm ::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvex2dConvex2dAlgorithm ::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
 
        if (!m_manifoldPtr)
        {
                //swapped?
-               m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
+               m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
                m_ownManifold = true;
        }
        resultOut->setPersistentManifold(m_manifoldPtr);
@@ -111,8 +111,8 @@ void btConvex2dConvex2dAlgorithm ::processCollision (btCollisionObject* body0,bt
        //resultOut->getPersistentManifold()->clearManifold();
 
 
-       btConvexShape* min0 = static_cast<btConvexShape*>(body0->getCollisionShape());
-       btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape());
+       const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
+       const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
 
        btVector3  normalOnB;
        btVector3  pointOnBWorld;
@@ -133,8 +133,8 @@ void btConvex2dConvex2dAlgorithm ::processCollision (btCollisionObject* body0,bt
                }
 
                input.m_stackAlloc = dispatchInfo.m_stackAllocator;
-               input.m_transformA = body0->getWorldTransform();
-               input.m_transformB = body1->getWorldTransform();
+               input.m_transformA = body0Wrap->getWorldTransform();
+               input.m_transformB = body1Wrap->getWorldTransform();
 
                gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 
index 53d13b8..18d9385 100644 (file)
@@ -45,12 +45,12 @@ class btConvex2dConvex2dAlgorithm : public btActivatingCollisionAlgorithm
 
 public:
 
-       btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
+       btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
 
 
        virtual ~btConvex2dConvex2dAlgorithm();
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -82,10 +82,10 @@ public:
                
                virtual ~CreateFunc();
 
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvex2dConvex2dAlgorithm));
-                       return new(mem) btConvex2dConvex2dAlgorithm(ci.m_manifold,ci,body0,body1,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+                       return new(mem) btConvex2dConvex2dAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
                }
        };
 
index d2b2c22..18fde77 100644 (file)
@@ -25,11 +25,12 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
-btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
-: btActivatingCollisionAlgorithm(ci,body0,body1),
+btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_isSwapped(isSwapped),
-m_btConvexTriangleCallback(ci.m_dispatcher1,body0,body1,isSwapped)
+m_btConvexTriangleCallback(ci.m_dispatcher1,body0Wrap,body1Wrap,isSwapped)
 {
 }
 
@@ -46,17 +47,17 @@ void        btConvexConcaveCollisionAlgorithm::getAllContactManifolds(btManifoldArray&
 }
 
 
-btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher*  dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped):
+btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher*  dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped):
          m_dispatcher(dispatcher),
        m_dispatchInfoPtr(0)
 {
-       m_convexBody = isSwapped? body1:body0;
-       m_triBody = isSwapped? body0:body1;
+       m_convexBodyWrap = isSwapped? body1Wrap:body0Wrap;
+       m_triBodyWrap = isSwapped? body0Wrap:body1Wrap;
        
          //
          // create the manifold from the dispatcher 'manifold pool'
          //
-         m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
+         m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBodyWrap->getCollisionObject(),m_triBodyWrap->getCollisionObject());
 
          clearCache();
 }
@@ -88,7 +89,7 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
        btCollisionAlgorithmConstructionInfo ci;
        ci.m_dispatcher1 = m_dispatcher;
 
-       btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
+       //const btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
 
 
 #if 0  
@@ -103,46 +104,63 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
        }
 #endif
        
-       if (m_convexBody->getCollisionShape()->isConvex())
+       if (m_convexBodyWrap->getCollisionShape()->isConvex())
        {
                btTriangleShape tm(triangle[0],triangle[1],triangle[2]);        
                tm.setMargin(m_collisionMarginTriangle);
                
-               btCollisionShape* tmpShape = ob->getCollisionShape();
-               ob->internalSetTemporaryCollisionShape( &tm );
+               
+               btCollisionObjectWrapper triObWrap(m_triBodyWrap,&tm,m_triBodyWrap->getCollisionObject(),m_triBodyWrap->getWorldTransform(),partId,triangleIndex);//correct transform?
+               btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap,&triObWrap,m_manifoldPtr);
 
-               btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr);
+               const btCollisionObjectWrapper* tmpWrap = 0;
 
-               if (m_resultOut->getBody0Internal() == m_triBody)
+               if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
                {
+                       tmpWrap = m_resultOut->getBody0Wrap();
+                       m_resultOut->setBody0Wrap(&triObWrap);
                        m_resultOut->setShapeIdentifiersA(partId,triangleIndex);
                }
                else
                {
+                       tmpWrap = m_resultOut->getBody1Wrap();
+                       m_resultOut->setBody1Wrap(&triObWrap);
                        m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
                }
        
-               colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
+               colAlgo->processCollision(m_convexBodyWrap,&triObWrap,*m_dispatchInfoPtr,m_resultOut);
+
+               if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
+               {
+                       m_resultOut->setBody0Wrap(tmpWrap);
+               } else
+               {
+                       m_resultOut->setBody1Wrap(tmpWrap);
+               }
+               
+
+
                colAlgo->~btCollisionAlgorithm();
                ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
-               ob->internalSetTemporaryCollisionShape( tmpShape);
        }
 
-
 }
 
 
 
-void   btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void   btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut)
 {
+       m_convexBodyWrap = convexBodyWrap;
+       m_triBodyWrap = triBodyWrap;
+
        m_dispatchInfoPtr = &dispatchInfo;
        m_collisionMarginTriangle = collisionMarginTriangle;
        m_resultOut = resultOut;
 
        //recalc aabbs
        btTransform convexInTriangleSpace;
-       convexInTriangleSpace = m_triBody->getWorldTransform().inverse() * m_convexBody->getWorldTransform();
-       btCollisionShape* convexShape = static_cast<btCollisionShape*>(m_convexBody->getCollisionShape());
+       convexInTriangleSpace = m_triBodyWrap->getWorldTransform().inverse() * m_convexBodyWrap->getWorldTransform();
+       const btCollisionShape* convexShape = static_cast<const btCollisionShape*>(m_convexBodyWrap->getCollisionShape());
        //CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
        convexShape->getAabb(convexInTriangleSpace,m_aabbMin,m_aabbMax);
        btScalar extraMargin = collisionMarginTriangle;
@@ -159,35 +177,34 @@ void btConvexConcaveCollisionAlgorithm::clearCache()
 
 }
 
-void btConvexConcaveCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexConcaveCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        
        
-       btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
-       btCollisionObject* triBody = m_isSwapped ? body0 : body1;
+       const btCollisionObjectWrapper* convexBodyWrap = m_isSwapped ? body1Wrap : body0Wrap;
+       const btCollisionObjectWrapper* triBodyWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
-       if (triBody->getCollisionShape()->isConcave())
+       if (triBodyWrap->getCollisionShape()->isConcave())
        {
 
 
-               btCollisionObject*      triOb = triBody;
-               btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
                
-               if (convexBody->getCollisionShape()->isConvex())
+               const btConcaveShape* concaveShape = static_cast<const btConcaveShape*>( triBodyWrap->getCollisionShape());
+               
+               if (convexBodyWrap->getCollisionShape()->isConvex())
                {
                        btScalar 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.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,convexBodyWrap,triBodyWrap,resultOut);
 
-                       m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
+                       m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBodyWrap->getCollisionObject(),triBodyWrap->getCollisionObject());
 
                        concaveShape->processAllTriangles( &m_btConvexTriangleCallback,m_btConvexTriangleCallback.getAabbMin(),m_btConvexTriangleCallback.getAabbMax());
                        
                        resultOut->refreshContactPoints();
+
+                       m_btConvexTriangleCallback.clearWrapperData();
        
                }
        
index f718d1d..e90d06e 100644 (file)
@@ -28,8 +28,8 @@ class btDispatcher;
 ///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;
+       const btCollisionObjectWrapper* m_convexBodyWrap;
+       const btCollisionObjectWrapper* m_triBodyWrap;
 
        btVector3       m_aabbMin;
        btVector3       m_aabbMax ;
@@ -45,10 +45,15 @@ int m_triangleCount;
        
        btPersistentManifold*   m_manifoldPtr;
 
-       btConvexTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+       btConvexTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
-       void    setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       void    setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut);
 
+       void    clearWrapperData()
+       {
+               m_convexBodyWrap = 0;
+               m_triBodyWrap = 0;
+       }
        virtual ~btConvexTriangleCallback();
 
        virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
@@ -81,11 +86,11 @@ class btConvexConcaveCollisionAlgorithm  : public btActivatingCollisionAlgorithm
 
 public:
 
-       btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+       btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
        virtual ~btConvexConcaveCollisionAlgorithm();
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        btScalar        calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -95,19 +100,19 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
-                       return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0,body1,false);
+                       return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
                }
        };
 
        struct SwappedCreateFunc :public        btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
-                       return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0,body1,true);
+                       return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
                }
        };
 
index dd1f3e2..62f98a8 100644 (file)
@@ -52,7 +52,7 @@ subject to the following restrictions:
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 ///////////
 
@@ -191,8 +191,8 @@ btConvexConvexAlgorithm::CreateFunc::~CreateFunc()
 { 
 }
 
-btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
-: btActivatingCollisionAlgorithm(ci,body0,body1),
+btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_simplexSolver(simplexSolver),
 m_pdSolver(pdSolver),
 m_ownManifold (false),
@@ -205,8 +205,8 @@ m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngu
 m_numPerturbationIterations(numPerturbationIterations),
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 {
-       (void)body0;
-       (void)body1;
+       (void)body0Wrap;
+       (void)body1Wrap;
 }
 
 
@@ -289,13 +289,13 @@ extern btScalar gContactBreakingThreshold;
 //
 // Convex-Convex collision algorithm
 //
-void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexConvexAlgorithm ::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
 
        if (!m_manifoldPtr)
        {
                //swapped?
-               m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1);
+               m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
                m_ownManifold = true;
        }
        resultOut->setPersistentManifold(m_manifoldPtr);
@@ -304,8 +304,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
        //resultOut->getPersistentManifold()->clearManifold();
        
 
-       btConvexShape* min0 = static_cast<btConvexShape*>(body0->getCollisionShape());
-       btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape());
+       const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
+       const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
 
        btVector3  normalOnB;
                btVector3  pointOnBWorld;
@@ -314,14 +314,14 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
        {
                btCapsuleShape* capsuleA = (btCapsuleShape*) min0;
                btCapsuleShape* capsuleB = (btCapsuleShape*) min1;
-               btVector3 localScalingA = capsuleA->getLocalScaling();
-               btVector3 localScalingB = capsuleB->getLocalScaling();
+       //      btVector3 localScalingA = capsuleA->getLocalScaling();
+       //      btVector3 localScalingB = capsuleB->getLocalScaling();
                
                btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
 
                btScalar dist = capsuleCapsuleDistance(normalOnB,       pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(),
                        capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(),
-                       body0->getWorldTransform(),body1->getWorldTransform(),threshold);
+                       body0Wrap->getWorldTransform(),body1Wrap->getWorldTransform(),threshold);
 
                if (dist<threshold)
                {
@@ -374,8 +374,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
        }
 
        input.m_stackAlloc = dispatchInfo.m_stackAllocator;
-       input.m_transformA = body0->getWorldTransform();
-       input.m_transformB = body1->getWorldTransform();
+       input.m_transformA = body0Wrap->getWorldTransform();
+       input.m_transformB = body1Wrap->getWorldTransform();
 
 
 
@@ -407,9 +407,51 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
                        {
                        }
                };
+
+               
+               struct btWithoutMarginResult : public btDiscreteCollisionDetectorInterface::Result
+               {
+                       btDiscreteCollisionDetectorInterface::Result* m_originalResult;
+                       btVector3       m_reportedNormalOnWorld;
+                       btScalar m_marginOnA;
+                       btScalar m_marginOnB;
+                       btScalar        m_reportedDistance;
+                       
+                       bool            m_foundResult;
+                       btWithoutMarginResult(btDiscreteCollisionDetectorInterface::Result* result, btScalar marginOnA, btScalar marginOnB)
+                       :m_originalResult(result),
+                       m_marginOnA(marginOnA),
+                       m_marginOnB(marginOnB),
+                       m_foundResult(false)
+                       {
+                       }
+                       
+                       virtual void setShapeIdentifiersA(int partId0,int index0){}
+                       virtual void setShapeIdentifiersB(int partId1,int index1){}
+                       virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorldOrg,btScalar depthOrg) 
+                       {
+                               m_reportedDistance = depthOrg;
+                               m_reportedNormalOnWorld = normalOnBInWorld;
+                               
+                               btVector3 adjustedPointB = pointInWorldOrg - normalOnBInWorld*m_marginOnB;
+                               m_reportedDistance = depthOrg+(m_marginOnA+m_marginOnB);
+                               if (m_reportedDistance<0.f)
+                               {
+                                       m_foundResult = true;                                   
+                               }
+                               m_originalResult->addContactPoint(normalOnBInWorld,adjustedPointB,m_reportedDistance);
+                       }
+               };
+
                
                btDummyResult dummy;
 
+///btBoxShape is an exception: its vertices are created WITH margin so don't subtract it
+
+               btScalar min0Margin = min0->getShapeType()==BOX_SHAPE_PROXYTYPE? 0.f : min0->getMargin();
+               btScalar min1Margin = min1->getShapeType()==BOX_SHAPE_PROXYTYPE? 0.f : min1->getMargin();
+
+               btWithoutMarginResult   withoutMargin(resultOut, min0Margin,min1Margin);
 
                btPolyhedralConvexShape* polyhedronA = (btPolyhedralConvexShape*) min0;
                btPolyhedralConvexShape* polyhedronB = (btPolyhedralConvexShape*) min1;
@@ -429,39 +471,42 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
                        {
                                foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis(
                                        *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
-                                       body0->getWorldTransform(), 
-                                       body1->getWorldTransform(),
-                                       sepNormalWorldSpace);
+                                       body0Wrap->getWorldTransform(), 
+                                       body1Wrap->getWorldTransform(),
+                                       sepNormalWorldSpace,*resultOut);
                        } else
                        {
 #ifdef ZERO_MARGIN
                                gjkPairDetector.setIgnoreMargin(true);
                                gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 #else
-                               //gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
-                               gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw);
+
+
+                               gjkPairDetector.getClosestPoints(input,withoutMargin,dispatchInfo.m_debugDraw);
+                               //gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw);
 #endif //ZERO_MARGIN
-                               btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2();
-                               if (l2>SIMD_EPSILON)
+                               //btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2();
+                               //if (l2>SIMD_EPSILON)
                                {
-                                       sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2);
+                                       sepNormalWorldSpace = withoutMargin.m_reportedNormalOnWorld;//gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2);
                                        //minDist = -1e30f;//gjkPairDetector.getCachedSeparatingDistance();
-                                       minDist = gjkPairDetector.getCachedSeparatingDistance()-min0->getMargin()-min1->getMargin();
+                                       minDist = withoutMargin.m_reportedDistance;//gjkPairDetector.getCachedSeparatingDistance()+min0->getMargin()+min1->getMargin();
        
 #ifdef ZERO_MARGIN
                                        foundSepAxis = true;//gjkPairDetector.getCachedSeparatingDistance()<0.f;
 #else
-                                       foundSepAxis = gjkPairDetector.getCachedSeparatingDistance()<(min0->getMargin()+min1->getMargin());
+                                       foundSepAxis = withoutMargin.m_foundResult && minDist<0;//-(min0->getMargin()+min1->getMargin());
 #endif
                                }
                        }
                        if (foundSepAxis)
                        {
+                               
 //                             printf("sepNormalWorldSpace=%f,%f,%f\n",sepNormalWorldSpace.getX(),sepNormalWorldSpace.getY(),sepNormalWorldSpace.getZ());
 
                                btPolyhedralContactClipping::clipHullAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
-                                       body0->getWorldTransform(), 
-                                       body1->getWorldTransform(), minDist-threshold, threshold, *resultOut);
+                                       body0Wrap->getWorldTransform(), 
+                                       body1Wrap->getWorldTransform(), minDist-threshold, threshold, *resultOut);
                                
                        }
                        if (m_ownManifold)
@@ -478,9 +523,9 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 
                                btVertexArray vertices;
                                btTriangleShape* tri = (btTriangleShape*)polyhedronB;
-                               vertices.push_back(     body1->getWorldTransform()*tri->m_vertices1[0]);
-                               vertices.push_back(     body1->getWorldTransform()*tri->m_vertices1[1]);
-                               vertices.push_back(     body1->getWorldTransform()*tri->m_vertices1[2]);
+                               vertices.push_back(     body1Wrap->getWorldTransform()*tri->m_vertices1[0]);
+                               vertices.push_back(     body1Wrap->getWorldTransform()*tri->m_vertices1[1]);
+                               vertices.push_back(     body1Wrap->getWorldTransform()*tri->m_vertices1[2]);
                                
                                //tri->initializePolyhedralFeatures();
 
@@ -496,9 +541,9 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
                                        polyhedronB->initializePolyhedralFeatures();
                                         foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis(
                                        *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
-                                       body0->getWorldTransform(), 
-                                       body1->getWorldTransform(),
-                                       sepNormalWorldSpace);
+                                       body0Wrap->getWorldTransform(), 
+                                       body1Wrap->getWorldTransform(),
+                                       sepNormalWorldSpace,*resultOut);
                                //       printf("sepNormalWorldSpace=%f,%f,%f\n",sepNormalWorldSpace.getX(),sepNormalWorldSpace.getY(),sepNormalWorldSpace.getZ());
 
                                } else
@@ -525,7 +570,7 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
                        if (foundSepAxis)
                        {
                                btPolyhedralContactClipping::clipFaceAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), 
-                                       body0->getWorldTransform(), vertices, minDist-threshold, maxDist, *resultOut);
+                                       body0Wrap->getWorldTransform(), vertices, minDist-threshold, maxDist, *resultOut);
                        }
                                
                                
@@ -599,15 +644,15 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
                                
                                if (perturbeA)
                                {
-                                       input.m_transformA.setBasis(  btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0->getWorldTransform().getBasis());
-                                       input.m_transformB = body1->getWorldTransform();
+                                       input.m_transformA.setBasis(  btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0Wrap->getWorldTransform().getBasis());
+                                       input.m_transformB = body1Wrap->getWorldTransform();
        #ifdef DEBUG_CONTACTS
                                        dispatchInfo.m_debugDraw->drawTransform(input.m_transformA,10.0);
        #endif //DEBUG_CONTACTS
                                } else
                                {
-                                       input.m_transformA = body0->getWorldTransform();
-                                       input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1->getWorldTransform().getBasis());
+                                       input.m_transformA = body0Wrap->getWorldTransform();
+                                       input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1Wrap->getWorldTransform().getBasis());
        #ifdef DEBUG_CONTACTS
                                        dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0);
        #endif
index 4380b80..51db0c6 100644 (file)
@@ -59,12 +59,11 @@ class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 
 public:
 
-       btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
-
+       btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
 
        virtual ~btConvexConvexAlgorithm();
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -96,10 +95,10 @@ public:
                
                virtual ~CreateFunc();
 
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConvexAlgorithm));
-                       return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0,body1,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+                       return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
                }
        };
 
index b2e9bfa..cce2d95 100644 (file)
@@ -19,10 +19,11 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 //#include <stdio.h>
 
-btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
+btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
 : btCollisionAlgorithm(ci),
 m_ownManifold(false),
 m_manifoldPtr(mf),
@@ -30,12 +31,12 @@ m_isSwapped(isSwapped),
 m_numPerturbationIterations(numPerturbationIterations),
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 {
-       btCollisionObject* convexObj = m_isSwapped? col1 : col0;
-       btCollisionObject* planeObj = m_isSwapped? col0 : col1;
+       const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? col1Wrap : col0Wrap;
+       const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? col0Wrap : col1Wrap;
 
-       if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj))
+       if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObjWrap->getCollisionObject(),planeObjWrap->getCollisionObject()))
        {
-               m_manifoldPtr = m_dispatcher->getNewManifold(convexObj,planeObj);
+               m_manifoldPtr = m_dispatcher->getNewManifold(convexObjWrap->getCollisionObject(),planeObjWrap->getCollisionObject());
                m_ownManifold = true;
        }
 }
@@ -50,25 +51,25 @@ btConvexPlaneCollisionAlgorithm::~btConvexPlaneCollisionAlgorithm()
        }
 }
 
-void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
-    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
-       btCollisionObject* planeObj = m_isSwapped? body0: body1;
+    const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+       const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? body0Wrap: body1Wrap;
 
-       btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
-       btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
+       btConvexShape* convexShape = (btConvexShape*) convexObjWrap->getCollisionShape();
+       btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObjWrap->getCollisionShape();
 
     bool hasCollision = false;
        const btVector3& planeNormal = planeShape->getPlaneNormal();
        const btScalar& planeConstant = planeShape->getPlaneConstant();
        
-       btTransform convexWorldTransform = convexObj->getWorldTransform();
+       btTransform convexWorldTransform = convexObjWrap->getWorldTransform();
        btTransform convexInPlaneTrans;
-       convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexWorldTransform;
+       convexInPlaneTrans= planeObjWrap->getWorldTransform().inverse() * convexWorldTransform;
        //now perturbe the convex-world transform
        convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot);
        btTransform planeInConvex;
-       planeInConvex= convexWorldTransform.inverse() * planeObj->getWorldTransform();
+       planeInConvex= convexWorldTransform.inverse() * planeObjWrap->getWorldTransform();
        
        btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
 
@@ -76,53 +77,53 @@ void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion&
        btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 
        btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
-       btVector3 vtxInPlaneWorld = planeObj->getWorldTransform() * vtxInPlaneProjected;
+       btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 
        hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
        resultOut->setPersistentManifold(m_manifoldPtr);
        if (hasCollision)
        {
                /// report a contact. internally this will be kept persistent, and contact reduction is done
-               btVector3 normalOnSurfaceB = planeObj->getWorldTransform().getBasis() * planeNormal;
+               btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
                btVector3 pOnB = vtxInPlaneWorld;
                resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
        }
 }
 
 
-void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexPlaneCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        (void)dispatchInfo;
        if (!m_manifoldPtr)
                return;
 
-       btCollisionObject* convexObj = m_isSwapped? body1 : body0;
-       btCollisionObject* planeObj = m_isSwapped? body0: body1;
+       const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+       const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? body0Wrap: body1Wrap;
 
-       btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
-       btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
+       btConvexShape* convexShape = (btConvexShape*) convexObjWrap->getCollisionShape();
+       btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObjWrap->getCollisionShape();
 
        bool hasCollision = false;
        const btVector3& planeNormal = planeShape->getPlaneNormal();
        const btScalar& planeConstant = planeShape->getPlaneConstant();
        btTransform planeInConvex;
-       planeInConvex= convexObj->getWorldTransform().inverse() * planeObj->getWorldTransform();
+       planeInConvex= convexObjWrap->getWorldTransform().inverse() * planeObjWrap->getWorldTransform();
        btTransform convexInPlaneTrans;
-       convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->getWorldTransform();
+       convexInPlaneTrans= planeObjWrap->getWorldTransform().inverse() * convexObjWrap->getWorldTransform();
 
        btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
        btVector3 vtxInPlane = convexInPlaneTrans(vtx);
        btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 
        btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
-       btVector3 vtxInPlaneWorld = planeObj->getWorldTransform() * vtxInPlaneProjected;
+       btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 
        hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
        resultOut->setPersistentManifold(m_manifoldPtr);
        if (hasCollision)
        {
                /// report a contact. internally this will be kept persistent, and contact reduction is done
-               btVector3 normalOnSurfaceB = planeObj->getWorldTransform().getBasis() * planeNormal;
+               btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
                btVector3 pOnB = vtxInPlaneWorld;
                resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
        }
@@ -148,7 +149,7 @@ void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0
                {
                        btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
                        btQuaternion rotq(planeNormal,iterationAngle);
-                       collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0,body1,dispatchInfo,resultOut);
+                       collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0Wrap,body1Wrap,dispatchInfo,resultOut);
                }
        }
 
index b9494f5..d28c430 100644 (file)
@@ -36,13 +36,13 @@ class btConvexPlaneCollisionAlgorithm : public btCollisionAlgorithm
 
 public:
 
-       btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold);
+       btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold);
 
        virtual ~btConvexPlaneCollisionAlgorithm();
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
-       void collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       void collideSingleContact (const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -65,15 +65,15 @@ public:
                {
                }
                
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexPlaneCollisionAlgorithm));
                        if (!m_swapped)
                        {
-                               return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,false,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+                               return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
                        } else
                        {
-                               return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,true,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+                               return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
                        }
                }
        };
index 81ed424..474785b 100644 (file)
@@ -78,10 +78,8 @@ protected:
        btCollisionAlgorithmCreateFunc* m_swappedCompoundCreateFunc;
        btCollisionAlgorithmCreateFunc* m_emptyCreateFunc;
        btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
-#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
        btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
        btCollisionAlgorithmCreateFunc* m_boxSphereCF;
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
 
        btCollisionAlgorithmCreateFunc* m_boxBoxCF;
        btCollisionAlgorithmCreateFunc* m_sphereTriangleCF;
index 9360543..5fa1c8b 100644 (file)
@@ -22,7 +22,7 @@ btEmptyAlgorithm::btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& c
 {
 }
 
-void btEmptyAlgorithm::processCollision (btCollisionObject* ,btCollisionObject* ,const btDispatcherInfo& ,btManifoldResult* )
+void btEmptyAlgorithm::processCollision (const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* ,const btDispatcherInfo& ,btManifoldResult* )
 {
 }
 
index f03c9dc..cb0f152 100644 (file)
@@ -30,7 +30,7 @@ public:
        
        btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -40,10 +40,10 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
-               {
-                       (void)body0;
-                       (void)body1;
+        virtual        btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+        {
+                       (void)body0Wrap;
+                       (void)body1Wrap;
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btEmptyAlgorithm));
                        return new(mem) btEmptyAlgorithm(ci);
                }
index 4353cda..73fa4e8 100644 (file)
@@ -6,7 +6,7 @@
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
 #include "LinearMath/btIDebugDraw.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 //#define DEBUG_INTERNAL_EDGE
 
@@ -450,18 +450,18 @@ bool      btClampNormal(const btVector3& edge,const btVector3& tri_normal_org,const b
 
 
 /// Changes a btManifoldPoint collision normal to the normal from the mesh.
-void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* colObj0,const btCollisionObject* colObj1, int partId0, int index0, int normalAdjustFlags)
+void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,const btCollisionObjectWrapper* colObj1Wrap, int partId0, int index0, int normalAdjustFlags)
 {
        //btAssert(colObj0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE);
-       if (colObj0->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
+       if (colObj0Wrap->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
                return;
 
        btBvhTriangleMeshShape* trimesh = 0;
        
-       if( colObj0->getRootCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE )
-          trimesh = ((btScaledBvhTriangleMeshShape*)colObj0->getRootCollisionShape())->getChildShape();
+       if( colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE )
+          trimesh = ((btScaledBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape())->getChildShape();
    else           
-          trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape();
+          trimesh = (btBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape();
           
        btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
        if (!triangleInfoMapPtr)
@@ -476,13 +476,13 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
 
        btScalar frontFacing = (normalAdjustFlags & BT_TRIANGLE_CONVEX_BACKFACE_MODE)==0? 1.f : -1.f;
        
-       const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0->getCollisionShape());
+       const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0Wrap->getCollisionShape());
        btVector3 v0,v1,v2;
        tri_shape->getVertex(0,v0);
        tri_shape->getVertex(1,v1);
        tri_shape->getVertex(2,v2);
 
-       btVector3 center = (v0+v1+v2)*btScalar(1./3.);
+       //btVector3 center = (v0+v1+v2)*btScalar(1./3.);
 
        btVector3 red(1,0,0), green(0,1,0),blue(0,0,1),white(1,1,1),black(0,0,0);
        btVector3 tri_normal;
@@ -505,7 +505,7 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
        int numConcaveEdgeHits = 0;
        int numConvexEdgeHits = 0;
 
-       btVector3 localContactNormalOnB = colObj0->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
+       btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
        localContactNormalOnB.normalize();//is this necessary?
        
        // Get closest edge
@@ -613,12 +613,12 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
                                        {
                                                if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
                                                {
-                                                       btVector3 newNormal = colObj0->getWorldTransform().getBasis() * clampedLocalNormal;
+                                                       btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
                                                        //                                      cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
                                                        cp.m_normalWorldOnB = newNormal;
                                                        // Reproject collision point along normal. (what about cp.m_distance1?)
                                                        cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-                                                       cp.m_localPointB = colObj0->getWorldTransform().invXform(cp.m_positionWorldOnB);
+                                                       cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
                                                        
                                                }
                                        }
@@ -694,19 +694,19 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
                                else
                                {
                                        numConvexEdgeHits++;
-                                       btVector3 localContactNormalOnB = colObj0->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
+                                       btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
                                        btVector3 clampedLocalNormal;
                                        bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB, info->m_edgeV1V2Angle,clampedLocalNormal);
                                        if (isClamped)
                                        {
                                                if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
                                                {
-                                                       btVector3 newNormal = colObj0->getWorldTransform().getBasis() * clampedLocalNormal;
+                                                       btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
                                                        //                                      cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
                                                        cp.m_normalWorldOnB = newNormal;
                                                        // Reproject collision point along normal.
                                                        cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-                                                       cp.m_localPointB = colObj0->getWorldTransform().invXform(cp.m_positionWorldOnB);
+                                                       cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
                                                }
                                        }
                                }
@@ -779,19 +779,19 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
                                        //                              printf("hitting convex edge\n");
 
 
-                                       btVector3 localContactNormalOnB = colObj0->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
+                                       btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
                                        btVector3 clampedLocalNormal;
                                        bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB,info->m_edgeV2V0Angle,clampedLocalNormal);
                                        if (isClamped)
                                        {
                                                if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
                                                {
-                                                       btVector3 newNormal = colObj0->getWorldTransform().getBasis() * clampedLocalNormal;
+                                                       btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
                                                        //                                      cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
                                                        cp.m_normalWorldOnB = newNormal;
                                                        // Reproject collision point along normal.
                                                        cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-                                                       cp.m_localPointB = colObj0->getWorldTransform().invXform(cp.m_positionWorldOnB);
+                                                       cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
                                                }
                                        }
                                } 
@@ -820,7 +820,7 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
                                {
                                        tri_normal *= -1;
                                }
-                               cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis()*tri_normal;
+                               cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis()*tri_normal;
                        } else
                        {
                                btVector3 newNormal = tri_normal *frontFacing;
@@ -831,12 +831,12 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject*
                                        return;
                                }
                                //modify the normal to be the triangle normal (or backfacing normal)
-                               cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() *newNormal;
+                               cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() *newNormal;
                        }
                                                
                        // Reproject collision point along normal.
                        cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-                       cp.m_localPointB = colObj0->getWorldTransform().invXform(cp.m_positionWorldOnB);
+                       cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
                }
        }
 }
index 9efb012..7d9aafe 100644 (file)
@@ -12,6 +12,7 @@
 
 class btBvhTriangleMeshShape;
 class btCollisionObject;
+struct btCollisionObjectWrapper;
 class btManifoldPoint;
 class btIDebugDraw;
 
@@ -31,7 +32,7 @@ void  btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangle
 
 ///Call the btFixMeshNormal to adjust the collision normal, using the triangle info map (generated using btGenerateInternalEdgeInfo)
 ///If this info map is missing, or the triangle is not store in this map, nothing will be done
-void   btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* trimeshColObj0,const btCollisionObject* otherColObj1, int partId0, int index0, int normalAdjustFlags = 0);
+void   btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* trimeshColObj0Wrap,const btCollisionObjectWrapper* otherColObj1Wrap, int partId0, int index0, int normalAdjustFlags = 0);
 
 ///Enable the BT_INTERNAL_EDGE_DEBUG_DRAW define and call btSetDebugDrawer, to get visual info to see if the internal edge utility works properly.
 ///If the utility doesn't work properly, you might have to adjust the threshold values in btTriangleInfoMap
index bf24246..4b2986a 100644 (file)
@@ -17,13 +17,30 @@ subject to the following restrictions:
 #include "btManifoldResult.h"
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.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        calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+{
+       btScalar friction = body0->getRollingFriction() * body1->getRollingFriction();
+
+       const btScalar MAX_FRICTION  = btScalar(10.);
+       if (friction < -MAX_FRICTION)
+               friction = -MAX_FRICTION;
+       if (friction > MAX_FRICTION)
+               friction = MAX_FRICTION;
+       return friction;
+
+}
+
+
 ///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       btManifoldResult::calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1)
 {
        btScalar friction = body0->getFriction() * body1->getFriction();
 
@@ -36,17 +53,17 @@ inline btScalar     calculateCombinedFriction(const btCollisionObject* body0,const b
 
 }
 
-inline btScalar        calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar       btManifoldResult::calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1)
 {
        return body0->getRestitution() * body1->getRestitution();
 }
 
 
 
-btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* body1)
+btManifoldResult::btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                :m_manifoldPtr(0),
-               m_body0(body0),
-               m_body1(body1)
+               m_body0Wrap(body0Wrap),
+               m_body1Wrap(body1Wrap)
 #ifdef DEBUG_PART_INDEX
                ,m_partId0(-1),
        m_partId1(-1),
@@ -54,8 +71,6 @@ btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* b
        m_index1(-1)
 #endif //DEBUG_PART_INDEX
 {
-       m_rootTransA = body0->getWorldTransform();
-       m_rootTransB = body1->getWorldTransform();
 }
 
 
@@ -68,7 +83,7 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
 //     if (depth > m_manifoldPtr->getContactProcessingThreshold())
                return;
 
-       bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
+       bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
 
        btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
 
@@ -77,12 +92,12 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
        
        if (isSwapped)
        {
-               localA = m_rootTransB.invXform(pointA );
-               localB = m_rootTransA.invXform(pointInWorld);
+               localA = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+               localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
        } else
        {
-               localA = m_rootTransA.invXform(pointA );
-               localB = m_rootTransB.invXform(pointInWorld);
+               localA = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+               localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
        }
 
        btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
@@ -91,9 +106,13 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
        
        int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
 
-       newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
-       newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
+       newPt.m_combinedFriction = calculateCombinedFriction(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
+       newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
+       newPt.m_combinedRollingFriction = calculateCombinedRollingFriction(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
+       btPlaneSpace1(newPt.m_normalWorldOnB,newPt.m_lateralFrictionDir1,newPt.m_lateralFrictionDir2);
+       
 
+       
    //BP mod, store contact triangles.
        if (isSwapped)
        {
@@ -122,13 +141,13 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
        //User can override friction and/or restitution
        if (gContactAddedCallback &&
                //and if either of the two bodies requires custom material
-                ((m_body0->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
-                  (m_body1->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
+                ((m_body0Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
+                  (m_body1Wrap->getCollisionObject()->getCollisionFlags() & 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)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1);
+               const btCollisionObjectWrapper* obj0Wrap = isSwapped? m_body1Wrap : m_body0Wrap;
+               const btCollisionObjectWrapper* obj1Wrap = isSwapped? m_body0Wrap : m_body1Wrap;
+               (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0Wrap,newPt.m_partId0,newPt.m_index0,obj1Wrap,newPt.m_partId1,newPt.m_index1);
        }
 
 }
index 18199b4..977b9a0 100644 (file)
@@ -18,14 +18,18 @@ subject to the following restrictions:
 #define BT_MANIFOLD_RESULT_H
 
 class btCollisionObject;
+struct btCollisionObjectWrapper;
+
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 class btManifoldPoint;
 
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 
 #include "LinearMath/btTransform.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 
-typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,      const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);
+typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,      const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1);
 extern ContactAddedCallback            gContactAddedCallback;
 
 //#define DEBUG_PART_INDEX 1
@@ -38,12 +42,8 @@ protected:
 
        btPersistentManifold* m_manifoldPtr;
 
-       //we need this for compounds
-       btTransform     m_rootTransA;
-       btTransform     m_rootTransB;
-
-       btCollisionObject* m_body0;
-       btCollisionObject* m_body1;
+       const btCollisionObjectWrapper* m_body0Wrap;
+       const btCollisionObjectWrapper* m_body1Wrap;
        int     m_partId0;
        int m_partId1;
        int m_index0;
@@ -63,7 +63,7 @@ public:
        {
        }
 
-       btManifoldResult(btCollisionObject* body0,btCollisionObject* body1);
+       btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
        virtual ~btManifoldResult() {};
 
@@ -102,27 +102,49 @@ public:
                if (!m_manifoldPtr->getNumContacts())
                        return;
 
-               bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
+               bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
 
                if (isSwapped)
                {
-                       m_manifoldPtr->refreshContactPoints(m_rootTransB,m_rootTransA);
+                       m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(),m_body0Wrap->getCollisionObject()->getWorldTransform());
                } else
                {
-                       m_manifoldPtr->refreshContactPoints(m_rootTransA,m_rootTransB);
+                       m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(),m_body1Wrap->getCollisionObject()->getWorldTransform());
                }
        }
 
+       const btCollisionObjectWrapper* getBody0Wrap() const
+       {
+               return m_body0Wrap;
+       }
+       const btCollisionObjectWrapper* getBody1Wrap() const
+       {
+               return m_body1Wrap;
+       }
+
+       void setBody0Wrap(const btCollisionObjectWrapper* obj0Wrap)
+       {
+               m_body0Wrap = obj0Wrap;
+       }
+
+       void setBody1Wrap(const btCollisionObjectWrapper* obj1Wrap)
+       {
+               m_body1Wrap = obj1Wrap;
+       }
+
        const btCollisionObject* getBody0Internal() const
        {
-               return m_body0;
+               return m_body0Wrap->getCollisionObject();
        }
 
        const btCollisionObject* getBody1Internal() const
        {
-               return m_body1;
+               return m_body1Wrap->getCollisionObject();
        }
-       
+
+       /// in the future we can let the user override the methods to combine restitution and friction
+       static btScalar calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1);
+       static btScalar calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1);
 };
 
 #endif //BT_MANIFOLD_RESULT_H
index 871c644..1344782 100644 (file)
@@ -319,8 +319,8 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
        {
                 btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
                 
-                btCollisionObject* colObj0 = static_cast<btCollisionObject*>(manifold->getBody0());
-                btCollisionObject* colObj1 = static_cast<btCollisionObject*>(manifold->getBody1());
+                const btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
+                const btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
                
                 ///@todo: check sleeping conditions!
                 if (((colObj0) && colObj0->getActivationState() != ISLAND_SLEEPING) ||
index 8df8769..e8b567e 100644 (file)
@@ -18,20 +18,21 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btBoxShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 //#include <stdio.h>
 
-btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped)
-: btActivatingCollisionAlgorithm(ci,col0,col1),
+btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped)
+: btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
 m_ownManifold(false),
 m_manifoldPtr(mf),
 m_isSwapped(isSwapped)
 {
-       btCollisionObject* sphereObj = m_isSwapped? col1 : col0;
-       btCollisionObject* boxObj = m_isSwapped? col0 : col1;
+       const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped? col1Wrap : col0Wrap;
+       const btCollisionObjectWrapper* boxObjWrap = m_isSwapped? col0Wrap : col1Wrap;
        
-       if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObj,boxObj))
+       if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObjWrap->getCollisionObject(),boxObjWrap->getCollisionObject()))
        {
-               m_manifoldPtr = m_dispatcher->getNewManifold(sphereObj,boxObj);
+               m_manifoldPtr = m_dispatcher->getNewManifold(sphereObjWrap->getCollisionObject(),boxObjWrap->getCollisionObject());
                m_ownManifold = true;
        }
 }
@@ -48,36 +49,31 @@ btSphereBoxCollisionAlgorithm::~btSphereBoxCollisionAlgorithm()
 
 
 
-void btSphereBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btSphereBoxCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
        (void)dispatchInfo;
        (void)resultOut;
        if (!m_manifoldPtr)
                return;
 
-       btCollisionObject* sphereObj = m_isSwapped? body1 : body0;
-       btCollisionObject* boxObj = m_isSwapped? body0 : body1;
+       const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+       const btCollisionObjectWrapper* boxObjWrap = m_isSwapped? body0Wrap : body1Wrap;
 
-
-       btSphereShape* sphere0 = (btSphereShape*)sphereObj->getCollisionShape();
+       btVector3 pOnBox;
 
        btVector3 normalOnSurfaceB;
-       btVector3 pOnBox,pOnSphere;
-       btVector3 sphereCenter = sphereObj->getWorldTransform().getOrigin();
+       btScalar penetrationDepth;
+       btVector3 sphereCenter = sphereObjWrap->getWorldTransform().getOrigin();
+       const btSphereShape* sphere0 = (const btSphereShape*)sphereObjWrap->getCollisionShape();
        btScalar radius = sphere0->getRadius();
-       
-       btScalar dist = getSphereDistance(boxObj,pOnBox,pOnSphere,sphereCenter,radius);
+       btScalar maxContactDistance = m_manifoldPtr->getContactBreakingThreshold();
 
        resultOut->setPersistentManifold(m_manifoldPtr);
 
-       if (dist < SIMD_EPSILON)
+       if (getSphereDistance(boxObjWrap, pOnBox, normalOnSurfaceB, penetrationDepth, sphereCenter, radius, maxContactDistance))
        {
-               btVector3 normalOnSurfaceB = (pOnBox- pOnSphere).normalize();
-
                /// report a contact. internally this will be kept persistent, and contact reduction is done
-
-               resultOut->addContactPoint(normalOnSurfaceB,pOnBox,dist);
-               
+               resultOut->addContactPoint(normalOnSurfaceB, pOnBox, penetrationDepth);
        }
 
        if (m_ownManifold)
@@ -102,159 +98,117 @@ btScalar btSphereBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
 }
 
 
-btScalar btSphereBoxCollisionAlgorithm::getSphereDistance(btCollisionObject* boxObj, btVector3& pointOnBox, btVector3& v3PointOnSphere, const btVector3& sphereCenter, btScalar fRadius ) 
+bool btSphereBoxCollisionAlgorithm::getSphereDistance(const btCollisionObjectWrapper* boxObjWrap, btVector3& pointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& sphereCenter, btScalar fRadius, btScalar maxContactDistance ) 
 {
-
-       btScalar margins;
-       btVector3 bounds[2];
-       btBoxShape* boxShape= (btBoxShape*)boxObj->getCollisionShape();
+       const btBoxShape* boxShape= (const btBoxShape*)boxObjWrap->getCollisionShape();
+       btVector3 const &boxHalfExtent = boxShape->getHalfExtentsWithoutMargin();
+       btScalar boxMargin = boxShape->getMargin();
+       penetrationDepth = 1.0f;
+
+       // convert the sphere position to the box's local space
+       btTransform const &m44T = boxObjWrap->getWorldTransform();
+       btVector3 sphereRelPos = m44T.invXform(sphereCenter);
+
+       // Determine the closest point to the sphere center in the box
+       btVector3 closestPoint = sphereRelPos;
+       closestPoint.setX( btMin(boxHalfExtent.getX(), closestPoint.getX()) );
+       closestPoint.setX( btMax(-boxHalfExtent.getX(), closestPoint.getX()) );
+       closestPoint.setY( btMin(boxHalfExtent.getY(), closestPoint.getY()) );
+       closestPoint.setY( btMax(-boxHalfExtent.getY(), closestPoint.getY()) );
+       closestPoint.setZ( btMin(boxHalfExtent.getZ(), closestPoint.getZ()) );
+       closestPoint.setZ( btMax(-boxHalfExtent.getZ(), closestPoint.getZ()) );
        
-       bounds[0] = -boxShape->getHalfExtentsWithoutMargin();
-       bounds[1] = boxShape->getHalfExtentsWithoutMargin();
-
-       margins = boxShape->getMargin();//also add sphereShape margin?
-
-       const btTransform&      m44T = boxObj->getWorldTransform();
-
-       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 = btScalar(10000000.0), fSepThis;
+       btScalar intersectionDist = fRadius + boxMargin;
+       btScalar contactDist = intersectionDist + maxContactDistance;
+       normal = sphereRelPos - closestPoint;
 
-       n[0].setValue( btScalar(-1.0),  btScalar(0.0),  btScalar(0.0) );
-       n[1].setValue(  btScalar(0.0), btScalar(-1.0),  btScalar(0.0) );
-       n[2].setValue(  btScalar(0.0),  btScalar(0.0), btScalar(-1.0) );
-       n[3].setValue(  btScalar(1.0),  btScalar(0.0),  btScalar(0.0) );
-       n[4].setValue(  btScalar(0.0),  btScalar(1.0),  btScalar(0.0) );
-       n[5].setValue(  btScalar(0.0),  btScalar(0.0),  btScalar(1.0) );
-
-       // convert  point in local space
-       prel = m44T.invXform( sphereCenter);
-       
-       bool    bFound = false;
+       //if there is no penetration, we are done
+       btScalar dist2 = normal.length2();
+       if (dist2 > contactDist * contactDist)
+       {
+               return false;
+       }
 
-       v3P = prel;
+       btScalar distance;
 
-       for (int i=0;i<6;i++)
+       //special case if the sphere center is inside the box
+       if (dist2 <= SIMD_EPSILON)
        {
-               int j = i<3? 0:1;
-               if ( (fSepThis = ((v3P-bounds[j]) .dot(n[i]))) > btScalar(0.0) )
-               {
-                       v3P = v3P - n[i]*fSepThis;              
-                       bFound = true;
-               }
+               distance = -getSpherePenetration(boxHalfExtent, sphereRelPos, closestPoint, normal);
        }
-       
-       //
-
-       if ( bFound )
+       else //compute the penetration details
        {
-               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)) > btScalar(0.0) )
-               {
-                       return btScalar(1.0);
-               }
-
-               // 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 *= btScalar(1.)/fSep;
-               }
-
-               return fSep;
+               distance = normal.length();
+               normal /= distance;
        }
 
-       //////////////////////////////////////////////////
-       // Deep penetration case
-
-       fPenetration = getSpherePenetration( boxObj,pointOnBox, v3PointOnSphere, sphereCenter, fRadius,bounds[0],bounds[1] );
+       pointOnBox = closestPoint + normal * boxMargin;
+//     v3PointOnSphere = sphereRelPos - (normal * fRadius);    
+       penetrationDepth = distance - intersectionDist;
 
-       bounds[0] = boundsVec[0];
-       bounds[1] = boundsVec[1];
-
-       if ( fPenetration <= btScalar(0.0) )
-               return (fPenetration-margins);
-       else
-               return btScalar(1.0);
+       // transform back in world space
+       btVector3 tmp = m44T(pointOnBox);
+       pointOnBox = tmp;
+//     tmp = m44T(v3PointOnSphere);
+//     v3PointOnSphere = tmp;
+       tmp = m44T.getBasis() * normal;
+       normal = tmp;
+
+       return true;
 }
 
-btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btCollisionObject* boxObj,btVector3& pointOnBox, btVector3& v3PointOnSphere, const btVector3& sphereCenter, btScalar fRadius, const btVector3& aabbMin, const btVector3& aabbMax
+btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btVector3 const &boxHalfExtent, btVector3 const &sphereRelPos, btVector3 &closestPoint, btVector3& normal 
 {
+       //project the center of the sphere on the closest face of the box
+       btScalar faceDist = boxHalfExtent.getX() - sphereRelPos.getX();
+       btScalar minDist = faceDist;
+       closestPoint.setX( boxHalfExtent.getX() );
+       normal.setValue(btScalar(1.0f),  btScalar(0.0f),  btScalar(0.0f));
+
+       faceDist = boxHalfExtent.getX() + sphereRelPos.getX();
+       if (faceDist < minDist)
+       {
+               minDist = faceDist;
+               closestPoint = sphereRelPos;
+               closestPoint.setX( -boxHalfExtent.getX() );
+               normal.setValue(btScalar(-1.0f),  btScalar(0.0f),  btScalar(0.0f));
+       }
 
-       btVector3 bounds[2];
-
-       bounds[0] = aabbMin;
-       bounds[1] = aabbMax;
-
-       btVector3       p0, tmp, prel, n[6], normal;
-       btScalar   fSep = btScalar(-10000000.0), fSepThis;
-
-       // set p0 and normal to a default value to shup up GCC
-       p0.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
-       normal.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
-
-       n[0].setValue( btScalar(-1.0),  btScalar(0.0),  btScalar(0.0) );
-       n[1].setValue(  btScalar(0.0), btScalar(-1.0),  btScalar(0.0) );
-       n[2].setValue(  btScalar(0.0),  btScalar(0.0), btScalar(-1.0) );
-       n[3].setValue(  btScalar(1.0),  btScalar(0.0),  btScalar(0.0) );
-       n[4].setValue(  btScalar(0.0),  btScalar(1.0),  btScalar(0.0) );
-       n[5].setValue(  btScalar(0.0),  btScalar(0.0),  btScalar(1.0) );
-
-       const btTransform&      m44T = boxObj->getWorldTransform();
-
-       // convert  point in local space
-       prel = m44T.invXform( sphereCenter);
-
-       ///////////
-
-       for (int i=0;i<6;i++)
+       faceDist = boxHalfExtent.getY() - sphereRelPos.getY();
+       if (faceDist < minDist)
        {
-               int j = i<3 ? 0:1;
-               if ( (fSepThis = ((prel-bounds[j]) .dot( n[i]))-fRadius) > btScalar(0.0) )      return btScalar(1.0);
-               if ( fSepThis > fSep )
-               {
-                       p0 = bounds[j]; normal = (btVector3&)n[i];
-                       fSep = fSepThis;
-               }
+               minDist = faceDist;
+               closestPoint = sphereRelPos;
+               closestPoint.setY( boxHalfExtent.getY() );
+               normal.setValue(btScalar(0.0f),  btScalar(1.0f),  btScalar(0.0f));
        }
 
-       pointOnBox = prel - normal*(normal.dot((prel-p0)));
-       v3PointOnSphere = pointOnBox + normal*fSep;
+       faceDist = boxHalfExtent.getY() + sphereRelPos.getY();
+       if (faceDist < minDist)
+       {
+               minDist = faceDist;
+               closestPoint = sphereRelPos;
+               closestPoint.setY( -boxHalfExtent.getY() );
+               normal.setValue(btScalar(0.0f),  btScalar(-1.0f),  btScalar(0.0f));
+       }
 
-       // transform back in world space
-       tmp  = m44T( pointOnBox);               
-       pointOnBox    = tmp;
-       tmp  = m44T( v3PointOnSphere);          v3PointOnSphere = tmp;
-       normal = (pointOnBox-v3PointOnSphere).normalize();
+       faceDist = boxHalfExtent.getZ() - sphereRelPos.getZ();
+       if (faceDist < minDist)
+       {
+               minDist = faceDist;
+               closestPoint = sphereRelPos;
+               closestPoint.setZ( boxHalfExtent.getZ() );
+               normal.setValue(btScalar(0.0f),  btScalar(0.0f),  btScalar(1.0f));
+       }
 
-       return fSep;
+       faceDist = boxHalfExtent.getZ() + sphereRelPos.getZ();
+       if (faceDist < minDist)
+       {
+               minDist = faceDist;
+               closestPoint = sphereRelPos;
+               closestPoint.setZ( -boxHalfExtent.getZ() );
+               normal.setValue(btScalar(0.0f),  btScalar(0.0f),  btScalar(-1.0f));
+       }
 
+       return minDist;
 }
-
index 60286ae..eefaedc 100644 (file)
@@ -34,11 +34,11 @@ class btSphereBoxCollisionAlgorithm : public btActivatingCollisionAlgorithm
        
 public:
 
-       btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped);
+       btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
        virtual ~btSphereBoxCollisionAlgorithm();
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -50,21 +50,21 @@ public:
                }
        }
 
-       btScalar getSphereDistance( btCollisionObject* boxObj,btVector3& v3PointOnBox, btVector3& v3PointOnSphere, const btVector3& v3SphereCenter, btScalar fRadius );
+       bool getSphereDistance( const btCollisionObjectWrapper* boxObjWrap, btVector3& v3PointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& v3SphereCenter, btScalar fRadius, btScalar maxContactDistance );
 
-       btScalar getSpherePenetration( btCollisionObject* boxObj, btVector3& v3PointOnBox, btVector3& v3PointOnSphere, const btVector3& v3SphereCenter, btScalar fRadius, const btVector3& aabbMin, const btVector3& aabbMax);
+       btScalar getSpherePenetration( btVector3 const &boxHalfExtent, btVector3 const &sphereRelPos, btVector3 &closestPoint, btVector3& normal );
        
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereBoxCollisionAlgorithm));
                        if (!m_swapped)
                        {
-                               return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0,body1,false);
+                               return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false);
                        } else
                        {
-                               return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0,body1,true);
+                               return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true);
                        }
                }
        };
index 5c4e78f..36ba21f 100644 (file)
@@ -17,15 +17,16 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
-btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1)
-: btActivatingCollisionAlgorithm(ci,col0,col1),
+btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap)
+: btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
 m_ownManifold(false),
 m_manifoldPtr(mf)
 {
        if (!m_manifoldPtr)
        {
-               m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1);
+               m_manifoldPtr = m_dispatcher->getNewManifold(col0Wrap->getCollisionObject(),col1Wrap->getCollisionObject());
                m_ownManifold = true;
        }
 }
@@ -39,7 +40,7 @@ btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
        }
 }
 
-void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        (void)dispatchInfo;
 
@@ -48,10 +49,10 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
 
        resultOut->setPersistentManifold(m_manifoldPtr);
 
-       btSphereShape* sphere0 = (btSphereShape*)col0->getCollisionShape();
-       btSphereShape* sphere1 = (btSphereShape*)col1->getCollisionShape();
+       btSphereShape* sphere0 = (btSphereShape*)col0Wrap->getCollisionShape();
+       btSphereShape* sphere1 = (btSphereShape*)col1Wrap->getCollisionShape();
 
-       btVector3 diff = col0->getWorldTransform().getOrigin()-  col1->getWorldTransform().getOrigin();
+       btVector3 diff = col0Wrap->getWorldTransform().getOrigin()-  col1Wrap->getWorldTransform().getOrigin();
        btScalar len = diff.length();
        btScalar radius0 = sphere0->getRadius();
        btScalar radius1 = sphere1->getRadius();
@@ -80,7 +81,7 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
        ///point on A (worldspace)
        ///btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;
        ///point on B (worldspace)
-       btVector3 pos1 = col1->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
+       btVector3 pos1 = col1Wrap->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
 
        /// report a contact. internally this will be kept persistent, and contact reduction is done
        
index e55acf2..3517a56 100644 (file)
@@ -32,12 +32,12 @@ class btSphereSphereCollisionAlgorithm : public btActivatingCollisionAlgorithm
        btPersistentManifold*   m_manifoldPtr;
        
 public:
-       btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
+       btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap);
 
        btSphereSphereCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
                : btActivatingCollisionAlgorithm(ci) {}
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -53,10 +53,10 @@ public:
 
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap)
                {
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereSphereCollisionAlgorithm));
-                       return new(mem) btSphereSphereCollisionAlgorithm(0,ci,body0,body1);
+                       return new(mem) btSphereSphereCollisionAlgorithm(0,ci,col0Wrap,col1Wrap);
                }
        };
 
index c327c3f..280a4d3 100644 (file)
@@ -19,17 +19,17 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "SphereTriangleDetector.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
-
-btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1,bool swapped)
-: btActivatingCollisionAlgorithm(ci,col0,col1),
+btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool swapped)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_ownManifold(false),
 m_manifoldPtr(mf),
 m_swapped(swapped)
 {
        if (!m_manifoldPtr)
        {
-               m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1);
+               m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
                m_ownManifold = true;
        }
 }
@@ -43,16 +43,16 @@ btSphereTriangleCollisionAlgorithm::~btSphereTriangleCollisionAlgorithm()
        }
 }
 
-void btSphereTriangleCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btSphereTriangleCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
        if (!m_manifoldPtr)
                return;
 
-       btCollisionObject* sphereObj = m_swapped? col1 : col0;
-       btCollisionObject* triObj = m_swapped? col0 : col1;
+       const btCollisionObjectWrapper* sphereObjWrap = m_swapped? col1Wrap : col0Wrap;
+       const btCollisionObjectWrapper* triObjWrap = m_swapped? col0Wrap : col1Wrap;
 
-       btSphereShape* sphere = (btSphereShape*)sphereObj->getCollisionShape();
-       btTriangleShape* triangle = (btTriangleShape*)triObj->getCollisionShape();
+       btSphereShape* sphere = (btSphereShape*)sphereObjWrap->getCollisionShape();
+       btTriangleShape* triangle = (btTriangleShape*)triObjWrap->getCollisionShape();
        
        /// report a contact. internally this will be kept persistent, and contact reduction is done
        resultOut->setPersistentManifold(m_manifoldPtr);
@@ -60,8 +60,8 @@ void btSphereTriangleCollisionAlgorithm::processCollision (btCollisionObject* co
        
        btDiscreteCollisionDetectorInterface::ClosestPointInput input;
        input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds
-       input.m_transformA = sphereObj->getWorldTransform();
-       input.m_transformB = triObj->getWorldTransform();
+       input.m_transformA = sphereObjWrap->getWorldTransform();
+       input.m_transformB = triObjWrap->getWorldTransform();
 
        bool swapResults = m_swapped;
 
index 7c6c4d8..6b6e39a 100644 (file)
@@ -32,12 +32,12 @@ class btSphereTriangleCollisionAlgorithm : public btActivatingCollisionAlgorithm
        bool    m_swapped;
        
 public:
-       btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool swapped);
+       btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool swapped);
 
        btSphereTriangleCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
                : btActivatingCollisionAlgorithm(ci) {}
 
-       virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+       virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
        virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
@@ -54,12 +54,12 @@ public:
        struct CreateFunc :public       btCollisionAlgorithmCreateFunc
        {
                
-               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+               virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
                {
                        
                        void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereTriangleCollisionAlgorithm));
 
-                       return new(mem) btSphereTriangleCollisionAlgorithm(ci.m_manifold,ci,body0,body1,m_swapped);
+                       return new(mem) btSphereTriangleCollisionAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_swapped);
                }
        };
 
index f4a9ca0..ce33378 100644 (file)
@@ -23,7 +23,7 @@ subject to the following restrictions:
 #include "LinearMath/btMinMax.h"
 
 ///The btBox2dShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
-class btBox2dShape: public btPolyhedralConvexShape
+ATTRIBUTE_ALIGNED16(class) btBox2dShape: public btPolyhedralConvexShape
 {
 
        //btVector3     m_boxHalfExtents1; //use m_implicitShapeDimensions instead
@@ -34,6 +34,8 @@ class btBox2dShape: public btPolyhedralConvexShape
 
 public:
 
+       BT_DECLARE_ALIGNED_ALLOCATOR();
+
        btVector3 getHalfExtentsWithMargin() const
        {
                btVector3 halfExtents = getHalfExtentsWithoutMargin();
index 0c5857d..715e3f2 100644 (file)
@@ -23,7 +23,7 @@ subject to the following restrictions:
 #include "LinearMath/btMinMax.h"
 
 ///The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
-class btBoxShape: public btPolyhedralConvexShape
+ATTRIBUTE_ALIGNED16(class) btBoxShape: public btPolyhedralConvexShape
 {
 
        //btVector3     m_boxHalfExtents1; //use m_implicitShapeDimensions instead
@@ -31,6 +31,8 @@ class btBoxShape: public btPolyhedralConvexShape
 
 public:
 
+BT_DECLARE_ALIGNED_ALLOCATOR();
+
        btVector3 getHalfExtentsWithMargin() const
        {
                btVector3 halfExtents = getHalfExtentsWithoutMargin();
index d1c2162..493d635 100644 (file)
@@ -21,7 +21,13 @@ subject to the following restrictions:
 #include "LinearMath/btAlignedAllocator.h"
 #include "btTriangleInfoMap.h"
 
-///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage.
+///The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving objects.
+///If you required moving concave triangle meshes, it is recommended to perform convex decomposition
+///using HACD, see Bullet/Demos/ConvexDecompositionDemo. 
+///Alternatively, you can use btGimpactMeshShape for moving concave triangle meshes.
+///btBvhTriangleMeshShape has several optimizations, such as bounding volume hierarchy and 
+///cache friendly traversal for PlayStation 3 Cell SPU. 
+///It is recommended to enable useQuantizedAabbCompression for better memory usage.
 ///It takes a triangle mesh as input, for example a btTriangleMesh or btTriangleIndexVertexArray. The btBvhTriangleMeshShape class allows for triangle mesh deformations by a refit or partialRefit method.
 ///Instead of building the bounding volume hierarchy acceleration structure, it is also possible to serialize (save) and deserialize (load) the structure from disk.
 ///See Demos\ConcaveDemo\ConcavePhysicsDemo.cpp for an example.
index ab763ab..7578bb2 100644 (file)
@@ -23,7 +23,7 @@ subject to the following restrictions:
 ///The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned around the X axis and btCapsuleShapeZ around the Z axis.
 ///The total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
 ///The btCapsuleShape is a convex hull of two spheres. The btMultiSphereShape is a more general collision shape that takes the convex hull of multiple sphere, so it can also represent a capsule when just using two spheres.
-class btCapsuleShape : public btConvexInternalShape
+ATTRIBUTE_ALIGNED16(class) btCapsuleShape : public btConvexInternalShape
 {
 protected:
        int     m_upAxis;
@@ -33,6 +33,9 @@ protected:
        btCapsuleShape() : btConvexInternalShape() {m_shapeType = CAPSULE_SHAPE_PROXYTYPE;};
 
 public:
+       
+       BT_DECLARE_ALIGNED_ALLOCATOR();
+       
        btCapsuleShape(btScalar radius,btScalar height);
 
        ///CollisionShape Interface
@@ -62,8 +65,8 @@ public:
                        halfExtents += btVector3(getMargin(),getMargin(),getMargin());
                        btMatrix3x3 abs_b = t.getBasis().absolute();  
                        btVector3 center = t.getOrigin();
-                       btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));              
-                       
+            btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
+        
                        aabbMin = center - extent;
                        aabbMax = center + extent;
        }
@@ -101,6 +104,14 @@ public:
 
        }
 
+       virtual btVector3       getAnisotropicRollingFrictionDirection() const
+       {
+               btVector3 aniDir(0,0,0);
+               aniDir[getUpAxis()]=1;
+               return aniDir;
+       }
+
+
        virtual int     calculateSerializeBufferSize() const;
 
        ///fills the dataBuffer and returns the struct name (and 0 on failure)
index 865c106..ff017a2 100644 (file)
@@ -24,7 +24,7 @@ class btSerializer;
 
 
 ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
-class btCollisionShape
+ATTRIBUTE_ALIGNED16(class) btCollisionShape
 {
 protected:
        int m_shapeType;
@@ -32,6 +32,8 @@ protected:
 
 public:
 
+       BT_DECLARE_ALIGNED_ALLOCATOR();
+
        btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0)
        {
        }
@@ -107,6 +109,13 @@ public:
 
        
        int             getShapeType() const { return m_shapeType; }
+
+       ///the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction
+       ///See Bullet/Demos/RollingFrictionDemo for an example
+       virtual btVector3       getAnisotropicRollingFrictionDirection() const
+       {
+               return btVector3(1,1,1);
+       }
        virtual void    setMargin(btScalar margin) = 0;
        virtual btScalar        getMargin() const = 0;
 
index 4eb860c..12f422f 100644 (file)
@@ -182,9 +182,7 @@ void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVect
 
        btVector3 center = trans(localCenter);
 
-       btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
-               abs_b[1].dot(localHalfExtents),
-               abs_b[2].dot(localHalfExtents));
+    btVector3 extent = localHalfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
        aabbMin = center-extent;
        aabbMax = center+extent;
        
index 2a03241..2917cc5 100644 (file)
@@ -33,12 +33,14 @@ typedef enum PHY_ScalarType {
 
 ///The btConcaveShape class provides an interface for non-moving (static) concave shapes.
 ///It has been implemented by the btStaticPlaneShape, btBvhTriangleMeshShape and btHeightfieldTerrainShape.
-class btConcaveShape : public btCollisionShape
+ATTRIBUTE_ALIGNED16(class) btConcaveShape : public btCollisionShape
 {
 protected:
        btScalar m_collisionMargin;
 
 public:
+       BT_DECLARE_ALIGNED_ALLOCATOR();
+       
        btConcaveShape();
 
        virtual ~btConcaveShape();
index b69b5c5..5966ae4 100644 (file)
@@ -20,7 +20,7 @@ subject to the following restrictions:
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
 
 ///The btConeShape implements a cone shape primitive, centered around the origin and aligned with the Y axis. The btConeShapeX is aligned around the X axis and btConeShapeZ around the Z axis.
-class btConeShape : public btConvexInternalShape
+ATTRIBUTE_ALIGNED16(class) btConeShape : public btConvexInternalShape
 
 {
 
@@ -32,6 +32,8 @@ class btConeShape : public btConvexInternalShape
 
 
 public:
+       BT_DECLARE_ALIGNED_ALLOCATOR();
+       
        btConeShape (btScalar radius,btScalar height);
        
        virtual btVector3       localGetSupportingVertex(const btVector3& vec) const;
@@ -82,6 +84,11 @@ public:
                        return m_coneIndices[1];
                }
 
+       virtual btVector3       getAnisotropicRollingFrictionDirection() const
+       {
+               return btVector3 (0,1,0);
+       }
+
        virtual void    setLocalScaling(const btVector3& scaling);
 
 };
@@ -91,6 +98,12 @@ class btConeShapeX : public btConeShape
 {
        public:
                btConeShapeX(btScalar radius,btScalar height);
+
+       virtual btVector3       getAnisotropicRollingFrictionDirection() const
+       {
+               return btVector3 (1,0,0);
+       }
+
 };
 
 ///btConeShapeZ implements a Cone shape, around the Z axis
@@ -98,6 +111,12 @@ class btConeShapeZ : public btConeShape
 {
        public:
                btConeShapeZ(btScalar radius,btScalar height);
+
+       virtual btVector3       getAnisotropicRollingFrictionDirection() const
+       {
+               return btVector3 (0,0,1);
+       }
+
 };
 #endif //BT_CONE_MINKOWSKI_H
 
index caf5432..bbd1caf 100644 (file)
@@ -21,12 +21,14 @@ subject to the following restrictions:
 
 ///The btConvex2dShape allows to use arbitrary convex shapes as 2d convex shapes, with the Z component assumed to be 0.
 ///For 2d boxes, the btBox2dShape is recommended.
-class btConvex2dShape : public btConvexShape
+ATTRIBUTE_ALIGNED16(class) btConvex2dShape : public btConvexShape
 {
        btConvexShape*  m_childConvexShape;
 
        public:
        
+       BT_DECLARE_ALIGNED_ALLOCATOR();
+       
        btConvex2dShape(        btConvexShape* convexChildShape);
        
        virtual ~btConvex2dShape();
index 2262459..0623e35 100644 (file)
@@ -13,6 +13,10 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 */
 
+#if defined (_WIN32) || defined (__i386__)
+#define BT_USE_SSE_IN_API
+#endif
+
 #include "btConvexHullShape.h"
 #include "BulletCollision/CollisionShapes/btCollisionMargin.h"
 
@@ -45,30 +49,28 @@ void btConvexHullShape::setLocalScaling(const btVector3& scaling)
        recalcLocalAabb();
 }
 
-void btConvexHullShape::addPoint(const btVector3& point)
+void btConvexHullShape::addPoint(const btVector3& point, bool recalculateLocalAabb)
 {
        m_unscaledPoints.push_back(point);
-       recalcLocalAabb();
+       if (recalculateLocalAabb)
+               recalcLocalAabb();
 
 }
 
 btVector3      btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
 {
        btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
-       btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
+       btScalar maxDot = btScalar(-BT_LARGE_FLOAT);
 
-       for (int i=0;i<m_unscaledPoints.size();i++)
-       {
-               btVector3 vtx = m_unscaledPoints[i] * m_localScaling;
+    // Here we take advantage of dot(a, b*c) = dot(a*b, c).  Note: This is true mathematically, but not numerically. 
+    if( 0 < m_unscaledPoints.size() )
+    {
+        btVector3 scaled&n