diff options
233 files changed, 7686 insertions, 2259 deletions
diff --git a/extern/bullet2/CMakeLists.txt b/extern/bullet2/CMakeLists.txt index ae7d282ca55..4bf26ab3794 100644 --- a/extern/bullet2/CMakeLists.txt +++ b/extern/bullet2/CMakeLists.txt @@ -43,9 +43,9 @@ set(SRC src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp - src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp + src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp src/BulletCollision/CollisionDispatch/btCollisionObject.cpp @@ -54,16 +54,21 @@ set(SRC src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp + src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btGhostObject.cpp + src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp + src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h src/BulletCollision/CollisionDispatch/btManifoldResult.cpp src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp src/BulletCollision/CollisionDispatch/btUnionFind.cpp + src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp src/BulletCollision/CollisionShapes/btBoxShape.cpp + src/BulletCollision/CollisionShapes/btBox2dShape.cpp src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp src/BulletCollision/CollisionShapes/btCapsuleShape.cpp src/BulletCollision/CollisionShapes/btCollisionShape.cpp @@ -73,14 +78,16 @@ set(SRC src/BulletCollision/CollisionShapes/btConvexHullShape.cpp src/BulletCollision/CollisionShapes/btConvexInternalShape.cpp src/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp + src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp src/BulletCollision/CollisionShapes/btConvexShape.cpp + src/BulletCollision/CollisionShapes/btConvex2dShape.cpp src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp src/BulletCollision/CollisionShapes/btCylinderShape.cpp src/BulletCollision/CollisionShapes/btEmptyShape.cpp src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp src/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp - src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp + src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp @@ -97,11 +104,11 @@ set(SRC src/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp src/BulletCollision/CollisionShapes/btUniformScalingShape.cpp src/BulletCollision/Gimpact/btContactProcessing.cpp + src/BulletCollision/Gimpact/btGenericPoolAllocator.cpp src/BulletCollision/Gimpact/btGImpactBvh.cpp src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.cpp src/BulletCollision/Gimpact/btGImpactQuantizedBvh.cpp src/BulletCollision/Gimpact/btGImpactShape.cpp - src/BulletCollision/Gimpact/btGenericPoolAllocator.cpp src/BulletCollision/Gimpact/btTriangleShapeEx.cpp src/BulletCollision/Gimpact/gim_box_set.cpp src/BulletCollision/Gimpact/gim_contact.cpp @@ -118,25 +125,28 @@ set(SRC src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.cpp src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp - src/BulletDynamics/Character/btKinematicCharacterController.cpp + src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp + src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp + src/BulletDynamics/ConstraintSolver/btHinge2Constraint.cpp src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp src/BulletDynamics/ConstraintSolver/btSliderConstraint.cpp src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.cpp src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp - src/BulletDynamics/Dynamics/Bullet-C-API.cpp - src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.cpp + src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp src/BulletDynamics/Dynamics/btRigidBody.cpp src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp + src/BulletDynamics/Dynamics/Bullet-C-API.cpp src/BulletDynamics/Vehicle/btRaycastVehicle.cpp src/BulletDynamics/Vehicle/btWheelInfo.cpp - src/BulletSoftBody/btDefaultSoftBodySolver.cpp + src/BulletDynamics/Character/btKinematicCharacterController.cpp + src/BulletSoftBody/btSoftBody.cpp src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp src/BulletSoftBody/btSoftBodyHelpers.cpp @@ -144,21 +154,16 @@ set(SRC src/BulletSoftBody/btSoftRigidCollisionAlgorithm.cpp src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp src/BulletSoftBody/btSoftSoftCollisionAlgorithm.cpp + src/BulletSoftBody/btDefaultSoftBodySolver.cpp + src/LinearMath/btAlignedAllocator.cpp src/LinearMath/btConvexHull.cpp + src/LinearMath/btConvexHullComputer.cpp src/LinearMath/btGeometryUtil.cpp src/LinearMath/btQuickprof.cpp src/LinearMath/btSerializer.cpp - # UNUSED - # src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp - # src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp - # src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp - # src/BulletCollision/CollisionShapes/btBox2dShape.cpp - # src/BulletCollision/CollisionShapes/btConvex2dShape.cpp - # src/BulletDynamics/ConstraintSolver/btHinge2Constraint.cpp - # src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp - - src/Bullet-C-Api.h + + src/BulletCollision/BroadphaseCollision/btAxisSweep3.h src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h @@ -171,9 +176,9 @@ set(SRC src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h - src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h + src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h @@ -183,6 +188,7 @@ set(SRC src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h + src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h @@ -193,7 +199,9 @@ set(SRC src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h src/BulletCollision/CollisionDispatch/btUnionFind.h + src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h src/BulletCollision/CollisionShapes/btBoxShape.h + src/BulletCollision/CollisionShapes/btBox2dShape.h src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h src/BulletCollision/CollisionShapes/btCapsuleShape.h src/BulletCollision/CollisionShapes/btCollisionMargin.h @@ -204,15 +212,17 @@ set(SRC src/BulletCollision/CollisionShapes/btConvexHullShape.h src/BulletCollision/CollisionShapes/btConvexInternalShape.h src/BulletCollision/CollisionShapes/btConvexPointCloudShape.h + src/BulletCollision/CollisionShapes/btConvexPolyhedron.h src/BulletCollision/CollisionShapes/btConvexShape.h + src/BulletCollision/CollisionShapes/btConvex2dShape.h src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h src/BulletCollision/CollisionShapes/btCylinderShape.h src/BulletCollision/CollisionShapes/btEmptyShape.h src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h src/BulletCollision/CollisionShapes/btMaterial.h src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h - src/BulletCollision/CollisionShapes/btMultiSphereShape.h src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h + src/BulletCollision/CollisionShapes/btMultiSphereShape.h src/BulletCollision/CollisionShapes/btOptimizedBvh.h src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h @@ -233,13 +243,13 @@ set(SRC src/BulletCollision/Gimpact/btBoxCollision.h src/BulletCollision/Gimpact/btClipPolygon.h src/BulletCollision/Gimpact/btContactProcessing.h + src/BulletCollision/Gimpact/btGenericPoolAllocator.h + src/BulletCollision/Gimpact/btGeometryOperations.h src/BulletCollision/Gimpact/btGImpactBvh.h src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h src/BulletCollision/Gimpact/btGImpactMassUtil.h src/BulletCollision/Gimpact/btGImpactQuantizedBvh.h src/BulletCollision/Gimpact/btGImpactShape.h - src/BulletCollision/Gimpact/btGenericPoolAllocator.h - src/BulletCollision/Gimpact/btGeometryOperations.h src/BulletCollision/Gimpact/btQuantization.h src/BulletCollision/Gimpact/btTriangleShapeEx.h src/BulletCollision/Gimpact/gim_array.h @@ -273,14 +283,15 @@ set(SRC src/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h - src/BulletDynamics/Character/btCharacterControllerInterface.h - src/BulletDynamics/Character/btKinematicCharacterController.h + src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h + src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h src/BulletDynamics/ConstraintSolver/btConstraintSolver.h src/BulletDynamics/ConstraintSolver/btContactConstraint.h src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h + src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h src/BulletDynamics/ConstraintSolver/btHingeConstraint.h src/BulletDynamics/ConstraintSolver/btJacobianEntry.h src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h @@ -290,41 +301,45 @@ set(SRC src/BulletDynamics/ConstraintSolver/btSolverBody.h src/BulletDynamics/ConstraintSolver/btSolverConstraint.h src/BulletDynamics/ConstraintSolver/btTypedConstraint.h + src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h src/BulletDynamics/Dynamics/btActionInterface.h - src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.h src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h src/BulletDynamics/Dynamics/btDynamicsWorld.h - src/BulletDynamics/Dynamics/btRigidBody.h src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h + src/BulletDynamics/Dynamics/btRigidBody.h src/BulletDynamics/Vehicle/btRaycastVehicle.h src/BulletDynamics/Vehicle/btVehicleRaycaster.h src/BulletDynamics/Vehicle/btWheelInfo.h - src/BulletSoftBody/btDefaultSoftBodySolver.h + src/BulletDynamics/Character/btCharacterControllerInterface.h + src/BulletDynamics/Character/btKinematicCharacterController.h + src/BulletSoftBody/btSoftBody.h - src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h src/BulletSoftBody/btSoftBodyData.h + src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h src/BulletSoftBody/btSoftBodyHelpers.h - src/BulletSoftBody/btSoftBodyInternals.h src/BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h - src/BulletSoftBody/btSoftBodySolverVertexBuffer.h - src/BulletSoftBody/btSoftBodySolvers.h src/BulletSoftBody/btSoftRigidCollisionAlgorithm.h src/BulletSoftBody/btSoftRigidDynamicsWorld.h src/BulletSoftBody/btSoftSoftCollisionAlgorithm.h src/BulletSoftBody/btSparseSDF.h + src/BulletSoftBody/btSoftBodySolvers.h + src/BulletSoftBody/btDefaultSoftBodySolver.h + src/BulletSoftBody/btSoftBodySolverVertexBuffer.h + src/LinearMath/btAabbUtil2.h src/LinearMath/btAlignedAllocator.h src/LinearMath/btAlignedObjectArray.h src/LinearMath/btConvexHull.h + src/LinearMath/btConvexHullComputer.h src/LinearMath/btDefaultMotionState.h src/LinearMath/btGeometryUtil.h + src/LinearMath/btGrahamScan2dConvexHull.h src/LinearMath/btHashMap.h src/LinearMath/btIDebugDraw.h src/LinearMath/btList.h src/LinearMath/btMatrix3x3.h src/LinearMath/btMinMax.h src/LinearMath/btMotionState.h - src/LinearMath/btPoint3.h src/LinearMath/btPoolAllocator.h src/LinearMath/btQuadWord.h src/LinearMath/btQuaternion.h @@ -332,20 +347,14 @@ set(SRC src/LinearMath/btRandom.h src/LinearMath/btScalar.h src/LinearMath/btSerializer.h - src/LinearMath/btSimdMinMax.h src/LinearMath/btStackAlloc.h src/LinearMath/btTransform.h src/LinearMath/btTransformUtil.h src/LinearMath/btVector3.h + + src/btBulletCollisionCommon.h src/btBulletDynamicsCommon.h - # src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h - # src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h - # src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h - # src/BulletCollision/CollisionShapes/btBox2dShape.h - # src/BulletCollision/CollisionShapes/btConvex2dShape.h - # src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h - # src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h ) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/extern/bullet2/patches/ghost_softbody.patch b/extern/bullet2/patches/ghost_softbody.patch new file mode 100644 index 00000000000..b150d57040d --- /dev/null +++ b/extern/bullet2/patches/ghost_softbody.patch @@ -0,0 +1,42 @@ +Index: extern/bullet2/src/BulletSoftBody/btSoftBody.cpp +=================================================================== +--- extern/bullet2/src/BulletSoftBody/btSoftBody.cpp (Revision 43904) ++++ extern/bullet2/src/BulletSoftBody/btSoftBody.cpp (Revision 43905) +@@ -2780,21 +2780,23 @@ + { + const RContact& c = psb->m_rcontacts[i]; + const sCti& cti = c.m_cti; +- btRigidBody* tmpRigid = btRigidBody::upcast(cti.m_colObj); + +- const btVector3 va = tmpRigid ? tmpRigid->getVelocityInLocalPoint(c.m_c1)*dt : btVector3(0,0,0); +- const btVector3 vb = c.m_node->m_x-c.m_node->m_q; +- const btVector3 vr = vb-va; +- const btScalar dn = btDot(vr, cti.m_normal); +- if(dn<=SIMD_EPSILON) +- { +- const btScalar dp = btMin( (btDot(c.m_node->m_x, cti.m_normal) + cti.m_offset), mrg ); +- const btVector3 fv = vr - (cti.m_normal * dn); +- // c0 is the impulse matrix, c3 is 1 - the friction coefficient or 0, c4 is the contact hardness coefficient +- const btVector3 impulse = c.m_c0 * ( (vr - (fv * c.m_c3) + (cti.m_normal * (dp * c.m_c4))) * kst ); +- c.m_node->m_x -= impulse * c.m_c2; +- if (tmpRigid) +- tmpRigid->applyImpulse(impulse,c.m_c1); ++ if (cti.m_colObj->hasContactResponse()) { ++ btRigidBody* tmpRigid = btRigidBody::upcast(cti.m_colObj); ++ const btVector3 va = tmpRigid ? tmpRigid->getVelocityInLocalPoint(c.m_c1)*dt : btVector3(0,0,0); ++ const btVector3 vb = c.m_node->m_x-c.m_node->m_q; ++ const btVector3 vr = vb-va; ++ const btScalar dn = btDot(vr, cti.m_normal); ++ if(dn<=SIMD_EPSILON) ++ { ++ const btScalar dp = btMin( (btDot(c.m_node->m_x, cti.m_normal) + cti.m_offset), mrg ); ++ const btVector3 fv = vr - (cti.m_normal * dn); ++ // c0 is the impulse matrix, c3 is 1 - the friction coefficient or 0, c4 is the contact hardness coefficient ++ const btVector3 impulse = c.m_c0 * ( (vr - (fv * c.m_c3) + (cti.m_normal * (dp * c.m_c4))) * kst ); ++ c.m_node->m_x -= impulse * c.m_c2; ++ if (tmpRigid) ++ tmpRigid->applyImpulse(impulse,c.m_c1); ++ } + } + } + } diff --git a/extern/bullet2/patches/pvs_warning_fixes.patch b/extern/bullet2/patches/pvs_warning_fixes.patch new file mode 100644 index 00000000000..5a3fe140454 --- /dev/null +++ b/extern/bullet2/patches/pvs_warning_fixes.patch @@ -0,0 +1,31 @@ +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 + { diff --git a/extern/bullet2/readme.txt b/extern/bullet2/readme.txt index e2546b049e3..e537ac26189 100644 --- a/extern/bullet2/readme.txt +++ b/extern/bullet2/readme.txt @@ -1,21 +1,15 @@ -*** -Apply bullet_compound_raycast.patch if not already applied in Bullet source -This patch is needed to return correct raycast results on compound shape. -/ben - - -*** These files in extern/bullet2 are NOT part of the Blender build yet *** - This is the new refactored version of Bullet physics library version 2.x -Soon this will replace the old Bullet version in extern/bullet. -First the integration in Blender Game Engine needs to be updated. -Once that is done all build systems can be updated to use/build extern/bullet2 files. - Questions? mail blender at erwincoumans.com, or check the bf-blender mailing list. Thanks, Erwin +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 diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h index 70cf3e4ace8..4f4d94b3cc7 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h @@ -16,8 +16,8 @@ // // 3. This notice may not be removed or altered from any source distribution. -#ifndef AXIS_SWEEP_3_H -#define AXIS_SWEEP_3_H +#ifndef BT_AXIS_SWEEP_3_H +#define BT_AXIS_SWEEP_3_H #include "LinearMath/btVector3.h" #include "btOverlappingPairCache.h" @@ -1026,7 +1026,7 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMaxUp(int axis, BP_FP_INT_TYPE ed /// The btAxisSweep3 is an efficient implementation of the 3d axis sweep and prune broadphase. -/// It uses arrays rather than lists for storage of the 3 axis. Also it operates using 16 bit integer coordinates instead of floats. +/// It uses arrays rather then lists for storage of the 3 axis. Also it operates using 16 bit integer coordinates instead of floats. /// For large worlds and many objects, use bt32BitAxisSweep3 or btDbvtBroadphase instead. bt32BitAxisSweep3 has higher precision and allows more then 16384 objects at the cost of more memory and bit of performance. class btAxisSweep3 : public btAxisSweep3Internal<unsigned short int> { @@ -1038,7 +1038,7 @@ public: /// The bt32BitAxisSweep3 allows higher precision quantization and more objects compared to the btAxisSweep3 sweep and prune. /// This comes at the cost of more memory per handle, and a bit slower performance. -/// It uses arrays rather than lists for storage of the 3 axis. +/// It uses arrays rather then lists for storage of the 3 axis. class bt32BitAxisSweep3 : public btAxisSweep3Internal<unsigned int> { public: diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h index fe414effbfc..f1bf00594d3 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BROADPHASE_INTERFACE_H -#define BROADPHASE_INTERFACE_H +#ifndef BT_BROADPHASE_INTERFACE_H +#define BT_BROADPHASE_INTERFACE_H @@ -79,4 +79,4 @@ public: }; -#endif //BROADPHASE_INTERFACE_H +#endif //BT_BROADPHASE_INTERFACE_H diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h index 62d349739c3..bb58b828936 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BROADPHASE_PROXY_H -#define BROADPHASE_PROXY_H +#ifndef BT_BROADPHASE_PROXY_H +#define BT_BROADPHASE_PROXY_H #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE #include "LinearMath/btVector3.h" @@ -246,7 +246,7 @@ class btBroadphasePairSortPredicate { public: - bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) + bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) const { const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1; const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1; @@ -266,5 +266,5 @@ SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphaseP } -#endif //BROADPHASE_PROXY_H +#endif //BT_BROADPHASE_PROXY_H diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h index 0d8bca41c8e..36eec97174f 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COLLISION_ALGORITHM_H -#define COLLISION_ALGORITHM_H +#ifndef BT_COLLISION_ALGORITHM_H +#define BT_COLLISION_ALGORITHM_H #include "LinearMath/btScalar.h" #include "LinearMath/btAlignedObjectArray.h" @@ -77,4 +77,4 @@ public: }; -#endif //COLLISION_ALGORITHM_H +#endif //BT_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.h index 2bb8ef5d2a7..409da80ae1b 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDbvt.h @@ -259,6 +259,7 @@ struct btDbvt btAlignedObjectArray<sStkNN> m_stkStack; + mutable btAlignedObjectArray<const btDbvtNode*> m_rayTestStack; // Methods @@ -955,7 +956,7 @@ inline void btDbvt::rayTestInternal( const btDbvtNode* root, int depth=1; int treshold=DOUBLE_STACKSIZE-2; - btAlignedObjectArray<const btDbvtNode*> stack; + btAlignedObjectArray<const btDbvtNode*>& stack = m_rayTestStack; stack.resize(DOUBLE_STACKSIZE); stack[0]=root; btVector3 bounds[2]; diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h index 8ded0006c3b..a79cf9402b1 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h @@ -13,9 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef _DISPATCHER_H -#define _DISPATCHER_H - +#ifndef BT_DISPATCHER_H +#define BT_DISPATCHER_H #include "LinearMath/btScalar.h" class btCollisionAlgorithm; @@ -27,6 +26,7 @@ class btOverlappingPairCache; class btPersistentManifold; class btStackAlloc; +class btPoolAllocator; struct btDispatcherInfo { @@ -40,7 +40,7 @@ struct btDispatcherInfo m_stepCount(0), m_dispatchFunc(DISPATCH_DISCRETE), m_timeOfImpact(btScalar(1.)), - m_useContinuous(false), + m_useContinuous(true), m_debugDraw(0), m_enableSatConvex(false), m_enableSPU(true), @@ -48,7 +48,6 @@ struct btDispatcherInfo m_allowedCcdPenetration(btScalar(0.04)), m_useConvexConservativeDistanceUtil(false), m_convexConservativeDistanceThreshold(0.0f), - m_convexMaxDistanceUseCPT(false), m_stackAllocator(0) { @@ -65,7 +64,6 @@ struct btDispatcherInfo btScalar m_allowedCcdPenetration; bool m_useConvexConservativeDistanceUtil; btScalar m_convexConservativeDistanceThreshold; - bool m_convexMaxDistanceUseCPT; btStackAlloc* m_stackAllocator; }; @@ -98,6 +96,10 @@ public: virtual btPersistentManifold** getInternalManifoldPointer() = 0; + virtual btPoolAllocator* getInternalManifoldPool() = 0; + + virtual const btPoolAllocator* getInternalManifoldPool() const = 0; + virtual void* allocateCollisionAlgorithm(int size) = 0; virtual void freeCollisionAlgorithm(void* ptr) = 0; @@ -105,4 +107,4 @@ public: }; -#endif //_DISPATCHER_H +#endif //BT_DISPATCHER_H diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp index 6712f528e97..81369fe9b50 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp @@ -341,7 +341,7 @@ class btMultiSapBroadphasePairSortPredicate { public: - bool operator() ( const btBroadphasePair& a1, const btBroadphasePair& b1 ) + bool operator() ( const btBroadphasePair& a1, const btBroadphasePair& b1 ) const { btMultiSapBroadphase::btMultiSapProxy* aProxy0 = a1.m_pProxy0 ? (btMultiSapBroadphase::btMultiSapProxy*)a1.m_pProxy0->m_multiSapParentProxy : 0; btMultiSapBroadphase::btMultiSapProxy* aProxy1 = a1.m_pProxy1 ? (btMultiSapBroadphase::btMultiSapProxy*)a1.m_pProxy1->m_multiSapParentProxy : 0; diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h index 3945afb8d70..7a3806c1d28 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef OVERLAPPING_PAIR_CACHE_H -#define OVERLAPPING_PAIR_CACHE_H +#ifndef BT_OVERLAPPING_PAIR_CACHE_H +#define BT_OVERLAPPING_PAIR_CACHE_H #include "btBroadphaseInterface.h" @@ -464,6 +464,6 @@ public: }; -#endif //OVERLAPPING_PAIR_CACHE_H +#endif //BT_OVERLAPPING_PAIR_CACHE_H diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h index 9e247d125f5..78382da79f0 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef QUANTIZED_BVH_H -#define QUANTIZED_BVH_H +#ifndef BT_QUANTIZED_BVH_H +#define BT_QUANTIZED_BVH_H class btSerializer; @@ -109,9 +109,9 @@ ATTRIBUTE_ALIGNED16 (struct) btOptimizedBvhNode //for child nodes int m_subPart; int m_triangleIndex; - int m_padding[5];//bad, due to alignment - +//pad the size to 64 bytes + char m_padding[20]; }; @@ -339,7 +339,7 @@ public: ///***************************************** expert/internal use only ************************* - void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.5)); + void setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.0)); QuantizedNodeArray& getLeafNodeArray() { return m_quantizedLeafNodes; } ///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized void buildInternal(); @@ -578,4 +578,4 @@ SIMD_FORCE_INLINE int btQuantizedBvh::calculateSerializeBufferSizeNew() const -#endif //QUANTIZED_BVH_H +#endif //BT_QUANTIZED_BVH_H diff --git a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h index 3e7c7ee3b62..7cb3c40a043 100644 --- a/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h +++ b/extern/bullet2/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SIMPLE_BROADPHASE_H -#define SIMPLE_BROADPHASE_H +#ifndef BT_SIMPLE_BROADPHASE_H +#define BT_SIMPLE_BROADPHASE_H #include "btOverlappingPairCache.h" @@ -167,5 +167,5 @@ public: -#endif //SIMPLE_BROADPHASE_H +#endif //BT_SIMPLE_BROADPHASE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h index f656e5c323a..22953af43fd 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SPHERE_TRIANGLE_DETECTOR_H -#define SPHERE_TRIANGLE_DETECTOR_H +#ifndef BT_SPHERE_TRIANGLE_DETECTOR_H +#define BT_SPHERE_TRIANGLE_DETECTOR_H #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h" @@ -47,5 +47,5 @@ private: btScalar m_contactBreakingThreshold; }; -#endif //SPHERE_TRIANGLE_DETECTOR_H +#endif //BT_SPHERE_TRIANGLE_DETECTOR_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h index 21342175238..97c5be77003 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BOX_2D_BOX_2D__COLLISION_ALGORITHM_H -#define BOX_2D_BOX_2D__COLLISION_ALGORITHM_H +#ifndef BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H +#define BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -62,5 +62,5 @@ public: }; -#endif //BOX_2D_BOX_2D__COLLISION_ALGORITHM_H +#endif //BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h index e7d2cc25c22..f0bbae61e3b 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BOX_BOX__COLLISION_ALGORITHM_H -#define BOX_BOX__COLLISION_ALGORITHM_H +#ifndef BT_BOX_BOX__COLLISION_ALGORITHM_H +#define BT_BOX_BOX__COLLISION_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -62,5 +62,5 @@ public: }; -#endif //BOX_BOX__COLLISION_ALGORITHM_H +#endif //BT_BOX_BOX__COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h index 605294d47bd..3c941f7deb2 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h @@ -16,8 +16,8 @@ subject to the following restrictions: 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BOX_BOX_DETECTOR_H -#define BOX_BOX_DETECTOR_H +#ifndef BT_BOX_BOX_DETECTOR_H +#define BT_BOX_BOX_DETECTOR_H class btBoxShape; diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h index 1db51a36d03..f63e0923b78 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h @@ -15,6 +15,7 @@ subject to the following restrictions: #ifndef BT_COLLISION_CONFIGURATION #define BT_COLLISION_CONFIGURATION + struct btCollisionAlgorithmCreateFunc; class btStackAlloc; diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h index a6da5f61a3c..1d7e74401dd 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COLLISION_CREATE_FUNC -#define COLLISION_CREATE_FUNC +#ifndef BT_COLLISION_CREATE_FUNC +#define BT_COLLISION_CREATE_FUNC #include "LinearMath/btAlignedObjectArray.h" class btCollisionAlgorithm; @@ -41,5 +41,5 @@ struct btCollisionAlgorithmCreateFunc return 0; } }; -#endif //COLLISION_CREATE_FUNC +#endif //BT_COLLISION_CREATE_FUNC diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp index 9fed44a19f7..29674f3be46 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp @@ -92,8 +92,16 @@ btPersistentManifold* btCollisionDispatcher::getNewManifold(void* b0,void* b1) mem = m_persistentManifoldPoolAllocator->allocate(sizeof(btPersistentManifold)); } else { - mem = btAlignedAlloc(sizeof(btPersistentManifold),16); - + //we got a pool memory overflow, by default we fallback to dynamically allocate memory. If we require a contiguous contact pool then assert. + if ((m_dispatcherFlags&CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION)==0) + { + mem = btAlignedAlloc(sizeof(btPersistentManifold),16); + } else + { + btAssert(0); + //make sure to increase the m_defaultMaxPersistentManifoldPoolSize in the btDefaultCollisionConstructionInfo/btDefaultCollisionConfiguration + return 0; + } } btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0,contactBreakingThreshold,contactProcessingThreshold); manifold->m_index1a = m_manifoldsPtr.size(); @@ -172,8 +180,7 @@ bool btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionO if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED)) { //broadphase filtering already deals with this - if ((body0->isStaticObject() || body0->isKinematicObject()) && - (body1->isStaticObject() || body1->isKinematicObject())) + if (body0->isStaticOrKinematicObject() && body1->isStaticOrKinematicObject()) { m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED; printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h index 3c4f039504a..5accad9a993 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COLLISION__DISPATCHER_H -#define COLLISION__DISPATCHER_H +#ifndef BT_COLLISION__DISPATCHER_H +#define BT_COLLISION__DISPATCHER_H #include "BulletCollision/BroadphaseCollision/btDispatcher.h" #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" @@ -67,7 +67,8 @@ public: enum DispatcherFlags { CD_STATIC_STATIC_REPORTED = 1, - CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2 + CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2, + CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4 }; int getDispatcherFlags() const @@ -90,7 +91,7 @@ public: btPersistentManifold** getInternalManifoldPointer() { - return &m_manifoldsPtr[0]; + return m_manifoldsPtr.size()? &m_manifoldsPtr[0] : 0; } btPersistentManifold* getManifoldByIndexInternal(int index) @@ -155,7 +156,17 @@ public: m_collisionConfiguration = config; } + virtual btPoolAllocator* getInternalManifoldPool() + { + return m_persistentManifoldPoolAllocator; + } + + virtual const btPoolAllocator* getInternalManifoldPool() const + { + return m_persistentManifoldPoolAllocator; + } + }; -#endif //COLLISION__DISPATCHER_H +#endif //BT_COLLISION__DISPATCHER_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h index 5de829824ff..3a11c967ac9 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionObject.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COLLISION_OBJECT_H -#define COLLISION_OBJECT_H +#ifndef BT_COLLISION_OBJECT_H +#define BT_COLLISION_OBJECT_H #include "LinearMath/btTransform.h" @@ -521,4 +521,4 @@ SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const -#endif //COLLISION_OBJECT_H +#endif //BT_COLLISION_OBJECT_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index bfe8d4f52fb..66b93b88efa 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -33,6 +33,7 @@ subject to the following restrictions: #include "LinearMath/btQuickprof.h" #include "LinearMath/btStackAlloc.h" #include "LinearMath/btSerializer.h" +#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h" //#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION @@ -154,7 +155,7 @@ void btCollisionWorld::updateSingleAabb(btCollisionObject* colObj) minAabb -= contactThreshold; maxAabb += contactThreshold; - if(getDispatchInfo().m_convexMaxDistanceUseCPT) + if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject()) { btVector3 minAabb2,maxAabb2; colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2); @@ -662,68 +663,103 @@ void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt triangleMesh->performConvexcast(&tccb,convexFromLocal,convexToLocal,boxMinLocal, boxMaxLocal); } else { - //BT_PROFILE("convexSweepConcave"); - btConcaveShape* concaveShape = (btConcaveShape*)collisionShape; - btTransform worldTocollisionObject = colObjWorldTransform.inverse(); - btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin(); - btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin(); - // rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation - btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis()); - - //ConvexCast::CastResult - struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback + if (collisionShape->getShapeType()==STATIC_PLANE_PROXYTYPE) { - btCollisionWorld::ConvexResultCallback* m_resultCallback; - 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): - btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), - m_resultCallback(resultCallback), - m_collisionObject(collisionObject), - m_triangleMesh(triangleMesh) + btConvexCast::CastResult castResult; + castResult.m_allowedPenetration = allowedPenetration; + castResult.m_fraction = resultCallback.m_closestHitFraction; + btStaticPlaneShape* planeShape = (btStaticPlaneShape*) collisionShape; + btContinuousConvexCollision convexCaster1(castShape,planeShape); + btConvexCast* castPtr = &convexCaster1; + + if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult)) { + //add hit + if (castResult.m_normal.length2() > btScalar(0.0001)) + { + if (castResult.m_fraction < resultCallback.m_closestHitFraction) + { + castResult.m_normal.normalize(); + btCollisionWorld::LocalConvexResult localConvexResult + ( + collisionObject, + 0, + castResult.m_normal, + castResult.m_hitPoint, + castResult.m_fraction + ); + + bool normalInWorldSpace = true; + resultCallback.addSingleResult(localConvexResult, normalInWorldSpace); + } + } } - - virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex ) + } else + { + //BT_PROFILE("convexSweepConcave"); + btConcaveShape* concaveShape = (btConcaveShape*)collisionShape; + btTransform worldTocollisionObject = colObjWorldTransform.inverse(); + btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin(); + btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin(); + // rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation + btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis()); + + //ConvexCast::CastResult + struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback { - btCollisionWorld::LocalShapeInfo shapeInfo; - shapeInfo.m_shapePart = partId; - shapeInfo.m_triangleIndex = triangleIndex; - if (hitFraction <= m_resultCallback->m_closestHitFraction) + btCollisionWorld::ConvexResultCallback* m_resultCallback; + 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): + btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), + m_resultCallback(resultCallback), + m_collisionObject(collisionObject), + m_triangleMesh(triangleMesh) { + } - btCollisionWorld::LocalConvexResult convexResult - (m_collisionObject, - &shapeInfo, - hitNormalLocal, - hitPointLocal, - hitFraction); - bool normalInWorldSpace = false; + virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex ) + { + btCollisionWorld::LocalShapeInfo shapeInfo; + shapeInfo.m_shapePart = partId; + shapeInfo.m_triangleIndex = triangleIndex; + if (hitFraction <= m_resultCallback->m_closestHitFraction) + { - return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace); - } - return hitFraction; - } + btCollisionWorld::LocalConvexResult convexResult + (m_collisionObject, + &shapeInfo, + hitNormalLocal, + hitPointLocal, + hitFraction); - }; + bool normalInWorldSpace = false; - BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform); - tccb.m_hitFraction = resultCallback.m_closestHitFraction; - tccb.m_allowedPenetration = allowedPenetration; - btVector3 boxMinLocal, boxMaxLocal; - castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal); + return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace); + } + return hitFraction; + } + + }; - btVector3 rayAabbMinLocal = convexFromLocal; - rayAabbMinLocal.setMin(convexToLocal); - btVector3 rayAabbMaxLocal = convexFromLocal; - rayAabbMaxLocal.setMax(convexToLocal); - rayAabbMinLocal += boxMinLocal; - rayAabbMaxLocal += boxMaxLocal; - concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal); + BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform); + tccb.m_hitFraction = resultCallback.m_closestHitFraction; + tccb.m_allowedPenetration = allowedPenetration; + btVector3 boxMinLocal, boxMaxLocal; + castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal); + + btVector3 rayAabbMinLocal = convexFromLocal; + rayAabbMinLocal.setMin(convexToLocal); + btVector3 rayAabbMaxLocal = convexFromLocal; + rayAabbMaxLocal.setMax(convexToLocal); + rayAabbMinLocal += boxMinLocal; + rayAabbMaxLocal += boxMaxLocal; + concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal); + } } } else { ///@todo : use AABB tree or other BVH acceleration structure! @@ -1162,15 +1198,14 @@ public: wv1 = m_worldTrans*triangle[1]; wv2 = m_worldTrans*triangle[2]; btVector3 center = (wv0+wv1+wv2)*btScalar(1./3.); - - btVector3 normal = (wv1-wv0).cross(wv2-wv0); - normal.normalize(); - btVector3 normalColor(1,1,0); - m_debugDrawer->drawLine(center,center+normal,normalColor); - - - - + + if (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawNormals ) + { + btVector3 normal = (wv1-wv0).cross(wv2-wv0); + normal.normalize(); + btVector3 normalColor(1,1,0); + m_debugDrawer->drawLine(center,center+normal,normalColor); + } m_debugDrawer->drawLine(wv0,wv1,m_color); m_debugDrawer->drawLine(wv1,wv2,m_color); m_debugDrawer->drawLine(wv2,wv0,m_color); @@ -1195,126 +1230,162 @@ void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const } 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; - } + /// for polyhedral shapes + if (shape->isPolyhedral()) + { + btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape; - case SPHERE_SHAPE_PROXYTYPE: + int i; + if (polyshape->getConvexPolyhedron()) { - const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape); - btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin + 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); + } + + } - getDebugDrawer()->drawSphere(radius, worldTransform, color); - break; - } - case MULTI_SPHERE_SHAPE_PROXYTYPE: + + } else { - const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape); - - btTransform childTransform; - childTransform.setIdentity(); - - for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--) + for (i=0;i<polyshape->getNumEdges();i++) { - childTransform.setOrigin(multiSphereShape->getSpherePosition(i)); - getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color); + btVector3 a,b; + polyshape->getEdge(i,a,b); + btVector3 wa = worldTransform * a; + btVector3 wb = worldTransform * b; + getDebugDrawer()->drawLine(wa,wb,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: + } + else + { + switch (shape->getShapeType()) { - 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 BOX_SHAPE_PROXYTYPE: + { + const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape); + btVector3 halfExtents = boxShape->getHalfExtentsWithMargin(); + getDebugDrawer()->drawBox(-halfExtents,halfExtents,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 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 - 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; + getDebugDrawer()->drawSphere(radius, worldTransform, color); + break; + } + case MULTI_SPHERE_SHAPE_PROXYTYPE: + { + const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape); - } - default: - { + btTransform childTransform; + childTransform.setIdentity(); - if (shape->isConcave()) - { - btConcaveShape* concaveMesh = (btConcaveShape*) shape; + for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--) + { + childTransform.setOrigin(multiSphereShape->getSpherePosition(i)); + getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color); + } - ///@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)); + break; + } + case CAPSULE_SHAPE_PROXYTYPE: + { + const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape); - DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); - concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax); + 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(); - if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE) + int upAxis= coneShape->getConeUpIndex(); + getDebugDrawer()->drawCone(radius, height, upAxis, worldTransform, color); + break; + + } + case CYLINDER_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); + 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; - /// for polyhedral shapes - if (shape->isPolyhedral()) + } + default: { - btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape; - int i; - for (i=0;i<polyshape->getNumEdges();i++) + if (shape->isConcave()) { - btVector3 a,b; - polyshape->getEdge(i,a,b); - btVector3 wa = worldTransform * a; - btVector3 wb = worldTransform * b; - getDebugDrawer()->drawLine(wa,wb,color); + 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); + } + + } } } @@ -1327,7 +1398,7 @@ void btCollisionWorld::debugDrawWorld() if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) { int numManifolds = getDispatcher()->getNumManifolds(); - btVector3 color(0,0,0); + btVector3 color(1,0.65,0); for (int i=0;i<numManifolds;i++) { btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i); @@ -1343,7 +1414,7 @@ void btCollisionWorld::debugDrawWorld() } } - if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)) + if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb))) { int i; @@ -1352,7 +1423,7 @@ void btCollisionWorld::debugDrawWorld() btCollisionObject* colObj = m_collisionObjects[i]; if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0) { - if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe) + if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)) { btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.)); switch(colObj->getActivationState()) @@ -1386,12 +1457,14 @@ void btCollisionWorld::debugDrawWorld() btVector3 minAabb2,maxAabb2; - colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2); - minAabb2 -= contactThreshold; - maxAabb2 += contactThreshold; - - minAabb.setMin(minAabb2); - maxAabb.setMax(maxAabb2); + if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject()) + { + colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2); + minAabb2 -= contactThreshold; + maxAabb2 += contactThreshold; + minAabb.setMin(minAabb2); + maxAabb.setMax(maxAabb2); + } m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec); } diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h index b42e2c40b21..0a92d2d6e15 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionWorld.h @@ -62,8 +62,8 @@ subject to the following restrictions: -#ifndef COLLISION_WORLD_H -#define COLLISION_WORLD_H +#ifndef BT_COLLISION_WORLD_H +#define BT_COLLISION_WORLD_H class btStackAlloc; class btCollisionShape; @@ -506,4 +506,4 @@ public: }; -#endif //COLLISION_WORLD_H +#endif //BT_COLLISION_WORLD_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h index 255e0af668c..404574989ab 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COMPOUND_COLLISION_ALGORITHM_H -#define COMPOUND_COLLISION_ALGORITHM_H +#ifndef BT_COMPOUND_COLLISION_ALGORITHM_H +#define BT_COMPOUND_COLLISION_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btDispatcher.h" @@ -83,4 +83,4 @@ public: }; -#endif //COMPOUND_COLLISION_ALGORITHM_H +#endif //BT_COMPOUND_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h index 5738401401e..53d13b87151 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_2D_CONVEX_2D_ALGORITHM_H -#define CONVEX_2D_CONVEX_2D_ALGORITHM_H +#ifndef BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H +#define BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h" #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" @@ -92,4 +92,4 @@ public: }; -#endif //CONVEX_2D_CONVEX_2D_ALGORITHM_H +#endif //BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp index 268ec4b6c7e..d2b2c221426 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp @@ -91,7 +91,7 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody); - +#if 0 ///debug drawing of the overlapping triangles if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe )) { @@ -100,17 +100,8 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color); m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(triangle[2]),color); m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color); - - //btVector3 center = triangle[0] + triangle[1]+triangle[2]; - //center *= btScalar(0.333333); - //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(center),color); - //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(center),color); - //m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(center),color); - } - - - //btCollisionObject* colObj = static_cast<btCollisionObject*>(m_convexProxy->m_clientObject); +#endif if (m_convexBody->getCollisionShape()->isConvex()) { @@ -119,7 +110,7 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i btCollisionShape* tmpShape = ob->getCollisionShape(); ob->internalSetTemporaryCollisionShape( &tm ); - + btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr); if (m_resultOut->getBody0Internal() == m_triBody) diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h index 984a4c39e8e..f718d1dec25 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_CONCAVE_COLLISION_ALGORITHM_H -#define CONVEX_CONCAVE_COLLISION_ALGORITHM_H +#ifndef BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H +#define BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btDispatcher.h" @@ -113,4 +113,4 @@ public: }; -#endif //CONVEX_CONCAVE_COLLISION_ALGORITHM_H +#endif //BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp index 94385fed909..dd1f3e2490f 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp @@ -17,6 +17,7 @@ subject to the following restrictions: ///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums ///with reproduction case //define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1 +//#define ZERO_MARGIN #include "btConvexConvexAlgorithm.h" @@ -26,6 +27,8 @@ subject to the following restrictions: #include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/CollisionShapes/btConvexShape.h" #include "BulletCollision/CollisionShapes/btCapsuleShape.h" +#include "BulletCollision/CollisionShapes/btTriangleShape.h" + #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" @@ -48,7 +51,7 @@ subject to the following restrictions: #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h" #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h" - +#include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h" /////////// @@ -331,6 +334,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl #endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER + + #ifdef USE_SEPDISTANCE_UTIL2 if (dispatchInfo.m_useConvexConservativeDistanceUtil) { @@ -357,13 +362,14 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl } else #endif //USE_SEPDISTANCE_UTIL2 { - if (dispatchInfo.m_convexMaxDistanceUseCPT) - { - input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold(); - } else - { - input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); - } + //if (dispatchInfo.m_convexMaxDistanceUseCPT) + //{ + // input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold(); + //} else + //{ + input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); +// } + input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared; } @@ -371,7 +377,7 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl input.m_transformA = body0->getWorldTransform(); input.m_transformB = body1->getWorldTransform(); - gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); + @@ -389,6 +395,155 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl } #endif //USE_SEPDISTANCE_UTIL2 + if (min0->isPolyhedral() && min1->isPolyhedral()) + { + + + struct btDummyResult : public btDiscreteCollisionDetectorInterface::Result + { + virtual void setShapeIdentifiersA(int partId0,int index0){} + virtual void setShapeIdentifiersB(int partId1,int index1){} + virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) + { + } + }; + + btDummyResult dummy; + + + btPolyhedralConvexShape* polyhedronA = (btPolyhedralConvexShape*) min0; + btPolyhedralConvexShape* polyhedronB = (btPolyhedralConvexShape*) min1; + if (polyhedronA->getConvexPolyhedron() && polyhedronB->getConvexPolyhedron()) + { + + + + + btScalar threshold = m_manifoldPtr->getContactBreakingThreshold(); + + btScalar minDist = -1e30f; + btVector3 sepNormalWorldSpace; + bool foundSepAxis = true; + + if (dispatchInfo.m_enableSatConvex) + { + foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis( + *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(), + body0->getWorldTransform(), + body1->getWorldTransform(), + sepNormalWorldSpace); + } 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); +#endif //ZERO_MARGIN + btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2(); + if (l2>SIMD_EPSILON) + { + sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2); + //minDist = -1e30f;//gjkPairDetector.getCachedSeparatingDistance(); + minDist = gjkPairDetector.getCachedSeparatingDistance()-min0->getMargin()-min1->getMargin(); + +#ifdef ZERO_MARGIN + foundSepAxis = true;//gjkPairDetector.getCachedSeparatingDistance()<0.f; +#else + foundSepAxis = gjkPairDetector.getCachedSeparatingDistance()<(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); + + } + if (m_ownManifold) + { + resultOut->refreshContactPoints(); + } + return; + + } else + { + //we can also deal with convex versus triangle (without connectivity data) + if (polyhedronA->getConvexPolyhedron() && polyhedronB->getShapeType()==TRIANGLE_SHAPE_PROXYTYPE) + { + + 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]); + + //tri->initializePolyhedralFeatures(); + + btScalar threshold = m_manifoldPtr->getContactBreakingThreshold(); + + btVector3 sepNormalWorldSpace; + btScalar minDist =-1e30f; + btScalar maxDist = threshold; + + bool foundSepAxis = false; + if (0) + { + polyhedronB->initializePolyhedralFeatures(); + foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis( + *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(), + body0->getWorldTransform(), + body1->getWorldTransform(), + sepNormalWorldSpace); + // printf("sepNormalWorldSpace=%f,%f,%f\n",sepNormalWorldSpace.getX(),sepNormalWorldSpace.getY(),sepNormalWorldSpace.getZ()); + + } else + { +#ifdef ZERO_MARGIN + gjkPairDetector.setIgnoreMargin(true); + gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); +#else + gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw); +#endif//ZERO_MARGIN + + btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2(); + if (l2>SIMD_EPSILON) + { + sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2); + //minDist = gjkPairDetector.getCachedSeparatingDistance(); + //maxDist = threshold; + minDist = gjkPairDetector.getCachedSeparatingDistance()-min0->getMargin()-min1->getMargin(); + foundSepAxis = true; + } + } + + + if (foundSepAxis) + { + btPolyhedralContactClipping::clipFaceAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), + body0->getWorldTransform(), vertices, minDist-threshold, maxDist, *resultOut); + } + + + if (m_ownManifold) + { + resultOut->refreshContactPoints(); + } + + return; + } + + } + + + } + + gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); + //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points @@ -398,66 +553,70 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl int i; btVector3 v0,v1; btVector3 sepNormalWorldSpace; + btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2(); - sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); - btPlaneSpace1(sepNormalWorldSpace,v0,v1); - - - bool perturbeA = true; - const btScalar angleLimit = 0.125f * SIMD_PI; - btScalar perturbeAngle; - btScalar radiusA = min0->getAngularMotionDisc(); - btScalar radiusB = min1->getAngularMotionDisc(); - if (radiusA < radiusB) - { - perturbeAngle = gContactBreakingThreshold /radiusA; - perturbeA = true; - } else + if (l2>SIMD_EPSILON) { - perturbeAngle = gContactBreakingThreshold / radiusB; - perturbeA = false; - } - if ( perturbeAngle > angleLimit ) - perturbeAngle = angleLimit; + sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2); + + btPlaneSpace1(sepNormalWorldSpace,v0,v1); - btTransform unPerturbedTransform; - if (perturbeA) - { - unPerturbedTransform = input.m_transformA; - } else - { - unPerturbedTransform = input.m_transformB; - } - - for ( i=0;i<m_numPerturbationIterations;i++) - { - if (v0.length2()>SIMD_EPSILON) + + bool perturbeA = true; + const btScalar angleLimit = 0.125f * SIMD_PI; + btScalar perturbeAngle; + btScalar radiusA = min0->getAngularMotionDisc(); + btScalar radiusB = min1->getAngularMotionDisc(); + if (radiusA < radiusB) { - btQuaternion perturbeRot(v0,perturbeAngle); - btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); - btQuaternion rotq(sepNormalWorldSpace,iterationAngle); - - + perturbeAngle = gContactBreakingThreshold /radiusA; + perturbeA = true; + } else + { + perturbeAngle = gContactBreakingThreshold / radiusB; + perturbeA = false; + } + if ( perturbeAngle > angleLimit ) + perturbeAngle = angleLimit; + + btTransform unPerturbedTransform; if (perturbeA) { - input.m_transformA.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0->getWorldTransform().getBasis()); - input.m_transformB = body1->getWorldTransform(); -#ifdef DEBUG_CONTACTS - dispatchInfo.m_debugDraw->drawTransform(input.m_transformA,10.0); -#endif //DEBUG_CONTACTS + unPerturbedTransform = input.m_transformA; } else { - input.m_transformA = body0->getWorldTransform(); - input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1->getWorldTransform().getBasis()); -#ifdef DEBUG_CONTACTS - dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0); -#endif + unPerturbedTransform = input.m_transformB; } - btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); - gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); + for ( i=0;i<m_numPerturbationIterations;i++) + { + if (v0.length2()>SIMD_EPSILON) + { + btQuaternion perturbeRot(v0,perturbeAngle); + btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); + btQuaternion rotq(sepNormalWorldSpace,iterationAngle); + + + if (perturbeA) + { + input.m_transformA.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0->getWorldTransform().getBasis()); + input.m_transformB = body1->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()); + #ifdef DEBUG_CONTACTS + dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0); + #endif + } + + btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); + gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); + } } - } } @@ -487,7 +646,7 @@ btScalar btConvexConvexAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, { (void)resultOut; (void)dispatchInfo; - ///rather than checking ALL pairs, only calculate TOI when motion exceeds threshold + ///Rather then checking ALL pairs, only calculate TOI when motion exceeds threshold ///Linear motion for one of objects needs to exceed m_ccdSquareMotionThreshold ///col0->m_worldTransform, diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h index d38aff6862c..4380b80eb4d 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_CONVEX_ALGORITHM_H -#define CONVEX_CONVEX_ALGORITHM_H +#ifndef BT_CONVEX_CONVEX_ALGORITHM_H +#define BT_CONVEX_CONVEX_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" @@ -106,4 +106,4 @@ public: }; -#endif //CONVEX_CONVEX_ALGORITHM_H +#endif //BT_CONVEX_CONVEX_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp index dda85dc693f..b2e9bfaf593 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp @@ -96,23 +96,41 @@ void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0 if (!m_manifoldPtr) return; - btCollisionObject* convexObj = m_isSwapped? body1 : body0; + btCollisionObject* convexObj = m_isSwapped? body1 : body0; btCollisionObject* planeObj = m_isSwapped? body0: body1; btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape(); btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); - + bool hasCollision = false; const btVector3& planeNormal = planeShape->getPlaneNormal(); - //const btScalar& planeConstant = planeShape->getPlaneConstant(); + const btScalar& planeConstant = planeShape->getPlaneConstant(); + btTransform planeInConvex; + planeInConvex= convexObj->getWorldTransform().inverse() * planeObj->getWorldTransform(); + btTransform convexInPlaneTrans; + convexInPlaneTrans= planeObj->getWorldTransform().inverse() * convexObj->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; - //first perform a collision query with the non-perturbated collision objects + hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold(); + resultOut->setPersistentManifold(m_manifoldPtr); + if (hasCollision) { - btQuaternion rotq(0,0,0,1); - collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut); + /// report a contact. internally this will be kept persistent, and contact reduction is done + btVector3 normalOnSurfaceB = planeObj->getWorldTransform().getBasis() * planeNormal; + btVector3 pOnB = vtxInPlaneWorld; + resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance); } - if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold) + //the perturbation algorithm doesn't work well with implicit surfaces such as spheres, cylinder and cones: + //they keep on rolling forever because of the additional off-center contact points + //so only enable the feature for polyhedral shapes (btBoxShape, btConvexHullShape etc) + if (convexShape->isPolyhedral() && resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold) { btVector3 v0,v1; btPlaneSpace1(planeNormal,v0,v1); diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h index f49ac45e772..b9494f5ad3b 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_PLANE_COLLISION_ALGORITHM_H -#define CONVEX_PLANE_COLLISION_ALGORITHM_H +#ifndef BT_CONVEX_PLANE_COLLISION_ALGORITHM_H +#define BT_CONVEX_PLANE_COLLISION_ALGORITHM_H #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -61,7 +61,7 @@ public: CreateFunc() : m_numPerturbationIterations(1), - m_minimumPointsPerturbationThreshold(1) + m_minimumPointsPerturbationThreshold(0) { } @@ -80,5 +80,5 @@ public: }; -#endif //CONVEX_PLANE_COLLISION_ALGORITHM_H +#endif //BT_CONVEX_PLANE_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp index c27d8ce0752..7faee6faf50 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp @@ -296,3 +296,14 @@ void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int nu convexConvex->m_numPerturbationIterations = numPerturbationIterations; convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold; } + +void btDefaultCollisionConfiguration::setPlaneConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold) +{ + btConvexPlaneCollisionAlgorithm::CreateFunc* cpCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_convexPlaneCF; + cpCF->m_numPerturbationIterations = numPerturbationIterations; + cpCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold; + + btConvexPlaneCollisionAlgorithm::CreateFunc* pcCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_planeConvexCF; + pcCF->m_numPerturbationIterations = numPerturbationIterations; + pcCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold; +} diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h index 6aa0d8c270f..81ed424a3db 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h @@ -129,6 +129,8 @@ public: ///@todo we could add a per-object setting of those parameters, for level-of-detail collision detection. void setConvexConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold = 3); + void setPlaneConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold = 3); + }; #endif //BT_DEFAULT_COLLISION_CONFIGURATION diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h index e54721dec21..f03c9dc3833 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef EMPTY_ALGORITH -#define EMPTY_ALGORITH +#ifndef BT_EMPTY_ALGORITH +#define BT_EMPTY_ALGORITH #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" #include "btCollisionCreateFunc.h" #include "btCollisionDispatcher.h" @@ -51,4 +51,4 @@ public: } ATTRIBUTE_ALIGNED(16); -#endif //EMPTY_ALGORITH +#endif //BT_EMPTY_ALGORITH diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp index 5cceb04dbb4..4353cdac0b1 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp @@ -1,6 +1,7 @@ #include "btInternalEdgeUtility.h" #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" +#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" #include "BulletCollision/CollisionShapes/btTriangleShape.h" #include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" @@ -9,7 +10,6 @@ //#define DEBUG_INTERNAL_EDGE - #ifdef DEBUG_INTERNAL_EDGE #include <stdio.h> #endif //DEBUG_INTERNAL_EDGE @@ -456,8 +456,14 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* if (colObj0->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE) return; - btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape(); - btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap(); + btBvhTriangleMeshShape* trimesh = 0; + + if( colObj0->getRootCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE ) + trimesh = ((btScaledBvhTriangleMeshShape*)colObj0->getRootCollisionShape())->getChildShape(); + else + trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape(); + + btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap(); if (!triangleInfoMapPtr) return; @@ -501,14 +507,63 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* btVector3 localContactNormalOnB = colObj0->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB; localContactNormalOnB.normalize();//is this necessary? - - if ((info->m_edgeV0V1Angle)< SIMD_2_PI) + + // Get closest edge + int bestedge=-1; + btScalar disttobestedge=BT_LARGE_FLOAT; + // + // Edge 0 -> 1 + if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) + { + btVector3 nearest; + btNearestPointInLineSegment( cp.m_localPointB, v0, v1, nearest ); + btScalar len=(contact-nearest).length(); + // + if( len < disttobestedge ) + { + bestedge=0; + disttobestedge=len; + } + } + // Edge 1 -> 2 + if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) + { + btVector3 nearest; + btNearestPointInLineSegment( cp.m_localPointB, v1, v2, nearest ); + btScalar len=(contact-nearest).length(); + // + if( len < disttobestedge ) + { + bestedge=1; + disttobestedge=len; + } + } + // Edge 2 -> 0 + if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) + { + btVector3 nearest; + btNearestPointInLineSegment( cp.m_localPointB, v2, v0, nearest ); + btScalar len=(contact-nearest).length(); + // + if( len < disttobestedge ) + { + bestedge=2; + disttobestedge=len; + } + } + +#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW + btVector3 upfix=tri_normal * btVector3(0.1f,0.1f,0.1f); + btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red ); +#endif + if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) { #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black); #endif btScalar len = (contact-nearest).length(); if(len<triangleInfoMapPtr->m_edgeDistanceThreshold) + if( bestedge==0 ) { btVector3 edge(v0-v1); isNearEdge = true; @@ -577,7 +632,11 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,green); #endif //BT_INTERNAL_EDGE_DEBUG_DRAW - if ((info->m_edgeV1V2Angle)< SIMD_2_PI) +#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW + btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix , green ); +#endif + + if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) { #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black); @@ -587,6 +646,7 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* btScalar len = (contact-nearest).length(); if(len<triangleInfoMapPtr->m_edgeDistanceThreshold) + if( bestedge==1 ) { isNearEdge = true; #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW @@ -658,8 +718,11 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,blue); #endif //BT_INTERNAL_EDGE_DEBUG_DRAW +#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW + btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix , blue ); +#endif - if ((info->m_edgeV2V0Angle)< SIMD_2_PI) + if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) { #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW @@ -668,6 +731,7 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* btScalar len = (contact-nearest).length(); if(len<triangleInfoMapPtr->m_edgeDistanceThreshold) + if( bestedge==2 ) { isNearEdge = true; #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW @@ -759,11 +823,17 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObject* cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis()*tri_normal; } else { + btVector3 newNormal = tri_normal *frontFacing; + //if the tri_normal is pointing opposite direction as the current local contact normal, skip it + btScalar d = newNormal.dot(localContactNormalOnB) ; + if (d< 0) + { + return; + } //modify the normal to be the triangle normal (or backfacing normal) - cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() *(tri_normal *frontFacing); + cp.m_normalWorldOnB = colObj0->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); diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp index fd684c056f7..bf24246ea2f 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp @@ -64,8 +64,8 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b btAssert(m_manifoldPtr); //order in manifold needs to match -// if (depth > m_manifoldPtr->getContactBreakingThreshold()) - if (depth > m_manifoldPtr->getContactProcessingThreshold()) + if (depth > m_manifoldPtr->getContactBreakingThreshold()) +// if (depth > m_manifoldPtr->getContactProcessingThreshold()) return; bool isSwapped = m_manifoldPtr->getBody0() != m_body0; diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h index 927e2bc4f76..18199b49752 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btManifoldResult.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ -#ifndef MANIFOLD_RESULT_H -#define MANIFOLD_RESULT_H +#ifndef BT_MANIFOLD_RESULT_H +#define BT_MANIFOLD_RESULT_H class btCollisionObject; #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" @@ -125,4 +125,4 @@ public: }; -#endif //MANIFOLD_RESULT_H +#endif //BT_MANIFOLD_RESULT_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp index bb2a7f23985..871c64415a2 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp @@ -47,6 +47,8 @@ void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */,btColl { btOverlappingPairCache* pairCachePtr = colWorld->getPairCache(); const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs(); + if (numOverlappingPairs) + { btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr(); for (int i=0;i<numOverlappingPairs;i++) @@ -63,6 +65,7 @@ void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */,btColl (colObj1)->getIslandTag()); } } + } } } @@ -190,7 +193,7 @@ class btPersistentManifoldSortPredicate { public: - SIMD_FORCE_INLINE bool operator() ( const btPersistentManifold* lhs, const btPersistentManifold* rhs ) + SIMD_FORCE_INLINE bool operator() ( const btPersistentManifold* lhs, const btPersistentManifold* rhs ) const { return getIslandId(lhs) < getIslandId(rhs); } @@ -327,11 +330,13 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio //kinematic objects don't merge islands, but wake up all connected objects if (colObj0->isKinematicObject() && colObj0->getActivationState() != ISLAND_SLEEPING) { - colObj1->activate(); + if (colObj0->hasContactResponse()) + colObj1->activate(); } if (colObj1->isKinematicObject() && colObj1->getActivationState() != ISLAND_SLEEPING) { - colObj0->activate(); + if (colObj1->hasContactResponse()) + colObj0->activate(); } if(m_splitIslands) { @@ -362,7 +367,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, { btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer(); int maxNumManifolds = dispatcher->getNumManifolds(); - callback->ProcessIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1); + callback->processIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1); } else { @@ -372,8 +377,10 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, int numManifolds = int (m_islandmanifold.size()); - //we should do radix sort, it it much faster (O(n) instead of O (n log2(n)) + //tried a radix sort, but quicksort/heapsort seems still faster + //@todo rewrite island management m_islandmanifold.quickSort(btPersistentManifoldSortPredicate()); + //m_islandmanifold.heapSort(btPersistentManifoldSortPredicate()); //now process all active islands (sets of manifolds for now) @@ -427,7 +434,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, if (!islandSleeping) { - callback->ProcessIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId); + callback->processIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId); // printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds); } diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h index d059f5d6b0d..e24c6afeca1 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SIMULATION_ISLAND_MANAGER_H -#define SIMULATION_ISLAND_MANAGER_H +#ifndef BT_SIMULATION_ISLAND_MANAGER_H +#define BT_SIMULATION_ISLAND_MANAGER_H #include "BulletCollision/CollisionDispatch/btUnionFind.h" #include "btCollisionCreateFunc.h" @@ -59,7 +59,7 @@ public: { virtual ~IslandCallback() {}; - virtual void ProcessIsland(btCollisionObject** bodies,int numBodies,class btPersistentManifold** manifolds,int numManifolds, int islandId) = 0; + virtual void processIsland(btCollisionObject** bodies,int numBodies,class btPersistentManifold** manifolds,int numManifolds, int islandId) = 0; }; void buildAndProcessIslands(btDispatcher* dispatcher,btCollisionWorld* collisionWorld, IslandCallback* callback); @@ -77,5 +77,5 @@ public: }; -#endif //SIMULATION_ISLAND_MANAGER_H +#endif //BT_SIMULATION_ISLAND_MANAGER_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h index 47111d1c4af..60286ae0aa4 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SPHERE_BOX_COLLISION_ALGORITHM_H -#define SPHERE_BOX_COLLISION_ALGORITHM_H +#ifndef BT_SPHERE_BOX_COLLISION_ALGORITHM_H +#define BT_SPHERE_BOX_COLLISION_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -71,5 +71,5 @@ public: }; -#endif //SPHERE_BOX_COLLISION_ALGORITHM_H +#endif //BT_SPHERE_BOX_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h index 7d07512ca66..e55acf277e6 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SPHERE_SPHERE_COLLISION_ALGORITHM_H -#define SPHERE_SPHERE_COLLISION_ALGORITHM_H +#ifndef BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H +#define BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -62,5 +62,5 @@ public: }; -#endif //SPHERE_SPHERE_COLLISION_ALGORITHM_H +#endif //BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h index 606c3635ae9..7c6c4d8f8d5 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SPHERE_TRIANGLE_COLLISION_ALGORITHM_H -#define SPHERE_TRIANGLE_COLLISION_ALGORITHM_H +#ifndef BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H +#define BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H #include "btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -65,5 +65,5 @@ public: }; -#endif //SPHERE_TRIANGLE_COLLISION_ALGORITHM_H +#endif //BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp b/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp index 4c4f58d44fa..5222933595d 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.cpp @@ -53,7 +53,7 @@ class btUnionFindElementSortPredicate { public: - bool operator() ( const btElement& lhs, const btElement& rhs ) + bool operator() ( const btElement& lhs, const btElement& rhs ) const { return lhs.m_id < rhs.m_id; } diff --git a/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h b/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h index 2cce335145b..ef2a29202f7 100644 --- a/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h +++ b/extern/bullet2/src/BulletCollision/CollisionDispatch/btUnionFind.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef UNION_FIND_H -#define UNION_FIND_H +#ifndef BT_UNION_FIND_H +#define BT_UNION_FIND_H #include "LinearMath/btAlignedObjectArray.h" @@ -126,4 +126,4 @@ class btUnionFind }; -#endif //UNION_FIND_H +#endif //BT_UNION_FIND_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBox2dShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBox2dShape.h index fc032069c03..f4a9ca03e5c 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBox2dShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBox2dShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef OBB_BOX_2D_SHAPE_H -#define OBB_BOX_2D_SHAPE_H +#ifndef BT_OBB_BOX_2D_SHAPE_H +#define BT_OBB_BOX_2D_SHAPE_H #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" #include "BulletCollision/CollisionShapes/btCollisionMargin.h" @@ -83,6 +83,7 @@ public: } + ///a btBox2dShape is a flat 2D box in the X-Y plane (Z extents are zero) btBox2dShape( const btVector3& boxHalfExtents) : btPolyhedralConvexShape(), m_centroid(0,0,0) @@ -97,6 +98,11 @@ public: m_normals[2].setValue(0,1,0); m_normals[3].setValue(-1,0,0); + btScalar minDimension = boxHalfExtents.getX(); + if (minDimension>boxHalfExtents.getY()) + minDimension = boxHalfExtents.getY(); + setSafeMargin(minDimension); + m_shapeType = BOX_2D_SHAPE_PROXYTYPE; btVector3 margin(getMargin(),getMargin(),getMargin()); m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin; @@ -358,6 +364,6 @@ public: }; -#endif //OBB_BOX_2D_SHAPE_H +#endif //BT_OBB_BOX_2D_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp index c6644efbef3..3859138f18a 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.cpp @@ -14,8 +14,18 @@ subject to the following restrictions: */ #include "btBoxShape.h" +btBoxShape::btBoxShape( const btVector3& boxHalfExtents) +: btPolyhedralConvexShape() +{ + m_shapeType = BOX_SHAPE_PROXYTYPE; + + setSafeMargin(boxHalfExtents); + + btVector3 margin(getMargin(),getMargin(),getMargin()); + m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin; +}; + -//{ void btBoxShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h index b405efc8e3c..0c5857dae62 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBoxShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef OBB_BOX_MINKOWSKI_H -#define OBB_BOX_MINKOWSKI_H +#ifndef BT_OBB_BOX_MINKOWSKI_H +#define BT_OBB_BOX_MINKOWSKI_H #include "btPolyhedralConvexShape.h" #include "btCollisionMargin.h" @@ -80,13 +80,7 @@ public: } - btBoxShape( const btVector3& boxHalfExtents) - : btPolyhedralConvexShape() - { - m_shapeType = BOX_SHAPE_PROXYTYPE; - btVector3 margin(getMargin(),getMargin(),getMargin()); - m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin; - }; + btBoxShape( const btVector3& boxHalfExtents); virtual void setMargin(btScalar collisionMargin) { @@ -145,7 +139,7 @@ public: virtual void getVertex(int i,btVector3& vtx) const { - btVector3 halfExtents = getHalfExtentsWithoutMargin(); + btVector3 halfExtents = getHalfExtentsWithMargin(); vtx = btVector3( halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1), @@ -313,6 +307,6 @@ public: }; -#endif //OBB_BOX_MINKOWSKI_H +#endif //BT_OBB_BOX_MINKOWSKI_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h index c269ef27bdb..d1c21629873 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BVH_TRIANGLE_MESH_SHAPE_H -#define BVH_TRIANGLE_MESH_SHAPE_H +#ifndef BT_BVH_TRIANGLE_MESH_SHAPE_H +#define BT_BVH_TRIANGLE_MESH_SHAPE_H #include "btTriangleMeshShape.h" #include "btOptimizedBvh.h" @@ -136,4 +136,4 @@ SIMD_FORCE_INLINE int btBvhTriangleMeshShape::calculateSerializeBufferSize() con -#endif //BVH_TRIANGLE_MESH_SHAPE_H +#endif //BT_BVH_TRIANGLE_MESH_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp index 2faa11d4360..864df26e931 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp @@ -55,7 +55,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter btVector3 pos(0,0,0); pos[getUpAxis()] = getHalfHeight(); - vtx = pos +vec*m_localScaling*(radius) - vec * getMargin(); + vtx = pos +vec*(radius) - vec * getMargin(); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -67,7 +67,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter btVector3 pos(0,0,0); pos[getUpAxis()] = -getHalfHeight(); - vtx = pos +vec*m_localScaling*(radius) - vec * getMargin(); + vtx = pos +vec*(radius) - vec * getMargin(); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -96,7 +96,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter { btVector3 pos(0,0,0); pos[getUpAxis()] = getHalfHeight(); - vtx = pos +vec*m_localScaling*(radius) - vec * getMargin(); + vtx = pos +vec*(radius) - vec * getMargin(); newDot = vec.dot(vtx); if (newDot > maxDot) { @@ -107,7 +107,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter { btVector3 pos(0,0,0); pos[getUpAxis()] = -getHalfHeight(); - vtx = pos +vec*m_localScaling*(radius) - vec * getMargin(); + vtx = pos +vec*(radius) - vec * getMargin(); newDot = vec.dot(vtx); if (newDot > maxDot) { diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h index 18fd026041f..474bf1fb499 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionMargin.h @@ -13,14 +13,15 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COLLISION_MARGIN_H -#define COLLISION_MARGIN_H - -//used by Gjk and some other algorithms +#ifndef BT_COLLISION_MARGIN_H +#define BT_COLLISION_MARGIN_H +///The CONVEX_DISTANCE_MARGIN is a default collision margin for convex collision shapes derived from btConvexInternalShape. +///This collision margin is used by Gjk and some other algorithms +///Note that when creating small objects, you need to make sure to set a smaller collision margin, using the 'setMargin' API #define CONVEX_DISTANCE_MARGIN btScalar(0.04)// btScalar(0.1)//;//btScalar(0.01) -#endif //COLLISION_MARGIN_H +#endif //BT_COLLISION_MARGIN_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h index f32bd736a99..865c1067744 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCollisionShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COLLISION_SHAPE_H -#define COLLISION_SHAPE_H +#ifndef BT_COLLISION_SHAPE_H +#define BT_COLLISION_SHAPE_H #include "LinearMath/btTransform.h" #include "LinearMath/btVector3.h" @@ -146,5 +146,5 @@ SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() const -#endif //COLLISION_SHAPE_H +#endif //BT_COLLISION_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h index 7f41dd4517b..141034a8e8c 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCompoundShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef COMPOUND_SHAPE_H -#define COMPOUND_SHAPE_H +#ifndef BT_COMPOUND_SHAPE_H +#define BT_COMPOUND_SHAPE_H #include "btCollisionShape.h" @@ -209,4 +209,4 @@ SIMD_FORCE_INLINE int btCompoundShape::calculateSerializeBufferSize() const -#endif //COMPOUND_SHAPE_H +#endif //BT_COMPOUND_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h index 2a370a47c75..2a03241c9d7 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConcaveShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONCAVE_SHAPE_H -#define CONCAVE_SHAPE_H +#ifndef BT_CONCAVE_SHAPE_H +#define BT_CONCAVE_SHAPE_H #include "btCollisionShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -57,4 +57,4 @@ public: }; -#endif //CONCAVE_SHAPE_H +#endif //BT_CONCAVE_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h index bd7d1443ac2..b69b5c5b0c8 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConeShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONE_MINKOWSKI_H -#define CONE_MINKOWSKI_H +#ifndef BT_CONE_MINKOWSKI_H +#define BT_CONE_MINKOWSKI_H #include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -99,5 +99,5 @@ class btConeShapeZ : public btConeShape public: btConeShapeZ(btScalar radius,btScalar height); }; -#endif //CONE_MINKOWSKI_H +#endif //BT_CONE_MINKOWSKI_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp index 69bc67cafab..226245979ab 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp @@ -208,4 +208,48 @@ const char* btConvexHullShape::serialize(void* dataBuffer, btSerializer* seriali return "btConvexHullShapeData"; } +void btConvexHullShape::project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const +{ +#if 1 + min = FLT_MAX; + max = -FLT_MAX; + btVector3 witnesPtMin; + btVector3 witnesPtMax; + + int numVerts = m_unscaledPoints.size(); + for(int i=0;i<numVerts;i++) + { + btVector3 vtx = m_unscaledPoints[i] * m_localScaling; + btVector3 pt = trans * vtx; + btScalar dp = pt.dot(dir); + if(dp < min) + { + min = dp; + witnesPtMin = pt; + } + if(dp > max) + { + max = dp; + witnesPtMax=pt; + } + } +#else + btVector3 localAxis = dir*trans.getBasis(); + btVector3 vtx1 = trans(localGetSupportingVertex(localAxis)); + btVector3 vtx2 = trans(localGetSupportingVertex(-localAxis)); + + min = vtx1.dot(dir); + max = vtx2.dot(dir); +#endif + + if(min>max) + { + btScalar tmp = min; + min = max; + max = tmp; + } + + +} + diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h index bf960f4df92..95a2af6a3a0 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexHullShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_HULL_SHAPE_H -#define CONVEX_HULL_SHAPE_H +#ifndef BT_CONVEX_HULL_SHAPE_H +#define BT_CONVEX_HULL_SHAPE_H #include "btPolyhedralConvexShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -73,6 +73,8 @@ public: virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; + virtual void project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const; + //debugging virtual const char* getName()const {return "Convex";} @@ -116,5 +118,5 @@ SIMD_FORCE_INLINE int btConvexHullShape::calculateSerializeBufferSize() const } -#endif //CONVEX_HULL_SHAPE_H +#endif //BT_CONVEX_HULL_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h index 12527731804..85cd9ef90c7 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexInternalShape.h @@ -21,6 +21,11 @@ subject to the following restrictions: ///The btConvexInternalShape is an internal base class, shared by most convex shape implementations. +///The btConvexInternalShape uses a default collision margin set to CONVEX_DISTANCE_MARGIN. +///This collision margin used by Gjk and some other algorithms, see also btCollisionMargin.h +///Note that when creating small shapes (derived from btConvexInternalShape), +///you need to make sure to set a smaller collision margin, using the 'setMargin' API +///There is a automatic mechanism 'setSafeMargin' used by btBoxShape and btCylinderShape class btConvexInternalShape : public btConvexShape { @@ -62,6 +67,23 @@ public: m_implicitShapeDimensions = dimensions; } + void setSafeMargin(btScalar minDimension, btScalar defaultMarginMultiplier = 0.1f) + { + btScalar safeMargin = defaultMarginMultiplier*minDimension; + if (safeMargin < getMargin()) + { + setMargin(safeMargin); + } + } + void setSafeMargin(const btVector3& halfExtents, btScalar defaultMarginMultiplier = 0.1f) + { + //see http://code.google.com/p/bullet/issues/detail?id=349 + //this margin check could could be added to other collision shapes too, + //or add some assert/warning somewhere + btScalar minDimension=halfExtents[halfExtents.minAxis()]; + setSafeMargin(minDimension, defaultMarginMultiplier); + } + ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const { diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp new file mode 100644 index 00000000000..1e26be531c2 --- /dev/null +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp @@ -0,0 +1,296 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +///This file was written by Erwin Coumans +///Separating axis rest based on work from Pierre Terdiman, see +///And contact clipping based on work from Simon Hobbs + +#include "btConvexPolyhedron.h" +#include "LinearMath/btHashMap.h" + +btConvexPolyhedron::btConvexPolyhedron() +{ + +} +btConvexPolyhedron::~btConvexPolyhedron() +{ + +} + + +inline bool IsAlmostZero(const btVector3& v) +{ + if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6) return false; + return true; +} + +struct btInternalVertexPair +{ + btInternalVertexPair(short int v0,short int v1) + :m_v0(v0), + m_v1(v1) + { + if (m_v1>m_v0) + btSwap(m_v0,m_v1); + } + short int m_v0; + short int m_v1; + int getHash() const + { + return m_v0+(m_v1<<16); + } + bool equals(const btInternalVertexPair& other) const + { + return m_v0==other.m_v0 && m_v1==other.m_v1; + } +}; + +struct btInternalEdge +{ + btInternalEdge() + :m_face0(-1), + m_face1(-1) + { + } + short int m_face0; + short int m_face1; +}; + +// + +#ifdef TEST_INTERNAL_OBJECTS +bool btConvexPolyhedron::testContainment() const +{ + for(int p=0;p<8;p++) + { + btVector3 LocalPt; + if(p==0) LocalPt = m_localCenter + btVector3(m_extents[0], m_extents[1], m_extents[2]); + else if(p==1) LocalPt = m_localCenter + btVector3(m_extents[0], m_extents[1], -m_extents[2]); + else if(p==2) LocalPt = m_localCenter + btVector3(m_extents[0], -m_extents[1], m_extents[2]); + else if(p==3) LocalPt = m_localCenter + btVector3(m_extents[0], -m_extents[1], -m_extents[2]); + else if(p==4) LocalPt = m_localCenter + btVector3(-m_extents[0], m_extents[1], m_extents[2]); + else if(p==5) LocalPt = m_localCenter + btVector3(-m_extents[0], m_extents[1], -m_extents[2]); + else if(p==6) LocalPt = m_localCenter + btVector3(-m_extents[0], -m_extents[1], m_extents[2]); + else if(p==7) LocalPt = m_localCenter + btVector3(-m_extents[0], -m_extents[1], -m_extents[2]); + + for(int i=0;i<m_faces.size();i++) + { + const btVector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]); + const btScalar d = LocalPt.dot(Normal) + m_faces[i].m_plane[3]; + if(d>0.0f) + return false; + } + } + return true; +} +#endif + +void btConvexPolyhedron::initialize() +{ + + btHashMap<btInternalVertexPair,btInternalEdge> edges; + + btScalar TotalArea = 0.0f; + + m_localCenter.setValue(0, 0, 0); + for(int i=0;i<m_faces.size();i++) + { + int numVertices = m_faces[i].m_indices.size(); + int NbTris = numVertices; + for(int j=0;j<NbTris;j++) + { + int k = (j+1)%numVertices; + btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]); + btInternalEdge* edptr = edges.find(vp); + btVector3 edge = m_vertices[vp.m_v1]-m_vertices[vp.m_v0]; + edge.normalize(); + + bool found = false; + + for (int p=0;p<m_uniqueEdges.size();p++) + { + + if (IsAlmostZero(m_uniqueEdges[p]-edge) || + IsAlmostZero(m_uniqueEdges[p]+edge)) + { + found = true; + break; + } + } + + if (!found) + { + m_uniqueEdges.push_back(edge); + } + + if (edptr) + { + btAssert(edptr->m_face0>=0); + btAssert(edptr->m_face1<0); + edptr->m_face1 = i; + } else + { + btInternalEdge ed; + ed.m_face0 = i; + edges.insert(vp,ed); + } + } + } + +#ifdef USE_CONNECTED_FACES + for(int i=0;i<m_faces.size();i++) + { + int numVertices = m_faces[i].m_indices.size(); + m_faces[i].m_connectedFaces.resize(numVertices); + + for(int j=0;j<numVertices;j++) + { + int k = (j+1)%numVertices; + btInternalVertexPair vp(m_faces[i].m_indices[j],m_faces[i].m_indices[k]); + btInternalEdge* edptr = edges.find(vp); + btAssert(edptr); + btAssert(edptr->m_face0>=0); + btAssert(edptr->m_face1>=0); + + int connectedFace = (edptr->m_face0==i)?edptr->m_face1:edptr->m_face0; + m_faces[i].m_connectedFaces[j] = connectedFace; + } + } +#endif//USE_CONNECTED_FACES + + for(int i=0;i<m_faces.size();i++) + { + int numVertices = m_faces[i].m_indices.size(); + int NbTris = numVertices-2; + + const btVector3& p0 = m_vertices[m_faces[i].m_indices[0]]; + for(int j=1;j<=NbTris;j++) + { + int k = (j+1)%numVertices; + const btVector3& p1 = m_vertices[m_faces[i].m_indices[j]]; + const btVector3& p2 = m_vertices[m_faces[i].m_indices[k]]; + btScalar Area = ((p0 - p1).cross(p0 - p2)).length() * 0.5f; + btVector3 Center = (p0+p1+p2)/3.0f; + m_localCenter += Area * Center; + TotalArea += Area; + } + } + m_localCenter /= TotalArea; + + + + +#ifdef TEST_INTERNAL_OBJECTS + if(1) + { + m_radius = FLT_MAX; + for(int i=0;i<m_faces.size();i++) + { + const btVector3 Normal(m_faces[i].m_plane[0], m_faces[i].m_plane[1], m_faces[i].m_plane[2]); + const btScalar dist = btFabs(m_localCenter.dot(Normal) + m_faces[i].m_plane[3]); + if(dist<m_radius) + m_radius = dist; + } + + + btScalar MinX = FLT_MAX; + btScalar MinY = FLT_MAX; + btScalar MinZ = FLT_MAX; + btScalar MaxX = -FLT_MAX; + btScalar MaxY = -FLT_MAX; + btScalar MaxZ = -FLT_MAX; + for(int i=0; i<m_vertices.size(); i++) + { + const btVector3& pt = m_vertices[i]; + if(pt.x()<MinX) MinX = pt.x(); + if(pt.x()>MaxX) MaxX = pt.x(); + if(pt.y()<MinY) MinY = pt.y(); + if(pt.y()>MaxY) MaxY = pt.y(); + if(pt.z()<MinZ) MinZ = pt.z(); + if(pt.z()>MaxZ) MaxZ = pt.z(); + } + mC.setValue(MaxX+MinX, MaxY+MinY, MaxZ+MinZ); + mE.setValue(MaxX-MinX, MaxY-MinY, MaxZ-MinZ); + + + +// const btScalar r = m_radius / sqrtf(2.0f); + const btScalar r = m_radius / sqrtf(3.0f); + const int LargestExtent = mE.maxAxis(); + const btScalar Step = (mE[LargestExtent]*0.5f - r)/1024.0f; + m_extents[0] = m_extents[1] = m_extents[2] = r; + m_extents[LargestExtent] = mE[LargestExtent]*0.5f; + bool FoundBox = false; + for(int j=0;j<1024;j++) + { + if(testContainment()) + { + FoundBox = true; + break; + } + + m_extents[LargestExtent] -= Step; + } + if(!FoundBox) + { + m_extents[0] = m_extents[1] = m_extents[2] = r; + } + else + { + // Refine the box + const btScalar Step = (m_radius - r)/1024.0f; + const int e0 = (1<<LargestExtent) & 3; + const int e1 = (1<<e0) & 3; + + for(int j=0;j<1024;j++) + { + const btScalar Saved0 = m_extents[e0]; + const btScalar Saved1 = m_extents[e1]; + m_extents[e0] += Step; + m_extents[e1] += Step; + + if(!testContainment()) + { + m_extents[e0] = Saved0; + m_extents[e1] = Saved1; + break; + } + } + } + } +#endif +} + + +void btConvexPolyhedron::project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const +{ + min = FLT_MAX; + max = -FLT_MAX; + int numVerts = m_vertices.size(); + for(int i=0;i<numVerts;i++) + { + btVector3 pt = trans * m_vertices[i]; + btScalar dp = pt.dot(dir); + if(dp < min) min = dp; + if(dp > max) max = dp; + } + if(min>max) + { + btScalar tmp = min; + min = max; + max = tmp; + } +}
\ No newline at end of file diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.h new file mode 100644 index 00000000000..08db39a33c8 --- /dev/null +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexPolyhedron.h @@ -0,0 +1,62 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +///This file was written by Erwin Coumans + + +#ifndef _BT_POLYHEDRAL_FEATURES_H +#define _BT_POLYHEDRAL_FEATURES_H + +#include "LinearMath/btTransform.h" +#include "LinearMath/btAlignedObjectArray.h" + +#define TEST_INTERNAL_OBJECTS 1 + + +struct btFace +{ + btAlignedObjectArray<int> m_indices; +// btAlignedObjectArray<int> m_connectedFaces; + btScalar m_plane[4]; +}; + + +class btConvexPolyhedron +{ + public: + btConvexPolyhedron(); + virtual ~btConvexPolyhedron(); + + btAlignedObjectArray<btVector3> m_vertices; + btAlignedObjectArray<btFace> m_faces; + btAlignedObjectArray<btVector3> m_uniqueEdges; + + btVector3 m_localCenter; + btVector3 m_extents; + btScalar m_radius; + btVector3 mC; + btVector3 mE; + + void initialize(); + bool testContainment() const; + + void project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const; +}; + + +#endif //_BT_POLYHEDRAL_FEATURES_H + + diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp index f5f3aa58aa4..8c67d8ebef1 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.cpp @@ -43,6 +43,23 @@ btConvexShape::~btConvexShape() } +void btConvexShape::project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const +{ + btVector3 localAxis = dir*trans.getBasis(); + btVector3 vtx1 = trans(localGetSupportingVertex(localAxis)); + btVector3 vtx2 = trans(localGetSupportingVertex(-localAxis)); + + min = vtx1.dot(dir); + max = vtx2.dot(dir); + + if(min>max) + { + btScalar tmp = min; + min = max; + max = tmp; + } +} + static btVector3 convexHullSupport (const btVector3& localDirOrg, const btVector3* points, int numPoints, const btVector3& localScaling) { @@ -227,7 +244,7 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV pos[capsuleUpAxis] = halfHeight; //vtx = pos +vec*(radius); - vtx = pos +vec*capsuleShape->getLocalScalingNV()*(radius) - vec * capsuleShape->getMarginNV(); + vtx = pos +vec*(radius) - vec * capsuleShape->getMarginNV(); newDot = vec.dot(vtx); @@ -242,7 +259,7 @@ btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btV pos[capsuleUpAxis] = -halfHeight; //vtx = pos +vec*(radius); - vtx = pos +vec*capsuleShape->getLocalScalingNV()*(radius) - vec * capsuleShape->getMarginNV(); + vtx = pos +vec*(radius) - vec * capsuleShape->getMarginNV(); newDot = vec.dot(vtx); if (newDot > maxDot) { diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h index 9c158259c1c..290cd9fd13c 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_SHAPE_INTERFACE1 -#define CONVEX_SHAPE_INTERFACE1 +#ifndef BT_CONVEX_SHAPE_INTERFACE1 +#define BT_CONVEX_SHAPE_INTERFACE1 #include "btCollisionShape.h" @@ -52,6 +52,8 @@ public: btScalar getMarginNonVirtual () const; void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const; + virtual void project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const; + //notice that the vectors should be unit length virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0; @@ -79,4 +81,4 @@ public: -#endif //CONVEX_SHAPE_INTERFACE1 +#endif //BT_CONVEX_SHAPE_INTERFACE1 diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h index f5167e74b80..af5d00388e8 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h @@ -12,8 +12,8 @@ subject to the following restrictions: 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONVEX_TRIANGLEMESH_SHAPE_H -#define CONVEX_TRIANGLEMESH_SHAPE_H +#ifndef BT_CONVEX_TRIANGLEMESH_SHAPE_H +#define BT_CONVEX_TRIANGLEMESH_SHAPE_H #include "btPolyhedralConvexShape.h" @@ -69,7 +69,7 @@ public: -#endif //CONVEX_TRIANGLEMESH_SHAPE_H +#endif //BT_CONVEX_TRIANGLEMESH_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp index c2e534b0b46..6cfe43be4da 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.cpp @@ -19,6 +19,8 @@ btCylinderShape::btCylinderShape (const btVector3& halfExtents) :btConvexInternalShape(), m_upAxis(1) { + setSafeMargin(halfExtents); + btVector3 margin(getMargin(),getMargin(),getMargin()); m_implicitShapeDimensions = (halfExtents * m_localScaling) - margin; m_shapeType = CYLINDER_SHAPE_PROXYTYPE; diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h index f7899265d31..125bfc78a77 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btCylinderShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CYLINDER_MINKOWSKI_H -#define CYLINDER_MINKOWSKI_H +#ifndef BT_CYLINDER_MINKOWSKI_H +#define BT_CYLINDER_MINKOWSKI_H #include "btBoxShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -196,5 +196,5 @@ SIMD_FORCE_INLINE const char* btCylinderShape::serialize(void* dataBuffer, btSer -#endif //CYLINDER_MINKOWSKI_H +#endif //BT_CYLINDER_MINKOWSKI_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h index 9f6b4435c29..87b7b66d1e1 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btEmptyShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef EMPTY_SHAPE_H -#define EMPTY_SHAPE_H +#ifndef BT_EMPTY_SHAPE_H +#define BT_EMPTY_SHAPE_H #include "btConcaveShape.h" @@ -67,4 +67,4 @@ protected: -#endif //EMPTY_SHAPE_H +#endif //BT_EMPTY_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp index 3a1e6f4a2b9..95631c30190 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp @@ -21,7 +21,7 @@ subject to the following restrictions: btHeightfieldTerrainShape::btHeightfieldTerrainShape ( -int heightStickWidth, int heightStickLength, void* heightfieldData, +int heightStickWidth, int heightStickLength, const void* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight,int upAxis, PHY_ScalarType hdt, bool flipQuadEdges ) @@ -33,7 +33,7 @@ PHY_ScalarType hdt, bool flipQuadEdges -btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges) +btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,const void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges) { // legacy constructor: support only float or unsigned char, // and min height is zero @@ -53,7 +53,7 @@ btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int h void btHeightfieldTerrainShape::initialize ( -int heightStickWidth, int heightStickLength, void* heightfieldData, +int heightStickWidth, int heightStickLength, const void* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, PHY_ScalarType hdt, bool flipQuadEdges ) diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h index 4f5d1e35bf3..78e231e08e6 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef HEIGHTFIELD_TERRAIN_SHAPE_H -#define HEIGHTFIELD_TERRAIN_SHAPE_H +#ifndef BT_HEIGHTFIELD_TERRAIN_SHAPE_H +#define BT_HEIGHTFIELD_TERRAIN_SHAPE_H #include "btConcaveShape.h" @@ -85,10 +85,10 @@ protected: btScalar m_heightScale; union { - unsigned char* m_heightfieldDataUnsignedChar; - short* m_heightfieldDataShort; - btScalar* m_heightfieldDataFloat; - void* m_heightfieldDataUnknown; + const unsigned char* m_heightfieldDataUnsignedChar; + const short* m_heightfieldDataShort; + const btScalar* m_heightfieldDataFloat; + const void* m_heightfieldDataUnknown; }; PHY_ScalarType m_heightDataType; @@ -111,7 +111,7 @@ protected: backwards-compatible without a lot of copy/paste. */ void initialize(int heightStickWidth, int heightStickLength, - void* heightfieldData, btScalar heightScale, + const void* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, PHY_ScalarType heightDataType, bool flipQuadEdges); @@ -123,7 +123,7 @@ public: heightScale is needed for any integer-based heightfield data types. */ btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength, - void* heightfieldData, btScalar heightScale, + const void* heightfieldData, btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis, PHY_ScalarType heightDataType, bool flipQuadEdges); @@ -135,7 +135,7 @@ public: compatibility reasons, heightScale is calculated as maxHeight / 65535 (and is only used when useFloatData = false). */ - btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges); + btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,const void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges); virtual ~btHeightfieldTerrainShape(); @@ -158,4 +158,4 @@ public: }; -#endif //HEIGHTFIELD_TERRAIN_SHAPE_H +#endif //BT_HEIGHTFIELD_TERRAIN_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h index 030e167da50..866f9b4da4d 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMaterial.h @@ -15,8 +15,8 @@ subject to the following restrictions: /// This file was created by Alex Silverman -#ifndef MATERIAL_H -#define MATERIAL_H +#ifndef BT_MATERIAL_H +#define BT_MATERIAL_H // Material class to be used by btMultimaterialTriangleMeshShape to store triangle properties class btMaterial @@ -31,5 +31,5 @@ public: btMaterial(btScalar fric, btScalar rest) { m_friction = fric; m_restitution = rest; } }; -#endif // MATERIAL_H +#endif // BT_MATERIAL_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h index d6fd040213b..6c844e8c0af 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMinkowskiSumShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef MINKOWSKI_SUM_SHAPE_H -#define MINKOWSKI_SUM_SHAPE_H +#ifndef BT_MINKOWSKI_SUM_SHAPE_H +#define BT_MINKOWSKI_SUM_SHAPE_H #include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -57,4 +57,4 @@ public: } }; -#endif //MINKOWSKI_SUM_SHAPE_H +#endif //BT_MINKOWSKI_SUM_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h index 3db7e320889..06c5d16d941 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultiSphereShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef MULTI_SPHERE_MINKOWSKI_H -#define MULTI_SPHERE_MINKOWSKI_H +#ifndef BT_MULTI_SPHERE_MINKOWSKI_H +#define BT_MULTI_SPHERE_MINKOWSKI_H #include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -96,4 +96,4 @@ SIMD_FORCE_INLINE int btMultiSphereShape::calculateSerializeBufferSize() const -#endif //MULTI_SPHERE_MINKOWSKI_H +#endif //BT_MULTI_SPHERE_MINKOWSKI_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h index 96b2ad95b6d..2b92ab7d1b7 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h @@ -15,8 +15,8 @@ subject to the following restrictions: /// This file was created by Alex Silverman -#ifndef BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H -#define BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H +#ifndef BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H +#define BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H #include "btBvhTriangleMeshShape.h" #include "btMaterial.h" @@ -117,4 +117,4 @@ public: } ; -#endif //BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H +#endif //BT_BVH_TRIANGLE_MATERIAL_MESH_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp index 981b8a2652c..6f36775f7c9 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.cpp @@ -43,7 +43,7 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized NodeTriangleCallback& operator=(NodeTriangleCallback& other) { - m_triangleNodes = other.m_triangleNodes; + m_triangleNodes.copyFromArray(other.m_triangleNodes); return *this; } @@ -84,7 +84,7 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles, bool useQuantized QuantizedNodeTriangleCallback& operator=(QuantizedNodeTriangleCallback& other) { - m_triangleNodes = other.m_triangleNodes; + m_triangleNodes.copyFromArray(other.m_triangleNodes); m_optimizedTree = other.m_optimizedTree; return *this; } diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h index 749fe6005dd..715961f5528 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btOptimizedBvh.h @@ -15,8 +15,8 @@ subject to the following restrictions: ///Contains contributions from Disney Studio's -#ifndef OPTIMIZED_BVH_H -#define OPTIMIZED_BVH_H +#ifndef BT_OPTIMIZED_BVH_H +#define BT_OPTIMIZED_BVH_H #include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h" @@ -60,6 +60,6 @@ public: }; -#endif //OPTIMIZED_BVH_H +#endif //BT_OPTIMIZED_BVH_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp index b1ecb3e432c..82def79cf55 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp @@ -14,10 +14,289 @@ subject to the following restrictions: */ #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" +#include "btConvexPolyhedron.h" +#include "LinearMath/btConvexHullComputer.h" +#include <new> +#include "LinearMath/btGeometryUtil.h" +#include "LinearMath/btGrahamScan2dConvexHull.h" -btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape() + +btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(), +m_polyhedron(0) +{ + +} + +btPolyhedralConvexShape::~btPolyhedralConvexShape() +{ + if (m_polyhedron) + { + btAlignedFree(m_polyhedron); + } +} + + +bool btPolyhedralConvexShape::initializePolyhedralFeatures() { + if (m_polyhedron) + btAlignedFree(m_polyhedron); + + void* mem = btAlignedAlloc(sizeof(btConvexPolyhedron),16); + m_polyhedron = new (mem) btConvexPolyhedron; + + btAlignedObjectArray<btVector3> orgVertices; + + for (int i=0;i<getNumVertices();i++) + { + btVector3& newVertex = orgVertices.expand(); + getVertex(i,newVertex); + } + +#if 0 + btAlignedObjectArray<btVector3> planeEquations; + btGeometryUtil::getPlaneEquationsFromVertices(orgVertices,planeEquations); + + btAlignedObjectArray<btVector3> shiftedPlaneEquations; + for (int p=0;p<planeEquations.size();p++) + { + btVector3 plane = planeEquations[p]; + plane[3] -= getMargin(); + shiftedPlaneEquations.push_back(plane); + } + + btAlignedObjectArray<btVector3> tmpVertices; + + btGeometryUtil::getVerticesFromPlaneEquations(shiftedPlaneEquations,tmpVertices); + btConvexHullComputer conv; + conv.compute(&tmpVertices[0].getX(), sizeof(btVector3),tmpVertices.size(),0.f,0.f); + +#else + btConvexHullComputer conv; + conv.compute(&orgVertices[0].getX(), sizeof(btVector3),orgVertices.size(),0.f,0.f); + +#endif + + + + btAlignedObjectArray<btVector3> faceNormals; + int numFaces = conv.faces.size(); + faceNormals.resize(numFaces); + btConvexHullComputer* convexUtil = &conv; + + + btAlignedObjectArray<btFace> tmpFaces; + tmpFaces.resize(numFaces); + + int numVertices = convexUtil->vertices.size(); + m_polyhedron->m_vertices.resize(numVertices); + for (int p=0;p<numVertices;p++) + { + m_polyhedron->m_vertices[p] = convexUtil->vertices[p]; + } + + + for (int i=0;i<numFaces;i++) + { + int face = convexUtil->faces[i]; + //printf("face=%d\n",face); + const btConvexHullComputer::Edge* firstEdge = &convexUtil->edges[face]; + const btConvexHullComputer::Edge* edge = firstEdge; + + btVector3 edges[3]; + int numEdges = 0; + //compute face normals + + btScalar maxCross2 = 0.f; + int chosenEdge = -1; + + do + { + + int src = edge->getSourceVertex(); + tmpFaces[i].m_indices.push_back(src); + int targ = edge->getTargetVertex(); + btVector3 wa = convexUtil->vertices[src]; + + btVector3 wb = convexUtil->vertices[targ]; + btVector3 newEdge = wb-wa; + newEdge.normalize(); + if (numEdges<2) + edges[numEdges++] = newEdge; + + edge = edge->getNextEdgeOfFace(); + } while (edge!=firstEdge); + + btScalar planeEq = 1e30f; + + + if (numEdges==2) + { + faceNormals[i] = edges[0].cross(edges[1]); + faceNormals[i].normalize(); + tmpFaces[i].m_plane[0] = faceNormals[i].getX(); + tmpFaces[i].m_plane[1] = faceNormals[i].getY(); + tmpFaces[i].m_plane[2] = faceNormals[i].getZ(); + tmpFaces[i].m_plane[3] = planeEq; + + } + else + { + btAssert(0);//degenerate? + faceNormals[i].setZero(); + } + + for (int v=0;v<tmpFaces[i].m_indices.size();v++) + { + btScalar eq = m_polyhedron->m_vertices[tmpFaces[i].m_indices[v]].dot(faceNormals[i]); + if (planeEq>eq) + { + planeEq=eq; + } + } + tmpFaces[i].m_plane[3] = -planeEq; + } + + //merge coplanar faces and copy them to m_polyhedron + + btScalar faceWeldThreshold= 0.999f; + btAlignedObjectArray<int> todoFaces; + for (int i=0;i<tmpFaces.size();i++) + todoFaces.push_back(i); + + while (todoFaces.size()) + { + btAlignedObjectArray<int> coplanarFaceGroup; + int refFace = todoFaces[todoFaces.size()-1]; + + coplanarFaceGroup.push_back(refFace); + btFace& faceA = tmpFaces[refFace]; + todoFaces.pop_back(); + + btVector3 faceNormalA(faceA.m_plane[0],faceA.m_plane[1],faceA.m_plane[2]); + for (int j=todoFaces.size()-1;j>=0;j--) + { + int i = todoFaces[j]; + btFace& faceB = tmpFaces[i]; + btVector3 faceNormalB(faceB.m_plane[0],faceB.m_plane[1],faceB.m_plane[2]); + if (faceNormalA.dot(faceNormalB)>faceWeldThreshold) + { + coplanarFaceGroup.push_back(i); + todoFaces.remove(i); + } + } + + + bool did_merge = false; + if (coplanarFaceGroup.size()>1) + { + //do the merge: use Graham Scan 2d convex hull + + btAlignedObjectArray<GrahamVector2> orgpoints; + + for (int i=0;i<coplanarFaceGroup.size();i++) + { +// m_polyhedron->m_faces.push_back(tmpFaces[coplanarFaceGroup[i]]); + + btFace& face = tmpFaces[coplanarFaceGroup[i]]; + btVector3 faceNormal(face.m_plane[0],face.m_plane[1],face.m_plane[2]); + btVector3 xyPlaneNormal(0,0,1); + + btQuaternion rotationArc = shortestArcQuat(faceNormal,xyPlaneNormal); + + for (int f=0;f<face.m_indices.size();f++) + { + int orgIndex = face.m_indices[f]; + btVector3 pt = m_polyhedron->m_vertices[orgIndex]; + btVector3 rotatedPt = quatRotate(rotationArc,pt); + rotatedPt.setZ(0); + bool found = false; + + for (int i=0;i<orgpoints.size();i++) + { + //if ((orgpoints[i].m_orgIndex == orgIndex) || ((rotatedPt-orgpoints[i]).length2()<0.0001)) + if (orgpoints[i].m_orgIndex == orgIndex) + { + found=true; + break; + } + } + if (!found) + orgpoints.push_back(GrahamVector2(rotatedPt,orgIndex)); + } + } + + btFace combinedFace; + for (int i=0;i<4;i++) + combinedFace.m_plane[i] = tmpFaces[coplanarFaceGroup[0]].m_plane[i]; + + btAlignedObjectArray<GrahamVector2> hull; + GrahamScanConvexHull2D(orgpoints,hull); + + for (int i=0;i<hull.size();i++) + { + combinedFace.m_indices.push_back(hull[i].m_orgIndex); + for(int k = 0; k < orgpoints.size(); k++) { + if(orgpoints[k].m_orgIndex == hull[i].m_orgIndex) { + orgpoints[k].m_orgIndex = -1; // invalidate... + break; + } + } + } + // are there rejected vertices? + bool reject_merge = false; + for(int i = 0; i < orgpoints.size(); i++) { + if(orgpoints[i].m_orgIndex == -1) + continue; // this is in the hull... + // this vertex is rejected -- is anybody else using this vertex? + for(int j = 0; j < tmpFaces.size(); j++) { + btFace& face = tmpFaces[j]; + // is this a face of the current coplanar group? + bool is_in_current_group = false; + for(int k = 0; k < coplanarFaceGroup.size(); k++) { + if(coplanarFaceGroup[k] == j) { + is_in_current_group = true; + break; + } + } + if(is_in_current_group) // ignore this face... + continue; + // does this face use this rejected vertex? + for(int v = 0; v < face.m_indices.size(); v++) { + if(face.m_indices[v] == orgpoints[i].m_orgIndex) { + // this rejected vertex is used in another face -- reject merge + reject_merge = true; + break; + } + } + if(reject_merge) + break; + } + if(reject_merge) + break; + } + if(!reject_merge) { + // do this merge! + did_merge = true; + m_polyhedron->m_faces.push_back(combinedFace); + } + } + if(!did_merge) + { + for (int i=0;i<coplanarFaceGroup.size();i++) + { + m_polyhedron->m_faces.push_back(tmpFaces[coplanarFaceGroup[i]]); + } + + } + + + + } + + m_polyhedron->initialize(); + + return true; } @@ -183,11 +462,14 @@ void btPolyhedralConvexAabbCachingShape::recalcLocalAabb() btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); vec[i] = btScalar(1.); btVector3 tmp = localGetSupportingVertex(vec); - m_localAabbMax[i] = tmp[i]+m_collisionMargin; + m_localAabbMax[i] = tmp[i]; vec[i] = btScalar(-1.); tmp = localGetSupportingVertex(vec); - m_localAabbMin[i] = tmp[i]-m_collisionMargin; + m_localAabbMin[i] = tmp[i]; } #endif } + + + diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h index 2c691b95652..ee2e1e28277 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h @@ -13,23 +13,37 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BU_SHAPE -#define BU_SHAPE +#ifndef BT_POLYHEDRAL_CONVEX_SHAPE_H +#define BT_POLYHEDRAL_CONVEX_SHAPE_H #include "LinearMath/btMatrix3x3.h" #include "btConvexInternalShape.h" +class btConvexPolyhedron; ///The btPolyhedralConvexShape is an internal interface class for polyhedral convex shapes. class btPolyhedralConvexShape : public btConvexInternalShape { + protected: + btConvexPolyhedron* m_polyhedron; + public: btPolyhedralConvexShape(); + virtual ~btPolyhedralConvexShape(); + + ///optional method mainly used to generate multiple contact points by clipping polyhedral features (faces/edges) + virtual bool initializePolyhedralFeatures(); + + const btConvexPolyhedron* getConvexPolyhedron() const + { + return m_polyhedron; + } + //brute force implementations virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; @@ -95,4 +109,4 @@ public: }; -#endif //BU_SHAPE +#endif //BT_POLYHEDRAL_CONVEX_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h index 4ab28555ba8..ff86ef319e9 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SCALED_BVH_TRIANGLE_MESH_SHAPE_H -#define SCALED_BVH_TRIANGLE_MESH_SHAPE_H +#ifndef BT_SCALED_BVH_TRIANGLE_MESH_SHAPE_H +#define BT_SCALED_BVH_TRIANGLE_MESH_SHAPE_H #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" @@ -90,4 +90,4 @@ SIMD_FORCE_INLINE const char* btScaledBvhTriangleMeshShape::serialize(void* data } -#endif //BVH_TRIANGLE_MESH_SHAPE_H +#endif //BT_SCALED_BVH_TRIANGLE_MESH_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h index 07b3500f994..642a2887435 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btShapeHull.h @@ -15,8 +15,8 @@ subject to the following restrictions: ///btShapeHull implemented by John McCutchan. -#ifndef _SHAPE_HULL_H -#define _SHAPE_HULL_H +#ifndef BT_SHAPE_HULL_H +#define BT_SHAPE_HULL_H #include "LinearMath/btAlignedObjectArray.h" #include "BulletCollision/CollisionShapes/btConvexShape.h" @@ -56,4 +56,4 @@ public: } }; -#endif //_SHAPE_HULL_H +#endif //BT_SHAPE_HULL_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h index f98372442ba..b192efeeb8d 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btSphereShape.h @@ -12,8 +12,8 @@ subject to the following restrictions: 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SPHERE_MINKOWSKI_H -#define SPHERE_MINKOWSKI_H +#ifndef BT_SPHERE_MINKOWSKI_H +#define BT_SPHERE_MINKOWSKI_H #include "btConvexInternalShape.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types @@ -70,4 +70,4 @@ public: }; -#endif //SPHERE_MINKOWSKI_H +#endif //BT_SPHERE_MINKOWSKI_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h index beb53ef33a1..b13825e610d 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStaticPlaneShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef STATIC_PLANE_SHAPE_H -#define STATIC_PLANE_SHAPE_H +#ifndef BT_STATIC_PLANE_SHAPE_H +#define BT_STATIC_PLANE_SHAPE_H #include "btConcaveShape.h" @@ -97,7 +97,7 @@ SIMD_FORCE_INLINE const char* btStaticPlaneShape::serialize(void* dataBuffer, bt } -#endif //STATIC_PLANE_SHAPE_H +#endif //BT_STATIC_PLANE_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp index bc2f9f21448..dd22fc5635a 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp @@ -253,9 +253,11 @@ const char* btStridingMeshInterface::serialize(void* dataBuffer, btSerializer* s memPtr->m_indices16 = 0; memPtr->m_indices32 = 0; memPtr->m_3indices16 = 0; + memPtr->m_3indices8 = 0; memPtr->m_vertices3f = 0; memPtr->m_vertices3d = 0; + switch (gfxindextype) { case PHY_INTEGER: diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h index 9e3e2ab0f59..f2b27ade8e8 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btStridingMeshInterface.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef STRIDING_MESHINTERFACE_H -#define STRIDING_MESHINTERFACE_H +#ifndef BT_STRIDING_MESHINTERFACE_H +#define BT_STRIDING_MESHINTERFACE_H #include "LinearMath/btVector3.h" #include "btTriangleCallback.h" @@ -159,4 +159,4 @@ SIMD_FORCE_INLINE int btStridingMeshInterface::calculateSerializeBufferSize() co -#endif //STRIDING_MESHINTERFACE_H +#endif //BT_STRIDING_MESHINTERFACE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h index 72e9f232876..6b7128efc8e 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTetrahedronShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BU_SIMPLEX_1TO4_SHAPE -#define BU_SIMPLEX_1TO4_SHAPE +#ifndef BT_SIMPLEX_1TO4_SHAPE +#define BT_SIMPLEX_1TO4_SHAPE #include "btPolyhedralConvexShape.h" @@ -71,4 +71,4 @@ public: }; -#endif //BU_SIMPLEX_1TO4_SHAPE +#endif //BT_SIMPLEX_1TO4_SHAPE diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h index 0499702b05b..461c57f8773 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleCallback.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef TRIANGLE_CALLBACK_H -#define TRIANGLE_CALLBACK_H +#ifndef BT_TRIANGLE_CALLBACK_H +#define BT_TRIANGLE_CALLBACK_H #include "LinearMath/btVector3.h" @@ -39,4 +39,4 @@ public: -#endif //TRIANGLE_CALLBACK_H +#endif //BT_TRIANGLE_CALLBACK_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h index c64ea6e7043..9e1544e87a4 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h @@ -29,9 +29,11 @@ ATTRIBUTE_ALIGNED16( struct) btIndexedMesh int m_numTriangles; const unsigned char * m_triangleIndexBase; + // Size in byte of the indices for one triangle (3*sizeof(index_type) if the indices are tightly packed) int m_triangleIndexStride; int m_numVertices; const unsigned char * m_vertexBase; + // Size of a vertex, in bytes int m_vertexStride; // The index type is set when adding an indexed mesh to the diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleInfoMap.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleInfoMap.h index 282a7702e80..1cea7045f20 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleInfoMap.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleInfoMap.h @@ -61,6 +61,7 @@ struct btTriangleInfoMap : public btInternalTriangleInfoMap btScalar m_planarEpsilon; ///used to determine if a triangle edge is planar with zero angle btScalar m_equalVertexThreshold; ///used to compute connectivity: if the distance between two vertices is smaller than m_equalVertexThreshold, they are considered to be 'shared' btScalar m_edgeDistanceThreshold; ///used to determine edge contacts: if the closest distance between a contact point and an edge is smaller than this distance threshold it is considered to "hit the edge" + btScalar m_maxEdgeAngleThreshold; //ignore edges that connect triangles at an angle larger than this m_maxEdgeAngleThreshold btScalar m_zeroAreaThreshold; ///used to determine if a triangle is degenerate (length squared of cross product of 2 triangle edges < threshold) @@ -71,6 +72,7 @@ struct btTriangleInfoMap : public btInternalTriangleInfoMap m_equalVertexThreshold = btScalar(0.0001)*btScalar(0.0001); m_edgeDistanceThreshold = btScalar(0.1); m_zeroAreaThreshold = btScalar(0.0001)*btScalar(0.0001); + m_maxEdgeAngleThreshold = SIMD_2_PI; } virtual ~btTriangleInfoMap() {} @@ -83,6 +85,7 @@ struct btTriangleInfoMap : public btInternalTriangleInfoMap }; +///those fields have to be float and not btScalar for the serialization to work properly struct btTriangleInfoData { int m_flags; diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h index d2624fe18e1..f623157fac1 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMesh.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef TRIANGLE_MESH_H -#define TRIANGLE_MESH_H +#ifndef BT_TRIANGLE_MESH_H +#define BT_TRIANGLE_MESH_H #include "btTriangleIndexVertexArray.h" #include "LinearMath/btVector3.h" @@ -65,5 +65,5 @@ class btTriangleMesh : public btTriangleIndexVertexArray }; -#endif //TRIANGLE_MESH_H +#endif //BT_TRIANGLE_MESH_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h index 2216698d275..c8caf8fe696 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleMeshShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef TRIANGLE_MESH_SHAPE_H -#define TRIANGLE_MESH_SHAPE_H +#ifndef BT_TRIANGLE_MESH_SHAPE_H +#define BT_TRIANGLE_MESH_SHAPE_H #include "btConcaveShape.h" #include "btStridingMeshInterface.h" @@ -86,4 +86,4 @@ public: -#endif //TRIANGLE_MESH_SHAPE_H +#endif //BT_TRIANGLE_MESH_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h index 847147cf6b4..71b0557384e 100644 --- a/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h +++ b/extern/bullet2/src/BulletCollision/CollisionShapes/btTriangleShape.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef OBB_TRIANGLE_MINKOWSKI_H -#define OBB_TRIANGLE_MINKOWSKI_H +#ifndef BT_OBB_TRIANGLE_MINKOWSKI_H +#define BT_OBB_TRIANGLE_MINKOWSKI_H #include "btConvexShape.h" #include "btBoxShape.h" @@ -178,5 +178,5 @@ public: }; -#endif //OBB_TRIANGLE_MINKOWSKI_H +#endif //BT_OBB_TRIANGLE_MINKOWSKI_H diff --git a/extern/bullet2/src/BulletCollision/Gimpact/btContactProcessing.cpp b/extern/bullet2/src/BulletCollision/Gimpact/btContactProcessing.cpp index c3b697bdd1e..eed31d839f8 100644 --- a/extern/bullet2/src/BulletCollision/Gimpact/btContactProcessing.cpp +++ b/extern/bullet2/src/BulletCollision/Gimpact/btContactProcessing.cpp @@ -58,7 +58,7 @@ class CONTACT_KEY_TOKEN_COMP { public: - bool operator() ( const CONTACT_KEY_TOKEN& a, const CONTACT_KEY_TOKEN& b ) + bool operator() ( const CONTACT_KEY_TOKEN& a, const CONTACT_KEY_TOKEN& b ) const { return ( a < b ); } diff --git a/extern/bullet2/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h b/extern/bullet2/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h index ae5d55ab7d9..6b6e07c983d 100644 --- a/extern/bullet2/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h @@ -21,8 +21,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef BVH_CONCAVE_COLLISION_ALGORITHM_H -#define BVH_CONCAVE_COLLISION_ALGORITHM_H +#ifndef BT_GIMPACT_BVH_CONCAVE_COLLISION_ALGORITHM_H +#define BT_GIMPACT_BVH_CONCAVE_COLLISION_ALGORITHM_H #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btDispatcher.h" @@ -303,4 +303,4 @@ public: -#endif //BVH_CONCAVE_COLLISION_ALGORITHM_H +#endif //BT_GIMPACT_BVH_CONCAVE_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletCollision/Gimpact/btQuantization.h b/extern/bullet2/src/BulletCollision/Gimpact/btQuantization.h index e0487c22766..bd2633cfc59 100644 --- a/extern/bullet2/src/BulletCollision/Gimpact/btQuantization.h +++ b/extern/bullet2/src/BulletCollision/Gimpact/btQuantization.h @@ -1,5 +1,5 @@ -#ifndef BT_QUANTIZATION_H_INCLUDED -#define BT_QUANTIZATION_H_INCLUDED +#ifndef BT_GIMPACT_QUANTIZATION_H_INCLUDED +#define BT_GIMPACT_QUANTIZATION_H_INCLUDED /*! \file btQuantization.h *\author Francisco Leon Najera @@ -85,4 +85,4 @@ SIMD_FORCE_INLINE btVector3 bt_unquantize( -#endif // GIM_VECTOR_H_INCLUDED +#endif // BT_GIMPACT_QUANTIZATION_H_INCLUDED diff --git a/extern/bullet2/src/BulletCollision/Gimpact/btTriangleShapeEx.h b/extern/bullet2/src/BulletCollision/Gimpact/btTriangleShapeEx.h index fcc981dfb69..973c2ed1277 100644 --- a/extern/bullet2/src/BulletCollision/Gimpact/btTriangleShapeEx.h +++ b/extern/bullet2/src/BulletCollision/Gimpact/btTriangleShapeEx.h @@ -22,8 +22,8 @@ subject to the following restrictions: */ -#ifndef TRIANGLE_SHAPE_EX_H -#define TRIANGLE_SHAPE_EX_H +#ifndef GIMPACT_TRIANGLE_SHAPE_EX_H +#define GIMPACT_TRIANGLE_SHAPE_EX_H #include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "BulletCollision/CollisionShapes/btTriangleShape.h" @@ -177,4 +177,4 @@ public: }; -#endif //TRIANGLE_MESH_SHAPE_H +#endif //GIMPACT_TRIANGLE_MESH_SHAPE_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp index 9ee83e7d561..91fcea57a3c 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp @@ -22,20 +22,72 @@ subject to the following restrictions: #include "btGjkPairDetector.h" #include "btPointCollector.h" +#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" btContinuousConvexCollision::btContinuousConvexCollision ( const btConvexShape* convexA,const btConvexShape* convexB,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* penetrationDepthSolver) :m_simplexSolver(simplexSolver), m_penetrationDepthSolver(penetrationDepthSolver), -m_convexA(convexA),m_convexB(convexB) +m_convexA(convexA),m_convexB1(convexB),m_planeShape(0) { } + +btContinuousConvexCollision::btContinuousConvexCollision( const btConvexShape* convexA,const btStaticPlaneShape* plane) +:m_simplexSolver(0), +m_penetrationDepthSolver(0), +m_convexA(convexA),m_convexB1(0),m_planeShape(plane) +{ +} + + /// This maximum should not be necessary. It allows for untested/degenerate cases in production code. /// You don't want your game ever to lock-up. #define MAX_ITERATIONS 64 +void btContinuousConvexCollision::computeClosestPoints( const btTransform& transA, const btTransform& transB,btPointCollector& pointCollector) +{ + if (m_convexB1) + { + m_simplexSolver->reset(); + btGjkPairDetector gjk(m_convexA,m_convexB1,m_convexA->getShapeType(),m_convexB1->getShapeType(),m_convexA->getMargin(),m_convexB1->getMargin(),m_simplexSolver,m_penetrationDepthSolver); + btGjkPairDetector::ClosestPointInput input; + input.m_transformA = transA; + input.m_transformB = transB; + gjk.getClosestPoints(input,pointCollector,0); + } else + { + //convex versus plane + const btConvexShape* convexShape = m_convexA; + const btStaticPlaneShape* planeShape = m_planeShape; + + bool hasCollision = false; + const btVector3& planeNormal = planeShape->getPlaneNormal(); + const btScalar& planeConstant = planeShape->getPlaneConstant(); + + btTransform convexWorldTransform = transA; + btTransform convexInPlaneTrans; + convexInPlaneTrans= transB.inverse() * convexWorldTransform; + btTransform planeInConvex; + planeInConvex= convexWorldTransform.inverse() * transB; + + btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal); + + btVector3 vtxInPlane = convexInPlaneTrans(vtx); + btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant); + + btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal; + btVector3 vtxInPlaneWorld = transB * vtxInPlaneProjected; + btVector3 normalOnSurfaceB = transB.getBasis() * planeNormal; + + pointCollector.addContactPoint( + normalOnSurfaceB, + vtxInPlaneWorld, + distance); + } +} + bool btContinuousConvexCollision::calcTimeOfImpact( const btTransform& fromA, const btTransform& toA, @@ -44,7 +96,6 @@ bool btContinuousConvexCollision::calcTimeOfImpact( CastResult& result) { - m_simplexSolver->reset(); /// compute linear and angular velocity for this interval, to interpolate btVector3 linVelA,angVelA,linVelB,angVelB; @@ -53,7 +104,7 @@ bool btContinuousConvexCollision::calcTimeOfImpact( btScalar boundingRadiusA = m_convexA->getAngularMotionDisc(); - btScalar boundingRadiusB = m_convexB->getAngularMotionDisc(); + btScalar boundingRadiusB = m_convexB1?m_convexB1->getAngularMotionDisc():0.f; btScalar maxAngularProjectedVelocity = angVelA.length() * boundingRadiusA + angVelB.length() * boundingRadiusB; btVector3 relLinVel = (linVelB-linVelA); @@ -64,7 +115,6 @@ bool btContinuousConvexCollision::calcTimeOfImpact( return false; - btScalar radius = btScalar(0.001); btScalar lambda = btScalar(0.); btVector3 v(1,0,0); @@ -83,28 +133,14 @@ bool btContinuousConvexCollision::calcTimeOfImpact( //first solution, using GJK - btTransform identityTrans; - identityTrans.setIdentity(); - - btSphereShape raySphere(btScalar(0.0)); - raySphere.setMargin(btScalar(0.)); - - + btScalar radius = 0.001f; // result.drawCoordSystem(sphereTr); btPointCollector pointCollector1; { - - btGjkPairDetector gjk(m_convexA,m_convexB,m_convexA->getShapeType(),m_convexB->getShapeType(),m_convexA->getMargin(),m_convexB->getMargin(),m_simplexSolver,m_penetrationDepthSolver); - btGjkPairDetector::ClosestPointInput input; - //we don't use margins during CCD - // gjk.setIgnoreMargin(true); - - input.m_transformA = fromA; - input.m_transformB = fromB; - gjk.getClosestPoints(input,pointCollector1,0); + computeClosestPoints(fromA,fromB,pointCollector1); hasResult = pointCollector1.m_hasResult; c = pointCollector1.m_pointInWorld; @@ -113,11 +149,12 @@ bool btContinuousConvexCollision::calcTimeOfImpact( if (hasResult) { btScalar dist; - dist = pointCollector1.m_distance; + dist = pointCollector1.m_distance + result.m_allowedPenetration; n = pointCollector1.m_normalOnBInWorld; - btScalar projectedLinearVelocity = relLinVel.dot(n); - + if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=SIMD_EPSILON) + return false; + //not close enough while (dist > radius) { @@ -125,19 +162,10 @@ bool btContinuousConvexCollision::calcTimeOfImpact( { result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1)); } - numIter++; - if (numIter > maxIter) - { - return false; //todo: report a failure - } btScalar dLambda = btScalar(0.); projectedLinearVelocity = relLinVel.dot(n); - //calculate safe moving fraction from distance / (linear+rotational velocity) - - //btScalar clippedDist = GEN_min(angularConservativeRadius,dist); - //btScalar clippedDist = dist; //don't report time of impact for motion away from the contact normal (or causes minor penetration) if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=SIMD_EPSILON) @@ -182,37 +210,27 @@ bool btContinuousConvexCollision::calcTimeOfImpact( result.DebugDraw( lambda ); btPointCollector pointCollector; - btGjkPairDetector gjk(m_convexA,m_convexB,m_simplexSolver,m_penetrationDepthSolver); - btGjkPairDetector::ClosestPointInput input; - input.m_transformA = interpolatedTransA; - input.m_transformB = interpolatedTransB; - gjk.getClosestPoints(input,pointCollector,0); + computeClosestPoints(interpolatedTransA,interpolatedTransB,pointCollector); + if (pointCollector.m_hasResult) { - if (pointCollector.m_distance < btScalar(0.)) - { - //degenerate ?! - result.m_fraction = lastLambda; - n = pointCollector.m_normalOnBInWorld; - result.m_normal=n;//.setValue(1,1,1);// = n; - result.m_hitPoint = pointCollector.m_pointInWorld; - return true; - } + dist = pointCollector.m_distance+result.m_allowedPenetration; c = pointCollector.m_pointInWorld; n = pointCollector.m_normalOnBInWorld; - dist = pointCollector.m_distance; } else { - //?? + result.reportFailure(-1, numIter); return false; } - + numIter++; + if (numIter > maxIter) + { + result.reportFailure(-2, numIter); + return false; + } } - if ((projectedLinearVelocity+ maxAngularProjectedVelocity)<=result.m_allowedPenetration)//SIMD_EPSILON) - return false; - result.m_fraction = lambda; result.m_normal = n; result.m_hitPoint = c; @@ -221,16 +239,5 @@ bool btContinuousConvexCollision::calcTimeOfImpact( return false; -/* -//todo: - //if movement away from normal, discard result - btVector3 move = transBLocalTo.getOrigin() - transBLocalFrom.getOrigin(); - if (result.m_fraction < btScalar(1.)) - { - if (move.dot(result.m_normal) <= btScalar(0.)) - { - } - } -*/ - } + diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h index 28c2b4d6156..bdc0572f75a 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h @@ -14,13 +14,14 @@ subject to the following restrictions: */ -#ifndef CONTINUOUS_COLLISION_CONVEX_CAST_H -#define CONTINUOUS_COLLISION_CONVEX_CAST_H +#ifndef BT_CONTINUOUS_COLLISION_CONVEX_CAST_H +#define BT_CONTINUOUS_COLLISION_CONVEX_CAST_H #include "btConvexCast.h" #include "btSimplexSolverInterface.h" class btConvexPenetrationDepthSolver; class btConvexShape; +class btStaticPlaneShape; /// btContinuousConvexCollision implements angular and linear time of impact for convex objects. /// Based on Brian Mirtich's Conservative Advancement idea (PhD thesis). @@ -31,13 +32,18 @@ class btContinuousConvexCollision : public btConvexCast btSimplexSolverInterface* m_simplexSolver; btConvexPenetrationDepthSolver* m_penetrationDepthSolver; const btConvexShape* m_convexA; - const btConvexShape* m_convexB; + //second object is either a convex or a plane (code sharing) + const btConvexShape* m_convexB1; + const btStaticPlaneShape* m_planeShape; + void computeClosestPoints( const btTransform& transA, const btTransform& transB,struct btPointCollector& pointCollector); public: btContinuousConvexCollision (const btConvexShape* shapeA,const btConvexShape* shapeB ,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); + btContinuousConvexCollision(const btConvexShape* shapeA,const btStaticPlaneShape* plane ); + virtual bool calcTimeOfImpact( const btTransform& fromA, const btTransform& toA, @@ -48,5 +54,6 @@ public: }; -#endif //CONTINUOUS_COLLISION_CONVEX_CAST_H + +#endif //BT_CONTINUOUS_COLLISION_CONVEX_CAST_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexCast.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexCast.h index b0bce341e41..bfd79d03beb 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexCast.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexCast.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ -#ifndef CONVEX_CAST_H -#define CONVEX_CAST_H +#ifndef BT_CONVEX_CAST_H +#define BT_CONVEX_CAST_H #include "LinearMath/btTransform.h" #include "LinearMath/btVector3.h" @@ -39,7 +39,7 @@ public: virtual void DebugDraw(btScalar fraction) {(void)fraction;} virtual void drawCoordSystem(const btTransform& trans) {(void)trans;} - + virtual void reportFailure(int errNo, int numIterations) {(void)errNo;(void)numIterations;} CastResult() :m_fraction(btScalar(BT_LARGE_FLOAT)), m_debugDrawer(0), @@ -70,4 +70,4 @@ public: CastResult& result) = 0; }; -#endif //CONVEX_CAST_H +#endif //BT_CONVEX_CAST_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h index 7e3fde8e291..72eb5aec461 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ -#ifndef __CONVEX_PENETRATION_DEPTH_H -#define __CONVEX_PENETRATION_DEPTH_H +#ifndef BT_CONVEX_PENETRATION_DEPTH_H +#define BT_CONVEX_PENETRATION_DEPTH_H class btStackAlloc; class btVector3; @@ -38,5 +38,5 @@ public: }; -#endif //CONVEX_PENETRATION_DEPTH_H +#endif //BT_CONVEX_PENETRATION_DEPTH_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h index bc711ad495c..f958cc523ef 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h @@ -14,8 +14,9 @@ subject to the following restrictions: */ -#ifndef DISCRETE_COLLISION_DETECTOR1_INTERFACE_H -#define DISCRETE_COLLISION_DETECTOR1_INTERFACE_H +#ifndef BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H +#define BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H + #include "LinearMath/btTransform.h" #include "LinearMath/btVector3.h" class btStackAlloc; @@ -86,4 +87,5 @@ struct btStorageResult : public btDiscreteCollisionDetectorInterface::Result } }; -#endif //DISCRETE_COLLISION_DETECTOR_INTERFACE1_H +#endif //BT_DISCRETE_COLLISION_DETECTOR1_INTERFACE_H + diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h index a977c9e83f7..6a42ee63b03 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h @@ -15,8 +15,8 @@ subject to the following restrictions: -#ifndef GJK_CONVEX_CAST_H -#define GJK_CONVEX_CAST_H +#ifndef BT_GJK_CONVEX_CAST_H +#define BT_GJK_CONVEX_CAST_H #include "BulletCollision/CollisionShapes/btCollisionMargin.h" @@ -47,4 +47,4 @@ public: }; -#endif //GJK_CONVEX_CAST_H +#endif //BT_GJK_CONVEX_CAST_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp index f74261d4b21..3268f06c2f9 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp @@ -511,7 +511,6 @@ namespace gjkepa2_impl { btVector3 n; btScalar d; - btScalar p; sSV* c[3]; sFace* f[3]; sFace* l[2]; @@ -657,7 +656,7 @@ namespace gjkepa2_impl remove(m_hull,best); append(m_stock,best); best=findbest(); - if(best->p>=outer.p) outer=*best; + outer=*best; } else { m_status=eStatus::InvalidHull;break; } } else { m_status=eStatus::AccuraryReached;break; } } else { m_status=eStatus::OutOfVertices;break; } @@ -696,6 +695,42 @@ namespace gjkepa2_impl m_result.p[0]=1; return(m_status); } + bool getedgedist(sFace* face, sSV* a, sSV* b, btScalar& dist) + { + const btVector3 ba = b->w - a->w; + const btVector3 n_ab = btCross(ba, face->n); // Outward facing edge normal direction, on triangle plane + const btScalar a_dot_nab = btDot(a->w, n_ab); // Only care about the sign to determine inside/outside, so not normalization required + + if(a_dot_nab < 0) + { + // Outside of edge a->b + + const btScalar ba_l2 = ba.length2(); + const btScalar a_dot_ba = btDot(a->w, ba); + const btScalar b_dot_ba = btDot(b->w, ba); + + if(a_dot_ba > 0) + { + // Pick distance vertex a + dist = a->w.length(); + } + else if(b_dot_ba < 0) + { + // Pick distance vertex b + dist = b->w.length(); + } + else + { + // Pick distance to edge a->b + const btScalar a_dot_b = btDot(a->w, b->w); + dist = btSqrt(btMax((a->w.length2() * b->w.length2() - a_dot_b * a_dot_b) / ba_l2, (btScalar)0)); + } + + return true; + } + + return false; + } sFace* newface(sSV* a,sSV* b,sSV* c,bool forced) { if(m_stock.root) @@ -710,41 +745,48 @@ namespace gjkepa2_impl face->n = btCross(b->w-a->w,c->w-a->w); const btScalar l=face->n.length(); const bool v=l>EPA_ACCURACY; - face->p = btMin(btMin( - btDot(a->w,btCross(face->n,a->w-b->w)), - btDot(b->w,btCross(face->n,b->w-c->w))), - btDot(c->w,btCross(face->n,c->w-a->w))) / - (v?l:1); - face->p = face->p>=-EPA_INSIDE_EPS?0:face->p; + if(v) { - face->d = btDot(a->w,face->n)/l; - face->n /= l; - if(forced||(face->d>=-EPA_PLANE_EPS)) + if(!(getedgedist(face, a, b, face->d) || + getedgedist(face, b, c, face->d) || + getedgedist(face, c, a, face->d))) + { + // Origin projects to the interior of the triangle + // Use distance to triangle plane + face->d = btDot(a->w, face->n) / l; + } + + face->n /= l; + if(forced || (face->d >= -EPA_PLANE_EPS)) { - return(face); - } else m_status=eStatus::NonConvex; - } else m_status=eStatus::Degenerated; - remove(m_hull,face); - append(m_stock,face); - return(0); + return face; + } + else + m_status=eStatus::NonConvex; + } + else + m_status=eStatus::Degenerated; + + remove(m_hull, face); + append(m_stock, face); + return 0; + } - m_status=m_stock.root?eStatus::OutOfVertices:eStatus::OutOfFaces; - return(0); + m_status = m_stock.root ? eStatus::OutOfVertices : eStatus::OutOfFaces; + return 0; } sFace* findbest() { sFace* minf=m_hull.root; btScalar mind=minf->d*minf->d; - btScalar maxp=minf->p; for(sFace* f=minf->l[1];f;f=f->l[1]) { const btScalar sqd=f->d*f->d; - if((f->p>=maxp)&&(sqd<mind)) + if(sqd<mind) { minf=f; mind=sqd; - maxp=f->p; } } return(minf); diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h index 2296527d7db..ac501d5ecfe 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h @@ -22,8 +22,9 @@ misrepresented as being the original software. /* GJK-EPA collision solver by Nathanael Presson, 2008 */ -#ifndef _68DA1F85_90B7_4bb0_A705_83B4040A75C6_ -#define _68DA1F85_90B7_4bb0_A705_83B4040A75C6_ +#ifndef BT_GJK_EPA2_H +#define BT_GJK_EPA2_H + #include "BulletCollision/CollisionShapes/btConvexShape.h" ///btGjkEpaSolver contributed under zlib by Nathanael Presson @@ -70,4 +71,5 @@ static bool SignedDistance( const btConvexShape* shape0,const btTransform& wtrs }; -#endif +#endif //BT_GJK_EPA2_H + diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h index cc6287c86b0..2277a19d981 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h @@ -16,8 +16,8 @@ subject to the following restrictions: -#ifndef GJK_PAIR_DETECTOR_H -#define GJK_PAIR_DETECTOR_H +#ifndef BT_GJK_PAIR_DETECTOR_H +#define BT_GJK_PAIR_DETECTOR_H #include "btDiscreteCollisionDetectorInterface.h" #include "BulletCollision/CollisionShapes/btCollisionMargin.h" @@ -100,4 +100,4 @@ public: }; -#endif //GJK_PAIR_DETECTOR_H +#endif //BT_GJK_PAIR_DETECTOR_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h index cd310570e06..0ce9dd25926 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h @@ -13,14 +13,14 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef MANIFOLD_CONTACT_POINT_H -#define MANIFOLD_CONTACT_POINT_H +#ifndef BT_MANIFOLD_CONTACT_POINT_H +#define BT_MANIFOLD_CONTACT_POINT_H #include "LinearMath/btVector3.h" #include "LinearMath/btTransformUtil.h" #ifdef PFX_USE_FREE_VECTORMATH - #include "physics_effects\base_level\solver\pfx_constraint_row.h" + #include "physics_effects/base_level/solver/pfx_constraint_row.h" typedef sce::PhysicsEffects::PfxConstraintRow btConstraintRow; #else // Don't change following order of parameters @@ -155,4 +155,4 @@ class btManifoldPoint }; -#endif //MANIFOLD_CONTACT_POINT_H +#endif //BT_MANIFOLD_CONTACT_POINT_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h index 7b6c8a63779..6a8fe52f36f 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef MINKOWSKI_PENETRATION_DEPTH_SOLVER_H -#define MINKOWSKI_PENETRATION_DEPTH_SOLVER_H +#ifndef BT_MINKOWSKI_PENETRATION_DEPTH_SOLVER_H +#define BT_MINKOWSKI_PENETRATION_DEPTH_SOLVER_H #include "btConvexPenetrationDepthSolver.h" @@ -36,5 +36,5 @@ public: ); }; -#endif //MINKOWSKI_PENETRATION_DEPTH_SOLVER_H +#endif //BT_MINKOWSKI_PENETRATION_DEPTH_SOLVER_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp index 924a8af87d1..954b8395299 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp @@ -21,7 +21,9 @@ subject to the following restrictions: btScalar gContactBreakingThreshold = btScalar(0.02); ContactDestroyedCallback gContactDestroyedCallback = 0; ContactProcessedCallback gContactProcessedCallback = 0; - +///gContactCalcArea3Points will approximate the convex hull area using 3 points +///when setting it to false, it will use 4 points to compute the area: it is more accurate but slower +bool gContactCalcArea3Points = true; btPersistentManifold::btPersistentManifold() @@ -84,10 +86,28 @@ void btPersistentManifold::clearUserCache(btManifoldPoint& pt) } +static inline btScalar calcArea4Points(const btVector3 &p0,const btVector3 &p1,const btVector3 &p2,const btVector3 &p3) +{ + // It calculates possible 3 area constructed from random 4 points and returns the biggest one. + + btVector3 a[3],b[3]; + a[0] = p0 - p1; + a[1] = p0 - p2; + a[2] = p0 - p3; + b[0] = p2 - p3; + b[1] = p1 - p3; + b[2] = p1 - p2; + + //todo: Following 3 cross production can be easily optimized by SIMD. + btVector3 tmp0 = a[0].cross(b[0]); + btVector3 tmp1 = a[1].cross(b[1]); + btVector3 tmp2 = a[2].cross(b[2]); + + return btMax(btMax(tmp0.length2(),tmp1.length2()),tmp2.length2()); +} int btPersistentManifold::sortCachedPoints(const btManifoldPoint& pt) { - //calculate 4 possible cases areas, and take biggest area //also need to keep 'deepest' @@ -106,6 +126,9 @@ int btPersistentManifold::sortCachedPoints(const btManifoldPoint& pt) #endif //KEEP_DEEPEST_POINT btScalar res0(btScalar(0.)),res1(btScalar(0.)),res2(btScalar(0.)),res3(btScalar(0.)); + + if (gContactCalcArea3Points) + { if (maxPenetrationIndex != 0) { btVector3 a0 = pt.m_localPointA-m_pointCache[1].m_localPointA; @@ -136,10 +159,29 @@ int btPersistentManifold::sortCachedPoints(const btManifoldPoint& pt) btVector3 cross = a3.cross(b3); res3 = cross.length2(); } + } + else + { + if(maxPenetrationIndex != 0) { + res0 = calcArea4Points(pt.m_localPointA,m_pointCache[1].m_localPointA,m_pointCache[2].m_localPointA,m_pointCache[3].m_localPointA); + } - btVector4 maxvec(res0,res1,res2,res3); - int biggestarea = maxvec.closestAxis4(); - return biggestarea; + if(maxPenetrationIndex != 1) { + res1 = calcArea4Points(pt.m_localPointA,m_pointCache[0].m_localPointA,m_pointCache[2].m_localPointA,m_pointCache[3].m_localPointA); + } + + if(maxPenetrationIndex != 2) { + res2 = calcArea4Points(pt.m_localPointA,m_pointCache[0].m_localPointA,m_pointCache[1].m_localPointA,m_pointCache[3].m_localPointA); + } + + if(maxPenetrationIndex != 3) { + res3 = calcArea4Points(pt.m_localPointA,m_pointCache[0].m_localPointA,m_pointCache[1].m_localPointA,m_pointCache[2].m_localPointA); + } + } + btVector4 maxvec(res0,res1,res2,res3); + int biggestarea = maxvec.closestAxis4(); + return biggestarea; + } diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h index c8aac637307..d877f09944f 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef PERSISTENT_MANIFOLD_H -#define PERSISTENT_MANIFOLD_H +#ifndef BT_PERSISTENT_MANIFOLD_H +#define BT_PERSISTENT_MANIFOLD_H #include "LinearMath/btVector3.h" @@ -197,14 +197,10 @@ public: #endif } + bool validContactDistance(const btManifoldPoint& pt) const { - if (pt.m_lifeTime >1) - { - return pt.m_distance1 <= getContactBreakingThreshold(); - } - return pt.m_distance1 <= getContactProcessingThreshold(); - + return pt.m_distance1 <= getContactBreakingThreshold(); } /// calculated new worldspace coordinates and depth, and reject points that exceed the collision margin void refreshContactPoints( const btTransform& trA,const btTransform& trB); @@ -229,4 +225,4 @@ public: -#endif //PERSISTENT_MANIFOLD_H +#endif //BT_PERSISTENT_MANIFOLD_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPointCollector.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPointCollector.h index 6ca60548e71..18da171011a 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPointCollector.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPointCollector.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef POINT_COLLECTOR_H -#define POINT_COLLECTOR_H +#ifndef BT_POINT_COLLECTOR_H +#define BT_POINT_COLLECTOR_H #include "btDiscreteCollisionDetectorInterface.h" @@ -60,5 +60,5 @@ struct btPointCollector : public btDiscreteCollisionDetectorInterface::Result } }; -#endif //POINT_COLLECTOR_H +#endif //BT_POINT_COLLECTOR_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp new file mode 100644 index 00000000000..db1909113b3 --- /dev/null +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp @@ -0,0 +1,440 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +///This file was written by Erwin Coumans +///Separating axis rest based on work from Pierre Terdiman, see +///And contact clipping based on work from Simon Hobbs + + +#include "btPolyhedralContactClipping.h" +#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h" + +#include <float.h> //for FLT_MAX + +int gExpectedNbTests=0; +int gActualNbTests = 0; +bool gUseInternalObject = true; + +// Clips a face to the back of a plane +void btPolyhedralContactClipping::clipFace(const btVertexArray& pVtxIn, btVertexArray& ppVtxOut, const btVector3& planeNormalWS,btScalar planeEqWS) +{ + + int ve; + btScalar ds, de; + int numVerts = pVtxIn.size(); + if (numVerts < 2) + return; + + btVector3 firstVertex=pVtxIn[pVtxIn.size()-1]; + btVector3 endVertex = pVtxIn[0]; + + ds = planeNormalWS.dot(firstVertex)+planeEqWS; + + for (ve = 0; ve < numVerts; ve++) + { + endVertex=pVtxIn[ve]; + + de = planeNormalWS.dot(endVertex)+planeEqWS; + + if (ds<0) + { + if (de<0) + { + // Start < 0, end < 0, so output endVertex + ppVtxOut.push_back(endVertex); + } + else + { + // Start < 0, end >= 0, so output intersection + ppVtxOut.push_back( firstVertex.lerp(endVertex,btScalar(ds * 1.f/(ds - de)))); + } + } + else + { + if (de<0) + { + // Start >= 0, end < 0 so output intersection and end + ppVtxOut.push_back(firstVertex.lerp(endVertex,btScalar(ds * 1.f/(ds - de)))); + ppVtxOut.push_back(endVertex); + } + } + firstVertex = endVertex; + ds = de; + } +} + + +static bool TestSepAxis(const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btVector3& sep_axis, btScalar& depth) +{ + btScalar Min0,Max0; + btScalar Min1,Max1; + hullA.project(transA,sep_axis, Min0, Max0); + hullB.project(transB, sep_axis, Min1, Max1); + + if(Max0<Min1 || Max1<Min0) + return false; + + btScalar d0 = Max0 - Min1; + assert(d0>=0.0f); + btScalar d1 = Max1 - Min0; + assert(d1>=0.0f); + depth = d0<d1 ? d0:d1; + return true; +} + + + +static int gActualSATPairTests=0; + +inline bool IsAlmostZero(const btVector3& v) +{ + if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6) return false; + return true; +} + +#ifdef TEST_INTERNAL_OBJECTS + +inline void BoxSupport(const btScalar extents[3], const btScalar sv[3], btScalar p[3]) +{ + // This version is ~11.000 cycles (4%) faster overall in one of the tests. +// IR(p[0]) = IR(extents[0])|(IR(sv[0])&SIGN_BITMASK); +// IR(p[1]) = IR(extents[1])|(IR(sv[1])&SIGN_BITMASK); +// IR(p[2]) = IR(extents[2])|(IR(sv[2])&SIGN_BITMASK); + p[0] = sv[0] < 0.0f ? -extents[0] : extents[0]; + p[1] = sv[1] < 0.0f ? -extents[1] : extents[1]; + p[2] = sv[2] < 0.0f ? -extents[2] : extents[2]; +} + +void InverseTransformPoint3x3(btVector3& out, const btVector3& in, const btTransform& tr) +{ + const btMatrix3x3& rot = tr.getBasis(); + const btVector3& r0 = rot[0]; + const btVector3& r1 = rot[1]; + const btVector3& r2 = rot[2]; + + const btScalar x = r0.x()*in.x() + r1.x()*in.y() + r2.x()*in.z(); + const btScalar y = r0.y()*in.x() + r1.y()*in.y() + r2.y()*in.z(); + const btScalar z = r0.z()*in.x() + r1.z()*in.y() + r2.z()*in.z(); + + out.setValue(x, y, z); +} + + bool TestInternalObjects( const btTransform& trans0, const btTransform& trans1, const btVector3& delta_c, const btVector3& axis, const btConvexPolyhedron& convex0, const btConvexPolyhedron& convex1, btScalar dmin) +{ + const btScalar dp = delta_c.dot(axis); + + btVector3 localAxis0; + InverseTransformPoint3x3(localAxis0, axis,trans0); + btVector3 localAxis1; + InverseTransformPoint3x3(localAxis1, axis,trans1); + + btScalar p0[3]; + BoxSupport(convex0.m_extents, localAxis0, p0); + btScalar p1[3]; + BoxSupport(convex1.m_extents, localAxis1, p1); + + const btScalar Radius0 = p0[0]*localAxis0.x() + p0[1]*localAxis0.y() + p0[2]*localAxis0.z(); + const btScalar Radius1 = p1[0]*localAxis1.x() + p1[1]*localAxis1.y() + p1[2]*localAxis1.z(); + + const btScalar MinRadius = Radius0>convex0.m_radius ? Radius0 : convex0.m_radius; + const btScalar MaxRadius = Radius1>convex1.m_radius ? Radius1 : convex1.m_radius; + + const btScalar MinMaxRadius = MaxRadius + MinRadius; + const btScalar d0 = MinMaxRadius + dp; + const btScalar d1 = MinMaxRadius - dp; + + const btScalar depth = d0<d1 ? d0:d1; + if(depth>dmin) + return false; + return true; +} +#endif //TEST_INTERNAL_OBJECTS + + +bool btPolyhedralContactClipping::findSeparatingAxis( const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, btVector3& sep) +{ + gActualSATPairTests++; + +//#ifdef TEST_INTERNAL_OBJECTS + const btVector3 c0 = transA * hullA.m_localCenter; + const btVector3 c1 = transB * hullB.m_localCenter; + const btVector3 DeltaC2 = c0 - c1; +//#endif + + btScalar dmin = FLT_MAX; + int curPlaneTests=0; + + int numFacesA = hullA.m_faces.size(); + // Test normals from hullA + for(int i=0;i<numFacesA;i++) + { + const btVector3 Normal(hullA.m_faces[i].m_plane[0], hullA.m_faces[i].m_plane[1], hullA.m_faces[i].m_plane[2]); + const btVector3 faceANormalWS = transA.getBasis() * Normal; + if (DeltaC2.dot(faceANormalWS)<0) + continue; + + curPlaneTests++; +#ifdef TEST_INTERNAL_OBJECTS + gExpectedNbTests++; + if(gUseInternalObject && !TestInternalObjects(transA,transB, DeltaC2, faceANormalWS, hullA, hullB, dmin)) + continue; + gActualNbTests++; +#endif + + btScalar d; + if(!TestSepAxis( hullA, hullB, transA,transB, faceANormalWS, d)) + return false; + + if(d<dmin) + { + dmin = d; + sep = faceANormalWS; + } + } + + int numFacesB = hullB.m_faces.size(); + // Test normals from hullB + for(int i=0;i<numFacesB;i++) + { + const btVector3 Normal(hullB.m_faces[i].m_plane[0], hullB.m_faces[i].m_plane[1], hullB.m_faces[i].m_plane[2]); + const btVector3 WorldNormal = transB.getBasis() * Normal; + if (DeltaC2.dot(WorldNormal)<0) + continue; + + curPlaneTests++; +#ifdef TEST_INTERNAL_OBJECTS + gExpectedNbTests++; + if(gUseInternalObject && !TestInternalObjects(transA,transB,DeltaC2, WorldNormal, hullA, hullB, dmin)) + continue; + gActualNbTests++; +#endif + + btScalar d; + if(!TestSepAxis(hullA, hullB,transA,transB, WorldNormal,d)) + return false; + + if(d<dmin) + { + dmin = d; + sep = WorldNormal; + } + } + + btVector3 edgeAstart,edgeAend,edgeBstart,edgeBend; + + int curEdgeEdge = 0; + // Test edges + for(int e0=0;e0<hullA.m_uniqueEdges.size();e0++) + { + const btVector3 edge0 = hullA.m_uniqueEdges[e0]; + const btVector3 WorldEdge0 = transA.getBasis() * edge0; + for(int e1=0;e1<hullB.m_uniqueEdges.size();e1++) + { + const btVector3 edge1 = hullB.m_uniqueEdges[e1]; + const btVector3 WorldEdge1 = transB.getBasis() * edge1; + + btVector3 Cross = WorldEdge0.cross(WorldEdge1); + curEdgeEdge++; + if(!IsAlmostZero(Cross)) + { + Cross = Cross.normalize(); + if (DeltaC2.dot(Cross)<0) + continue; + + +#ifdef TEST_INTERNAL_OBJECTS + gExpectedNbTests++; + if(gUseInternalObject && !TestInternalObjects(transA,transB,DeltaC2, Cross, hullA, hullB, dmin)) + continue; + gActualNbTests++; +#endif + + btScalar dist; + if(!TestSepAxis( hullA, hullB, transA,transB, Cross, dist)) + return false; + + if(dist<dmin) + { + dmin = dist; + sep = Cross; + } + } + } + + } + + const btVector3 deltaC = transB.getOrigin() - transA.getOrigin(); + if((deltaC.dot(sep))>0.0f) + sep = -sep; + + return true; +} + +void btPolyhedralContactClipping::clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA, const btTransform& transA, btVertexArray& worldVertsB1, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut) +{ + btVertexArray worldVertsB2; + btVertexArray* pVtxIn = &worldVertsB1; + btVertexArray* pVtxOut = &worldVertsB2; + pVtxOut->reserve(pVtxIn->size()); + + int closestFaceA=-1; + { + btScalar dmin = FLT_MAX; + for(int face=0;face<hullA.m_faces.size();face++) + { + const btVector3 Normal(hullA.m_faces[face].m_plane[0], hullA.m_faces[face].m_plane[1], hullA.m_faces[face].m_plane[2]); + const btVector3 faceANormalWS = transA.getBasis() * Normal; + + btScalar d = faceANormalWS.dot(separatingNormal); + if (d < dmin) + { + dmin = d; + closestFaceA = face; + } + } + } + if (closestFaceA<0) + return; + + const btFace& polyA = hullA.m_faces[closestFaceA]; + + // clip polygon to back of planes of all faces of hull A that are adjacent to witness face + int numContacts = pVtxIn->size(); + int numVerticesA = polyA.m_indices.size(); + for(int e0=0;e0<numVerticesA;e0++) + { + const btVector3& a = hullA.m_vertices[polyA.m_indices[e0]]; + const btVector3& b = hullA.m_vertices[polyA.m_indices[(e0+1)%numVerticesA]]; + const btVector3 edge0 = a - b; + const btVector3 WorldEdge0 = transA.getBasis() * edge0; + btVector3 worldPlaneAnormal1 = transA.getBasis()* btVector3(polyA.m_plane[0],polyA.m_plane[1],polyA.m_plane[2]); + + btVector3 planeNormalWS1 = -WorldEdge0.cross(worldPlaneAnormal1);//.cross(WorldEdge0); + btVector3 worldA1 = transA*a; + btScalar planeEqWS1 = -worldA1.dot(planeNormalWS1); + +//int otherFace=0; +#ifdef BLA1 + int otherFace = polyA.m_connectedFaces[e0]; + btVector3 localPlaneNormal (hullA.m_faces[otherFace].m_plane[0],hullA.m_faces[otherFace].m_plane[1],hullA.m_faces[otherFace].m_plane[2]); + btScalar localPlaneEq = hullA.m_faces[otherFace].m_plane[3]; + + btVector3 planeNormalWS = transA.getBasis()*localPlaneNormal; + btScalar planeEqWS=localPlaneEq-planeNormalWS.dot(transA.getOrigin()); +#else + btVector3 planeNormalWS = planeNormalWS1; + btScalar planeEqWS=planeEqWS1; + +#endif + //clip face + + clipFace(*pVtxIn, *pVtxOut,planeNormalWS,planeEqWS); + btSwap(pVtxIn,pVtxOut); + pVtxOut->resize(0); + } + + + +//#define ONLY_REPORT_DEEPEST_POINT + + btVector3 point; + + + // only keep points that are behind the witness face + { + btVector3 localPlaneNormal (polyA.m_plane[0],polyA.m_plane[1],polyA.m_plane[2]); + btScalar localPlaneEq = polyA.m_plane[3]; + btVector3 planeNormalWS = transA.getBasis()*localPlaneNormal; + btScalar planeEqWS=localPlaneEq-planeNormalWS.dot(transA.getOrigin()); + for (int i=0;i<pVtxIn->size();i++) + { + + btScalar depth = planeNormalWS.dot(pVtxIn->at(i))+planeEqWS; + if (depth <=minDist) + { +// printf("clamped: depth=%f to minDist=%f\n",depth,minDist); + depth = minDist; + } + + if (depth <=maxDist) + { + btVector3 point = pVtxIn->at(i); +#ifdef ONLY_REPORT_DEEPEST_POINT + curMaxDist = depth; +#else +#if 0 + if (depth<-3) + { + printf("error in btPolyhedralContactClipping depth = %f\n", depth); + printf("likely wrong separatingNormal passed in\n"); + } +#endif + resultOut.addContactPoint(separatingNormal,point,depth); +#endif + } + } + } +#ifdef ONLY_REPORT_DEEPEST_POINT + if (curMaxDist<maxDist) + { + resultOut.addContactPoint(separatingNormal,point,curMaxDist); + } +#endif //ONLY_REPORT_DEEPEST_POINT + +} + + +void btPolyhedralContactClipping::clipHullAgainstHull(const btVector3& separatingNormal1, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut) +{ + + btVector3 separatingNormal = separatingNormal1.normalized(); + const btVector3 c0 = transA * hullA.m_localCenter; + const btVector3 c1 = transB * hullB.m_localCenter; + const btVector3 DeltaC2 = c0 - c1; + + + btScalar curMaxDist=maxDist; + int closestFaceB=-1; + btScalar dmax = -FLT_MAX; + { + for(int face=0;face<hullB.m_faces.size();face++) + { + const btVector3 Normal(hullB.m_faces[face].m_plane[0], hullB.m_faces[face].m_plane[1], hullB.m_faces[face].m_plane[2]); + const btVector3 WorldNormal = transB.getBasis() * Normal; + btScalar d = WorldNormal.dot(separatingNormal); + if (d > dmax) + { + dmax = d; + closestFaceB = face; + } + } + } + btVertexArray worldVertsB1; + { + const btFace& polyB = hullB.m_faces[closestFaceB]; + const int numVertices = polyB.m_indices.size(); + for(int e0=0;e0<numVertices;e0++) + { + const btVector3& b = hullB.m_vertices[polyB.m_indices[e0]]; + worldVertsB1.push_back(transB*b); + } + } + + + if (closestFaceB>=0) + clipFaceAgainstHull(separatingNormal, hullA, transA,worldVertsB1, minDist, maxDist,resultOut); + +} diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h new file mode 100644 index 00000000000..99103df2027 --- /dev/null +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h @@ -0,0 +1,46 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +///This file was written by Erwin Coumans + + +#ifndef BT_POLYHEDRAL_CONTACT_CLIPPING_H +#define BT_POLYHEDRAL_CONTACT_CLIPPING_H + + +#include "LinearMath/btAlignedObjectArray.h" +#include "LinearMath/btTransform.h" +#include "btDiscreteCollisionDetectorInterface.h" + +class btConvexPolyhedron; + +typedef btAlignedObjectArray<btVector3> btVertexArray; + +// Clips a face to the back of a plane +struct btPolyhedralContactClipping +{ + static void clipHullAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist, btDiscreteCollisionDetectorInterface::Result& resultOut); + static void clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA, const btTransform& transA, btVertexArray& worldVertsB1, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut); + + static bool findSeparatingAxis( const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, btVector3& sep); + + ///the clipFace method is used internally + static void clipFace(const btVertexArray& pVtxIn, btVertexArray& ppVtxOut, const btVector3& planeNormalWS,btScalar planeEqWS); + +}; + +#endif // BT_POLYHEDRAL_CONTACT_CLIPPING_H + diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h index bdd1add36d2..f012889a70e 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef RAYCAST_TRI_CALLBACK_H -#define RAYCAST_TRI_CALLBACK_H +#ifndef BT_RAYCAST_TRI_CALLBACK_H +#define BT_RAYCAST_TRI_CALLBACK_H #include "BulletCollision/CollisionShapes/btTriangleCallback.h" #include "LinearMath/btTransform.h" @@ -68,5 +68,5 @@ public: virtual btScalar reportHit (const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex) = 0; }; -#endif //RAYCAST_TRI_CALLBACK_H +#endif //BT_RAYCAST_TRI_CALLBACK_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h index 823b4e7158b..da8a13914c9 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h @@ -15,8 +15,8 @@ subject to the following restrictions: -#ifndef SIMPLEX_SOLVER_INTERFACE_H -#define SIMPLEX_SOLVER_INTERFACE_H +#ifndef BT_SIMPLEX_SOLVER_INTERFACE_H +#define BT_SIMPLEX_SOLVER_INTERFACE_H #include "LinearMath/btVector3.h" @@ -59,5 +59,5 @@ class btSimplexSolverInterface }; #endif -#endif //SIMPLEX_SOLVER_INTERFACE_H +#endif //BT_SIMPLEX_SOLVER_INTERFACE_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h index 05662db5d23..6c8127983eb 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ -#ifndef SUBSIMPLEX_CONVEX_CAST_H -#define SUBSIMPLEX_CONVEX_CAST_H +#ifndef BT_SUBSIMPLEX_CONVEX_CAST_H +#define BT_SUBSIMPLEX_CONVEX_CAST_H #include "btConvexCast.h" #include "btSimplexSolverInterface.h" @@ -47,4 +47,4 @@ public: }; -#endif //SUBSIMPLEX_CONVEX_CAST_H +#endif //BT_SUBSIMPLEX_CONVEX_CAST_H diff --git a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h index 9a4f552924c..f1c7613efa1 100644 --- a/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h +++ b/extern/bullet2/src/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h @@ -15,8 +15,8 @@ subject to the following restrictions: -#ifndef btVoronoiSimplexSolver_H -#define btVoronoiSimplexSolver_H +#ifndef BT_VORONOI_SIMPLEX_SOLVER_H +#define BT_VORONOI_SIMPLEX_SOLVER_H #include "btSimplexSolverInterface.h" @@ -175,4 +175,5 @@ public: }; -#endif //VoronoiSimplexSolver +#endif //BT_VORONOI_SIMPLEX_SOLVER_H + diff --git a/extern/bullet2/src/BulletDynamics/Character/btCharacterControllerInterface.h b/extern/bullet2/src/BulletDynamics/Character/btCharacterControllerInterface.h index 19373daa241..c81813c92be 100644 --- a/extern/bullet2/src/BulletDynamics/Character/btCharacterControllerInterface.h +++ b/extern/bullet2/src/BulletDynamics/Character/btCharacterControllerInterface.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CHARACTER_CONTROLLER_INTERFACE_H -#define CHARACTER_CONTROLLER_INTERFACE_H +#ifndef BT_CHARACTER_CONTROLLER_INTERFACE_H +#define BT_CHARACTER_CONTROLLER_INTERFACE_H #include "LinearMath/btVector3.h" #include "BulletDynamics/Dynamics/btActionInterface.h" @@ -42,4 +42,5 @@ public: virtual bool onGround () const = 0; }; -#endif +#endif //BT_CHARACTER_CONTROLLER_INTERFACE_H + diff --git a/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.h b/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.h index 704355c0ae1..ef01f8a3e60 100644 --- a/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.h +++ b/extern/bullet2/src/BulletDynamics/Character/btKinematicCharacterController.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ -#ifndef KINEMATIC_CHARACTER_CONTROLLER_H -#define KINEMATIC_CHARACTER_CONTROLLER_H +#ifndef BT_KINEMATIC_CHARACTER_CONTROLLER_H +#define BT_KINEMATIC_CHARACTER_CONTROLLER_H #include "LinearMath/btVector3.h" @@ -25,6 +25,7 @@ subject to the following restrictions: class btCollisionShape; +class btConvexShape; class btRigidBody; class btCollisionWorld; class btCollisionDispatcher; @@ -159,4 +160,4 @@ public: bool onGround () const; }; -#endif // KINEMATIC_CHARACTER_CONTROLLER_H +#endif // BT_KINEMATIC_CHARACTER_CONTROLLER_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp index bc371e4062d..755544f0dee 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp @@ -638,6 +638,11 @@ void btConeTwistConstraint::calcAngleInfo2(const btTransform& transA, const btTr btTransform trDeltaAB = trB * trPose * trA.inverse(); btQuaternion qDeltaAB = trDeltaAB.getRotation(); btVector3 swingAxis = btVector3(qDeltaAB.x(), qDeltaAB.y(), qDeltaAB.z()); + float swingAxisLen2 = swingAxis.length2(); + if(btFuzzyZero(swingAxisLen2)) + { + return; + } m_swingAxis = swingAxis; m_swingAxis.normalize(); m_swingCorrection = qDeltaAB.getAngle(); @@ -918,7 +923,7 @@ void btConeTwistConstraint::computeTwistLimitInfo(const btQuaternion& qTwist, if (twistAngle > SIMD_PI) // long way around. flip quat and recalculate. { - qMinTwist = operator-(qTwist); + qMinTwist = -(qTwist); twistAngle = qMinTwist.getAngle(); } if (twistAngle < 0) diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h index c1c5aa851b6..868e62f063e 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h @@ -33,8 +33,8 @@ and swing 1 and 2 are along the z and y axes respectively. -#ifndef CONETWISTCONSTRAINT_H -#define CONETWISTCONSTRAINT_H +#ifndef BT_CONETWISTCONSTRAINT_H +#define BT_CONETWISTCONSTRAINT_H #include "LinearMath/btVector3.h" #include "btJacobianEntry.h" @@ -343,4 +343,4 @@ SIMD_FORCE_INLINE const char* btConeTwistConstraint::serialize(void* dataBuffer, } -#endif //CONETWISTCONSTRAINT_H +#endif //BT_CONETWISTCONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConstraintSolver.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConstraintSolver.h index 7a8e9c1953d..6f673102be2 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConstraintSolver.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btConstraintSolver.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONSTRAINT_SOLVER_H -#define CONSTRAINT_SOLVER_H +#ifndef BT_CONSTRAINT_SOLVER_H +#define BT_CONSTRAINT_SOLVER_H #include "LinearMath/btScalar.h" @@ -49,4 +49,4 @@ public: -#endif //CONSTRAINT_SOLVER_H +#endif //BT_CONSTRAINT_SOLVER_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp index d97096d9f26..88859182925 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.cpp @@ -68,9 +68,53 @@ void btContactConstraint::buildJacobian() #include "LinearMath/btMinMax.h" #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" -#define ASSERT2 btAssert -#define USE_INTERNAL_APPLY_IMPULSE 1 + +//response between two dynamic objects without friction, assuming 0 penetration depth +btScalar resolveSingleCollision( + btRigidBody* body1, + btCollisionObject* colObj2, + const btVector3& contactPositionWorld, + const btVector3& contactNormalOnB, + const btContactSolverInfo& solverInfo, + btScalar distance) +{ + btRigidBody* body2 = btRigidBody::upcast(colObj2); + + + const btVector3& normal = contactNormalOnB; + + btVector3 rel_pos1 = contactPositionWorld - body1->getWorldTransform().getOrigin(); + btVector3 rel_pos2 = contactPositionWorld - colObj2->getWorldTransform().getOrigin(); + + btVector3 vel1 = body1->getVelocityInLocalPoint(rel_pos1); + btVector3 vel2 = body2? body2->getVelocityInLocalPoint(rel_pos2) : btVector3(0,0,0); + btVector3 vel = vel1 - vel2; + btScalar rel_vel; + rel_vel = normal.dot(vel); + + btScalar combinedRestitution = body1->getRestitution() * colObj2->getRestitution(); + btScalar restitution = combinedRestitution* -rel_vel; + + btScalar positionalError = solverInfo.m_erp *-distance /solverInfo.m_timeStep ; + btScalar velocityError = -(1.0f + restitution) * rel_vel;// * damping; + btScalar denom0 = body1->computeImpulseDenominator(contactPositionWorld,normal); + btScalar denom1 = body2? body2->computeImpulseDenominator(contactPositionWorld,normal) : 0.f; + btScalar relaxation = 1.f; + btScalar jacDiagABInv = relaxation/(denom0+denom1); + + btScalar penetrationImpulse = positionalError * jacDiagABInv; + btScalar velocityImpulse = velocityError * jacDiagABInv; + + btScalar normalImpulse = penetrationImpulse+velocityImpulse; + normalImpulse = 0.f > normalImpulse ? 0.f: normalImpulse; + + body1->applyImpulse(normal*(normalImpulse), rel_pos1); + if (body2) + body2->applyImpulse(-normal*(normalImpulse), rel_pos2); + + return normalImpulse; +} //bilateral constraint between two dynamic objects @@ -83,7 +127,7 @@ void resolveSingleBilateral(btRigidBody& body1, const btVector3& pos1, btScalar normalLenSqr = normal.length2(); - ASSERT2(btFabs(normalLenSqr) < btScalar(1.1)); + btAssert(btFabs(normalLenSqr) < btScalar(1.1)); if (normalLenSqr > btScalar(1.1)) { impulse = btScalar(0.); diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.h index 63c1a417bc1..477c79d1756 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactConstraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONTACT_CONSTRAINT_H -#define CONTACT_CONSTRAINT_H +#ifndef BT_CONTACT_CONSTRAINT_H +#define BT_CONTACT_CONSTRAINT_H #include "LinearMath/btVector3.h" #include "btJacobianEntry.h" @@ -57,6 +57,9 @@ public: }; +///very basic collision resolution without friction +btScalar resolveSingleCollision(btRigidBody* body1, class btCollisionObject* colObj2, const btVector3& contactPositionWorld,const btVector3& contactNormalOnB, const struct btContactSolverInfo& solverInfo,btScalar distance); + ///resolveSingleBilateral is an obsolete methods used for vehicle friction between two dynamic objects void resolveSingleBilateral(btRigidBody& body1, const btVector3& pos1, @@ -65,4 +68,4 @@ void resolveSingleBilateral(btRigidBody& body1, const btVector3& pos1, -#endif //CONTACT_CONSTRAINT_H +#endif //BT_CONTACT_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h index db5bb5e4c51..6204cb3d16c 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btContactSolverInfo.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef CONTACT_SOLVER_INFO -#define CONTACT_SOLVER_INFO +#ifndef BT_CONTACT_SOLVER_INFO +#define BT_CONTACT_SOLVER_INFO enum btSolverMode { @@ -84,4 +84,4 @@ struct btContactSolverInfo : public btContactSolverInfoData } }; -#endif //CONTACT_SOLVER_INFO +#endif //BT_CONTACT_SOLVER_INFO diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp index 7c5e4f6e7b2..8ff9940bba3 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp @@ -130,12 +130,20 @@ int btRotationalLimitMotor::testLimitValue(btScalar test_value) { m_currentLimit = 1;//low limit violation m_currentLimitError = test_value - m_loLimit; + if(m_currentLimitError>SIMD_PI) + m_currentLimitError-=SIMD_2_PI; + else if(m_currentLimitError<-SIMD_PI) + m_currentLimitError+=SIMD_2_PI; return 1; } else if (test_value> m_hiLimit) { m_currentLimit = 2;//High limit violation m_currentLimitError = test_value - m_hiLimit; + if(m_currentLimitError>SIMD_PI) + m_currentLimitError-=SIMD_2_PI; + else if(m_currentLimitError<-SIMD_PI) + m_currentLimitError+=SIMD_2_PI; return 2; }; @@ -1067,4 +1075,4 @@ void btGeneric6DofConstraint::setAxis(const btVector3& axis1,const btVector3& ax m_frameInB = m_rbB.getCenterOfMassTransform().inverse() * frameInW; calculateTransforms(); -}
\ No newline at end of file +} diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h index ab745ca5ad6..a8e7bc22902 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h @@ -24,8 +24,8 @@ http://gimpact.sf.net */ -#ifndef GENERIC_6DOF_CONSTRAINT_H -#define GENERIC_6DOF_CONSTRAINT_H +#ifndef BT_GENERIC_6DOF_CONSTRAINT_H +#define BT_GENERIC_6DOF_CONSTRAINT_H #include "LinearMath/btVector3.h" #include "btJacobianEntry.h" @@ -611,4 +611,4 @@ SIMD_FORCE_INLINE const char* btGeneric6DofConstraint::serialize(void* dataBuffe -#endif //GENERIC_6DOF_CONSTRAINT_H +#endif //BT_GENERIC_6DOF_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp index d3503456625..2b38714987b 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.cpp @@ -21,6 +21,19 @@ subject to the following restrictions: btGeneric6DofSpringConstraint::btGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) : btGeneric6DofConstraint(rbA, rbB, frameInA, frameInB, useLinearReferenceFrameA) { + init(); +} + + +btGeneric6DofSpringConstraint::btGeneric6DofSpringConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB) + : btGeneric6DofConstraint(rbB, frameInB, useLinearReferenceFrameB) +{ + init(); +} + + +void btGeneric6DofSpringConstraint::init() +{ m_objectType = D6_SPRING_CONSTRAINT_TYPE; for(int i = 0; i < 6; i++) diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h index 16ff973e427..31e0cd531ae 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef GENERIC_6DOF_SPRING_CONSTRAINT_H -#define GENERIC_6DOF_SPRING_CONSTRAINT_H +#ifndef BT_GENERIC_6DOF_SPRING_CONSTRAINT_H +#define BT_GENERIC_6DOF_SPRING_CONSTRAINT_H #include "LinearMath/btVector3.h" @@ -39,9 +39,11 @@ protected: btScalar m_equilibriumPoint[6]; btScalar m_springStiffness[6]; btScalar m_springDamping[6]; // between 0 and 1 (1 == no damping) + void init(); void internalUpdateSprings(btConstraintInfo2* info); public: btGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + btGeneric6DofSpringConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB); void enableSpring(int index, bool onOff); void setStiffness(int index, btScalar stiffness); void setDamping(int index, btScalar damping); @@ -93,5 +95,5 @@ SIMD_FORCE_INLINE const char* btGeneric6DofSpringConstraint::serialize(void* dat return "btGeneric6DofConstraintData"; } -#endif // GENERIC_6DOF_SPRING_CONSTRAINT_H +#endif // BT_GENERIC_6DOF_SPRING_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h index 15fd4a014cc..a76452ddb64 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHinge2Constraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef HINGE2_CONSTRAINT_H -#define HINGE2_CONSTRAINT_H +#ifndef BT_HINGE2_CONSTRAINT_H +#define BT_HINGE2_CONSTRAINT_H @@ -54,5 +54,5 @@ public: -#endif // HINGE2_CONSTRAINT_H +#endif // BT_HINGE2_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp index 144beef1cd6..9e3a2baeed9 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp @@ -37,15 +37,15 @@ subject to the following restrictions: btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, const btVector3& axisInA,const btVector3& axisInB, bool useReferenceFrameA) :btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA,rbB), +#ifdef _BT_USE_CENTER_LIMIT_ + m_limit(), +#endif m_angularOnly(false), m_enableAngularMotor(false), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useReferenceFrameA(useReferenceFrameA), m_flags(0) -#ifdef _BT_USE_CENTER_LIMIT_ - ,m_limit() -#endif { m_rbAFrame.getOrigin() = pivotInA; @@ -93,14 +93,15 @@ btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const bt btHingeConstraint::btHingeConstraint(btRigidBody& rbA,const btVector3& pivotInA,const btVector3& axisInA, bool useReferenceFrameA) -:btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA), m_angularOnly(false), m_enableAngularMotor(false), +:btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA), +#ifdef _BT_USE_CENTER_LIMIT_ +m_limit(), +#endif +m_angularOnly(false), m_enableAngularMotor(false), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useReferenceFrameA(useReferenceFrameA), m_flags(0) -#ifdef _BT_USE_CENTER_LIMIT_ -,m_limit() -#endif { // since no frame is given, assume this to be zero angle and just pick rb transform axis @@ -142,15 +143,15 @@ m_flags(0) btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA) :btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA,rbB),m_rbAFrame(rbAFrame),m_rbBFrame(rbBFrame), +#ifdef _BT_USE_CENTER_LIMIT_ +m_limit(), +#endif m_angularOnly(false), m_enableAngularMotor(false), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useReferenceFrameA(useReferenceFrameA), m_flags(0) -#ifdef _BT_USE_CENTER_LIMIT_ -,m_limit() -#endif { #ifndef _BT_USE_CENTER_LIMIT_ //start with free @@ -168,15 +169,15 @@ m_flags(0) btHingeConstraint::btHingeConstraint(btRigidBody& rbA, const btTransform& rbAFrame, bool useReferenceFrameA) :btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA),m_rbAFrame(rbAFrame),m_rbBFrame(rbAFrame), +#ifdef _BT_USE_CENTER_LIMIT_ +m_limit(), +#endif m_angularOnly(false), m_enableAngularMotor(false), m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), m_useReferenceFrameA(useReferenceFrameA), m_flags(0) -#ifdef _BT_USE_CENTER_LIMIT_ -,m_limit() -#endif { ///not providing rigidbody B means implicitly using worldspace for body B @@ -663,7 +664,7 @@ void btHingeConstraint::setMotorTarget(const btQuaternion& qAinB, btScalar dt) btScalar targetAngle = qHinge.getAngle(); if (targetAngle > SIMD_PI) // long way around. flip quat and recalculate. { - qHinge = operator-(qHinge); + qHinge = -(qHinge); targetAngle = qHinge.getAngle(); } if (qHinge.getZ() < 0) diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h index 50e3f73cb6d..cb2973e1d1d 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btHingeConstraint.h @@ -15,8 +15,9 @@ subject to the following restrictions: /* Hinge Constraint by Dirk Gregorius. Limits added by Marcus Hennix at Starbreeze Studios */ -#ifndef HINGECONSTRAINT_H -#define HINGECONSTRAINT_H +#ifndef BT_HINGECONSTRAINT_H +#define BT_HINGECONSTRAINT_H + #define _BT_USE_CENTER_LIMIT_ 1 @@ -377,4 +378,4 @@ SIMD_FORCE_INLINE const char* btHingeConstraint::serialize(void* dataBuffer, btS return btHingeConstraintDataName; } -#endif //HINGECONSTRAINT_H +#endif //BT_HINGECONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h index 22a8af66b8e..f1994a2dfd8 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btJacobianEntry.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef JACOBIAN_ENTRY_H -#define JACOBIAN_ENTRY_H +#ifndef BT_JACOBIAN_ENTRY_H +#define BT_JACOBIAN_ENTRY_H #include "LinearMath/btVector3.h" #include "BulletDynamics/Dynamics/btRigidBody.h" @@ -153,4 +153,4 @@ public: }; -#endif //JACOBIAN_ENTRY_H +#endif //BT_JACOBIAN_ENTRY_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h index b589ee68254..b3bda03eec1 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef POINT2POINTCONSTRAINT_H -#define POINT2POINTCONSTRAINT_H +#ifndef BT_POINT2POINTCONSTRAINT_H +#define BT_POINT2POINTCONSTRAINT_H #include "LinearMath/btVector3.h" #include "btJacobianEntry.h" @@ -158,4 +158,4 @@ SIMD_FORCE_INLINE const char* btPoint2PointConstraint::serialize(void* dataBuffe return btPoint2PointConstraintDataName; } -#endif //POINT2POINTCONSTRAINT_H +#endif //BT_POINT2POINTCONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp index 0fc93cd3756..ab074224028 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp @@ -225,7 +225,7 @@ void btSequentialImpulseConstraintSolver::resolveSplitPenetrationImpulseCacheFri resultUpperLess = _mm_cmplt_ps(sum,upperLimit1); __m128 lowMinApplied = _mm_sub_ps(lowerLimit1,cpAppliedImp); deltaImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse) ); - c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum) ); + c.m_appliedPushImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum) ); __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal.mVec128,body1.internalGetInvMass().mVec128); __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal).mVec128,body2.internalGetInvMass().mVec128); __m128 impulseMagnitude = deltaImpulse; @@ -740,13 +740,13 @@ void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* m } } - btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc) { BT_PROFILE("solveGroupCacheFriendlySetup"); (void)stackAlloc; (void)debugDrawer; + m_maxOverrideNumSolverIterations = 0; if (!(numConstraints + numManifolds)) { @@ -788,6 +788,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol { btTypedConstraint* constraint = constraints[j]; constraint->buildJacobian(); + constraint->internalSetAppliedImpulse(0.0f); } } //btRigidBody* rb0=0,*rb1=0; @@ -804,7 +805,14 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol for (i=0;i<numConstraints;i++) { btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i]; - constraints[i]->getInfo1(&info1); + if (constraints[i]->isEnabled()) + { + constraints[i]->getInfo1(&info1); + } else + { + info1.m_numConstraintRows = 0; + info1.nub = 0; + } totalNumRows += info1.m_numConstraintRows; } m_tmpSolverNonContactConstraintPool.resize(totalNumRows); @@ -823,23 +831,26 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol btSolverConstraint* currentConstraintRow = &m_tmpSolverNonContactConstraintPool[currentRow]; btTypedConstraint* constraint = constraints[i]; + btRigidBody& rbA = constraint->getRigidBodyA(); + btRigidBody& rbB = constraint->getRigidBodyB(); + int overrideNumSolverIterations = constraint->getOverrideNumSolverIterations() > 0 ? constraint->getOverrideNumSolverIterations() : infoGlobal.m_numIterations; + if (overrideNumSolverIterations>m_maxOverrideNumSolverIterations) + m_maxOverrideNumSolverIterations = overrideNumSolverIterations; - btRigidBody& rbA = constraint->getRigidBodyA(); - btRigidBody& rbB = constraint->getRigidBodyB(); - int j; for ( j=0;j<info1.m_numConstraintRows;j++) { memset(¤tConstraintRow[j],0,sizeof(btSolverConstraint)); - currentConstraintRow[j].m_lowerLimit = -FLT_MAX; - currentConstraintRow[j].m_upperLimit = FLT_MAX; + currentConstraintRow[j].m_lowerLimit = -SIMD_INFINITY; + currentConstraintRow[j].m_upperLimit = SIMD_INFINITY; currentConstraintRow[j].m_appliedImpulse = 0.f; currentConstraintRow[j].m_appliedPushImpulse = 0.f; currentConstraintRow[j].m_solverBodyA = &rbA; currentConstraintRow[j].m_solverBodyB = &rbB; + currentConstraintRow[j].m_overrideNumSolverIterations = overrideNumSolverIterations; } rbA.internalGetDeltaLinearVelocity().setValue(0.f,0.f,0.f); @@ -872,6 +883,17 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol for ( j=0;j<info1.m_numConstraintRows;j++) { btSolverConstraint& solverConstraint = currentConstraintRow[j]; + + if (solverConstraint.m_upperLimit>=constraints[i]->getBreakingImpulseThreshold()) + { + solverConstraint.m_upperLimit = constraints[i]->getBreakingImpulseThreshold(); + } + + if (solverConstraint.m_lowerLimit<=-constraints[i]->getBreakingImpulseThreshold()) + { + solverConstraint.m_lowerLimit = -constraints[i]->getBreakingImpulseThreshold(); + } + solverConstraint.m_originalContactPoint = constraint; { @@ -939,15 +961,20 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol btContactSolverInfo info = infoGlobal; - + int numNonContactPool = m_tmpSolverNonContactConstraintPool.size(); int numConstraintPool = m_tmpSolverContactConstraintPool.size(); int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size(); ///@todo: use stack allocator for such temporarily memory, same for solver bodies/constraints + m_orderNonContactConstraintPool.resize(numNonContactPool); m_orderTmpConstraintPool.resize(numConstraintPool); m_orderFrictionConstraintPool.resize(numFrictionPool); { int i; + for (i=0;i<numNonContactPool;i++) + { + m_orderNonContactConstraintPool[i] = i; + } for (i=0;i<numConstraintPool;i++) { m_orderTmpConstraintPool[i] = i; @@ -965,6 +992,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration, btCollisionObject** /*bodies */,int /*numBodies*/,btPersistentManifold** /*manifoldPtr*/, int /*numManifolds*/,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* /*debugDrawer*/,btStackAlloc* /*stackAlloc*/) { + int numNonContactPool = m_tmpSolverNonContactConstraintPool.size(); int numConstraintPool = m_tmpSolverContactConstraintPool.size(); int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size(); @@ -973,18 +1001,29 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER) { if ((iteration & 7) == 0) { - for (j=0; j<numConstraintPool; ++j) { - int tmp = m_orderTmpConstraintPool[j]; + for (j=0; j<numNonContactPool; ++j) { + int tmp = m_orderNonContactConstraintPool[j]; int swapi = btRandInt2(j+1); - m_orderTmpConstraintPool[j] = m_orderTmpConstraintPool[swapi]; - m_orderTmpConstraintPool[swapi] = tmp; + m_orderNonContactConstraintPool[j] = m_orderNonContactConstraintPool[swapi]; + m_orderNonContactConstraintPool[swapi] = tmp; } - for (j=0; j<numFrictionPool; ++j) { - int tmp = m_orderFrictionConstraintPool[j]; - int swapi = btRandInt2(j+1); - m_orderFrictionConstraintPool[j] = m_orderFrictionConstraintPool[swapi]; - m_orderFrictionConstraintPool[swapi] = tmp; + //contact/friction constraints are not solved more than + if (iteration< infoGlobal.m_numIterations) + { + for (j=0; j<numConstraintPool; ++j) { + int tmp = m_orderTmpConstraintPool[j]; + int swapi = btRandInt2(j+1); + m_orderTmpConstraintPool[j] = m_orderTmpConstraintPool[swapi]; + m_orderTmpConstraintPool[swapi] = tmp; + } + + for (j=0; j<numFrictionPool; ++j) { + int tmp = m_orderFrictionConstraintPool[j]; + int swapi = btRandInt2(j+1); + m_orderFrictionConstraintPool[j] = m_orderFrictionConstraintPool[swapi]; + m_orderFrictionConstraintPool[swapi] = tmp; + } } } } @@ -994,36 +1033,41 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration ///solve all joint constraints, using SIMD, if available for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++) { - btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; - resolveSingleConstraintRowGenericSIMD(*constraint.m_solverBodyA,*constraint.m_solverBodyB,constraint); + btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[m_orderNonContactConstraintPool[j]]; + if (iteration < constraint.m_overrideNumSolverIterations) + resolveSingleConstraintRowGenericSIMD(*constraint.m_solverBodyA,*constraint.m_solverBodyB,constraint); } - for (j=0;j<numConstraints;j++) + if (iteration< infoGlobal.m_numIterations) { - constraints[j]->solveConstraintObsolete(constraints[j]->getRigidBodyA(),constraints[j]->getRigidBodyB(),infoGlobal.m_timeStep); - } - - ///solve all contact constraints using SIMD, if available - int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); - for (j=0;j<numPoolConstraints;j++) - { - const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; - resolveSingleConstraintRowLowerLimitSIMD(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); + for (j=0;j<numConstraints;j++) + { + constraints[j]->solveConstraintObsolete(constraints[j]->getRigidBodyA(),constraints[j]->getRigidBodyB(),infoGlobal.m_timeStep); + } - } - ///solve all friction constraints, using SIMD, if available - int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); - for (j=0;j<numFrictionPoolConstraints;j++) - { - btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; - btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; + ///solve all contact constraints using SIMD, if available + int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); + for (j=0;j<numPoolConstraints;j++) + { + const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; + resolveSingleConstraintRowLowerLimitSIMD(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); - if (totalImpulse>btScalar(0)) + } + + ///solve all friction constraints, using SIMD, if available + int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); + for (j=0;j<numFrictionPoolConstraints;j++) { - solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); - solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; + btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; + btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; + + if (totalImpulse>btScalar(0)) + { + solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); + solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; - resolveSingleConstraintRowGenericSIMD(*solveManifold.m_solverBodyA, *solveManifold.m_solverBodyB,solveManifold); + resolveSingleConstraintRowGenericSIMD(*solveManifold.m_solverBodyA, *solveManifold.m_solverBodyB,solveManifold); + } } } } else @@ -1032,34 +1076,38 @@ btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration ///solve all joint constraints for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++) { - btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; - resolveSingleConstraintRowGeneric(*constraint.m_solverBodyA,*constraint.m_solverBodyB,constraint); + btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[m_orderNonContactConstraintPool[j]]; + if (iteration < constraint.m_overrideNumSolverIterations) + resolveSingleConstraintRowGeneric(*constraint.m_solverBodyA,*constraint.m_solverBodyB,constraint); } - for (j=0;j<numConstraints;j++) - { - constraints[j]->solveConstraintObsolete(constraints[j]->getRigidBodyA(),constraints[j]->getRigidBodyB(),infoGlobal.m_timeStep); - } - ///solve all contact constraints - int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); - for (j=0;j<numPoolConstraints;j++) + if (iteration< infoGlobal.m_numIterations) { - const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; - resolveSingleConstraintRowLowerLimit(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); - } - ///solve all friction constraints - int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); - for (j=0;j<numFrictionPoolConstraints;j++) - { - btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; - btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; - - if (totalImpulse>btScalar(0)) + for (j=0;j<numConstraints;j++) { - solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); - solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; + constraints[j]->solveConstraintObsolete(constraints[j]->getRigidBodyA(),constraints[j]->getRigidBodyB(),infoGlobal.m_timeStep); + } + ///solve all contact constraints + int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); + for (j=0;j<numPoolConstraints;j++) + { + const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; + resolveSingleConstraintRowLowerLimit(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); + } + ///solve all friction constraints + int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); + for (j=0;j<numFrictionPoolConstraints;j++) + { + btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; + btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; - resolveSingleConstraintRowGeneric(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); + if (totalImpulse>btScalar(0)) + { + solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); + solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; + + resolveSingleConstraintRowGeneric(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); + } } } } @@ -1111,16 +1159,18 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations( { BT_PROFILE("solveGroupCacheFriendlyIterations"); - - //should traverse the contacts random order... - int iteration; { - for ( iteration = 0;iteration<infoGlobal.m_numIterations;iteration++) + ///this is a special step to resolve penetrations (just for contacts) + solveGroupCacheFriendlySplitImpulseIterations(bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer,stackAlloc); + + int maxIterations = m_maxOverrideNumSolverIterations > infoGlobal.m_numIterations? m_maxOverrideNumSolverIterations : infoGlobal.m_numIterations; + + for ( int iteration = 0 ; iteration< maxIterations ; iteration++) + //for ( int iteration = maxIterations-1 ; iteration >= 0;iteration--) { solveSingleIteration(iteration, bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer,stackAlloc); } - solveGroupCacheFriendlySplitImpulseIterations(bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer,stackAlloc); } return 0.f; } @@ -1151,9 +1201,11 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyFinish(btCo { const btSolverConstraint& solverConstr = m_tmpSolverNonContactConstraintPool[j]; btTypedConstraint* constr = (btTypedConstraint*)solverConstr.m_originalContactPoint; - btScalar sum = constr->internalGetAppliedImpulse(); - sum += solverConstr.m_appliedImpulse; - constr->internalSetAppliedImpulse(sum); + constr->internalSetAppliedImpulse(solverConstr.m_appliedImpulse); + if (btFabs(solverConstr.m_appliedImpulse)>=constr->getBreakingImpulseThreshold()) + { + constr->setEnabled(false); + } } diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h index f268ec9ae74..bb377db8db9 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H -#define SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H +#ifndef BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H +#define BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H #include "btConstraintSolver.h" class btIDebugDraw; @@ -33,8 +33,10 @@ protected: btConstraintArray m_tmpSolverNonContactConstraintPool; btConstraintArray m_tmpSolverContactFrictionConstraintPool; btAlignedObjectArray<int> m_orderTmpConstraintPool; + btAlignedObjectArray<int> m_orderNonContactConstraintPool; btAlignedObjectArray<int> m_orderFrictionConstraintPool; btAlignedObjectArray<btTypedConstraint::btConstraintInfo1> m_tmpConstraintSizesPool; + int m_maxOverrideNumSolverIterations; void setupFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyIdB, btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2, @@ -124,5 +126,5 @@ typedef btSequentialImpulseConstraintSolver btSequentialImpulseConstraintSolverP #endif -#endif //SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H +#endif //BT_SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSliderConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSliderConstraint.h index e9723a7bb40..2edc8d2b2e1 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSliderConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSliderConstraint.h @@ -22,8 +22,8 @@ TODO: - add conversion for ODE constraint solver */ -#ifndef SLIDER_CONSTRAINT_H -#define SLIDER_CONSTRAINT_H +#ifndef BT_SLIDER_CONSTRAINT_H +#define BT_SLIDER_CONSTRAINT_H @@ -236,7 +236,10 @@ public: btScalar getTargetAngMotorVelocity() { return m_targetAngMotorVelocity; } void setMaxAngMotorForce(btScalar maxAngMotorForce) { m_maxAngMotorForce = maxAngMotorForce; } btScalar getMaxAngMotorForce() { return m_maxAngMotorForce; } - btScalar getLinearPos() { return m_linPos; } + + btScalar getLinearPos() const { return m_linPos; } + btScalar getAngularPos() const { return m_angPos; } + // access for ODE solver @@ -326,5 +329,5 @@ SIMD_FORCE_INLINE const char* btSliderConstraint::serialize(void* dataBuffer, bt -#endif //SLIDER_CONSTRAINT_H +#endif //BT_SLIDER_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.h index 057d3fac827..e8bfabf864e 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolve2LinearConstraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SOLVE_2LINEAR_CONSTRAINT_H -#define SOLVE_2LINEAR_CONSTRAINT_H +#ifndef BT_SOLVE_2LINEAR_CONSTRAINT_H +#define BT_SOLVE_2LINEAR_CONSTRAINT_H #include "LinearMath/btMatrix3x3.h" #include "LinearMath/btVector3.h" @@ -104,4 +104,4 @@ public: }; -#endif //SOLVE_2LINEAR_CONSTRAINT_H +#endif //BT_SOLVE_2LINEAR_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h index 79e45a4383b..179e79d7911 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btSolverConstraint.h @@ -51,6 +51,8 @@ ATTRIBUTE_ALIGNED64 (struct) btSolverConstraint btScalar m_unusedPadding0; }; + int m_overrideNumSolverIterations; + union { int m_frictionIndex; diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp index 8212c36ff4e..06bde5e7eec 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp @@ -25,7 +25,10 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rb :btTypedObject(type), m_userConstraintType(-1), m_userConstraintId(-1), +m_breakingImpulseThreshold(SIMD_INFINITY), +m_isEnabled(true), m_needsFeedback(false), +m_overrideNumSolverIterations(-1), m_rbA(rbA), m_rbB(getFixedBody()), m_appliedImpulse(btScalar(0.)), @@ -38,7 +41,10 @@ btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rb :btTypedObject(type), m_userConstraintType(-1), m_userConstraintId(-1), +m_breakingImpulseThreshold(SIMD_INFINITY), +m_isEnabled(true), m_needsFeedback(false), +m_overrideNumSolverIterations(-1), m_rbA(rbA), m_rbB(rbB), m_appliedImpulse(btScalar(0.)), @@ -114,6 +120,10 @@ const char* btTypedConstraint::serialize(void* dataBuffer, btSerializer* seriali tcd->m_objectType = m_objectType; tcd->m_needsFeedback = m_needsFeedback; + tcd->m_overrideNumSolverIterations = m_overrideNumSolverIterations; + tcd->m_breakingImpulseThreshold = float(m_breakingImpulseThreshold); + tcd->m_isEnabled = m_isEnabled? 1: 0; + tcd->m_userConstraintId =m_userConstraintId; tcd->m_userConstraintType =m_userConstraintType; diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h index 65e6d558300..a16e869a973 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btTypedConstraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef TYPED_CONSTRAINT_H -#define TYPED_CONSTRAINT_H +#ifndef BT_TYPED_CONSTRAINT_H +#define BT_TYPED_CONSTRAINT_H class btRigidBody; #include "LinearMath/btScalar.h" @@ -62,7 +62,11 @@ class btTypedConstraint : public btTypedObject void* m_userConstraintPtr; }; - bool m_needsFeedback; + btScalar m_breakingImpulseThreshold; + bool m_isEnabled; + bool m_needsFeedback; + int m_overrideNumSolverIterations; + btTypedConstraint& operator=(btTypedConstraint& other) { @@ -80,7 +84,6 @@ protected: ///internal method used by the constraint solver, don't use them directly btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact); - static btRigidBody& getFixedBody(); public: @@ -92,6 +95,8 @@ public: int m_numConstraintRows,nub; }; + static btRigidBody& getFixedBody(); + struct btConstraintInfo2 { // integrator parameters: frames per second (1/stepsize), default error // reduction parameter (0..1). @@ -126,6 +131,18 @@ public: btScalar m_damping; }; + int getOverrideNumSolverIterations() const + { + return m_overrideNumSolverIterations; + } + + ///override the number of constraint solver iterations used to solve this constraint + ///-1 will use the default number of iterations, as specified in SolverInfo.m_numIterations + void setOverrideNumSolverIterations(int overideNumIterations) + { + m_overrideNumSolverIterations = overideNumIterations; + } + ///internal method used by the constraint solver, don't use them directly virtual void buildJacobian() {}; @@ -155,6 +172,28 @@ public: return m_appliedImpulse; } + + btScalar getBreakingImpulseThreshold() const + { + return m_breakingImpulseThreshold; + } + + void setBreakingImpulseThreshold(btScalar threshold) + { + m_breakingImpulseThreshold = threshold; + } + + bool isEnabled() const + { + return m_isEnabled; + } + + void setEnabled(bool enabled) + { + m_isEnabled=enabled; + } + + ///internal method used by the constraint solver, don't use them directly virtual void solveConstraintObsolete(btRigidBody& /*bodyA*/,btRigidBody& /*bodyB*/,btScalar /*timeStep*/) {}; @@ -302,7 +341,10 @@ struct btTypedConstraintData float m_dbgDrawSize; int m_disableCollisionsBetweenLinkedBodies; - char m_pad4[4]; + int m_overrideNumSolverIterations; + + float m_breakingImpulseThreshold; + int m_isEnabled; }; @@ -407,4 +449,4 @@ public: -#endif //TYPED_CONSTRAINT_H +#endif //BT_TYPED_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp index 40c56e77954..b009f41aec8 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.cpp @@ -27,7 +27,7 @@ subject to the following restrictions: // constructor // anchor, axis1 and axis2 are in world coordinate system // axis1 must be orthogonal to axis2 -btUniversalConstraint::btUniversalConstraint(btRigidBody& rbA, btRigidBody& rbB, btVector3& anchor, btVector3& axis1, btVector3& axis2) +btUniversalConstraint::btUniversalConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& anchor, const btVector3& axis1, const btVector3& axis2) : btGeneric6DofConstraint(rbA, rbB, btTransform::getIdentity(), btTransform::getIdentity(), true), m_anchor(anchor), m_axis1(axis1), @@ -42,8 +42,8 @@ btUniversalConstraint::btUniversalConstraint(btRigidBody& rbA, btRigidBody& rbB, // new position of X, allowed limits are (-PI,PI); // So to simulate ODE Universal joint we should use parent axis as Z, child axis as Y and limit all other DOFs // Build the frame in world coordinate system first - btVector3 zAxis = axis1.normalize(); - btVector3 yAxis = axis2.normalize(); + btVector3 zAxis = m_axis1.normalize(); + btVector3 yAxis = m_axis2.normalize(); btVector3 xAxis = yAxis.cross(zAxis); // we want right coordinate system btTransform frameInW; frameInW.setIdentity(); diff --git a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h index a8d404a591c..a86939164ec 100644 --- a/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h +++ b/extern/bullet2/src/BulletDynamics/ConstraintSolver/btUniversalConstraint.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef UNIVERSAL_CONSTRAINT_H -#define UNIVERSAL_CONSTRAINT_H +#ifndef BT_UNIVERSAL_CONSTRAINT_H +#define BT_UNIVERSAL_CONSTRAINT_H @@ -41,7 +41,7 @@ public: // constructor // anchor, axis1 and axis2 are in world coordinate system // axis1 must be orthogonal to axis2 - btUniversalConstraint(btRigidBody& rbA, btRigidBody& rbB, btVector3& anchor, btVector3& axis1, btVector3& axis2); + btUniversalConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& anchor, const btVector3& axis1, const btVector3& axis2); // access const btVector3& getAnchor() { return m_calculatedTransformA.getOrigin(); } const btVector3& getAnchor2() { return m_calculatedTransformB.getOrigin(); } @@ -58,5 +58,5 @@ public: -#endif // UNIVERSAL_CONSTRAINT_H +#endif // BT_UNIVERSAL_CONSTRAINT_H diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.cpp deleted file mode 100644 index 23501c4435e..00000000000 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - -#include "btContinuousDynamicsWorld.h" -#include "LinearMath/btQuickprof.h" - -//collision detection -#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" -#include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h" -#include "BulletCollision/CollisionShapes/btCollisionShape.h" -#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h" - -//rigidbody & constraints -#include "BulletDynamics/Dynamics/btRigidBody.h" -#include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h" -#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h" -#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h" - - - -#include <stdio.h> - -btContinuousDynamicsWorld::btContinuousDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration) -:btDiscreteDynamicsWorld(dispatcher,pairCache,constraintSolver,collisionConfiguration) -{ -} - -btContinuousDynamicsWorld::~btContinuousDynamicsWorld() -{ -} - - -void btContinuousDynamicsWorld::internalSingleStepSimulation( btScalar timeStep) -{ - - startProfiling(timeStep); - - if(0 != m_internalPreTickCallback) { - (*m_internalPreTickCallback)(this, timeStep); - } - - - ///update aabbs information - updateAabbs(); - //static int frame=0; -// printf("frame %d\n",frame++); - - ///apply gravity, predict motion - predictUnconstraintMotion(timeStep); - - btDispatcherInfo& dispatchInfo = getDispatchInfo(); - - dispatchInfo.m_timeStep = timeStep; - dispatchInfo.m_stepCount = 0; - dispatchInfo.m_debugDraw = getDebugDrawer(); - - ///perform collision detection - performDiscreteCollisionDetection(); - - calculateSimulationIslands(); - - - getSolverInfo().m_timeStep = timeStep; - - - - ///solve contact and other joint constraints - solveConstraints(getSolverInfo()); - - ///CallbackTriggers(); - calculateTimeOfImpacts(timeStep); - - btScalar toi = dispatchInfo.m_timeOfImpact; -// if (toi < 1.f) -// printf("toi = %f\n",toi); - if (toi < 0.f) - printf("toi = %f\n",toi); - - - ///integrate transforms - integrateTransforms(timeStep * toi); - - ///update vehicle simulation - updateActions(timeStep); - - updateActivationState( timeStep ); - - if(0 != m_internalTickCallback) { - (*m_internalTickCallback)(this, timeStep); - } -} - -void btContinuousDynamicsWorld::calculateTimeOfImpacts(btScalar timeStep) -{ - ///these should be 'temporal' aabbs! - updateTemporalAabbs(timeStep); - - ///'toi' is the global smallest time of impact. However, we just calculate the time of impact for each object individually. - ///so we handle the case moving versus static properly, and we cheat for moving versus moving - btScalar toi = 1.f; - - - btDispatcherInfo& dispatchInfo = getDispatchInfo(); - dispatchInfo.m_timeStep = timeStep; - dispatchInfo.m_timeOfImpact = 1.f; - dispatchInfo.m_stepCount = 0; - dispatchInfo.m_dispatchFunc = btDispatcherInfo::DISPATCH_CONTINUOUS; - - ///calculate time of impact for overlapping pairs - - - btDispatcher* dispatcher = getDispatcher(); - if (dispatcher) - dispatcher->dispatchAllCollisionPairs(m_broadphasePairCache->getOverlappingPairCache(),dispatchInfo,m_dispatcher1); - - toi = dispatchInfo.m_timeOfImpact; - - dispatchInfo.m_dispatchFunc = btDispatcherInfo::DISPATCH_DISCRETE; - -} - -void btContinuousDynamicsWorld::updateTemporalAabbs(btScalar timeStep) -{ - - btVector3 temporalAabbMin,temporalAabbMax; - - for ( int i=0;i<m_collisionObjects.size();i++) - { - btCollisionObject* colObj = m_collisionObjects[i]; - - btRigidBody* body = btRigidBody::upcast(colObj); - if (body) - { - body->getCollisionShape()->getAabb(m_collisionObjects[i]->getWorldTransform(),temporalAabbMin,temporalAabbMax); - const btVector3& linvel = body->getLinearVelocity(); - - //make the AABB temporal - btScalar temporalAabbMaxx = temporalAabbMax.getX(); - btScalar temporalAabbMaxy = temporalAabbMax.getY(); - btScalar temporalAabbMaxz = temporalAabbMax.getZ(); - btScalar temporalAabbMinx = temporalAabbMin.getX(); - btScalar temporalAabbMiny = temporalAabbMin.getY(); - btScalar temporalAabbMinz = temporalAabbMin.getZ(); - - // add linear motion - btVector3 linMotion = linvel*timeStep; - - if (linMotion.x() > 0.f) - temporalAabbMaxx += linMotion.x(); - else - temporalAabbMinx += linMotion.x(); - if (linMotion.y() > 0.f) - temporalAabbMaxy += linMotion.y(); - else - temporalAabbMiny += linMotion.y(); - if (linMotion.z() > 0.f) - temporalAabbMaxz += linMotion.z(); - else - temporalAabbMinz += linMotion.z(); - - //add conservative angular motion - btScalar angularMotion(0);// = angvel.length() * GetAngularMotionDisc() * timeStep; - btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion); - temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz); - temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz); - - temporalAabbMin -= angularMotion3d; - temporalAabbMax += angularMotion3d; - - m_broadphasePairCache->setAabb(body->getBroadphaseHandle(),temporalAabbMin,temporalAabbMax,m_dispatcher1); - } - } - - //update aabb (of all moved objects) - - m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1); - - - -} - - - diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.h deleted file mode 100644 index 61c8dea03eb..00000000000 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btContinuousDynamicsWorld.h +++ /dev/null @@ -1,46 +0,0 @@ -/* -Bullet Continuous Collision Detection and Physics Library -Copyright (c) 2003-2007 Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef BT_CONTINUOUS_DYNAMICS_WORLD_H -#define BT_CONTINUOUS_DYNAMICS_WORLD_H - -#include "btDiscreteDynamicsWorld.h" - -///btContinuousDynamicsWorld adds optional (per object) continuous collision detection for fast moving objects to the btDiscreteDynamicsWorld. -///This copes with fast moving objects that otherwise would tunnel/miss collisions. -///Under construction, don't use yet! Please use btDiscreteDynamicsWorld instead. -class btContinuousDynamicsWorld : public btDiscreteDynamicsWorld -{ - - void updateTemporalAabbs(btScalar timeStep); - - public: - - btContinuousDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver,btCollisionConfiguration* collisionConfiguration); - virtual ~btContinuousDynamicsWorld(); - - ///time stepping with calculation of time of impact for selected fast moving objects - virtual void internalSingleStepSimulation( btScalar timeStep); - - virtual void calculateTimeOfImpacts(btScalar timeStep); - - virtual btDynamicsWorldType getWorldType() const - { - return BT_CONTINUOUS_DYNAMICS_WORLD; - } - -}; - -#endif //BT_CONTINUOUS_DYNAMICS_WORLD_H diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index e1eada07c82..954ef241adc 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -35,6 +35,8 @@ subject to the following restrictions: #include "BulletDynamics/ConstraintSolver/btConeTwistConstraint.h" #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" +#include "BulletDynamics/ConstraintSolver/btContactConstraint.h" + #include "LinearMath/btIDebugDraw.h" #include "BulletCollision/CollisionShapes/btSphereShape.h" @@ -46,6 +48,167 @@ subject to the following restrictions: #include "LinearMath/btSerializer.h" +#if 0 +btAlignedObjectArray<btVector3> debugContacts; +btAlignedObjectArray<btVector3> debugNormals; +int startHit=2; +int firstHit=startHit; +#endif + +SIMD_FORCE_INLINE int btGetConstraintIslandId(const btTypedConstraint* lhs) +{ + int islandId; + + const btCollisionObject& rcolObj0 = lhs->getRigidBodyA(); + const btCollisionObject& rcolObj1 = lhs->getRigidBodyB(); + islandId= rcolObj0.getIslandTag()>=0?rcolObj0.getIslandTag():rcolObj1.getIslandTag(); + return islandId; + +} + + +class btSortConstraintOnIslandPredicate +{ + public: + + bool operator() ( const btTypedConstraint* lhs, const btTypedConstraint* rhs ) const + { + int rIslandId0,lIslandId0; + rIslandId0 = btGetConstraintIslandId(rhs); + lIslandId0 = btGetConstraintIslandId(lhs); + return lIslandId0 < rIslandId0; + } +}; + +struct InplaceSolverIslandCallback : public btSimulationIslandManager::IslandCallback +{ + btContactSolverInfo* m_solverInfo; + btConstraintSolver* m_solver; + btTypedConstraint** m_sortedConstraints; + int m_numConstraints; + btIDebugDraw* m_debugDrawer; + btStackAlloc* m_stackAlloc; + btDispatcher* m_dispatcher; + + btAlignedObjectArray<btCollisionObject*> m_bodies; + btAlignedObjectArray<btPersistentManifold*> m_manifolds; + btAlignedObjectArray<btTypedConstraint*> m_constraints; + + + InplaceSolverIslandCallback( + btConstraintSolver* solver, + btStackAlloc* stackAlloc, + btDispatcher* dispatcher) + :m_solverInfo(NULL), + m_solver(solver), + m_sortedConstraints(NULL), + m_numConstraints(0), + m_debugDrawer(NULL), + m_stackAlloc(stackAlloc), + m_dispatcher(dispatcher) + { + + } + + InplaceSolverIslandCallback& operator=(InplaceSolverIslandCallback& other) + { + btAssert(0); + (void)other; + return *this; + } + + SIMD_FORCE_INLINE void setup ( btContactSolverInfo* solverInfo, btTypedConstraint** sortedConstraints, int numConstraints, btIDebugDraw* debugDrawer) + { + btAssert(solverInfo); + m_solverInfo = solverInfo; + m_sortedConstraints = sortedConstraints; + m_numConstraints = numConstraints; + m_debugDrawer = debugDrawer; + m_bodies.resize (0); + m_manifolds.resize (0); + m_constraints.resize (0); + } + + + virtual void processIsland(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifolds,int numManifolds, int islandId) + { + if (islandId<0) + { + if (numManifolds + m_numConstraints) + { + ///we don't split islands, so all constraints/contact manifolds/bodies are passed into the solver regardless the island id + m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,&m_sortedConstraints[0],m_numConstraints,*m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); + } + } else + { + //also add all non-contact constraints/joints for this island + btTypedConstraint** startConstraint = 0; + int numCurConstraints = 0; + int i; + + //find the first constraint for this island + for (i=0;i<m_numConstraints;i++) + { + if (btGetConstraintIslandId(m_sortedConstraints[i]) == islandId) + { + startConstraint = &m_sortedConstraints[i]; + break; + } + } + //count the number of constraints in this island + for (;i<m_numConstraints;i++) + { + if (btGetConstraintIslandId(m_sortedConstraints[i]) == islandId) + { + numCurConstraints++; + } + } + + if (m_solverInfo->m_minimumSolverBatchSize<=1) + { + ///only call solveGroup if there is some work: avoid virtual function call, its overhead can be excessive + if (numManifolds + numCurConstraints) + { + m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,*m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); + } + } else + { + + for (i=0;i<numBodies;i++) + m_bodies.push_back(bodies[i]); + for (i=0;i<numManifolds;i++) + m_manifolds.push_back(manifolds[i]); + for (i=0;i<numCurConstraints;i++) + m_constraints.push_back(startConstraint[i]); + if ((m_constraints.size()+m_manifolds.size())>m_solverInfo->m_minimumSolverBatchSize) + { + processConstraints(); + } else + { + //printf("deferred\n"); + } + } + } + } + void processConstraints() + { + if (m_manifolds.size() + m_constraints.size()>0) + { + + btCollisionObject** bodies = m_bodies.size()? &m_bodies[0]:0; + btPersistentManifold** manifold = m_manifolds.size()?&m_manifolds[0]:0; + btTypedConstraint** constraints = m_constraints.size()?&m_constraints[0]:0; + + m_solver->solveGroup( bodies,m_bodies.size(),manifold, m_manifolds.size(),constraints, m_constraints.size() ,*m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); + } + m_bodies.resize(0); + m_manifolds.resize(0); + m_constraints.resize(0); + + } + +}; + btDiscreteDynamicsWorld::btDiscreteDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache,btConstraintSolver* constraintSolver, btCollisionConfiguration* collisionConfiguration) @@ -54,7 +217,9 @@ m_constraintSolver(constraintSolver), m_gravity(0,-10,0), m_localTime(0), m_synchronizeAllMotionStates(false), -m_profileTimings(0) +m_profileTimings(0), +m_sortedConstraints (), +m_solverIslandCallback ( NULL ) { if (!m_constraintSolver) { @@ -72,6 +237,11 @@ m_profileTimings(0) } m_ownsIslandManager = true; + + { + void* mem = btAlignedAlloc(sizeof(InplaceSolverIslandCallback),16); + m_solverIslandCallback = new (mem) InplaceSolverIslandCallback (constraintSolver, m_stackAlloc, dispatcher); + } } @@ -83,6 +253,11 @@ btDiscreteDynamicsWorld::~btDiscreteDynamicsWorld() m_islandManager->~btSimulationIslandManager(); btAlignedFree( m_islandManager); } + if (m_solverIslandCallback) + { + m_solverIslandCallback->~InplaceSolverIslandCallback(); + btAlignedFree(m_solverIslandCallback); + } if (m_ownsConstraintSolver) { @@ -138,7 +313,7 @@ void btDiscreteDynamicsWorld::debugDrawWorld() - if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)) + if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb | btIDebugDraw::DBG_DrawNormals))) { int i; @@ -314,9 +489,11 @@ void btDiscreteDynamicsWorld::internalSingleStepSimulation(btScalar timeStep) dispatchInfo.m_stepCount = 0; dispatchInfo.m_debugDraw = getDebugDrawer(); + ///perform collision detection performDiscreteCollisionDetection(); + calculateSimulationIslands(); @@ -524,187 +701,39 @@ void btDiscreteDynamicsWorld::removeCharacter(btActionInterface* character) } -SIMD_FORCE_INLINE int btGetConstraintIslandId(const btTypedConstraint* lhs) -{ - int islandId; - - const btCollisionObject& rcolObj0 = lhs->getRigidBodyA(); - const btCollisionObject& rcolObj1 = lhs->getRigidBodyB(); - islandId= rcolObj0.getIslandTag()>=0?rcolObj0.getIslandTag():rcolObj1.getIslandTag(); - return islandId; - -} - - -class btSortConstraintOnIslandPredicate -{ - public: - - bool operator() ( const btTypedConstraint* lhs, const btTypedConstraint* rhs ) - { - int rIslandId0,lIslandId0; - rIslandId0 = btGetConstraintIslandId(rhs); - lIslandId0 = btGetConstraintIslandId(lhs); - return lIslandId0 < rIslandId0; - } -}; - void btDiscreteDynamicsWorld::solveConstraints(btContactSolverInfo& solverInfo) { BT_PROFILE("solveConstraints"); - struct InplaceSolverIslandCallback : public btSimulationIslandManager::IslandCallback - { - - btContactSolverInfo& m_solverInfo; - btConstraintSolver* m_solver; - btTypedConstraint** m_sortedConstraints; - int m_numConstraints; - btIDebugDraw* m_debugDrawer; - btStackAlloc* m_stackAlloc; - btDispatcher* m_dispatcher; - - btAlignedObjectArray<btCollisionObject*> m_bodies; - btAlignedObjectArray<btPersistentManifold*> m_manifolds; - btAlignedObjectArray<btTypedConstraint*> m_constraints; - - - InplaceSolverIslandCallback( - btContactSolverInfo& solverInfo, - btConstraintSolver* solver, - btTypedConstraint** sortedConstraints, - int numConstraints, - btIDebugDraw* debugDrawer, - btStackAlloc* stackAlloc, - btDispatcher* dispatcher) - :m_solverInfo(solverInfo), - m_solver(solver), - m_sortedConstraints(sortedConstraints), - m_numConstraints(numConstraints), - m_debugDrawer(debugDrawer), - m_stackAlloc(stackAlloc), - m_dispatcher(dispatcher) - { - - } - - - InplaceSolverIslandCallback& operator=(InplaceSolverIslandCallback& other) - { - btAssert(0); - (void)other; - return *this; - } - virtual void ProcessIsland(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifolds,int numManifolds, int islandId) - { - if (islandId<0) - { - if (numManifolds + m_numConstraints) - { - ///we don't split islands, so all constraints/contact manifolds/bodies are passed into the solver regardless the island id - m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,&m_sortedConstraints[0],m_numConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); - } - } else - { - //also add all non-contact constraints/joints for this island - btTypedConstraint** startConstraint = 0; - int numCurConstraints = 0; - int i; - - //find the first constraint for this island - for (i=0;i<m_numConstraints;i++) - { - if (btGetConstraintIslandId(m_sortedConstraints[i]) == islandId) - { - startConstraint = &m_sortedConstraints[i]; - break; - } - } - //count the number of constraints in this island - for (;i<m_numConstraints;i++) - { - if (btGetConstraintIslandId(m_sortedConstraints[i]) == islandId) - { - numCurConstraints++; - } - } - - if (m_solverInfo.m_minimumSolverBatchSize<=1) - { - ///only call solveGroup if there is some work: avoid virtual function call, its overhead can be excessive - if (numManifolds + numCurConstraints) - { - m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); - } - } else - { - - for (i=0;i<numBodies;i++) - m_bodies.push_back(bodies[i]); - for (i=0;i<numManifolds;i++) - m_manifolds.push_back(manifolds[i]); - for (i=0;i<numCurConstraints;i++) - m_constraints.push_back(startConstraint[i]); - if ((m_constraints.size()+m_manifolds.size())>m_solverInfo.m_minimumSolverBatchSize) - { - processConstraints(); - } else - { - //printf("deferred\n"); - } - } - } - } - void processConstraints() - { - if (m_manifolds.size() + m_constraints.size()>0) - { - m_solver->solveGroup( &m_bodies[0],m_bodies.size(), &m_manifolds[0], m_manifolds.size(), &m_constraints[0], m_constraints.size() ,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); - } - m_bodies.resize(0); - m_manifolds.resize(0); - m_constraints.resize(0); - - } - - }; - - - - //sorted version of all btTypedConstraint, based on islandId - btAlignedObjectArray<btTypedConstraint*> sortedConstraints; - sortedConstraints.resize( m_constraints.size()); + m_sortedConstraints.resize( m_constraints.size()); int i; for (i=0;i<getNumConstraints();i++) { - sortedConstraints[i] = m_constraints[i]; + m_sortedConstraints[i] = m_constraints[i]; } // btAssert(0); - sortedConstraints.quickSort(btSortConstraintOnIslandPredicate()); + m_sortedConstraints.quickSort(btSortConstraintOnIslandPredicate()); - btTypedConstraint** constraintsPtr = getNumConstraints() ? &sortedConstraints[0] : 0; - - InplaceSolverIslandCallback solverCallback( solverInfo, m_constraintSolver, constraintsPtr,sortedConstraints.size(), m_debugDrawer,m_stackAlloc,m_dispatcher1); + btTypedConstraint** constraintsPtr = getNumConstraints() ? &m_sortedConstraints[0] : 0; + m_solverIslandCallback->setup(&solverInfo,constraintsPtr,m_sortedConstraints.size(),getDebugDrawer()); m_constraintSolver->prepareSolve(getCollisionWorld()->getNumCollisionObjects(), getCollisionWorld()->getDispatcher()->getNumManifolds()); /// solve all the constraints for this island - m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld(),&solverCallback); + m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld(),m_solverIslandCallback); - solverCallback.processConstraints(); + m_solverIslandCallback->processConstraints(); m_constraintSolver->allSolved(solverInfo, m_debugDrawer, m_stackAlloc); } - - void btDiscreteDynamicsWorld::calculateSimulationIslands() { BT_PROFILE("calculateSimulationIslands"); @@ -717,18 +746,20 @@ void btDiscreteDynamicsWorld::calculateSimulationIslands() for (i=0;i< numConstraints ; i++ ) { btTypedConstraint* constraint = m_constraints[i]; - - const btRigidBody* colObj0 = &constraint->getRigidBodyA(); - const btRigidBody* colObj1 = &constraint->getRigidBodyB(); - - if (((colObj0) && (!(colObj0)->isStaticOrKinematicObject())) && - ((colObj1) && (!(colObj1)->isStaticOrKinematicObject()))) + if (constraint->isEnabled()) { - if (colObj0->isActive() || colObj1->isActive()) + const btRigidBody* colObj0 = &constraint->getRigidBodyA(); + const btRigidBody* colObj1 = &constraint->getRigidBodyB(); + + if (((colObj0) && (!(colObj0)->isStaticOrKinematicObject())) && + ((colObj1) && (!(colObj1)->isStaticOrKinematicObject()))) { + if (colObj0->isActive() || colObj1->isActive()) + { - getSimulationIslandManager()->getUnionFind().unite((colObj0)->getIslandTag(), - (colObj1)->getIslandTag()); + getSimulationIslandManager()->getUnionFind().unite((colObj0)->getIslandTag(), + (colObj1)->getIslandTag()); + } } } } @@ -745,12 +776,13 @@ void btDiscreteDynamicsWorld::calculateSimulationIslands() class btClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback { +public: + btCollisionObject* m_me; btScalar m_allowedPenetration; btOverlappingPairCache* m_pairCache; btDispatcher* m_dispatcher; - public: btClosestNotMeConvexResultCallback (btCollisionObject* me,const btVector3& fromA,const btVector3& toA,btOverlappingPairCache* pairCache,btDispatcher* dispatcher) : btCollisionWorld::ClosestConvexResultCallback(fromA,toA), @@ -797,6 +829,7 @@ public: //call needsResponse, see http://code.google.com/p/bullet/issues/detail?id=179 if (m_dispatcher->needsResponse(m_me,otherObj)) { +#if 0 ///don't do CCD when there are already contact points (touching contact/penetration) btAlignedObjectArray<btPersistentManifold*> manifoldArray; btBroadphasePair* collisionPair = m_pairCache->findPair(m_me->getBroadphaseHandle(),proxy0); @@ -814,8 +847,11 @@ public: } } } +#endif + return true; } - return true; + + return false; } @@ -824,7 +860,6 @@ public: ///internal debugging variable. this value shouldn't be too high int gNumClampedCcdMotions=0; -//#include "stdio.h" void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep) { BT_PROFILE("integrateTransforms"); @@ -836,34 +871,93 @@ void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep) if (body->isActive() && (!body->isStaticOrKinematicObject())) { + body->predictIntegratedTransform(timeStep, predictedTrans); + btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); - if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion) + + + if (getDispatchInfo().m_useContinuous && body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion) { BT_PROFILE("CCD motion clamping"); if (body->getCollisionShape()->isConvex()) { gNumClampedCcdMotions++; - +#ifdef USE_STATIC_ONLY + class StaticOnlyCallback : public btClosestNotMeConvexResultCallback + { + public: + + StaticOnlyCallback (btCollisionObject* me,const btVector3& fromA,const btVector3& toA,btOverlappingPairCache* pairCache,btDispatcher* dispatcher) : + btClosestNotMeConvexResultCallback(me,fromA,toA,pairCache,dispatcher) + { + } + + virtual bool needsCollision(btBroadphaseProxy* proxy0) const + { + btCollisionObject* otherObj = (btCollisionObject*) proxy0->m_clientObject; + if (!otherObj->isStaticOrKinematicObject()) + return false; + return btClosestNotMeConvexResultCallback::needsCollision(proxy0); + } + }; + + StaticOnlyCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher()); +#else btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher()); +#endif //btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); + sweepResults.m_allowedPenetration=getDispatchInfo().m_allowedCcdPenetration; sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup; sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask; + btTransform modifiedPredictedTrans = predictedTrans; + modifiedPredictedTrans.setBasis(body->getWorldTransform().getBasis()); - convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults); + convexSweepTest(&tmpSphere,body->getWorldTransform(),modifiedPredictedTrans,sweepResults); if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f)) { + + //printf("clamped integration to hit fraction = %f\n",fraction); body->setHitFraction(sweepResults.m_closestHitFraction); body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans); body->setHitFraction(0.f); -// printf("clamped integration to hit fraction = %f\n",fraction); + body->proceedToTransform( predictedTrans); + +#if 0 + btVector3 linVel = body->getLinearVelocity(); + + btScalar maxSpeed = body->getCcdMotionThreshold()/getSolverInfo().m_timeStep; + btScalar maxSpeedSqr = maxSpeed*maxSpeed; + if (linVel.length2()>maxSpeedSqr) + { + linVel.normalize(); + linVel*= maxSpeed; + body->setLinearVelocity(linVel); + btScalar ms2 = body->getLinearVelocity().length2(); + body->predictIntegratedTransform(timeStep, predictedTrans); + + btScalar sm2 = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); + btScalar smt = body->getCcdSquareMotionThreshold(); + printf("sm2=%f\n",sm2); + } +#else + //response between two dynamic objects without friction, assuming 0 penetration depth + btScalar appliedImpulse = 0.f; + btScalar depth = 0.f; + appliedImpulse = resolveSingleCollision(body,sweepResults.m_hitCollisionObject,sweepResults.m_hitPointWorld,sweepResults.m_hitNormalWorld,getSolverInfo(), depth); + + +#endif + + continue; } } } + body->proceedToTransform( predictedTrans); } } @@ -873,6 +967,7 @@ void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep) + void btDiscreteDynamicsWorld::predictUnconstraintMotion(btScalar timeStep) { BT_PROFILE("predictUnconstraintMotion"); diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h index df47c29044f..23a38dd2a12 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h @@ -27,6 +27,8 @@ class btTypedConstraint; class btActionInterface; class btIDebugDraw; +struct InplaceSolverIslandCallback; + #include "LinearMath/btAlignedObjectArray.h" @@ -35,6 +37,9 @@ class btIDebugDraw; class btDiscreteDynamicsWorld : public btDynamicsWorld { protected: + + btAlignedObjectArray<btTypedConstraint*> m_sortedConstraints; + InplaceSolverIslandCallback* m_solverIslandCallback; btConstraintSolver* m_constraintSolver; diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h index 105317920ae..6b0093371b8 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btDynamicsWorld.h @@ -32,7 +32,8 @@ enum btDynamicsWorldType { BT_SIMPLE_DYNAMICS_WORLD=1, BT_DISCRETE_DYNAMICS_WORLD=2, - BT_CONTINUOUS_DYNAMICS_WORLD=3 + BT_CONTINUOUS_DYNAMICS_WORLD=3, + BT_SOFT_RIGID_DYNAMICS_WORLD=4 }; ///The btDynamicsWorld is the interface class for several dynamics implementation, basic, discrete, parallel, and continuous etc. diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp index aefb26a1be2..911b5072394 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.cpp @@ -286,7 +286,7 @@ btQuaternion btRigidBody::getOrientation() const void btRigidBody::setCenterOfMassTransform(const btTransform& xform) { - if (isStaticOrKinematicObject()) + if (isKinematicObject()) { m_interpolationWorldTransform = m_worldTransform; } else @@ -309,8 +309,9 @@ bool btRigidBody::checkCollideWithOverride(btCollisionObject* co) for (int i = 0; i < m_constraintRefs.size(); ++i) { btTypedConstraint* c = m_constraintRefs[i]; - if (&c->getRigidBodyA() == otherRb || &c->getRigidBodyB() == otherRb) - return false; + if (c->isEnabled()) + if (&c->getRigidBodyA() == otherRb || &c->getRigidBodyB() == otherRb) + return false; } return true; diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h index 5a7ba97ccbc..7c121e6df13 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef RIGIDBODY_H -#define RIGIDBODY_H +#ifndef BT_RIGIDBODY_H +#define BT_RIGIDBODY_H #include "LinearMath/btAlignedObjectArray.h" #include "LinearMath/btTransform.h" @@ -687,5 +687,5 @@ struct btRigidBodyDoubleData -#endif +#endif //BT_RIGIDBODY_H diff --git a/extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h b/extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h index 07a727e2efe..d48d2e39c4d 100644 --- a/extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h +++ b/extern/bullet2/src/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h @@ -23,7 +23,7 @@ class btOverlappingPairCache; class btConstraintSolver; ///The btSimpleDynamicsWorld serves as unit-test and to verify more complicated and optimized dynamics worlds. -///Please use btDiscreteDynamicsWorld instead (or btContinuousDynamicsWorld once it is finished). +///Please use btDiscreteDynamicsWorld instead class btSimpleDynamicsWorld : public btDynamicsWorld { protected: diff --git a/extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.h b/extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.h index ac42f1313be..f59555f94d2 100644 --- a/extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.h +++ b/extern/bullet2/src/BulletDynamics/Vehicle/btRaycastVehicle.h @@ -8,8 +8,8 @@ * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ -#ifndef RAYCASTVEHICLE_H -#define RAYCASTVEHICLE_H +#ifndef BT_RAYCASTVEHICLE_H +#define BT_RAYCASTVEHICLE_H #include "BulletDynamics/Dynamics/btRigidBody.h" #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h" @@ -232,5 +232,5 @@ public: }; -#endif //RAYCASTVEHICLE_H +#endif //BT_RAYCASTVEHICLE_H diff --git a/extern/bullet2/src/BulletDynamics/Vehicle/btVehicleRaycaster.h b/extern/bullet2/src/BulletDynamics/Vehicle/btVehicleRaycaster.h index 5112ce6d420..3cc909c6530 100644 --- a/extern/bullet2/src/BulletDynamics/Vehicle/btVehicleRaycaster.h +++ b/extern/bullet2/src/BulletDynamics/Vehicle/btVehicleRaycaster.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/ + * Copyright (c) 2005 Erwin Coumans http://bulletphysics.org * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, @@ -8,8 +8,8 @@ * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ -#ifndef VEHICLE_RAYCASTER_H -#define VEHICLE_RAYCASTER_H +#ifndef BT_VEHICLE_RAYCASTER_H +#define BT_VEHICLE_RAYCASTER_H #include "LinearMath/btVector3.h" @@ -31,5 +31,5 @@ virtual ~btVehicleRaycaster() }; -#endif //VEHICLE_RAYCASTER_H +#endif //BT_VEHICLE_RAYCASTER_H diff --git a/extern/bullet2/src/BulletDynamics/Vehicle/btWheelInfo.h b/extern/bullet2/src/BulletDynamics/Vehicle/btWheelInfo.h index b74f8c80acb..f916053ecac 100644 --- a/extern/bullet2/src/BulletDynamics/Vehicle/btWheelInfo.h +++ b/extern/bullet2/src/BulletDynamics/Vehicle/btWheelInfo.h @@ -8,8 +8,8 @@ * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ -#ifndef WHEEL_INFO_H -#define WHEEL_INFO_H +#ifndef BT_WHEEL_INFO_H +#define BT_WHEEL_INFO_H #include "LinearMath/btVector3.h" #include "LinearMath/btTransform.h" @@ -115,5 +115,5 @@ struct btWheelInfo }; -#endif //WHEEL_INFO_H +#endif //BT_WHEEL_INFO_H diff --git a/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.cpp b/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.cpp index c876ebf1fd6..d1435b65cda 100644 --- a/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.cpp +++ b/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.cpp @@ -35,7 +35,7 @@ btDefaultSoftBodySolver::~btDefaultSoftBodySolver() } // In this case the data is already in the soft bodies so there is no need for us to do anything -void btDefaultSoftBodySolver::copyBackToSoftBodies() +void btDefaultSoftBodySolver::copyBackToSoftBodies(bool bMove) { } diff --git a/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.h b/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.h index 8e7db3daf98..7d9092ce5b9 100644 --- a/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.h +++ b/extern/bullet2/src/BulletSoftBody/btDefaultSoftBodySolver.h @@ -46,7 +46,7 @@ public: virtual void optimize( btAlignedObjectArray< btSoftBody * > &softBodies,bool forceUpdate=false ); - virtual void copyBackToSoftBodies(); + virtual void copyBackToSoftBodies(bool bMove = true); virtual void solveConstraints( float solverdt ); diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBody.cpp b/extern/bullet2/src/BulletSoftBody/btSoftBody.cpp index 0d19fd193e7..9c06841801c 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBody.cpp +++ b/extern/bullet2/src/BulletSoftBody/btSoftBody.cpp @@ -19,9 +19,10 @@ subject to the following restrictions: #include "btSoftBodyData.h" #include "LinearMath/btSerializer.h" + // btSoftBody::btSoftBody(btSoftBodyWorldInfo* worldInfo,int node_count, const btVector3* x, const btScalar* m) -:m_worldInfo(worldInfo),m_softBodySolver(0) +:m_softBodySolver(0),m_worldInfo(worldInfo) { /* Init */ initDefaults(); @@ -357,14 +358,14 @@ void btSoftBody::appendTetra(int node0, // -void btSoftBody::appendAnchor(int node,btRigidBody* body, bool disableCollisionBetweenLinkedBodies) +void btSoftBody::appendAnchor(int node,btRigidBody* body, bool disableCollisionBetweenLinkedBodies,btScalar influence) { btVector3 local = body->getWorldTransform().inverse()*m_nodes[node].m_x; - appendAnchor(node,body,local,disableCollisionBetweenLinkedBodies); + appendAnchor(node,body,local,disableCollisionBetweenLinkedBodies,influence); } // -void btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies) +void btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies,btScalar influence) { if (disableCollisionBetweenLinkedBodies) { @@ -379,6 +380,7 @@ void btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& loc a.m_body = body; a.m_local = localPivot; a.m_node->m_battach = 1; + a.m_influence = influence; m_anchors.push_back(a); } @@ -451,6 +453,167 @@ void btSoftBody::addForce(const btVector3& force,int node) } } +void btSoftBody::addAeroForceToNode(const btVector3& windVelocity,int nodeIndex) +{ + btAssert(nodeIndex >= 0 && nodeIndex < m_nodes.size()); + + const btScalar dt = m_sst.sdt; + const btScalar kLF = m_cfg.kLF; + const btScalar kDG = m_cfg.kDG; + const btScalar kPR = m_cfg.kPR; + const btScalar kVC = m_cfg.kVC; + const bool as_lift = kLF>0; + const bool as_drag = kDG>0; + const bool as_aero = as_lift || as_drag; + const bool as_vaero = as_aero && (m_cfg.aeromodel < btSoftBody::eAeroModel::F_TwoSided); + + Node& n = m_nodes[nodeIndex]; + + if( n.m_im>0 ) + { + btSoftBody::sMedium medium; + + EvaluateMedium(m_worldInfo, n.m_x, medium); + medium.m_velocity = windVelocity; + medium.m_density = m_worldInfo->air_density; + + /* Aerodynamics */ + if(as_vaero) + { + const btVector3 rel_v = n.m_v - medium.m_velocity; + const btScalar rel_v_len = rel_v.length(); + const btScalar rel_v2 = rel_v.length2(); + + if(rel_v2>SIMD_EPSILON) + { + const btVector3 rel_v_nrm = rel_v.normalized(); + btVector3 nrm = n.m_n; + + if (m_cfg.aeromodel == btSoftBody::eAeroModel::V_TwoSidedLiftDrag) + { + nrm *= (btScalar)( (btDot(nrm,rel_v) < 0) ? -1 : +1); + btVector3 fDrag(0, 0, 0); + btVector3 fLift(0, 0, 0); + + btScalar n_dot_v = nrm.dot(rel_v_nrm); + btScalar tri_area = 0.5f * n.m_area; + + fDrag = 0.5f * kDG * medium.m_density * rel_v2 * tri_area * n_dot_v * (-rel_v_nrm); + + // Check angle of attack + // cos(10º) = 0.98480 + if ( 0 < n_dot_v && n_dot_v < 0.98480f) + fLift = 0.5f * kLF * medium.m_density * rel_v_len * tri_area * btSqrt(1.0f-n_dot_v*n_dot_v) * (nrm.cross(rel_v_nrm).cross(rel_v_nrm)); + + n.m_f += fDrag; + n.m_f += fLift; + } + else if (m_cfg.aeromodel == btSoftBody::eAeroModel::V_Point || m_cfg.aeromodel == btSoftBody::eAeroModel::V_OneSided || m_cfg.aeromodel == btSoftBody::eAeroModel::V_TwoSided) + { + if (btSoftBody::eAeroModel::V_TwoSided) + nrm *= (btScalar)( (btDot(nrm,rel_v) < 0) ? -1 : +1); + + const btScalar dvn = btDot(rel_v,nrm); + /* Compute forces */ + if(dvn>0) + { + btVector3 force(0,0,0); + const btScalar c0 = n.m_area * dvn * rel_v2/2; + const btScalar c1 = c0 * medium.m_density; + force += nrm*(-c1*kLF); + force += rel_v.normalized() * (-c1 * kDG); + ApplyClampedForce(n, force, dt); + } + } + } + } + } +} + +void btSoftBody::addAeroForceToFace(const btVector3& windVelocity,int faceIndex) +{ + const btScalar dt = m_sst.sdt; + const btScalar kLF = m_cfg.kLF; + const btScalar kDG = m_cfg.kDG; + const btScalar kPR = m_cfg.kPR; + const btScalar kVC = m_cfg.kVC; + const bool as_lift = kLF>0; + const bool as_drag = kDG>0; + const bool as_aero = as_lift || as_drag; + const bool as_faero = as_aero && (m_cfg.aeromodel >= btSoftBody::eAeroModel::F_TwoSided); + + if(as_faero) + { + btSoftBody::Face& f=m_faces[faceIndex]; + + btSoftBody::sMedium medium; + + const btVector3 v=(f.m_n[0]->m_v+f.m_n[1]->m_v+f.m_n[2]->m_v)/3; + const btVector3 x=(f.m_n[0]->m_x+f.m_n[1]->m_x+f.m_n[2]->m_x)/3; + EvaluateMedium(m_worldInfo,x,medium); + medium.m_velocity = windVelocity; + medium.m_density = m_worldInfo->air_density; + const btVector3 rel_v=v-medium.m_velocity; + const btScalar rel_v_len = rel_v.length(); + const btScalar rel_v2=rel_v.length2(); + + if(rel_v2>SIMD_EPSILON) + { + const btVector3 rel_v_nrm = rel_v.normalized(); + btVector3 nrm = f.m_normal; + + if (m_cfg.aeromodel == btSoftBody::eAeroModel::F_TwoSidedLiftDrag) + { + nrm *= (btScalar)( (btDot(nrm,rel_v) < 0) ? -1 : +1); + + btVector3 fDrag(0, 0, 0); + btVector3 fLift(0, 0, 0); + + btScalar n_dot_v = nrm.dot(rel_v_nrm); + btScalar tri_area = 0.5f * f.m_ra; + + fDrag = 0.5f * kDG * medium.m_density * rel_v2 * tri_area * n_dot_v * (-rel_v_nrm); + + // Check angle of attack + // cos(10º) = 0.98480 + if ( 0 < n_dot_v && n_dot_v < 0.98480f) + fLift = 0.5f * kLF * medium.m_density * rel_v_len * tri_area * btSqrt(1.0f-n_dot_v*n_dot_v) * (nrm.cross(rel_v_nrm).cross(rel_v_nrm)); + + fDrag /= 3; + fLift /= 3; + + for(int j=0;j<3;++j) + { + if (f.m_n[j]->m_im>0) + { + f.m_n[j]->m_f += fDrag; + f.m_n[j]->m_f += fLift; + } + } + } + else if (m_cfg.aeromodel == btSoftBody::eAeroModel::F_OneSided || m_cfg.aeromodel == btSoftBody::eAeroModel::F_TwoSided) + { + if (btSoftBody::eAeroModel::F_TwoSided) + nrm *= (btScalar)( (btDot(nrm,rel_v) < 0) ? -1 : +1); + + const btScalar dvn=btDot(rel_v,nrm); + /* Compute forces */ + if(dvn>0) + { + btVector3 force(0,0,0); + const btScalar c0 = f.m_ra*dvn*rel_v2; + const btScalar c1 = c0*medium.m_density; + force += nrm*(-c1*kLF); + force += rel_v.normalized()*(-c1*kDG); + force /= 3; + for(int j=0;j<3;++j) ApplyClampedForce(*f.m_n[j],force,dt); + } + } + } + } + +} + // void btSoftBody::addVelocity(const btVector3& velocity) { @@ -1820,7 +1983,7 @@ btScalar btSoftBody::RayFromToCaster::rayFromToTriangle( const btVector3& rayF void btSoftBody::pointersToIndices() { #define PTR2IDX(_p_,_b_) reinterpret_cast<btSoftBody::Node*>((_p_)-(_b_)) - btSoftBody::Node* base=&m_nodes[0]; + btSoftBody::Node* base=m_nodes.size() ? &m_nodes[0] : 0; int i,ni; for(i=0,ni=m_nodes.size();i<ni;++i) @@ -1864,7 +2027,7 @@ void btSoftBody::indicesToPointers(const int* map) { #define IDX2PTR(_p_,_b_) map?(&(_b_)[map[(((char*)_p_)-(char*)0)]]): \ (&(_b_)[(((char*)_p_)-(char*)0)]) - btSoftBody::Node* base=&m_nodes[0]; + btSoftBody::Node* base=m_nodes.size() ? &m_nodes[0]:0; int i,ni; for(i=0,ni=m_nodes.size();i<ni;++i) @@ -1908,11 +2071,12 @@ int btSoftBody::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const { int cnt=0; + btVector3 dir = rayTo-rayFrom; + + if(bcountonly||m_fdbvt.empty()) {/* Full search */ - btVector3 dir = rayTo-rayFrom; - dir.normalize(); - + for(int i=0,ni=m_faces.size();i<ni;++i) { const btSoftBody::Face& f=m_faces[i]; @@ -1947,6 +2111,37 @@ int btSoftBody::rayTest(const btVector3& rayFrom,const btVector3& rayTo, cnt=1; } } + + for (int i=0;i<m_tetras.size();i++) + { + const btSoftBody::Tetra& tet = m_tetras[i]; + int tetfaces[4][3] = {{0,1,2},{0,1,3},{1,2,3},{0,2,3}}; + for (int f=0;f<4;f++) + { + + int index0=tetfaces[f][0]; + int index1=tetfaces[f][1]; + int index2=tetfaces[f][2]; + btVector3 v0=tet.m_n[index0]->m_x; + btVector3 v1=tet.m_n[index1]->m_x; + btVector3 v2=tet.m_n[index2]->m_x; + + + const btScalar t=RayFromToCaster::rayFromToTriangle( rayFrom,rayTo,dir, + v0,v1,v2, + mint); + if(t>0) + { + ++cnt; + if(!bcountonly) + { + feature=btSoftBody::eFeature::Tetra; + index=i; + mint=t; + } + } + } + } return(cnt); } @@ -2660,44 +2855,8 @@ void btSoftBody::applyForces() { if(use_medium) { - EvaluateMedium(m_worldInfo, n.m_x, medium); - medium.m_velocity = m_windVelocity; - medium.m_density = m_worldInfo->air_density; - /* Aerodynamics */ - if(as_vaero) - { - const btVector3 rel_v = n.m_v - medium.m_velocity; - const btScalar rel_v2 = rel_v.length2(); - if(rel_v2>SIMD_EPSILON) - { - btVector3 nrm = n.m_n; - /* Setup normal */ - switch(m_cfg.aeromodel) - { - case btSoftBody::eAeroModel::V_Point: - nrm = NormalizeAny(rel_v); - break; - case btSoftBody::eAeroModel::V_TwoSided: - nrm *= (btScalar)( (btDot(nrm,rel_v) < 0) ? -1 : +1); - break; - default: - { - } - } - const btScalar dvn = btDot(rel_v,nrm); - /* Compute forces */ - if(dvn>0) - { - btVector3 force(0,0,0); - const btScalar c0 = n.m_area * dvn * rel_v2/2; - const btScalar c1 = c0 * medium.m_density; - force += nrm*(-c1*kLF); - force += rel_v.normalized() * (-c1 * kDG); - ApplyClampedForce(n, force, dt); - } - } - } + addAeroForceToNode(m_windVelocity, i); } /* Pressure */ if(as_pressure) @@ -2711,43 +2870,14 @@ void btSoftBody::applyForces() } } } + /* Per face forces */ for(i=0,ni=m_faces.size();i<ni;++i) { btSoftBody::Face& f=m_faces[i]; - if(as_faero) - { - const btVector3 v=(f.m_n[0]->m_v+f.m_n[1]->m_v+f.m_n[2]->m_v)/3; - const btVector3 x=(f.m_n[0]->m_x+f.m_n[1]->m_x+f.m_n[2]->m_x)/3; - EvaluateMedium(m_worldInfo,x,medium); - const btVector3 rel_v=v-medium.m_velocity; - const btScalar rel_v2=rel_v.length2(); - if(rel_v2>SIMD_EPSILON) - { - btVector3 nrm=f.m_normal; - /* Setup normal */ - switch(m_cfg.aeromodel) - { - case btSoftBody::eAeroModel::F_TwoSided: - nrm*=(btScalar)(btDot(nrm,rel_v)<0?-1:+1);break; - default: - { - } - } - const btScalar dvn=btDot(rel_v,nrm); - /* Compute forces */ - if(dvn>0) - { - btVector3 force(0,0,0); - const btScalar c0 = f.m_ra*dvn*rel_v2; - const btScalar c1 = c0*medium.m_density; - force += nrm*(-c1*kLF); - force += rel_v.normalized()*(-c1*kDG); - force /= 3; - for(int j=0;j<3;++j) ApplyClampedForce(*f.m_n[j],force,dt); - } - } - } + + /* Aerodynamics */ + addAeroForceToFace(m_windVelocity, i); } } @@ -2765,7 +2895,7 @@ void btSoftBody::PSolve_Anchors(btSoftBody* psb,btScalar kst,btScalar ti) const btVector3 va=a.m_body->getVelocityInLocalPoint(a.m_c1)*dt; const btVector3 vb=n.m_x-n.m_q; const btVector3 vr=(va-vb)+(wa-n.m_x)*kAHR; - const btVector3 impulse=a.m_c0*vr; + const btVector3 impulse=a.m_c0*vr*a.m_influence; n.m_x+=impulse*a.m_c2; a.m_body->applyImpulse(-impulse,a.m_c1); } @@ -3196,7 +3326,7 @@ const char* btSoftBody::serialize(void* dataBuffer, class btSerializer* serializ sbd->m_config.m_softRigidClusterImpulseSplit = m_cfg.kSR_SPLT_CL; sbd->m_config.m_softKineticClusterImpulseSplit = m_cfg.kSK_SPLT_CL; sbd->m_config.m_softSoftClusterImpulseSplit = m_cfg.kSS_SPLT_CL; - + //pose for shape matching { sbd->m_pose = (SoftBodyPoseData*)serializer->getUniquePointer((void*)&m_pose); diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBody.h b/extern/bullet2/src/BulletSoftBody/btSoftBody.h index ad8678f28b2..ba589486f26 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBody.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftBody.h @@ -80,11 +80,13 @@ public: ///eAeroModel struct eAeroModel { enum _ { - V_Point, ///Vertex normals are oriented toward velocity - V_TwoSided, ///Vertex normals are fliped to match velocity - V_OneSided, ///Vertex normals are taken as it is - F_TwoSided, ///Face normals are fliped to match velocity - F_OneSided, ///Face normals are taken as it is + V_Point, ///Vertex normals are oriented toward velocity + V_TwoSided, ///Vertex normals are flipped to match velocity + V_TwoSidedLiftDrag, ///Vertex normals are flipped to match velocity and lift and drag forces are applied + V_OneSided, ///Vertex normals are taken as it is + F_TwoSided, ///Face normals are flipped to match velocity + F_TwoSidedLiftDrag, ///Face normals are flipped to match velocity and lift and drag forces are applied + F_OneSided, ///Face normals are taken as it is END };}; @@ -117,6 +119,7 @@ public: Node, Link, Face, + Tetra, END };}; @@ -282,6 +285,7 @@ public: Node* m_node; // Node pointer btVector3 m_local; // Anchor position in body space btRigidBody* m_body; // Body + btScalar m_influence; btMatrix3x3 m_c0; // Impulse matrix btVector3 m_c1; // Relative anchor btScalar m_c2; // ima*dt @@ -752,8 +756,8 @@ public: /* Append anchor */ void appendAnchor( int node, - btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false); - void appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false); + btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1); + void appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1); /* Append linear joint */ void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1); void appendLinearJoint(const LJoint::Specs& specs,Body body=Body()); @@ -767,6 +771,12 @@ public: /* Add force (or gravity) to a node of the body */ void addForce( const btVector3& force, int node); + /* Add aero force to a node of the body */ + void addAeroForceToNode(const btVector3& windVelocity,int nodeIndex); + + /* Add aero force to a face of the body */ + void addAeroForceToFace(const btVector3& windVelocity,int faceIndex); + /* Add velocity to the entire body */ void addVelocity( const btVector3& velocity); diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp b/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp index 04ee7ea77cf..d99be3b8138 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp +++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.cpp @@ -95,7 +95,7 @@ void btSoftBodyTriangleCallback::processTriangle(btVector3* triangle,int partId, ci.m_dispatcher1 = m_dispatcher; ///debug drawing of the overlapping triangles - if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe) + if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe)) { btVector3 color(1,1,0); btTransform& tr = ob->getWorldTransform(); diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h b/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h index f311419d4a8..8a09fff2a37 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyConcaveCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H -#define SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H +#ifndef BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H +#define BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btDispatcher.h" @@ -152,4 +152,4 @@ public: }; -#endif //SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H +#endif //BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp b/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp index 1a271066497..0fb3560e94c 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp +++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.cpp @@ -19,6 +19,8 @@ subject to the following restrictions: #include <string.h> #include "btSoftBodyHelpers.h" #include "LinearMath/btConvexHull.h" +#include "LinearMath/btConvexHullComputer.h" + // static void drawVertex( btIDebugDraw* idraw, @@ -183,6 +185,35 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb, { vertices[j]=psb->m_clusters[i]->m_nodes[j]->m_x; } +#define USE_NEW_CONVEX_HULL_COMPUTER +#ifdef USE_NEW_CONVEX_HULL_COMPUTER + btConvexHullComputer computer; + int stride = sizeof(btVector3); + int count = vertices.size(); + btScalar shrink=0.f; + btScalar shrinkClamp=0.f; + computer.compute(&vertices[0].getX(),stride,count,shrink,shrinkClamp); + for (int i=0;i<computer.faces.size();i++) + { + + int face = computer.faces[i]; + //printf("face=%d\n",face); + const btConvexHullComputer::Edge* firstEdge = &computer.edges[face]; + const btConvexHullComputer::Edge* edge = firstEdge->getNextEdgeOfFace(); + + int v0 = firstEdge->getSourceVertex(); + int v1 = firstEdge->getTargetVertex(); + while (edge!=firstEdge) + { + int v2 = edge->getTargetVertex(); + idraw->drawTriangle(computer.vertices[v0],computer.vertices[v1],computer.vertices[v2],color,1); + edge = edge->getNextEdgeOfFace(); + v0=v1; + v1=v2; + }; + } +#else + HullDesc hdsc(QF_TRIANGLES,vertices.size(),&vertices[0]); HullResult hres; HullLibrary hlib; @@ -201,6 +232,8 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb, color,1); } hlib.ReleaseResult(hres); +#endif + } /* Velocities */ #if 0 @@ -296,7 +329,7 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb, { const btScalar scl=(btScalar)0.8; const btScalar alp=(btScalar)1; - const btVector3 col((btScalar)0.7,(btScalar)0.7,(btScalar)0.7); + const btVector3 col((btScalar)0.3,(btScalar)0.3,(btScalar)0.7); for(int i=0;i<psb->m_tetras.size();++i) { const btSoftBody::Tetra& t=psb->m_tetras[i]; diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.h b/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.h index 49b1f0bbce8..620a52fe394 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyHelpers.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SOFT_BODY_HELPERS_H -#define SOFT_BODY_HELPERS_H +#ifndef BT_SOFT_BODY_HELPERS_H +#define BT_SOFT_BODY_HELPERS_H #include "btSoftBody.h" @@ -140,4 +140,4 @@ struct btSoftBodyHelpers }; -#endif //SOFT_BODY_HELPERS_H +#endif //BT_SOFT_BODY_HELPERS_H diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h b/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h index 885571069d0..5ef8db19396 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftBodyInternals.h @@ -70,7 +70,7 @@ public: ///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t. virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const { - /* t should be identity, but better be safe than...fast? */ + /* t is usually identity, except when colliding against btCompoundShape. See Issue 512 */ const btVector3 mins=m_body->m_bounds[0]; const btVector3 maxs=m_body->m_bounds[1]; const btVector3 crns[]={t*btVector3(mins.x(),mins.y(),mins.z()), diff --git a/extern/bullet2/src/BulletSoftBody/btSoftBodySolvers.h b/extern/bullet2/src/BulletSoftBody/btSoftBodySolvers.h index 440084c5f7b..2fcd8b67616 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftBodySolvers.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftBodySolvers.h @@ -73,7 +73,7 @@ public: virtual void optimize( btAlignedObjectArray< btSoftBody * > &softBodies , bool forceUpdate=false) = 0; /** Copy necessary data back to the original soft body source objects. */ - virtual void copyBackToSoftBodies() = 0; + virtual void copyBackToSoftBodies(bool bMove = true) = 0; /** Predict motion of soft bodies into next timestep */ virtual void predictMotion( float solverdt ) = 0; diff --git a/extern/bullet2/src/BulletSoftBody/btSoftRigidCollisionAlgorithm.h b/extern/bullet2/src/BulletSoftBody/btSoftRigidCollisionAlgorithm.h index adc3844e363..7658e3c2252 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftRigidCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftRigidCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SOFT_RIGID_COLLISION_ALGORITHM_H -#define SOFT_RIGID_COLLISION_ALGORITHM_H +#ifndef BT_SOFT_RIGID_COLLISION_ALGORITHM_H +#define BT_SOFT_RIGID_COLLISION_ALGORITHM_H #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -70,6 +70,6 @@ public: }; -#endif //SOFT_RIGID_COLLISION_ALGORITHM_H +#endif //BT_SOFT_RIGID_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp b/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp index 1b9b5e392a1..8f4be231c13 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp +++ b/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.cpp @@ -165,7 +165,7 @@ void btSoftRigidDynamicsWorld::debugDrawWorld() for ( i=0;i<this->m_softBodies.size();i++) { btSoftBody* psb=(btSoftBody*)this->m_softBodies[i]; - if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe)) + if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe))) { btSoftBodyHelpers::DrawFrame(psb,m_debugDrawer); btSoftBodyHelpers::Draw(psb,m_debugDrawer,m_drawFlags); @@ -300,12 +300,19 @@ void btSoftRigidDynamicsWorld::rayTestSingle(const btTransform& rayFromTrans,con shapeInfo.m_shapePart = 0; shapeInfo.m_triangleIndex = softResult.index; // get the normal - btVector3 normal = softBody->m_faces[softResult.index].m_normal; btVector3 rayDir = rayToTrans.getOrigin() - rayFromTrans.getOrigin(); - if (normal.dot(rayDir) > 0) { - // normal always point toward origin of the ray - normal = -normal; + btVector3 normal=-rayDir; + normal.normalize(); + + if (softResult.feature == btSoftBody::eFeature::Face) + { + normal = softBody->m_faces[softResult.index].m_normal; + if (normal.dot(rayDir) > 0) { + // normal always point toward origin of the ray + normal = -normal; + } } + btCollisionWorld::LocalRayResult rayResult (collisionObject, &shapeInfo, diff --git a/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.h b/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.h index 7d8d0cb7daa..3e0efafd6c7 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftRigidDynamicsWorld.h @@ -73,6 +73,10 @@ public: return m_sbi; } + virtual btDynamicsWorldType getWorldType() const + { + return BT_SOFT_RIGID_DYNAMICS_WORLD; + } btSoftBodyArray& getSoftBodyArray() { diff --git a/extern/bullet2/src/BulletSoftBody/btSoftSoftCollisionAlgorithm.h b/extern/bullet2/src/BulletSoftBody/btSoftSoftCollisionAlgorithm.h index 1b34e0af60f..92d683c1dc8 100644 --- a/extern/bullet2/src/BulletSoftBody/btSoftSoftCollisionAlgorithm.h +++ b/extern/bullet2/src/BulletSoftBody/btSoftSoftCollisionAlgorithm.h @@ -13,8 +13,8 @@ subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -#ifndef SOFT_SOFT_COLLISION_ALGORITHM_H -#define SOFT_SOFT_COLLISION_ALGORITHM_H +#ifndef BT_SOFT_SOFT_COLLISION_ALGORITHM_H +#define BT_SOFT_SOFT_COLLISION_ALGORITHM_H #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" @@ -64,6 +64,6 @@ public: }; -#endif //SOFT_SOFT_COLLISION_ALGORITHM_H +#endif //BT_SOFT_SOFT_COLLISION_ALGORITHM_H diff --git a/extern/bullet2/src/BulletSoftBody/btSparseSDF.h b/extern/bullet2/src/BulletSoftBody/btSparseSDF.h index cc4266732ae..90a26cdf7e3 100644 --- a/extern/bullet2/src/BulletSoftBody/btSparseSDF.h +++ b/extern/bullet2/src/BulletSoftBody/btSparseSDF.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ ///btSparseSdf implementation by Nathanael Presson -#ifndef _14F9D17F_EAE8_4aba_B41C_292DB2AA70F3_ -#define _14F9D17F_EAE8_4aba_B41C_292DB2AA70F3_ +#ifndef BT_SPARSE_SDF_H +#define BT_SPARSE_SDF_H #include "BulletCollision/CollisionDispatch/btCollisionObject.h" #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h" @@ -303,4 +303,4 @@ struct btSparseSdf }; -#endif +#endif //BT_SPARSE_SDF_H diff --git a/extern/bullet2/src/LinearMath/btAabbUtil2.h b/extern/bullet2/src/LinearMath/btAabbUtil2.h index 532ce1bf633..42b721dea22 100644 --- a/extern/bullet2/src/LinearMath/btAabbUtil2.h +++ b/extern/bullet2/src/LinearMath/btAabbUtil2.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef AABB_UTIL2 -#define AABB_UTIL2 +#ifndef BT_AABB_UTIL2 +#define BT_AABB_UTIL2 #include "btTransform.h" #include "btVector3.h" @@ -231,6 +231,6 @@ SIMD_FORCE_INLINE void btTransformAabb(const btVector3& localAabbMin,const btVec } #endif //USE_BANCHLESS -#endif +#endif //BT_AABB_UTIL2 diff --git a/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp b/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp index 189b759d237..c4c0ceb2ed2 100644 --- a/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp +++ b/extern/bullet2/src/LinearMath/btAlignedAllocator.cpp @@ -58,16 +58,18 @@ static inline void btAlignedFreeDefault(void *ptr) free(ptr); } #else + + + + + static inline void *btAlignedAllocDefault(size_t size, int alignment) { void *ret; char *real; - unsigned long offset; - real = (char *)sAllocFunc(size + sizeof(void *) + (alignment-1)); if (real) { - offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1); - ret = (void *)((real + sizeof(void *)) + offset); + ret = btAlignPointer(real + sizeof(void *),alignment); *((void **)(ret)-1) = (void *)(real); } else { ret = (void *)(real); @@ -110,7 +112,6 @@ void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filen { void *ret; char *real; - unsigned long offset; gTotalBytesAlignedAllocs += size; gNumAlignedAllocs++; @@ -118,9 +119,7 @@ void* btAlignedAllocInternal (size_t size, int alignment,int line,char* filen real = (char *)sAllocFunc(size + 2*sizeof(void *) + (alignment-1)); if (real) { - offset = (alignment - (unsigned long)(real + 2*sizeof(void *))) & -(alignment-1); - ret = (void *)((real + 2*sizeof(void *)) + offset); + ret = (void*) btAlignPointer((real + 2*sizeof(void *), alignment); *((void **)(ret)-1) = (void *)(real); *((int*)(ret)-2) = size; diff --git a/extern/bullet2/src/LinearMath/btAlignedObjectArray.h b/extern/bullet2/src/LinearMath/btAlignedObjectArray.h index 955bb128e83..36090e13c89 100644 --- a/extern/bullet2/src/LinearMath/btAlignedObjectArray.h +++ b/extern/bullet2/src/LinearMath/btAlignedObjectArray.h @@ -28,6 +28,7 @@ subject to the following restrictions: #define BT_USE_PLACEMENT_NEW 1 //#define BT_USE_MEMCPY 1 //disable, because it is cumbersome to find out for each platform where memcpy is defined. It can be in <memory.h> or <string.h> or otherwise... +#define BT_ALLOW_ARRAY_COPY_OPERATOR // enabling this can accidently perform deep copies of data if you are not careful #ifdef BT_USE_MEMCPY #include <memory.h> @@ -53,7 +54,19 @@ class btAlignedObjectArray //PCK: added this line bool m_ownsMemory; - protected: +#ifdef BT_ALLOW_ARRAY_COPY_OPERATOR +public: + SIMD_FORCE_INLINE btAlignedObjectArray<T>& operator=(const btAlignedObjectArray<T> &other) + { + copyFromArray(other); + return *this; + } +#else//BT_ALLOW_ARRAY_COPY_OPERATOR +private: + SIMD_FORCE_INLINE btAlignedObjectArray<T>& operator=(const btAlignedObjectArray<T> &other); +#endif//BT_ALLOW_ARRAY_COPY_OPERATOR + +protected: SIMD_FORCE_INLINE int allocSize(int size) { return (size ? size*2 : 1); @@ -140,21 +153,29 @@ class btAlignedObjectArray SIMD_FORCE_INLINE const T& at(int n) const { + btAssert(n>=0); + btAssert(n<size()); return m_data[n]; } SIMD_FORCE_INLINE T& at(int n) { + btAssert(n>=0); + btAssert(n<size()); return m_data[n]; } SIMD_FORCE_INLINE const T& operator[](int n) const { + btAssert(n>=0); + btAssert(n<size()); return m_data[n]; } SIMD_FORCE_INLINE T& operator[](int n) { + btAssert(n>=0); + btAssert(n<size()); return m_data[n]; } @@ -171,6 +192,7 @@ class btAlignedObjectArray SIMD_FORCE_INLINE void pop_back() { + btAssert(m_size>0); m_size--; m_data[m_size].~T(); } @@ -291,8 +313,9 @@ class btAlignedObjectArray } }; + template <typename L> - void quickSortInternal(L CompareFunc,int lo, int hi) + void quickSortInternal(const L& CompareFunc,int lo, int hi) { // lo is the lower index, hi is the upper index // of the region of array a that is to be sorted @@ -322,7 +345,7 @@ class btAlignedObjectArray template <typename L> - void quickSort(L CompareFunc) + void quickSort(const L& CompareFunc) { //don't sort 0 or 1 elements if (size()>1) @@ -334,7 +357,7 @@ class btAlignedObjectArray ///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/ template <typename L> - void downHeap(T *pArr, int k, int n,L CompareFunc) + void downHeap(T *pArr, int k, int n, const L& CompareFunc) { /* PRE: a[k+1..N] is a heap */ /* POST: a[k..N] is a heap */ @@ -380,7 +403,7 @@ class btAlignedObjectArray } template <typename L> - void heapSort(L CompareFunc) + void heapSort(const L& CompareFunc) { /* sort a[0..N-1], N.B. 0 to N-1 */ int k; diff --git a/extern/bullet2/src/LinearMath/btConvexHull.h b/extern/bullet2/src/LinearMath/btConvexHull.h index a23fa4d550f..69c52bc6f83 100644 --- a/extern/bullet2/src/LinearMath/btConvexHull.h +++ b/extern/bullet2/src/LinearMath/btConvexHull.h @@ -16,8 +16,8 @@ subject to the following restrictions: ///includes modifications/improvements by John Ratcliff, see BringOutYourDead below. -#ifndef CD_HULL_H -#define CD_HULL_H +#ifndef BT_CD_HULL_H +#define BT_CD_HULL_H #include "btVector3.h" #include "btAlignedObjectArray.h" @@ -237,5 +237,5 @@ private: }; -#endif +#endif //BT_CD_HULL_H diff --git a/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp b/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp new file mode 100644 index 00000000000..c03c901c051 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btConvexHullComputer.cpp @@ -0,0 +1,2751 @@ +/* +Copyright (c) 2011 Ole Kniemeyer, MAXON, www.maxon.net + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include <string.h> + +#include "btConvexHullComputer.h" +#include "btAlignedObjectArray.h" +#include "btMinMax.h" +#include "btVector3.h" + +#ifdef __GNUC__ + #include <stdint.h> +#elif defined(_MSC_VER) + typedef __int32 int32_t; + typedef __int64 int64_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int64 uint64_t; +#else + typedef int int32_t; + typedef long long int int64_t; + typedef unsigned int uint32_t; + typedef unsigned long long int uint64_t; +#endif + + +//The definition of USE_X86_64_ASM is moved into the build system. You can enable it manually by commenting out the following lines +//#if (defined(__GNUC__) && defined(__x86_64__) && !defined(__ICL)) // || (defined(__ICL) && defined(_M_X64)) bug in Intel compiler, disable inline assembly +// #define USE_X86_64_ASM +//#endif + + +//#define DEBUG_CONVEX_HULL +//#define SHOW_ITERATIONS + +#if defined(DEBUG_CONVEX_HULL) || defined(SHOW_ITERATIONS) + #include <stdio.h> +#endif + +// Convex hull implementation based on Preparata and Hong +// Ole Kniemeyer, MAXON Computer GmbH +class btConvexHullInternal +{ + public: + + class Point64 + { + public: + int64_t x; + int64_t y; + int64_t z; + + Point64(int64_t x, int64_t y, int64_t z): x(x), y(y), z(z) + { + } + + bool isZero() + { + return (x == 0) && (y == 0) && (z == 0); + } + + int64_t dot(const Point64& b) const + { + return x * b.x + y * b.y + z * b.z; + } + }; + + class Point32 + { + public: + int32_t x; + int32_t y; + int32_t z; + int index; + + Point32() + { + } + + Point32(int32_t x, int32_t y, int32_t z): x(x), y(y), z(z), index(-1) + { + } + + bool operator==(const Point32& b) const + { + return (x == b.x) && (y == b.y) && (z == b.z); + } + + bool operator!=(const Point32& b) const + { + return (x != b.x) || (y != b.y) || (z != b.z); + } + + bool isZero() + { + return (x == 0) && (y == 0) && (z == 0); + } + + Point64 cross(const Point32& b) const + { + return Point64(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); + } + + Point64 cross(const Point64& b) const + { + return Point64(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); + } + + int64_t dot(const Point32& b) const + { + return x * b.x + y * b.y + z * b.z; + } + + int64_t dot(const Point64& b) const + { + return x * b.x + y * b.y + z * b.z; + } + + Point32 operator+(const Point32& b) const + { + return Point32(x + b.x, y + b.y, z + b.z); + } + + Point32 operator-(const Point32& b) const + { + return Point32(x - b.x, y - b.y, z - b.z); + } + }; + + class Int128 + { + public: + uint64_t low; + uint64_t high; + + Int128() + { + } + + Int128(uint64_t low, uint64_t high): low(low), high(high) + { + } + + Int128(uint64_t low): low(low), high(0) + { + } + + Int128(int64_t value): low(value), high((value >= 0) ? 0 : (uint64_t) -1LL) + { + } + + static Int128 mul(int64_t a, int64_t b); + + static Int128 mul(uint64_t a, uint64_t b); + + Int128 operator-() const + { + return Int128((uint64_t) -(int64_t)low, ~high + (low == 0)); + } + + Int128 operator+(const Int128& b) const + { +#ifdef USE_X86_64_ASM + Int128 result; + __asm__ ("addq %[bl], %[rl]\n\t" + "adcq %[bh], %[rh]\n\t" + : [rl] "=r" (result.low), [rh] "=r" (result.high) + : "0"(low), "1"(high), [bl] "g"(b.low), [bh] "g"(b.high) + : "cc" ); + return result; +#else + uint64_t lo = low + b.low; + return Int128(lo, high + b.high + (lo < low)); +#endif + } + + Int128 operator-(const Int128& b) const + { +#ifdef USE_X86_64_ASM + Int128 result; + __asm__ ("subq %[bl], %[rl]\n\t" + "sbbq %[bh], %[rh]\n\t" + : [rl] "=r" (result.low), [rh] "=r" (result.high) + : "0"(low), "1"(high), [bl] "g"(b.low), [bh] "g"(b.high) + : "cc" ); + return result; +#else + return *this + -b; +#endif + } + + Int128& operator+=(const Int128& b) + { +#ifdef USE_X86_64_ASM + __asm__ ("addq %[bl], %[rl]\n\t" + "adcq %[bh], %[rh]\n\t" + : [rl] "=r" (low), [rh] "=r" (high) + : "0"(low), "1"(high), [bl] "g"(b.low), [bh] "g"(b.high) + : "cc" ); +#else + uint64_t lo = low + b.low; + if (lo < low) + { + ++high; + } + low = lo; + high += b.high; +#endif + return *this; + } + + Int128& operator++() + { + if (++low == 0) + { + ++high; + } + return *this; + } + + Int128 operator*(int64_t b) const; + + btScalar toScalar() const + { + return ((int64_t) high >= 0) ? btScalar(high) * (btScalar(0x100000000LL) * btScalar(0x100000000LL)) + btScalar(low) + : -(-*this).toScalar(); + } + + int getSign() const + { + return ((int64_t) high < 0) ? -1 : (high || low) ? 1 : 0; + } + + bool operator<(const Int128& b) const + { + return (high < b.high) || ((high == b.high) && (low < b.low)); + } + + int ucmp(const Int128&b) const + { + if (high < b.high) + { + return -1; + } + if (high > b.high) + { + return 1; + } + if (low < b.low) + { + return -1; + } + if (low > b.low) + { + return 1; + } + return 0; + } + }; + + + class Rational64 + { + private: + uint64_t m_numerator; + uint64_t m_denominator; + int sign; + + public: + Rational64(int64_t numerator, int64_t denominator) + { + if (numerator > 0) + { + sign = 1; + m_numerator = (uint64_t) numerator; + } + else if (numerator < 0) + { + sign = -1; + m_numerator = (uint64_t) -numerator; + } + else + { + sign = 0; + m_numerator = 0; + } + if (denominator > 0) + { + m_denominator = (uint64_t) denominator; + } + else if (denominator < 0) + { + sign = -sign; + m_denominator = (uint64_t) -denominator; + } + else + { + m_denominator = 0; + } + } + + bool isNegativeInfinity() const + { + return (sign < 0) && (m_denominator == 0); + } + + bool isNaN() const + { + return (sign == 0) && (m_denominator == 0); + } + + int compare(const Rational64& b) const; + + btScalar toScalar() const + { + return sign * ((m_denominator == 0) ? SIMD_INFINITY : (btScalar) m_numerator / m_denominator); + } + }; + + + class Rational128 + { + private: + Int128 numerator; + Int128 denominator; + int sign; + bool isInt64; + + public: + Rational128(int64_t value) + { + if (value > 0) + { + sign = 1; + this->numerator = value; + } + else if (value < 0) + { + sign = -1; + this->numerator = -value; + } + else + { + sign = 0; + this->numerator = (uint64_t) 0; + } + this->denominator = (uint64_t) 1; + isInt64 = true; + } + + Rational128(const Int128& numerator, const Int128& denominator) + { + sign = numerator.getSign(); + if (sign >= 0) + { + this->numerator = numerator; + } + else + { + this->numerator = -numerator; + } + int dsign = denominator.getSign(); + if (dsign >= 0) + { + this->denominator = denominator; + } + else + { + sign = -sign; + this->denominator = -denominator; + } + isInt64 = false; + } + + int compare(const Rational128& b) const; + + int compare(int64_t b) const; + + btScalar toScalar() const + { + return sign * ((denominator.getSign() == 0) ? SIMD_INFINITY : numerator.toScalar() / denominator.toScalar()); + } + }; + + class PointR128 + { + public: + Int128 x; + Int128 y; + Int128 z; + Int128 denominator; + + PointR128() + { + } + + PointR128(Int128 x, Int128 y, Int128 z, Int128 denominator): x(x), y(y), z(z), denominator(denominator) + { + } + + btScalar xvalue() const + { + return x.toScalar() / denominator.toScalar(); + } + + btScalar yvalue() const + { + return y.toScalar() / denominator.toScalar(); + } + + btScalar zvalue() const + { + return z.toScalar() / denominator.toScalar(); + } + }; + + + class Edge; + class Face; + + class Vertex + { + public: + Vertex* next; + Vertex* prev; + Edge* edges; + Face* firstNearbyFace; + Face* lastNearbyFace; + PointR128 point128; + Point32 point; + int copy; + + Vertex(): next(NULL), prev(NULL), edges(NULL), firstNearbyFace(NULL), lastNearbyFace(NULL), copy(-1) + { + } + +#ifdef DEBUG_CONVEX_HULL + void print() + { + printf("V%d (%d, %d, %d)", point.index, point.x, point.y, point.z); + } + + void printGraph(); +#endif + + Point32 operator-(const Vertex& b) const + { + return point - b.point; + } + + Rational128 dot(const Point64& b) const + { + return (point.index >= 0) ? Rational128(point.dot(b)) + : Rational128(point128.x * b.x + point128.y * b.y + point128.z * b.z, point128.denominator); + } + + btScalar xvalue() const + { + return (point.index >= 0) ? btScalar(point.x) : point128.xvalue(); + } + + btScalar yvalue() const + { + return (point.index >= 0) ? btScalar(point.y) : point128.yvalue(); + } + + btScalar zvalue() const + { + return (point.index >= 0) ? btScalar(point.z) : point128.zvalue(); + } + + void receiveNearbyFaces(Vertex* src) + { + if (lastNearbyFace) + { + lastNearbyFace->nextWithSameNearbyVertex = src->firstNearbyFace; + } + else + { + firstNearbyFace = src->firstNearbyFace; + } + if (src->lastNearbyFace) + { + lastNearbyFace = src->lastNearbyFace; + } + for (Face* f = src->firstNearbyFace; f; f = f->nextWithSameNearbyVertex) + { + btAssert(f->nearbyVertex == src); + f->nearbyVertex = this; + } + src->firstNearbyFace = NULL; + src->lastNearbyFace = NULL; + } + }; + + + class Edge + { + public: + Edge* next; + Edge* prev; + Edge* reverse; + Vertex* target; + Face* face; + int copy; + + ~Edge() + { + next = NULL; + prev = NULL; + reverse = NULL; + target = NULL; + face = NULL; + } + + void link(Edge* n) + { + btAssert(reverse->target == n->reverse->target); + next = n; + n->prev = this; + } + +#ifdef DEBUG_CONVEX_HULL + void print() + { + printf("E%p : %d -> %d, n=%p p=%p (0 %d\t%d\t%d) -> (%d %d %d)", this, reverse->target->point.index, target->point.index, next, prev, + reverse->target->point.x, reverse->target->point.y, reverse->target->point.z, target->point.x, target->point.y, target->point.z); + } +#endif + }; + + class Face + { + public: + Face* next; + Vertex* nearbyVertex; + Face* nextWithSameNearbyVertex; + Point32 origin; + Point32 dir0; + Point32 dir1; + + Face(): next(NULL), nearbyVertex(NULL), nextWithSameNearbyVertex(NULL) + { + } + + void init(Vertex* a, Vertex* b, Vertex* c) + { + nearbyVertex = a; + origin = a->point; + dir0 = *b - *a; + dir1 = *c - *a; + if (a->lastNearbyFace) + { + a->lastNearbyFace->nextWithSameNearbyVertex = this; + } + else + { + a->firstNearbyFace = this; + } + a->lastNearbyFace = this; + } + + Point64 getNormal() + { + return dir0.cross(dir1); + } + }; + + template<typename UWord, typename UHWord> class DMul + { + private: + static uint32_t high(uint64_t value) + { + return (uint32_t) (value >> 32); + } + + static uint32_t low(uint64_t value) + { + return (uint32_t) value; + } + + static uint64_t mul(uint32_t a, uint32_t b) + { + return (uint64_t) a * (uint64_t) b; + } + + static void shlHalf(uint64_t& value) + { + value <<= 32; + } + + static uint64_t high(Int128 value) + { + return value.high; + } + + static uint64_t low(Int128 value) + { + return value.low; + } + + static Int128 mul(uint64_t a, uint64_t b) + { + return Int128::mul(a, b); + } + + static void shlHalf(Int128& value) + { + value.high = value.low; + value.low = 0; + } + + public: + + static void mul(UWord a, UWord b, UWord& resLow, UWord& resHigh) + { + UWord p00 = mul(low(a), low(b)); + UWord p01 = mul(low(a), high(b)); + UWord p10 = mul(high(a), low(b)); + UWord p11 = mul(high(a), high(b)); + UWord p0110 = UWord(low(p01)) + UWord(low(p10)); + p11 += high(p01); + p11 += high(p10); + p11 += high(p0110); + shlHalf(p0110); + p00 += p0110; + if (p00 < p0110) + { + ++p11; + } + resLow = p00; + resHigh = p11; + } + }; + + private: + + class IntermediateHull + { + public: + Vertex* minXy; + Vertex* maxXy; + Vertex* minYx; + Vertex* maxYx; + + IntermediateHull(): minXy(NULL), maxXy(NULL), minYx(NULL), maxYx(NULL) + { + } + + void print(); + }; + + enum Orientation {NONE, CLOCKWISE, COUNTER_CLOCKWISE}; + + template <typename T> class PoolArray + { + private: + T* array; + int size; + + public: + PoolArray<T>* next; + + PoolArray(int size): size(size), next(NULL) + { + array = (T*) btAlignedAlloc(sizeof(T) * size, 16); + } + + ~PoolArray() + { + btAlignedFree(array); + } + + T* init() + { + T* o = array; + for (int i = 0; i < size; i++, o++) + { + o->next = (i+1 < size) ? o + 1 : NULL; + } + return array; + } + }; + + template <typename T> class Pool + { + private: + PoolArray<T>* arrays; + PoolArray<T>* nextArray; + T* freeObjects; + int arraySize; + + public: + Pool(): arrays(NULL), nextArray(NULL), freeObjects(NULL), arraySize(256) + { + } + + ~Pool() + { + while (arrays) + { + PoolArray<T>* p = arrays; + arrays = p->next; + p->~PoolArray<T>(); + btAlignedFree(p); + } + } + + void reset() + { + nextArray = arrays; + freeObjects = NULL; + } + + void setArraySize(int arraySize) + { + this->arraySize = arraySize; + } + + T* newObject() + { + T* o = freeObjects; + if (!o) + { + PoolArray<T>* p = nextArray; + if (p) + { + nextArray = p->next; + } + else + { + p = new(btAlignedAlloc(sizeof(PoolArray<T>), 16)) PoolArray<T>(arraySize); + p->next = arrays; + arrays = p; + } + o = p->init(); + } + freeObjects = o->next; + return new(o) T(); + }; + + void freeObject(T* object) + { + object->~T(); + object->next = freeObjects; + freeObjects = object; + } + }; + + btVector3 scaling; + btVector3 center; + Pool<Vertex> vertexPool; + Pool<Edge> edgePool; + Pool<Face> facePool; + btAlignedObjectArray<Vertex*> originalVertices; + int mergeStamp; + int minAxis; + int medAxis; + int maxAxis; + int usedEdgePairs; + int maxUsedEdgePairs; + + static Orientation getOrientation(const Edge* prev, const Edge* next, const Point32& s, const Point32& t); + Edge* findMaxAngle(bool ccw, const Vertex* start, const Point32& s, const Point64& rxs, const Point64& sxrxs, Rational64& minCot); + void findEdgeForCoplanarFaces(Vertex* c0, Vertex* c1, Edge*& e0, Edge*& e1, Vertex* stop0, Vertex* stop1); + + Edge* newEdgePair(Vertex* from, Vertex* to); + + void removeEdgePair(Edge* edge) + { + Edge* n = edge->next; + Edge* r = edge->reverse; + + btAssert(edge->target && r->target); + + if (n != edge) + { + n->prev = edge->prev; + edge->prev->next = n; + r->target->edges = n; + } + else + { + r->target->edges = NULL; + } + + n = r->next; + + if (n != r) + { + n->prev = r->prev; + r->prev->next = n; + edge->target->edges = n; + } + else + { + edge->target->edges = NULL; + } + + edgePool.freeObject(edge); + edgePool.freeObject(r); + usedEdgePairs--; + } + + void computeInternal(int start, int end, IntermediateHull& result); + + bool mergeProjection(IntermediateHull& h0, IntermediateHull& h1, Vertex*& c0, Vertex*& c1); + + void merge(IntermediateHull& h0, IntermediateHull& h1); + + btVector3 toBtVector(const Point32& v); + + btVector3 getBtNormal(Face* face); + + bool shiftFace(Face* face, btScalar amount, btAlignedObjectArray<Vertex*> stack); + + public: + Vertex* vertexList; + + void compute(const void* coords, bool doubleCoords, int stride, int count); + + btVector3 getCoordinates(const Vertex* v); + + btScalar shrink(btScalar amount, btScalar clampAmount); +}; + + +btConvexHullInternal::Int128 btConvexHullInternal::Int128::operator*(int64_t b) const +{ + bool negative = (int64_t) high < 0; + Int128 a = negative ? -*this : *this; + if (b < 0) + { + negative = !negative; + b = -b; + } + Int128 result = mul(a.low, (uint64_t) b); + result.high += a.high * (uint64_t) b; + return negative ? -result : result; +} + +btConvexHullInternal::Int128 btConvexHullInternal::Int128::mul(int64_t a, int64_t b) +{ + Int128 result; + +#ifdef USE_X86_64_ASM + __asm__ ("imulq %[b]" + : "=a" (result.low), "=d" (result.high) + : "0"(a), [b] "r"(b) + : "cc" ); + return result; + +#else + bool negative = a < 0; + if (negative) + { + a = -a; + } + if (b < 0) + { + negative = !negative; + b = -b; + } + DMul<uint64_t, uint32_t>::mul((uint64_t) a, (uint64_t) b, result.low, result.high); + return negative ? -result : result; +#endif +} + +btConvexHullInternal::Int128 btConvexHullInternal::Int128::mul(uint64_t a, uint64_t b) +{ + Int128 result; + +#ifdef USE_X86_64_ASM + __asm__ ("mulq %[b]" + : "=a" (result.low), "=d" (result.high) + : "0"(a), [b] "r"(b) + : "cc" ); + +#else + DMul<uint64_t, uint32_t>::mul(a, b, result.low, result.high); +#endif + + return result; +} + +int btConvexHullInternal::Rational64::compare(const Rational64& b) const +{ + if (sign != b.sign) + { + return sign - b.sign; + } + else if (sign == 0) + { + return 0; + } + + // return (numerator * b.denominator > b.numerator * denominator) ? sign : (numerator * b.denominator < b.numerator * denominator) ? -sign : 0; + +#ifdef USE_X86_64_ASM + + int result; + int64_t tmp; + int64_t dummy; + __asm__ ("mulq %[bn]\n\t" + "movq %%rax, %[tmp]\n\t" + "movq %%rdx, %%rbx\n\t" + "movq %[tn], %%rax\n\t" + "mulq %[bd]\n\t" + "subq %[tmp], %%rax\n\t" + "sbbq %%rbx, %%rdx\n\t" // rdx:rax contains 128-bit-difference "numerator*b.denominator - b.numerator*denominator" + "setnsb %%bh\n\t" // bh=1 if difference is non-negative, bh=0 otherwise + "orq %%rdx, %%rax\n\t" + "setnzb %%bl\n\t" // bl=1 if difference if non-zero, bl=0 if it is zero + "decb %%bh\n\t" // now bx=0x0000 if difference is zero, 0xff01 if it is negative, 0x0001 if it is positive (i.e., same sign as difference) + "shll $16, %%ebx\n\t" // ebx has same sign as difference + : "=&b"(result), [tmp] "=&r"(tmp), "=a"(dummy) + : "a"(denominator), [bn] "g"(b.numerator), [tn] "g"(numerator), [bd] "g"(b.denominator) + : "%rdx", "cc" ); + return result ? result ^ sign // if sign is +1, only bit 0 of result is inverted, which does not change the sign of result (and cannot result in zero) + // if sign is -1, all bits of result are inverted, which changes the sign of result (and again cannot result in zero) + : 0; + +#else + + return sign * Int128::mul(m_numerator, b.m_denominator).ucmp(Int128::mul(m_denominator, b.m_numerator)); + +#endif +} + +int btConvexHullInternal::Rational128::compare(const Rational128& b) const +{ + if (sign != b.sign) + { + return sign - b.sign; + } + else if (sign == 0) + { + return 0; + } + if (isInt64) + { + return -b.compare(sign * (int64_t) numerator.low); + } + + Int128 nbdLow, nbdHigh, dbnLow, dbnHigh; + DMul<Int128, uint64_t>::mul(numerator, b.denominator, nbdLow, nbdHigh); + DMul<Int128, uint64_t>::mul(denominator, b.numerator, dbnLow, dbnHigh); + + int cmp = nbdHigh.ucmp(dbnHigh); + if (cmp) + { + return cmp * sign; + } + return nbdLow.ucmp(dbnLow) * sign; +} + +int btConvexHullInternal::Rational128::compare(int64_t b) const +{ + if (isInt64) + { + int64_t a = sign * (int64_t) numerator.low; + return (a > b) ? 1 : (a < b) ? -1 : 0; + } + if (b > 0) + { + if (sign <= 0) + { + return -1; + } + } + else if (b < 0) + { + if (sign >= 0) + { + return 1; + } + b = -b; + } + else + { + return sign; + } + + return numerator.ucmp(denominator * b) * sign; +} + + +btConvexHullInternal::Edge* btConvexHullInternal::newEdgePair(Vertex* from, Vertex* to) +{ + btAssert(from && to); + Edge* e = edgePool.newObject(); + Edge* r = edgePool.newObject(); + e->reverse = r; + r->reverse = e; + e->copy = mergeStamp; + r->copy = mergeStamp; + e->target = to; + r->target = from; + e->face = NULL; + r->face = NULL; + usedEdgePairs++; + if (usedEdgePairs > maxUsedEdgePairs) + { + maxUsedEdgePairs = usedEdgePairs; + } + return e; +} + +bool btConvexHullInternal::mergeProjection(IntermediateHull& h0, IntermediateHull& h1, Vertex*& c0, Vertex*& c1) +{ + Vertex* v0 = h0.maxYx; + Vertex* v1 = h1.minYx; + if ((v0->point.x == v1->point.x) && (v0->point.y == v1->point.y)) + { + btAssert(v0->point.z < v1->point.z); + Vertex* v1p = v1->prev; + if (v1p == v1) + { + c0 = v0; + if (v1->edges) + { + btAssert(v1->edges->next == v1->edges); + v1 = v1->edges->target; + btAssert(v1->edges->next == v1->edges); + } + c1 = v1; + return false; + } + Vertex* v1n = v1->next; + v1p->next = v1n; + v1n->prev = v1p; + if (v1 == h1.minXy) + { + if ((v1n->point.x < v1p->point.x) || ((v1n->point.x == v1p->point.x) && (v1n->point.y < v1p->point.y))) + { + h1.minXy = v1n; + } + else + { + h1.minXy = v1p; + } + } + if (v1 == h1.maxXy) + { + if ((v1n->point.x > v1p->point.x) || ((v1n->point.x == v1p->point.x) && (v1n->point.y > v1p->point.y))) + { + h1.maxXy = v1n; + } + else + { + h1.maxXy = v1p; + } + } + } + + v0 = h0.maxXy; + v1 = h1.maxXy; + Vertex* v00 = NULL; + Vertex* v10 = NULL; + int32_t sign = 1; + + for (int side = 0; side <= 1; side++) + { + int32_t dx = (v1->point.x - v0->point.x) * sign; + if (dx > 0) + { + while (true) + { + int32_t dy = v1->point.y - v0->point.y; + + Vertex* w0 = side ? v0->next : v0->prev; + if (w0 != v0) + { + int32_t dx0 = (w0->point.x - v0->point.x) * sign; + int32_t dy0 = w0->point.y - v0->point.y; + if ((dy0 <= 0) && ((dx0 == 0) || ((dx0 < 0) && (dy0 * dx <= dy * dx0)))) + { + v0 = w0; + dx = (v1->point.x - v0->point.x) * sign; + continue; + } + } + + Vertex* w1 = side ? v1->next : v1->prev; + if (w1 != v1) + { + int32_t dx1 = (w1->point.x - v1->point.x) * sign; + int32_t dy1 = w1->point.y - v1->point.y; + int32_t dxn = (w1->point.x - v0->point.x) * sign; + if ((dxn > 0) && (dy1 < 0) && ((dx1 == 0) || ((dx1 < 0) && (dy1 * dx < dy * dx1)))) + { + v1 = w1; + dx = dxn; + continue; + } + } + + break; + } + } + else if (dx < 0) + { + while (true) + { + int32_t dy = v1->point.y - v0->point.y; + + Vertex* w1 = side ? v1->prev : v1->next; + if (w1 != v1) + { + int32_t dx1 = (w1->point.x - v1->point.x) * sign; + int32_t dy1 = w1->point.y - v1->point.y; + if ((dy1 >= 0) && ((dx1 == 0) || ((dx1 < 0) && (dy1 * dx <= dy * dx1)))) + { + v1 = w1; + dx = (v1->point.x - v0->point.x) * sign; + continue; + } + } + + Vertex* w0 = side ? v0->prev : v0->next; + if (w0 != v0) + { + int32_t dx0 = (w0->point.x - v0->point.x) * sign; + int32_t dy0 = w0->point.y - v0->point.y; + int32_t dxn = (v1->point.x - w0->point.x) * sign; + if ((dxn < 0) && (dy0 > 0) && ((dx0 == 0) || ((dx0 < 0) && (dy0 * dx < dy * dx0)))) + { + v0 = w0; + dx = dxn; + continue; + } + } + + break; + } + } + else + { + int32_t x = v0->point.x; + int32_t y0 = v0->point.y; + Vertex* w0 = v0; + Vertex* t; + while (((t = side ? w0->next : w0->prev) != v0) && (t->point.x == x) && (t->point.y <= y0)) + { + w0 = t; + y0 = t->point.y; + } + v0 = w0; + + int32_t y1 = v1->point.y; + Vertex* w1 = v1; + while (((t = side ? w1->prev : w1->next) != v1) && (t->point.x == x) && (t->point.y >= y1)) + { + w1 = t; + y1 = t->point.y; + } + v1 = w1; + } + + if (side == 0) + { + v00 = v0; + v10 = v1; + + v0 = h0.minXy; + v1 = h1.minXy; + sign = -1; + } + } + + v0->prev = v1; + v1->next = v0; + + v00->next = v10; + v10->prev = v00; + + if (h1.minXy->point.x < h0.minXy->point.x) + { + h0.minXy = h1.minXy; + } + if (h1.maxXy->point.x >= h0.maxXy->point.x) + { + h0.maxXy = h1.maxXy; + } + + h0.maxYx = h1.maxYx; + + c0 = v00; + c1 = v10; + + return true; +} + +void btConvexHullInternal::computeInternal(int start, int end, IntermediateHull& result) +{ + int n = end - start; + switch (n) + { + case 0: + result.minXy = NULL; + result.maxXy = NULL; + result.minYx = NULL; + result.maxYx = NULL; + return; + case 2: + { + Vertex* v = originalVertices[start]; + Vertex* w = v + 1; + if (v->point != w->point) + { + int32_t dx = v->point.x - w->point.x; + int32_t dy = v->point.y - w->point.y; + + if ((dx == 0) && (dy == 0)) + { + if (v->point.z > w->point.z) + { + Vertex* t = w; + w = v; + v = t; + } + btAssert(v->point.z < w->point.z); + v->next = v; + v->prev = v; + result.minXy = v; + result.maxXy = v; + result.minYx = v; + result.maxYx = v; + } + else + { + v->next = w; + v->prev = w; + w->next = v; + w->prev = v; + + if ((dx < 0) || ((dx == 0) && (dy < 0))) + { + result.minXy = v; + result.maxXy = w; + } + else + { + result.minXy = w; + result.maxXy = v; + } + + if ((dy < 0) || ((dy == 0) && (dx < 0))) + { + result.minYx = v; + result.maxYx = w; + } + else + { + result.minYx = w; + result.maxYx = v; + } + } + + Edge* e = newEdgePair(v, w); + e->link(e); + v->edges = e; + + e = e->reverse; + e->link(e); + w->edges = e; + + return; + } + } + // lint -fallthrough + case 1: + { + Vertex* v = originalVertices[start]; + v->edges = NULL; + v->next = v; + v->prev = v; + + result.minXy = v; + result.maxXy = v; + result.minYx = v; + result.maxYx = v; + + return; + } + } + + int split0 = start + n / 2; + Point32 p = originalVertices[split0-1]->point; + int split1 = split0; + while ((split1 < end) && (originalVertices[split1]->point == p)) + { + split1++; + } + computeInternal(start, split0, result); + IntermediateHull hull1; + computeInternal(split1, end, hull1); +#ifdef DEBUG_CONVEX_HULL + printf("\n\nMerge\n"); + result.print(); + hull1.print(); +#endif + merge(result, hull1); +#ifdef DEBUG_CONVEX_HULL + printf("\n Result\n"); + result.print(); +#endif +} + +#ifdef DEBUG_CONVEX_HULL +void btConvexHullInternal::IntermediateHull::print() +{ + printf(" Hull\n"); + for (Vertex* v = minXy; v; ) + { + printf(" "); + v->print(); + if (v == maxXy) + { + printf(" maxXy"); + } + if (v == minYx) + { + printf(" minYx"); + } + if (v == maxYx) + { + printf(" maxYx"); + } + if (v->next->prev != v) + { + printf(" Inconsistency"); + } + printf("\n"); + v = v->next; + if (v == minXy) + { + break; + } + } + if (minXy) + { + minXy->copy = (minXy->copy == -1) ? -2 : -1; + minXy->printGraph(); + } +} + +void btConvexHullInternal::Vertex::printGraph() +{ + print(); + printf("\nEdges\n"); + Edge* e = edges; + if (e) + { + do + { + e->print(); + printf("\n"); + e = e->next; + } while (e != edges); + do + { + Vertex* v = e->target; + if (v->copy != copy) + { + v->copy = copy; + v->printGraph(); + } + e = e->next; + } while (e != edges); + } +} +#endif + +btConvexHullInternal::Orientation btConvexHullInternal::getOrientation(const Edge* prev, const Edge* next, const Point32& s, const Point32& t) +{ + btAssert(prev->reverse->target == next->reverse->target); + if (prev->next == next) + { + if (prev->prev == next) + { + Point64 n = t.cross(s); + Point64 m = (*prev->target - *next->reverse->target).cross(*next->target - *next->reverse->target); + btAssert(!m.isZero()); + int64_t dot = n.dot(m); + btAssert(dot != 0); + return (dot > 0) ? COUNTER_CLOCKWISE : CLOCKWISE; + } + return COUNTER_CLOCKWISE; + } + else if (prev->prev == next) + { + return CLOCKWISE; + } + else + { + return NONE; + } +} + +btConvexHullInternal::Edge* btConvexHullInternal::findMaxAngle(bool ccw, const Vertex* start, const Point32& s, const Point64& rxs, const Point64& sxrxs, Rational64& minCot) +{ + Edge* minEdge = NULL; + +#ifdef DEBUG_CONVEX_HULL + printf("find max edge for %d\n", start->point.index); +#endif + Edge* e = start->edges; + if (e) + { + do + { + if (e->copy > mergeStamp) + { + Point32 t = *e->target - *start; + Rational64 cot(t.dot(sxrxs), t.dot(rxs)); +#ifdef DEBUG_CONVEX_HULL + printf(" Angle is %f (%d) for ", (float) btAtan(cot.toScalar()), (int) cot.isNaN()); + e->print(); +#endif + if (cot.isNaN()) + { + btAssert(ccw ? (t.dot(s) < 0) : (t.dot(s) > 0)); + } + else + { + int cmp; + if (minEdge == NULL) + { + minCot = cot; + minEdge = e; + } + else if ((cmp = cot.compare(minCot)) < 0) + { + minCot = cot; + minEdge = e; + } + else if ((cmp == 0) && (ccw == (getOrientation(minEdge, e, s, t) == COUNTER_CLOCKWISE))) + { + minEdge = e; + } + } +#ifdef DEBUG_CONVEX_HULL + printf("\n"); +#endif + } + e = e->next; + } while (e != start->edges); + } + return minEdge; +} + +void btConvexHullInternal::findEdgeForCoplanarFaces(Vertex* c0, Vertex* c1, Edge*& e0, Edge*& e1, Vertex* stop0, Vertex* stop1) +{ + Edge* start0 = e0; + Edge* start1 = e1; + Point32 et0 = start0 ? start0->target->point : c0->point; + Point32 et1 = start1 ? start1->target->point : c1->point; + Point32 s = c1->point - c0->point; + Point64 normal = ((start0 ? start0 : start1)->target->point - c0->point).cross(s); + int64_t dist = c0->point.dot(normal); + btAssert(!start1 || (start1->target->point.dot(normal) == dist)); + Point64 perp = s.cross(normal); + btAssert(!perp.isZero()); + +#ifdef DEBUG_CONVEX_HULL + printf(" Advancing %d %d (%p %p, %d %d)\n", c0->point.index, c1->point.index, start0, start1, start0 ? start0->target->point.index : -1, start1 ? start1->target->point.index : -1); +#endif + + int64_t maxDot0 = et0.dot(perp); + if (e0) + { + while (e0->target != stop0) + { + Edge* e = e0->reverse->prev; + if (e->target->point.dot(normal) < dist) + { + break; + } + btAssert(e->target->point.dot(normal) == dist); + if (e->copy == mergeStamp) + { + break; + } + int64_t dot = e->target->point.dot(perp); + if (dot <= maxDot0) + { + break; + } + maxDot0 = dot; + e0 = e; + et0 = e->target->point; + } + } + + int64_t maxDot1 = et1.dot(perp); + if (e1) + { + while (e1->target != stop1) + { + Edge* e = e1->reverse->next; + if (e->target->point.dot(normal) < dist) + { + break; + } + btAssert(e->target->point.dot(normal) == dist); + if (e->copy == mergeStamp) + { + break; + } + int64_t dot = e->target->point.dot(perp); + if (dot <= maxDot1) + { + break; + } + maxDot1 = dot; + e1 = e; + et1 = e->target->point; + } + } + +#ifdef DEBUG_CONVEX_HULL + printf(" Starting at %d %d\n", et0.index, et1.index); +#endif + + int64_t dx = maxDot1 - maxDot0; + if (dx > 0) + { + while (true) + { + int64_t dy = (et1 - et0).dot(s); + + if (e0 && (e0->target != stop0)) + { + Edge* f0 = e0->next->reverse; + if (f0->copy > mergeStamp) + { + int64_t dx0 = (f0->target->point - et0).dot(perp); + int64_t dy0 = (f0->target->point - et0).dot(s); + if ((dx0 == 0) ? (dy0 < 0) : ((dx0 < 0) && (Rational64(dy0, dx0).compare(Rational64(dy, dx)) >= 0))) + { + et0 = f0->target->point; + dx = (et1 - et0).dot(perp); + e0 = (e0 == start0) ? NULL : f0; + continue; + } + } + } + + if (e1 && (e1->target != stop1)) + { + Edge* f1 = e1->reverse->next; + if (f1->copy > mergeStamp) + { + Point32 d1 = f1->target->point - et1; + if (d1.dot(normal) == 0) + { + int64_t dx1 = d1.dot(perp); + int64_t dy1 = d1.dot(s); + int64_t dxn = (f1->target->point - et0).dot(perp); + if ((dxn > 0) && ((dx1 == 0) ? (dy1 < 0) : ((dx1 < 0) && (Rational64(dy1, dx1).compare(Rational64(dy, dx)) > 0)))) + { + e1 = f1; + et1 = e1->target->point; + dx = dxn; + continue; + } + } + else + { + btAssert((e1 == start1) && (d1.dot(normal) < 0)); + } + } + } + + break; + } + } + else if (dx < 0) + { + while (true) + { + int64_t dy = (et1 - et0).dot(s); + + if (e1 && (e1->target != stop1)) + { + Edge* f1 = e1->prev->reverse; + if (f1->copy > mergeStamp) + { + int64_t dx1 = (f1->target->point - et1).dot(perp); + int64_t dy1 = (f1->target->point - et1).dot(s); + if ((dx1 == 0) ? (dy1 > 0) : ((dx1 < 0) && (Rational64(dy1, dx1).compare(Rational64(dy, dx)) <= 0))) + { + et1 = f1->target->point; + dx = (et1 - et0).dot(perp); + e1 = (e1 == start1) ? NULL : f1; + continue; + } + } + } + + if (e0 && (e0->target != stop0)) + { + Edge* f0 = e0->reverse->prev; + if (f0->copy > mergeStamp) + { + Point32 d0 = f0->target->point - et0; + if (d0.dot(normal) == 0) + { + int64_t dx0 = d0.dot(perp); + int64_t dy0 = d0.dot(s); + int64_t dxn = (et1 - f0->target->point).dot(perp); + if ((dxn < 0) && ((dx0 == 0) ? (dy0 > 0) : ((dx0 < 0) && (Rational64(dy0, dx0).compare(Rational64(dy, dx)) < 0)))) + { + e0 = f0; + et0 = e0->target->point; + dx = dxn; + continue; + } + } + else + { + btAssert((e0 == start0) && (d0.dot(normal) < 0)); + } + } + } + + break; + } + } +#ifdef DEBUG_CONVEX_HULL + printf(" Advanced edges to %d %d\n", et0.index, et1.index); +#endif +} + + +void btConvexHullInternal::merge(IntermediateHull& h0, IntermediateHull& h1) +{ + if (!h1.maxXy) + { + return; + } + if (!h0.maxXy) + { + h0 = h1; + return; + } + + mergeStamp--; + + Vertex* c0 = NULL; + Edge* toPrev0 = NULL; + Edge* firstNew0 = NULL; + Edge* pendingHead0 = NULL; + Edge* pendingTail0 = NULL; + Vertex* c1 = NULL; + Edge* toPrev1 = NULL; + Edge* firstNew1 = NULL; + Edge* pendingHead1 = NULL; + Edge* pendingTail1 = NULL; + Point32 prevPoint; + + if (mergeProjection(h0, h1, c0, c1)) + { + Point32 s = *c1 - *c0; + Point64 normal = Point32(0, 0, -1).cross(s); + Point64 t = s.cross(normal); + btAssert(!t.isZero()); + + Edge* e = c0->edges; + Edge* start0 = NULL; + if (e) + { + do + { + int64_t dot = (*e->target - *c0).dot(normal); + btAssert(dot <= 0); + if ((dot == 0) && ((*e->target - *c0).dot(t) > 0)) + { + if (!start0 || (getOrientation(start0, e, s, Point32(0, 0, -1)) == CLOCKWISE)) + { + start0 = e; + } + } + e = e->next; + } while (e != c0->edges); + } + + e = c1->edges; + Edge* start1 = NULL; + if (e) + { + do + { + int64_t dot = (*e->target - *c1).dot(normal); + btAssert(dot <= 0); + if ((dot == 0) && ((*e->target - *c1).dot(t) > 0)) + { + if (!start1 || (getOrientation(start1, e, s, Point32(0, 0, -1)) == COUNTER_CLOCKWISE)) + { + start1 = e; + } + } + e = e->next; + } while (e != c1->edges); + } + + if (start0 || start1) + { + findEdgeForCoplanarFaces(c0, c1, start0, start1, NULL, NULL); + if (start0) + { + c0 = start0->target; + } + if (start1) + { + c1 = start1->target; + } + } + + prevPoint = c1->point; + prevPoint.z++; + } + else + { + prevPoint = c1->point; + prevPoint.x++; + } + + Vertex* first0 = c0; + Vertex* first1 = c1; + bool firstRun = true; + + while (true) + { + Point32 s = *c1 - *c0; + Point32 r = prevPoint - c0->point; + Point64 rxs = r.cross(s); + Point64 sxrxs = s.cross(rxs); + +#ifdef DEBUG_CONVEX_HULL + printf("\n Checking %d %d\n", c0->point.index, c1->point.index); +#endif + Rational64 minCot0(0, 0); + Edge* min0 = findMaxAngle(false, c0, s, rxs, sxrxs, minCot0); + Rational64 minCot1(0, 0); + Edge* min1 = findMaxAngle(true, c1, s, rxs, sxrxs, minCot1); + if (!min0 && !min1) + { + Edge* e = newEdgePair(c0, c1); + e->link(e); + c0->edges = e; + + e = e->reverse; + e->link(e); + c1->edges = e; + return; + } + else + { + int cmp = !min0 ? 1 : !min1 ? -1 : minCot0.compare(minCot1); +#ifdef DEBUG_CONVEX_HULL + printf(" -> Result %d\n", cmp); +#endif + if (firstRun || ((cmp >= 0) ? !minCot1.isNegativeInfinity() : !minCot0.isNegativeInfinity())) + { + Edge* e = newEdgePair(c0, c1); + if (pendingTail0) + { + pendingTail0->prev = e; + } + else + { + pendingHead0 = e; + } + e->next = pendingTail0; + pendingTail0 = e; + + e = e->reverse; + if (pendingTail1) + { + pendingTail1->next = e; + } + else + { + pendingHead1 = e; + } + e->prev = pendingTail1; + pendingTail1 = e; + } + + Edge* e0 = min0; + Edge* e1 = min1; + +#ifdef DEBUG_CONVEX_HULL + printf(" Found min edges to %d %d\n", e0 ? e0->target->point.index : -1, e1 ? e1->target->point.index : -1); +#endif + + if (cmp == 0) + { + findEdgeForCoplanarFaces(c0, c1, e0, e1, NULL, NULL); + } + + if ((cmp >= 0) && e1) + { + if (toPrev1) + { + for (Edge* e = toPrev1->next, *n = NULL; e != min1; e = n) + { + n = e->next; + removeEdgePair(e); + } + } + + if (pendingTail1) + { + if (toPrev1) + { + toPrev1->link(pendingHead1); + } + else + { + min1->prev->link(pendingHead1); + firstNew1 = pendingHead1; + } + pendingTail1->link(min1); + pendingHead1 = NULL; + pendingTail1 = NULL; + } + else if (!toPrev1) + { + firstNew1 = min1; + } + + prevPoint = c1->point; + c1 = e1->target; + toPrev1 = e1->reverse; + } + + if ((cmp <= 0) && e0) + { + if (toPrev0) + { + for (Edge* e = toPrev0->prev, *n = NULL; e != min0; e = n) + { + n = e->prev; + removeEdgePair(e); + } + } + + if (pendingTail0) + { + if (toPrev0) + { + pendingHead0->link(toPrev0); + } + else + { + pendingHead0->link(min0->next); + firstNew0 = pendingHead0; + } + min0->link(pendingTail0); + pendingHead0 = NULL; + pendingTail0 = NULL; + } + else if (!toPrev0) + { + firstNew0 = min0; + } + + prevPoint = c0->point; + c0 = e0->target; + toPrev0 = e0->reverse; + } + } + + if ((c0 == first0) && (c1 == first1)) + { + if (toPrev0 == NULL) + { + pendingHead0->link(pendingTail0); + c0->edges = pendingTail0; + } + else + { + for (Edge* e = toPrev0->prev, *n = NULL; e != firstNew0; e = n) + { + n = e->prev; + removeEdgePair(e); + } + if (pendingTail0) + { + pendingHead0->link(toPrev0); + firstNew0->link(pendingTail0); + } + } + + if (toPrev1 == NULL) + { + pendingTail1->link(pendingHead1); + c1->edges = pendingTail1; + } + else + { + for (Edge* e = toPrev1->next, *n = NULL; e != firstNew1; e = n) + { + n = e->next; + removeEdgePair(e); + } + if (pendingTail1) + { + toPrev1->link(pendingHead1); + pendingTail1->link(firstNew1); + } + } + + return; + } + + firstRun = false; + } +} + + +static bool pointCmp(const btConvexHullInternal::Point32& p, const btConvexHullInternal::Point32& q) +{ + return (p.y < q.y) || ((p.y == q.y) && ((p.x < q.x) || ((p.x == q.x) && (p.z < q.z)))); +} + +void btConvexHullInternal::compute(const void* coords, bool doubleCoords, int stride, int count) +{ + btVector3 min(btScalar(1e30), btScalar(1e30), btScalar(1e30)), max(btScalar(-1e30), btScalar(-1e30), btScalar(-1e30)); + const char* ptr = (const char*) coords; + if (doubleCoords) + { + for (int i = 0; i < count; i++) + { + const double* v = (const double*) ptr; + btVector3 p((btScalar) v[0], (btScalar) v[1], (btScalar) v[2]); + ptr += stride; + min.setMin(p); + max.setMax(p); + } + } + else + { + for (int i = 0; i < count; i++) + { + const float* v = (const float*) ptr; + btVector3 p(v[0], v[1], v[2]); + ptr += stride; + min.setMin(p); + max.setMax(p); + } + } + + btVector3 s = max - min; + maxAxis = s.maxAxis(); + minAxis = s.minAxis(); + if (minAxis == maxAxis) + { + minAxis = (maxAxis + 1) % 3; + } + medAxis = 3 - maxAxis - minAxis; + + s /= btScalar(10216); + if (((medAxis + 1) % 3) != maxAxis) + { + s *= -1; + } + scaling = s; + + if (s[0] != 0) + { + s[0] = btScalar(1) / s[0]; + } + if (s[1] != 0) + { + s[1] = btScalar(1) / s[1]; + } + if (s[2] != 0) + { + s[2] = btScalar(1) / s[2]; + } + + center = (min + max) * btScalar(0.5); + + btAlignedObjectArray<Point32> points; + points.resize(count); + ptr = (const char*) coords; + if (doubleCoords) + { + for (int i = 0; i < count; i++) + { + const double* v = (const double*) ptr; + btVector3 p((btScalar) v[0], (btScalar) v[1], (btScalar) v[2]); + ptr += stride; + p = (p - center) * s; + points[i].x = (int32_t) p[medAxis]; + points[i].y = (int32_t) p[maxAxis]; + points[i].z = (int32_t) p[minAxis]; + points[i].index = i; + } + } + else + { + for (int i = 0; i < count; i++) + { + const float* v = (const float*) ptr; + btVector3 p(v[0], v[1], v[2]); + ptr += stride; + p = (p - center) * s; + points[i].x = (int32_t) p[medAxis]; + points[i].y = (int32_t) p[maxAxis]; + points[i].z = (int32_t) p[minAxis]; + points[i].index = i; + } + } + points.quickSort(pointCmp); + + vertexPool.reset(); + vertexPool.setArraySize(count); + originalVertices.resize(count); + for (int i = 0; i < count; i++) + { + Vertex* v = vertexPool.newObject(); + v->edges = NULL; + v->point = points[i]; + v->copy = -1; + originalVertices[i] = v; + } + + points.clear(); + + edgePool.reset(); + edgePool.setArraySize(6 * count); + + usedEdgePairs = 0; + maxUsedEdgePairs = 0; + + mergeStamp = -3; + + IntermediateHull hull; + computeInternal(0, count, hull); + vertexList = hull.minXy; +#ifdef DEBUG_CONVEX_HULL + printf("max. edges %d (3v = %d)", maxUsedEdgePairs, 3 * count); +#endif +} + +btVector3 btConvexHullInternal::toBtVector(const Point32& v) +{ + btVector3 p; + p[medAxis] = btScalar(v.x); + p[maxAxis] = btScalar(v.y); + p[minAxis] = btScalar(v.z); + return p * scaling; +} + +btVector3 btConvexHullInternal::getBtNormal(Face* face) +{ + return toBtVector(face->dir0).cross(toBtVector(face->dir1)).normalized(); +} + +btVector3 btConvexHullInternal::getCoordinates(const Vertex* v) +{ + btVector3 p; + p[medAxis] = v->xvalue(); + p[maxAxis] = v->yvalue(); + p[minAxis] = v->zvalue(); + return p * scaling + center; +} + +btScalar btConvexHullInternal::shrink(btScalar amount, btScalar clampAmount) +{ + if (!vertexList) + { + return 0; + } + int stamp = --mergeStamp; + btAlignedObjectArray<Vertex*> stack; + vertexList->copy = stamp; + stack.push_back(vertexList); + btAlignedObjectArray<Face*> faces; + + Point32 ref = vertexList->point; + Int128 hullCenterX(0, 0); + Int128 hullCenterY(0, 0); + Int128 hullCenterZ(0, 0); + Int128 volume(0, 0); + + while (stack.size() > 0) + { + Vertex* v = stack[stack.size() - 1]; + stack.pop_back(); + Edge* e = v->edges; + if (e) + { + do + { + if (e->target->copy != stamp) + { + e->target->copy = stamp; + stack.push_back(e->target); + } + if (e->copy != stamp) + { + Face* face = facePool.newObject(); + face->init(e->target, e->reverse->prev->target, v); + faces.push_back(face); + Edge* f = e; + + Vertex* a = NULL; + Vertex* b = NULL; + do + { + if (a && b) + { + int64_t vol = (v->point - ref).dot((a->point - ref).cross(b->point - ref)); + btAssert(vol >= 0); + Point32 c = v->point + a->point + b->point + ref; + hullCenterX += vol * c.x; + hullCenterY += vol * c.y; + hullCenterZ += vol * c.z; + volume += vol; + } + + btAssert(f->copy != stamp); + f->copy = stamp; + f->face = face; + + a = b; + b = f->target; + + f = f->reverse->prev; + } while (f != e); + } + e = e->next; + } while (e != v->edges); + } + } + + if (volume.getSign() <= 0) + { + return 0; + } + + btVector3 hullCenter; + hullCenter[medAxis] = hullCenterX.toScalar(); + hullCenter[maxAxis] = hullCenterY.toScalar(); + hullCenter[minAxis] = hullCenterZ.toScalar(); + hullCenter /= 4 * volume.toScalar(); + hullCenter *= scaling; + + int faceCount = faces.size(); + + if (clampAmount > 0) + { + btScalar minDist = SIMD_INFINITY; + for (int i = 0; i < faceCount; i++) + { + btVector3 normal = getBtNormal(faces[i]); + btScalar dist = normal.dot(toBtVector(faces[i]->origin) - hullCenter); + if (dist < minDist) + { + minDist = dist; + } + } + + if (minDist <= 0) + { + return 0; + } + + amount = btMin(amount, minDist * clampAmount); + } + + unsigned int seed = 243703; + for (int i = 0; i < faceCount; i++, seed = 1664525 * seed + 1013904223) + { + btSwap(faces[i], faces[seed % faceCount]); + } + + for (int i = 0; i < faceCount; i++) + { + if (!shiftFace(faces[i], amount, stack)) + { + return -amount; + } + } + + return amount; +} + +bool btConvexHullInternal::shiftFace(Face* face, btScalar amount, btAlignedObjectArray<Vertex*> stack) +{ + btVector3 origShift = getBtNormal(face) * -amount; + if (scaling[0] != 0) + { + origShift[0] /= scaling[0]; + } + if (scaling[1] != 0) + { + origShift[1] /= scaling[1]; + } + if (scaling[2] != 0) + { + origShift[2] /= scaling[2]; + } + Point32 shift((int32_t) origShift[medAxis], (int32_t) origShift[maxAxis], (int32_t) origShift[minAxis]); + if (shift.isZero()) + { + return true; + } + Point64 normal = face->getNormal(); +#ifdef DEBUG_CONVEX_HULL + printf("\nShrinking face (%d %d %d) (%d %d %d) (%d %d %d) by (%d %d %d)\n", + face->origin.x, face->origin.y, face->origin.z, face->dir0.x, face->dir0.y, face->dir0.z, face->dir1.x, face->dir1.y, face->dir1.z, shift.x, shift.y, shift.z); +#endif + int64_t origDot = face->origin.dot(normal); + Point32 shiftedOrigin = face->origin + shift; + int64_t shiftedDot = shiftedOrigin.dot(normal); + btAssert(shiftedDot <= origDot); + if (shiftedDot >= origDot) + { + return false; + } + + Edge* intersection = NULL; + + Edge* startEdge = face->nearbyVertex->edges; +#ifdef DEBUG_CONVEX_HULL + printf("Start edge is "); + startEdge->print(); + printf(", normal is (%lld %lld %lld), shifted dot is %lld\n", normal.x, normal.y, normal.z, shiftedDot); +#endif + Rational128 optDot = face->nearbyVertex->dot(normal); + int cmp = optDot.compare(shiftedDot); +#ifdef SHOW_ITERATIONS + int n = 0; +#endif + if (cmp >= 0) + { + Edge* e = startEdge; + do + { +#ifdef SHOW_ITERATIONS + n++; +#endif + Rational128 dot = e->target->dot(normal); + btAssert(dot.compare(origDot) <= 0); +#ifdef DEBUG_CONVEX_HULL + printf("Moving downwards, edge is "); + e->print(); + printf(", dot is %f (%f %lld)\n", (float) dot.toScalar(), (float) optDot.toScalar(), shiftedDot); +#endif + if (dot.compare(optDot) < 0) + { + int c = dot.compare(shiftedDot); + optDot = dot; + e = e->reverse; + startEdge = e; + if (c < 0) + { + intersection = e; + break; + } + cmp = c; + } + e = e->prev; + } while (e != startEdge); + + if (!intersection) + { + return false; + } + } + else + { + Edge* e = startEdge; + do + { +#ifdef SHOW_ITERATIONS + n++; +#endif + Rational128 dot = e->target->dot(normal); + btAssert(dot.compare(origDot) <= 0); +#ifdef DEBUG_CONVEX_HULL + printf("Moving upwards, edge is "); + e->print(); + printf(", dot is %f (%f %lld)\n", (float) dot.toScalar(), (float) optDot.toScalar(), shiftedDot); +#endif + if (dot.compare(optDot) > 0) + { + cmp = dot.compare(shiftedDot); + if (cmp >= 0) + { + intersection = e; + break; + } + optDot = dot; + e = e->reverse; + startEdge = e; + } + e = e->prev; + } while (e != startEdge); + + if (!intersection) + { + return true; + } + } + +#ifdef SHOW_ITERATIONS + printf("Needed %d iterations to find initial intersection\n", n); +#endif + + if (cmp == 0) + { + Edge* e = intersection->reverse->next; +#ifdef SHOW_ITERATIONS + n = 0; +#endif + while (e->target->dot(normal).compare(shiftedDot) <= 0) + { +#ifdef SHOW_ITERATIONS + n++; +#endif + e = e->next; + if (e == intersection->reverse) + { + return true; + } +#ifdef DEBUG_CONVEX_HULL + printf("Checking for outwards edge, current edge is "); + e->print(); + printf("\n"); +#endif + } +#ifdef SHOW_ITERATIONS + printf("Needed %d iterations to check for complete containment\n", n); +#endif + } + + Edge* firstIntersection = NULL; + Edge* faceEdge = NULL; + Edge* firstFaceEdge = NULL; + +#ifdef SHOW_ITERATIONS + int m = 0; +#endif + while (true) + { +#ifdef SHOW_ITERATIONS + m++; +#endif +#ifdef DEBUG_CONVEX_HULL + printf("Intersecting edge is "); + intersection->print(); + printf("\n"); +#endif + if (cmp == 0) + { + Edge* e = intersection->reverse->next; + startEdge = e; +#ifdef SHOW_ITERATIONS + n = 0; +#endif + while (true) + { +#ifdef SHOW_ITERATIONS + n++; +#endif + if (e->target->dot(normal).compare(shiftedDot) >= 0) + { + break; + } + intersection = e->reverse; + e = e->next; + if (e == startEdge) + { + return true; + } + } +#ifdef SHOW_ITERATIONS + printf("Needed %d iterations to advance intersection\n", n); +#endif + } + +#ifdef DEBUG_CONVEX_HULL + printf("Advanced intersecting edge to "); + intersection->print(); + printf(", cmp = %d\n", cmp); +#endif + + if (!firstIntersection) + { + firstIntersection = intersection; + } + else if (intersection == firstIntersection) + { + break; + } + + int prevCmp = cmp; + Edge* prevIntersection = intersection; + Edge* prevFaceEdge = faceEdge; + + Edge* e = intersection->reverse; +#ifdef SHOW_ITERATIONS + n = 0; +#endif + while (true) + { +#ifdef SHOW_ITERATIONS + n++; +#endif + e = e->reverse->prev; + btAssert(e != intersection->reverse); + cmp = e->target->dot(normal).compare(shiftedDot); +#ifdef DEBUG_CONVEX_HULL + printf("Testing edge "); + e->print(); + printf(" -> cmp = %d\n", cmp); +#endif + if (cmp >= 0) + { + intersection = e; + break; + } + } +#ifdef SHOW_ITERATIONS + printf("Needed %d iterations to find other intersection of face\n", n); +#endif + + if (cmp > 0) + { + Vertex* removed = intersection->target; + e = intersection->reverse; + if (e->prev == e) + { + removed->edges = NULL; + } + else + { + removed->edges = e->prev; + e->prev->link(e->next); + e->link(e); + } +#ifdef DEBUG_CONVEX_HULL + printf("1: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z); +#endif + + Point64 n0 = intersection->face->getNormal(); + Point64 n1 = intersection->reverse->face->getNormal(); + int64_t m00 = face->dir0.dot(n0); + int64_t m01 = face->dir1.dot(n0); + int64_t m10 = face->dir0.dot(n1); + int64_t m11 = face->dir1.dot(n1); + int64_t r0 = (intersection->face->origin - shiftedOrigin).dot(n0); + int64_t r1 = (intersection->reverse->face->origin - shiftedOrigin).dot(n1); + Int128 det = Int128::mul(m00, m11) - Int128::mul(m01, m10); + btAssert(det.getSign() != 0); + Vertex* v = vertexPool.newObject(); + v->point.index = -1; + v->copy = -1; + v->point128 = PointR128(Int128::mul(face->dir0.x * r0, m11) - Int128::mul(face->dir0.x * r1, m01) + + Int128::mul(face->dir1.x * r1, m00) - Int128::mul(face->dir1.x * r0, m10) + det * shiftedOrigin.x, + Int128::mul(face->dir0.y * r0, m11) - Int128::mul(face->dir0.y * r1, m01) + + Int128::mul(face->dir1.y * r1, m00) - Int128::mul(face->dir1.y * r0, m10) + det * shiftedOrigin.y, + Int128::mul(face->dir0.z * r0, m11) - Int128::mul(face->dir0.z * r1, m01) + + Int128::mul(face->dir1.z * r1, m00) - Int128::mul(face->dir1.z * r0, m10) + det * shiftedOrigin.z, + det); + v->point.x = (int32_t) v->point128.xvalue(); + v->point.y = (int32_t) v->point128.yvalue(); + v->point.z = (int32_t) v->point128.zvalue(); + intersection->target = v; + v->edges = e; + + stack.push_back(v); + stack.push_back(removed); + stack.push_back(NULL); + } + + if (cmp || prevCmp || (prevIntersection->reverse->next->target != intersection->target)) + { + faceEdge = newEdgePair(prevIntersection->target, intersection->target); + if (prevCmp == 0) + { + faceEdge->link(prevIntersection->reverse->next); + } + if ((prevCmp == 0) || prevFaceEdge) + { + prevIntersection->reverse->link(faceEdge); + } + if (cmp == 0) + { + intersection->reverse->prev->link(faceEdge->reverse); + } + faceEdge->reverse->link(intersection->reverse); + } + else + { + faceEdge = prevIntersection->reverse->next; + } + + if (prevFaceEdge) + { + if (prevCmp > 0) + { + faceEdge->link(prevFaceEdge->reverse); + } + else if (faceEdge != prevFaceEdge->reverse) + { + stack.push_back(prevFaceEdge->target); + while (faceEdge->next != prevFaceEdge->reverse) + { + Vertex* removed = faceEdge->next->target; + removeEdgePair(faceEdge->next); + stack.push_back(removed); +#ifdef DEBUG_CONVEX_HULL + printf("2: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z); +#endif + } + stack.push_back(NULL); + } + } + faceEdge->face = face; + faceEdge->reverse->face = intersection->face; + + if (!firstFaceEdge) + { + firstFaceEdge = faceEdge; + } + } +#ifdef SHOW_ITERATIONS + printf("Needed %d iterations to process all intersections\n", m); +#endif + + if (cmp > 0) + { + firstFaceEdge->reverse->target = faceEdge->target; + firstIntersection->reverse->link(firstFaceEdge); + firstFaceEdge->link(faceEdge->reverse); + } + else if (firstFaceEdge != faceEdge->reverse) + { + stack.push_back(faceEdge->target); + while (firstFaceEdge->next != faceEdge->reverse) + { + Vertex* removed = firstFaceEdge->next->target; + removeEdgePair(firstFaceEdge->next); + stack.push_back(removed); +#ifdef DEBUG_CONVEX_HULL + printf("3: Removed part contains (%d %d %d)\n", removed->point.x, removed->point.y, removed->point.z); +#endif + } + stack.push_back(NULL); + } + + btAssert(stack.size() > 0); + vertexList = stack[0]; + +#ifdef DEBUG_CONVEX_HULL + printf("Removing part\n"); +#endif +#ifdef SHOW_ITERATIONS + n = 0; +#endif + int pos = 0; + while (pos < stack.size()) + { + int end = stack.size(); + while (pos < end) + { + Vertex* kept = stack[pos++]; +#ifdef DEBUG_CONVEX_HULL + kept->print(); +#endif + bool deeper = false; + Vertex* removed; + while ((removed = stack[pos++]) != NULL) + { +#ifdef SHOW_ITERATIONS + n++; +#endif + kept->receiveNearbyFaces(removed); + while (removed->edges) + { + if (!deeper) + { + deeper = true; + stack.push_back(kept); + } + stack.push_back(removed->edges->target); + removeEdgePair(removed->edges); + } + } + if (deeper) + { + stack.push_back(NULL); + } + } + } +#ifdef SHOW_ITERATIONS + printf("Needed %d iterations to remove part\n", n); +#endif + + stack.resize(0); + face->origin = shiftedOrigin; + + return true; +} + + +static int getVertexCopy(btConvexHullInternal::Vertex* vertex, btAlignedObjectArray<btConvexHullInternal::Vertex*>& vertices) +{ + int index = vertex->copy; + if (index < 0) + { + index = vertices.size(); + vertex->copy = index; + vertices.push_back(vertex); +#ifdef DEBUG_CONVEX_HULL + printf("Vertex %d gets index *%d\n", vertex->point.index, index); +#endif + } + return index; +} + +btScalar btConvexHullComputer::compute(const void* coords, bool doubleCoords, int stride, int count, btScalar shrink, btScalar shrinkClamp) +{ + if (count <= 0) + { + vertices.clear(); + edges.clear(); + faces.clear(); + return 0; + } + + btConvexHullInternal hull; + hull.compute(coords, doubleCoords, stride, count); + + btScalar shift = 0; + if ((shrink > 0) && ((shift = hull.shrink(shrink, shrinkClamp)) < 0)) + { + vertices.clear(); + edges.clear(); + faces.clear(); + return shift; + } + + vertices.resize(0); + edges.resize(0); + faces.resize(0); + + btAlignedObjectArray<btConvexHullInternal::Vertex*> oldVertices; + getVertexCopy(hull.vertexList, oldVertices); + int copied = 0; + while (copied < oldVertices.size()) + { + btConvexHullInternal::Vertex* v = oldVertices[copied]; + vertices.push_back(hull.getCoordinates(v)); + btConvexHullInternal::Edge* firstEdge = v->edges; + if (firstEdge) + { + int firstCopy = -1; + int prevCopy = -1; + btConvexHullInternal::Edge* e = firstEdge; + do + { + if (e->copy < 0) + { + int s = edges.size(); + edges.push_back(Edge()); + edges.push_back(Edge()); + Edge* c = &edges[s]; + Edge* r = &edges[s + 1]; + e->copy = s; + e->reverse->copy = s + 1; + c->reverse = 1; + r->reverse = -1; + c->targetVertex = getVertexCopy(e->target, oldVertices); + r->targetVertex = copied; +#ifdef DEBUG_CONVEX_HULL + printf(" CREATE: Vertex *%d has edge to *%d\n", copied, c->getTargetVertex()); +#endif + } + if (prevCopy >= 0) + { + edges[e->copy].next = prevCopy - e->copy; + } + else + { + firstCopy = e->copy; + } + prevCopy = e->copy; + e = e->next; + } while (e != firstEdge); + edges[firstCopy].next = prevCopy - firstCopy; + } + copied++; + } + + for (int i = 0; i < copied; i++) + { + btConvexHullInternal::Vertex* v = oldVertices[i]; + btConvexHullInternal::Edge* firstEdge = v->edges; + if (firstEdge) + { + btConvexHullInternal::Edge* e = firstEdge; + do + { + if (e->copy >= 0) + { +#ifdef DEBUG_CONVEX_HULL + printf("Vertex *%d has edge to *%d\n", i, edges[e->copy].getTargetVertex()); +#endif + faces.push_back(e->copy); + btConvexHullInternal::Edge* f = e; + do + { +#ifdef DEBUG_CONVEX_HULL + printf(" Face *%d\n", edges[f->copy].getTargetVertex()); +#endif + f->copy = -1; + f = f->reverse->prev; + } while (f != e); + } + e = e->next; + } while (e != firstEdge); + } + } + + return shift; +} + + + + + diff --git a/extern/bullet2/src/LinearMath/btConvexHullComputer.h b/extern/bullet2/src/LinearMath/btConvexHullComputer.h new file mode 100644 index 00000000000..7240ac4fb52 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btConvexHullComputer.h @@ -0,0 +1,103 @@ +/* +Copyright (c) 2011 Ole Kniemeyer, MAXON, www.maxon.net + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef BT_CONVEX_HULL_COMPUTER_H +#define BT_CONVEX_HULL_COMPUTER_H + +#include "btVector3.h" +#include "btAlignedObjectArray.h" + +/// Convex hull implementation based on Preparata and Hong +/// See http://code.google.com/p/bullet/issues/detail?id=275 +/// Ole Kniemeyer, MAXON Computer GmbH +class btConvexHullComputer +{ + private: + btScalar compute(const void* coords, bool doubleCoords, int stride, int count, btScalar shrink, btScalar shrinkClamp); + + public: + + class Edge + { + private: + int next; + int reverse; + int targetVertex; + + friend class btConvexHullComputer; + + public: + int getSourceVertex() const + { + return (this + reverse)->targetVertex; + } + + int getTargetVertex() const + { + return targetVertex; + } + + const Edge* getNextEdgeOfVertex() const // clockwise list of all edges of a vertex + { + return this + next; + } + + const Edge* getNextEdgeOfFace() const // counter-clockwise list of all edges of a face + { + return (this + reverse)->getNextEdgeOfVertex(); + } + + const Edge* getReverseEdge() const + { + return this + reverse; + } + }; + + + // Vertices of the output hull + btAlignedObjectArray<btVector3> vertices; + + // Edges of the output hull + btAlignedObjectArray<Edge> edges; + + // Faces of the convex hull. Each entry is an index into the "edges" array pointing to an edge of the face. Faces are planar n-gons + btAlignedObjectArray<int> faces; + + /* + Compute convex hull of "count" vertices stored in "coords". "stride" is the difference in bytes + between the addresses of consecutive vertices. If "shrink" is positive, the convex hull is shrunken + by that amount (each face is moved by "shrink" length units towards the center along its normal). + If "shrinkClamp" is positive, "shrink" is clamped to not exceed "shrinkClamp * innerRadius", where "innerRadius" + is the minimum distance of a face to the center of the convex hull. + + The returned value is the amount by which the hull has been shrunken. If it is negative, the amount was so large + that the resulting convex hull is empty. + + The output convex hull can be found in the member variables "vertices", "edges", "faces". + */ + btScalar compute(const float* coords, int stride, int count, btScalar shrink, btScalar shrinkClamp) + { + return compute(coords, false, stride, count, shrink, shrinkClamp); + } + + // same as above, but double precision + btScalar compute(const double* coords, int stride, int count, btScalar shrink, btScalar shrinkClamp) + { + return compute(coords, true, stride, count, shrink, shrinkClamp); + } +}; + + +#endif //BT_CONVEX_HULL_COMPUTER_H + diff --git a/extern/bullet2/src/LinearMath/btDefaultMotionState.h b/extern/bullet2/src/LinearMath/btDefaultMotionState.h index 7858a10d219..a6b7ef15ac8 100644 --- a/extern/bullet2/src/LinearMath/btDefaultMotionState.h +++ b/extern/bullet2/src/LinearMath/btDefaultMotionState.h @@ -1,5 +1,5 @@ -#ifndef DEFAULT_MOTION_STATE_H -#define DEFAULT_MOTION_STATE_H +#ifndef BT_DEFAULT_MOTION_STATE_H +#define BT_DEFAULT_MOTION_STATE_H #include "btMotionState.h" @@ -37,4 +37,4 @@ struct btDefaultMotionState : public btMotionState }; -#endif //DEFAULT_MOTION_STATE_H +#endif //BT_DEFAULT_MOTION_STATE_H diff --git a/extern/bullet2/src/LinearMath/btGrahamScan2dConvexHull.h b/extern/bullet2/src/LinearMath/btGrahamScan2dConvexHull.h new file mode 100644 index 00000000000..d7bd3eb8911 --- /dev/null +++ b/extern/bullet2/src/LinearMath/btGrahamScan2dConvexHull.h @@ -0,0 +1,110 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef GRAHAM_SCAN_2D_CONVEX_HULL_H +#define GRAHAM_SCAN_2D_CONVEX_HULL_H + + +#include "btVector3.h" +#include "btAlignedObjectArray.h" + +struct GrahamVector2 : public btVector3 +{ + GrahamVector2(const btVector3& org, int orgIndex) + :btVector3(org), + m_orgIndex(orgIndex) + { + } + btScalar m_angle; + int m_orgIndex; +}; + + +struct btAngleCompareFunc { + btVector3 m_anchor; + btAngleCompareFunc(const btVector3& anchor) + : m_anchor(anchor) + { + } + bool operator()(const GrahamVector2& a, const GrahamVector2& b) const { + if (a.m_angle != b.m_angle) + return a.m_angle < b.m_angle; + else + { + btScalar al = (a-m_anchor).length2(); + btScalar bl = (b-m_anchor).length2(); + if (al != bl) + return al < bl; + else + { + return a.m_orgIndex < b.m_orgIndex; + } + } + } +}; + +inline void GrahamScanConvexHull2D(btAlignedObjectArray<GrahamVector2>& originalPoints, btAlignedObjectArray<GrahamVector2>& hull) +{ + if (originalPoints.size()<=1) + { + for (int i=0;i<originalPoints.size();i++) + hull.push_back(originalPoints[0]); + return; + } + //step1 : find anchor point with smallest x/y and move it to first location + //also precompute angles + for (int i=0;i<originalPoints.size();i++) + { + const btVector3& left = originalPoints[i]; + const btVector3& right = originalPoints[0]; + if (left.x() < right.x() || !(right.x() < left.x()) && left.y() < right.y()) + { + originalPoints.swap(0,i); + } + } + + for (int i=0;i<originalPoints.size();i++) + { + btVector3 xvec(1,0,0); + btVector3 ar = originalPoints[i]-originalPoints[0]; + originalPoints[i].m_angle = btCross(xvec, ar).dot(btVector3(0,0,1)) / ar.length(); + } + + //step 2: sort all points, based on 'angle' with this anchor + btAngleCompareFunc comp(originalPoints[0]); + originalPoints.quickSortInternal(comp,1,originalPoints.size()-1); + + int i; + for (i = 0; i<2; i++) + hull.push_back(originalPoints[i]); + + //step 3: keep all 'convex' points and discard concave points (using back tracking) + for (; i != originalPoints.size(); i++) + { + bool isConvex = false; + while (!isConvex&& hull.size()>1) { + btVector3& a = hull[hull.size()-2]; + btVector3& b = hull[hull.size()-1]; + isConvex = btCross(a-b,a-originalPoints[i]).dot(btVector3(0,0,1))> 0; + if (!isConvex) + hull.pop_back(); + else + hull.push_back(originalPoints[i]); + } + } +} + +#endif //GRAHAM_SCAN_2D_CONVEX_HULL_H diff --git a/extern/bullet2/src/LinearMath/btHashMap.h b/extern/bullet2/src/LinearMath/btHashMap.h index e3302b5e9ff..ce07db3ac6b 100644 --- a/extern/bullet2/src/LinearMath/btHashMap.h +++ b/extern/bullet2/src/LinearMath/btHashMap.h @@ -1,3 +1,19 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + #ifndef BT_HASH_MAP_H #define BT_HASH_MAP_H diff --git a/extern/bullet2/src/LinearMath/btIDebugDraw.h b/extern/bullet2/src/LinearMath/btIDebugDraw.h index 48c15806a7d..935502f844f 100644 --- a/extern/bullet2/src/LinearMath/btIDebugDraw.h +++ b/extern/bullet2/src/LinearMath/btIDebugDraw.h @@ -14,8 +14,8 @@ subject to the following restrictions: */ -#ifndef IDEBUG_DRAW__H -#define IDEBUG_DRAW__H +#ifndef BT_IDEBUG_DRAW__H +#define BT_IDEBUG_DRAW__H #include "btVector3.h" #include "btTransform.h" @@ -46,6 +46,7 @@ class btIDebugDraw DBG_DrawConstraints = (1 << 11), DBG_DrawConstraintLimits = (1 << 12), DBG_FastWireframe = (1<<13), + DBG_DrawNormals = (1<<14), DBG_MAX_DEBUG_DRAW_MODE }; @@ -413,5 +414,5 @@ class btIDebugDraw }; -#endif //IDEBUG_DRAW__H +#endif //BT_IDEBUG_DRAW__H diff --git a/extern/bullet2/src/LinearMath/btList.h b/extern/bullet2/src/LinearMath/btList.h index c87b47faf2b..eec80a7064b 100644 --- a/extern/bullet2/src/LinearMath/btList.h +++ b/extern/bullet2/src/LinearMath/btList.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef GEN_LIST_H -#define GEN_LIST_H +#ifndef BT_GEN_LIST_H +#define BT_GEN_LIST_H class btGEN_Link { public: @@ -67,7 +67,7 @@ private: btGEN_Link m_tail; }; -#endif +#endif //BT_GEN_LIST_H diff --git a/extern/bullet2/src/LinearMath/btMinMax.h b/extern/bullet2/src/LinearMath/btMinMax.h index 80601c1e232..5b436e9ba4e 100644 --- a/extern/bullet2/src/LinearMath/btMinMax.h +++ b/extern/bullet2/src/LinearMath/btMinMax.h @@ -14,10 +14,10 @@ subject to the following restrictions: -#ifndef GEN_MINMAX_H -#define GEN_MINMAX_H +#ifndef BT_GEN_MINMAX_H +#define BT_GEN_MINMAX_H -#include "LinearMath/btScalar.h" +#include "btScalar.h" template <class T> SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) @@ -68,4 +68,4 @@ SIMD_FORCE_INLINE void btClamp(T& a, const T& lb, const T& ub) } } -#endif +#endif //BT_GEN_MINMAX_H diff --git a/extern/bullet2/src/LinearMath/btPoint3.h b/extern/bullet2/src/LinearMath/btPoint3.h deleted file mode 100644 index a2020e26d12..00000000000 --- a/extern/bullet2/src/LinearMath/btPoint3.h +++ /dev/null @@ -1,24 +0,0 @@ -/* -Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - - -#ifndef btPoint3_H -#define btPoint3_H - -#include "btVector3.h" - -typedef btVector3 btPoint3; - -#endif diff --git a/extern/bullet2/src/LinearMath/btPoolAllocator.h b/extern/bullet2/src/LinearMath/btPoolAllocator.h index e3b4be9b155..ef2084537a2 100644 --- a/extern/bullet2/src/LinearMath/btPoolAllocator.h +++ b/extern/bullet2/src/LinearMath/btPoolAllocator.h @@ -62,6 +62,11 @@ public: return m_maxElements - m_freeCount; } + int getMaxCount() const + { + return m_maxElements; + } + void* allocate(int size) { // release mode fix diff --git a/extern/bullet2/src/LinearMath/btQuadWord.h b/extern/bullet2/src/LinearMath/btQuadWord.h index c657afd2bb1..d5e9daa45a2 100644 --- a/extern/bullet2/src/LinearMath/btQuadWord.h +++ b/extern/bullet2/src/LinearMath/btQuadWord.h @@ -13,8 +13,8 @@ subject to the following restrictions: */ -#ifndef SIMD_QUADWORD_H -#define SIMD_QUADWORD_H +#ifndef BT_SIMD_QUADWORD_H +#define BT_SIMD_QUADWORD_H #include "btScalar.h" #include "btMinMax.h" @@ -177,4 +177,4 @@ protected: }; -#endif //SIMD_QUADWORD_H +#endif //BT_SIMD_QUADWORD_H diff --git a/extern/bullet2/src/LinearMath/btQuaternion.h b/extern/bullet2/src/LinearMath/btQuaternion.h index 15cf5f868d9..ee79f6eaeee 100644 --- a/extern/bullet2/src/LinearMath/btQuaternion.h +++ b/extern/bullet2/src/LinearMath/btQuaternion.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef SIMD__QUATERNION_H_ -#define SIMD__QUATERNION_H_ +#ifndef BT_SIMD__QUATERNION_H_ +#define BT_SIMD__QUATERNION_H_ #include "btVector3.h" @@ -212,11 +212,12 @@ public: /**@brief Return the axis of the rotation represented by this quaternion */ btVector3 getAxis() const { - btScalar s_squared = btScalar(1.) - btPow(m_floats[3], btScalar(2.)); + btScalar s_squared = 1.f-m_floats[3]*m_floats[3]; + if (s_squared < btScalar(10.) * SIMD_EPSILON) //Check for divide by zero return btVector3(1.0, 0.0, 0.0); // Arbitrary - btScalar s = btSqrt(s_squared); - return btVector3(m_floats[0] / s, m_floats[1] / s, m_floats[2] / s); + btScalar s = 1.f/btSqrt(s_squared); + return btVector3(m_floats[0] * s, m_floats[1] * s, m_floats[2] * s); } /**@brief Return the inverse of this quaternion */ @@ -279,23 +280,25 @@ public: * Slerp interpolates assuming constant velocity. */ btQuaternion slerp(const btQuaternion& q, const btScalar& t) const { - btScalar theta = angle(q); - if (theta != btScalar(0.0)) + btScalar magnitude = btSqrt(length2() * q.length2()); + btAssert(magnitude > btScalar(0)); + + btScalar product = dot(q) / magnitude; + if (btFabs(product) != btScalar(1)) { - btScalar d = btScalar(1.0) / btSin(theta); - btScalar s0 = btSin((btScalar(1.0) - t) * theta); - btScalar s1 = btSin(t * theta); - if (dot(q) < 0) // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp - return btQuaternion((m_floats[0] * s0 + -q.x() * s1) * d, - (m_floats[1] * s0 + -q.y() * s1) * d, - (m_floats[2] * s0 + -q.z() * s1) * d, - (m_floats[3] * s0 + -q.m_floats[3] * s1) * d); - else - return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d, - (m_floats[1] * s0 + q.y() * s1) * d, - (m_floats[2] * s0 + q.z() * s1) * d, - (m_floats[3] * s0 + q.m_floats[3] * s1) * d); - + // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp + const btScalar sign = (product < 0) ? btScalar(-1) : btScalar(1); + + const btScalar theta = btAcos(sign * product); + const btScalar s1 = btSin(sign * t * theta); + const btScalar d = btScalar(1.0) / btSin(theta); + const btScalar s0 = btSin((btScalar(1.0) - t) * theta); + + return btQuaternion( + (m_floats[0] * s0 + q.x() * s1) * d, + (m_floats[1] * s0 + q.y() * s1) * d, + (m_floats[2] * s0 + q.z() * s1) * d, + (m_floats[3] * s0 + q.m_floats[3] * s1) * d); } else { @@ -315,12 +318,6 @@ public: }; -/**@brief Return the negative of a quaternion */ -SIMD_FORCE_INLINE btQuaternion -operator-(const btQuaternion& q) -{ - return btQuaternion(-q.x(), -q.y(), -q.z(), -q.w()); -} @@ -426,7 +423,7 @@ shortestArcQuatNormalize2(btVector3& v0,btVector3& v1) return shortestArcQuat(v0,v1); } -#endif +#endif //BT_SIMD__QUATERNION_H_ diff --git a/extern/bullet2/src/LinearMath/btQuickprof.cpp b/extern/bullet2/src/LinearMath/btQuickprof.cpp index 14534068a0d..544aee89d02 100644 --- a/extern/bullet2/src/LinearMath/btQuickprof.cpp +++ b/extern/bullet2/src/LinearMath/btQuickprof.cpp @@ -276,7 +276,8 @@ CProfileNode::CProfileNode( const char * name, CProfileNode * parent ) : RecursionCounter( 0 ), Parent( parent ), Child( NULL ), - Sibling( NULL ) + Sibling( NULL ), + m_userPtr(0) { Reset(); } diff --git a/extern/bullet2/src/LinearMath/btQuickprof.h b/extern/bullet2/src/LinearMath/btQuickprof.h index adfbbe6149c..93f3f4a60fa 100644 --- a/extern/bullet2/src/LinearMath/btQuickprof.h +++ b/extern/bullet2/src/LinearMath/btQuickprof.h @@ -12,8 +12,8 @@ -#ifndef QUICK_PROF_H -#define QUICK_PROF_H +#ifndef BT_QUICK_PROF_H +#define BT_QUICK_PROF_H //To disable built-in profiling, please comment out next line //#define BT_NO_PROFILE 1 @@ -82,7 +82,8 @@ public: const char * Get_Name( void ) { return Name; } int Get_Total_Calls( void ) { return TotalCalls; } float Get_Total_Time( void ) { return TotalTime; } - + void* GetUserPointer() const {return m_userPtr;} + void SetUserPointer(void* ptr) { m_userPtr = ptr;} protected: const char * Name; @@ -94,6 +95,7 @@ protected: CProfileNode * Parent; CProfileNode * Child; CProfileNode * Sibling; + void* m_userPtr; }; ///An iterator to navigate through the tree @@ -115,15 +117,20 @@ public: int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); } float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); } + void* Get_Current_UserPointer( void ) { return CurrentChild->GetUserPointer(); } + void Set_Current_UserPointer(void* ptr) {CurrentChild->SetUserPointer(ptr);} // Access the current parent const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); } int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); } float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); } + + protected: CProfileNode * CurrentParent; CProfileNode * CurrentChild; + CProfileIterator( CProfileNode * start ); friend class CProfileManager; @@ -191,6 +198,6 @@ public: -#endif //QUICK_PROF_H +#endif //BT_QUICK_PROF_H diff --git a/extern/bullet2/src/LinearMath/btRandom.h b/extern/bullet2/src/LinearMath/btRandom.h index fdf65e01caf..4cbfc6bfe9f 100644 --- a/extern/bullet2/src/LinearMath/btRandom.h +++ b/extern/bullet2/src/LinearMath/btRandom.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef GEN_RANDOM_H -#define GEN_RANDOM_H +#ifndef BT_GEN_RANDOM_H +#define BT_GEN_RANDOM_H #ifdef MT19937 @@ -38,5 +38,5 @@ SIMD_FORCE_INLINE unsigned int GEN_rand() { return rand(); } #endif -#endif +#endif //BT_GEN_RANDOM_H diff --git a/extern/bullet2/src/LinearMath/btScalar.h b/extern/bullet2/src/LinearMath/btScalar.h index 6ba6c5ad30d..ecae972243c 100644 --- a/extern/bullet2/src/LinearMath/btScalar.h +++ b/extern/bullet2/src/LinearMath/btScalar.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef SIMD___SCALAR_H -#define SIMD___SCALAR_H +#ifndef BT_SCALAR_H +#define BT_SCALAR_H #ifdef BT_MANAGED_CODE //Aligned data types not supported in managed code @@ -25,12 +25,10 @@ subject to the following restrictions: #include <math.h> #include <stdlib.h>//size_t for MSVC 6.0 -#include <cstdlib> -#include <cfloat> #include <float.h> -/* SVN $Revision: 35500 $ on $Date: 2011-03-12 21:34:17 +0100 (Sat, 12 Mar 2011) $ from http://bullet.googlecode.com*/ -#define BT_BULLET_VERSION 278 +/* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/ +#define BT_BULLET_VERSION 280 inline int btGetVersion() { @@ -521,4 +519,29 @@ struct btTypedObject return m_objectType; } }; -#endif //SIMD___SCALAR_H + + + +///align a pointer to the provided alignment, upwards +template <typename T>T* btAlignPointer(T* unalignedPtr, size_t alignment) +{ + + struct btConvertPointerSizeT + { + union + { + T* ptr; + size_t integer; + }; + }; + btConvertPointerSizeT converter; + + + const size_t bit_mask = ~(alignment - 1); + converter.ptr = unalignedPtr; + converter.integer += alignment-1; + converter.integer &= bit_mask; + return converter.ptr; +} + +#endif //BT_SCALAR_H diff --git a/extern/bullet2/src/LinearMath/btSerializer.cpp b/extern/bullet2/src/LinearMath/btSerializer.cpp index c6d387e6133..49c25b7ea2a 100644 --- a/extern/bullet2/src/LinearMath/btSerializer.cpp +++ b/extern/bullet2/src/LinearMath/btSerializer.cpp @@ -1,5 +1,5 @@ -unsigned char sBulletDNAstr[]= { -83,68,78,65,78,65,77,69,42,1,0,0,109,95,115,105,122,101,0,109, +char sBulletDNAstr[]= { +83,68,78,65,78,65,77,69,44,1,0,0,109,95,115,105,122,101,0,109, 95,99,97,112,97,99,105,116,121,0,42,109,95,100,97,116,97,0,109,95, 99,111,108,108,105,115,105,111,110,83,104,97,112,101,115,0,109,95,99,111, 108,108,105,115,105,111,110,79,98,106,101,99,116,115,0,109,95,99,111,110, @@ -130,292 +130,297 @@ unsigned char sBulletDNAstr[]= { 112,108,105,101,100,73,109,112,117,108,115,101,0,109,95,100,98,103,68,114, 97,119,83,105,122,101,0,109,95,100,105,115,97,98,108,101,67,111,108,108, 105,115,105,111,110,115,66,101,116,119,101,101,110,76,105,110,107,101,100,66, -111,100,105,101,115,0,109,95,112,97,100,52,91,52,93,0,109,95,116,121, -112,101,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,109,95,112, -105,118,111,116,73,110,65,0,109,95,112,105,118,111,116,73,110,66,0,109, -95,114,98,65,70,114,97,109,101,0,109,95,114,98,66,70,114,97,109,101, -0,109,95,117,115,101,82,101,102,101,114,101,110,99,101,70,114,97,109,101, -65,0,109,95,97,110,103,117,108,97,114,79,110,108,121,0,109,95,101,110, -97,98,108,101,65,110,103,117,108,97,114,77,111,116,111,114,0,109,95,109, -111,116,111,114,84,97,114,103,101,116,86,101,108,111,99,105,116,121,0,109, -95,109,97,120,77,111,116,111,114,73,109,112,117,108,115,101,0,109,95,108, -111,119,101,114,76,105,109,105,116,0,109,95,117,112,112,101,114,76,105,109, -105,116,0,109,95,108,105,109,105,116,83,111,102,116,110,101,115,115,0,109, -95,98,105,97,115,70,97,99,116,111,114,0,109,95,114,101,108,97,120,97, -116,105,111,110,70,97,99,116,111,114,0,109,95,115,119,105,110,103,83,112, -97,110,49,0,109,95,115,119,105,110,103,83,112,97,110,50,0,109,95,116, -119,105,115,116,83,112,97,110,0,109,95,100,97,109,112,105,110,103,0,109, -95,108,105,110,101,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95, -108,105,110,101,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,97, -110,103,117,108,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95,97, -110,103,117,108,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,117, -115,101,76,105,110,101,97,114,82,101,102,101,114,101,110,99,101,70,114,97, -109,101,65,0,109,95,117,115,101,79,102,102,115,101,116,70,111,114,67,111, -110,115,116,114,97,105,110,116,70,114,97,109,101,0,109,95,54,100,111,102, -68,97,116,97,0,109,95,115,112,114,105,110,103,69,110,97,98,108,101,100, -91,54,93,0,109,95,101,113,117,105,108,105,98,114,105,117,109,80,111,105, -110,116,91,54,93,0,109,95,115,112,114,105,110,103,83,116,105,102,102,110, -101,115,115,91,54,93,0,109,95,115,112,114,105,110,103,68,97,109,112,105, -110,103,91,54,93,0,109,95,108,105,110,101,97,114,83,116,105,102,102,110, -101,115,115,0,109,95,97,110,103,117,108,97,114,83,116,105,102,102,110,101, -115,115,0,109,95,118,111,108,117,109,101,83,116,105,102,102,110,101,115,115, -0,42,109,95,109,97,116,101,114,105,97,108,0,109,95,112,111,115,105,116, -105,111,110,0,109,95,112,114,101,118,105,111,117,115,80,111,115,105,116,105, -111,110,0,109,95,118,101,108,111,99,105,116,121,0,109,95,97,99,99,117, -109,117,108,97,116,101,100,70,111,114,99,101,0,109,95,110,111,114,109,97, -108,0,109,95,97,114,101,97,0,109,95,97,116,116,97,99,104,0,109,95, -110,111,100,101,73,110,100,105,99,101,115,91,50,93,0,109,95,114,101,115, -116,76,101,110,103,116,104,0,109,95,98,98,101,110,100,105,110,103,0,109, -95,110,111,100,101,73,110,100,105,99,101,115,91,51,93,0,109,95,114,101, -115,116,65,114,101,97,0,109,95,99,48,91,52,93,0,109,95,110,111,100, -101,73,110,100,105,99,101,115,91,52,93,0,109,95,114,101,115,116,86,111, -108,117,109,101,0,109,95,99,49,0,109,95,99,50,0,109,95,99,48,0, -109,95,108,111,99,97,108,70,114,97,109,101,0,42,109,95,114,105,103,105, -100,66,111,100,121,0,109,95,110,111,100,101,73,110,100,101,120,0,109,95, -97,101,114,111,77,111,100,101,108,0,109,95,98,97,117,109,103,97,114,116, -101,0,109,95,100,114,97,103,0,109,95,108,105,102,116,0,109,95,112,114, -101,115,115,117,114,101,0,109,95,118,111,108,117,109,101,0,109,95,100,121, -110,97,109,105,99,70,114,105,99,116,105,111,110,0,109,95,112,111,115,101, -77,97,116,99,104,0,109,95,114,105,103,105,100,67,111,110,116,97,99,116, -72,97,114,100,110,101,115,115,0,109,95,107,105,110,101,116,105,99,67,111, -110,116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116, -67,111,110,116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,97,110, -99,104,111,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,82, -105,103,105,100,67,108,117,115,116,101,114,72,97,114,100,110,101,115,115,0, -109,95,115,111,102,116,75,105,110,101,116,105,99,67,108,117,115,116,101,114, -72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,83,111,102,116,67, -108,117,115,116,101,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102, -116,82,105,103,105,100,67,108,117,115,116,101,114,73,109,112,117,108,115,101, -83,112,108,105,116,0,109,95,115,111,102,116,75,105,110,101,116,105,99,67, -108,117,115,116,101,114,73,109,112,117,108,115,101,83,112,108,105,116,0,109, -95,115,111,102,116,83,111,102,116,67,108,117,115,116,101,114,73,109,112,117, -108,115,101,83,112,108,105,116,0,109,95,109,97,120,86,111,108,117,109,101, -0,109,95,116,105,109,101,83,99,97,108,101,0,109,95,118,101,108,111,99, -105,116,121,73,116,101,114,97,116,105,111,110,115,0,109,95,112,111,115,105, -116,105,111,110,73,116,101,114,97,116,105,111,110,115,0,109,95,100,114,105, -102,116,73,116,101,114,97,116,105,111,110,115,0,109,95,99,108,117,115,116, -101,114,73,116,101,114,97,116,105,111,110,115,0,109,95,114,111,116,0,109, -95,115,99,97,108,101,0,109,95,97,113,113,0,109,95,99,111,109,0,42, -109,95,112,111,115,105,116,105,111,110,115,0,42,109,95,119,101,105,103,104, -116,115,0,109,95,110,117,109,80,111,115,105,116,105,111,110,115,0,109,95, -110,117,109,87,101,105,103,116,115,0,109,95,98,118,111,108,117,109,101,0, -109,95,98,102,114,97,109,101,0,109,95,102,114,97,109,101,120,102,111,114, -109,0,109,95,108,111,99,105,105,0,109,95,105,110,118,119,105,0,109,95, -118,105,109,112,117,108,115,101,115,91,50,93,0,109,95,100,105,109,112,117, -108,115,101,115,91,50,93,0,109,95,108,118,0,109,95,97,118,0,42,109, -95,102,114,97,109,101,114,101,102,115,0,42,109,95,110,111,100,101,73,110, -100,105,99,101,115,0,42,109,95,109,97,115,115,101,115,0,109,95,110,117, -109,70,114,97,109,101,82,101,102,115,0,109,95,110,117,109,78,111,100,101, -115,0,109,95,110,117,109,77,97,115,115,101,115,0,109,95,105,100,109,97, -115,115,0,109,95,105,109,97,115,115,0,109,95,110,118,105,109,112,117,108, -115,101,115,0,109,95,110,100,105,109,112,117,108,115,101,115,0,109,95,110, -100,97,109,112,105,110,103,0,109,95,108,100,97,109,112,105,110,103,0,109, -95,97,100,97,109,112,105,110,103,0,109,95,109,97,116,99,104,105,110,103, -0,109,95,109,97,120,83,101,108,102,67,111,108,108,105,115,105,111,110,73, -109,112,117,108,115,101,0,109,95,115,101,108,102,67,111,108,108,105,115,105, -111,110,73,109,112,117,108,115,101,70,97,99,116,111,114,0,109,95,99,111, -110,116,97,105,110,115,65,110,99,104,111,114,0,109,95,99,111,108,108,105, -100,101,0,109,95,99,108,117,115,116,101,114,73,110,100,101,120,0,42,109, -95,98,111,100,121,65,0,42,109,95,98,111,100,121,66,0,109,95,114,101, -102,115,91,50,93,0,109,95,99,102,109,0,109,95,101,114,112,0,109,95, -115,112,108,105,116,0,109,95,100,101,108,101,116,101,0,109,95,114,101,108, -80,111,115,105,116,105,111,110,91,50,93,0,109,95,98,111,100,121,65,116, -121,112,101,0,109,95,98,111,100,121,66,116,121,112,101,0,109,95,106,111, -105,110,116,84,121,112,101,0,42,109,95,112,111,115,101,0,42,42,109,95, -109,97,116,101,114,105,97,108,115,0,42,109,95,110,111,100,101,115,0,42, -109,95,108,105,110,107,115,0,42,109,95,102,97,99,101,115,0,42,109,95, -116,101,116,114,97,104,101,100,114,97,0,42,109,95,97,110,99,104,111,114, -115,0,42,109,95,99,108,117,115,116,101,114,115,0,42,109,95,106,111,105, -110,116,115,0,109,95,110,117,109,77,97,116,101,114,105,97,108,115,0,109, -95,110,117,109,76,105,110,107,115,0,109,95,110,117,109,70,97,99,101,115, -0,109,95,110,117,109,84,101,116,114,97,104,101,100,114,97,0,109,95,110, -117,109,65,110,99,104,111,114,115,0,109,95,110,117,109,67,108,117,115,116, -101,114,115,0,109,95,110,117,109,74,111,105,110,116,115,0,109,95,99,111, -110,102,105,103,0,0,0,0,84,89,80,69,72,0,0,0,99,104,97,114, -0,117,99,104,97,114,0,115,104,111,114,116,0,117,115,104,111,114,116,0, -105,110,116,0,108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116, -0,100,111,117,98,108,101,0,118,111,105,100,0,80,111,105,110,116,101,114, -65,114,114,97,121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101, -109,0,76,105,115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51, -70,108,111,97,116,68,97,116,97,0,98,116,86,101,99,116,111,114,51,68, -111,117,98,108,101,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120, -51,70,108,111,97,116,68,97,116,97,0,98,116,77,97,116,114,105,120,51, -120,51,68,111,117,98,108,101,68,97,116,97,0,98,116,84,114,97,110,115, -102,111,114,109,70,108,111,97,116,68,97,116,97,0,98,116,84,114,97,110, -115,102,111,114,109,68,111,117,98,108,101,68,97,116,97,0,98,116,66,118, -104,83,117,98,116,114,101,101,73,110,102,111,68,97,116,97,0,98,116,79, -112,116,105,109,105,122,101,100,66,118,104,78,111,100,101,70,108,111,97,116, -68,97,116,97,0,98,116,79,112,116,105,109,105,122,101,100,66,118,104,78, -111,100,101,68,111,117,98,108,101,68,97,116,97,0,98,116,81,117,97,110, -116,105,122,101,100,66,118,104,78,111,100,101,68,97,116,97,0,98,116,81, -117,97,110,116,105,122,101,100,66,118,104,70,108,111,97,116,68,97,116,97, -0,98,116,81,117,97,110,116,105,122,101,100,66,118,104,68,111,117,98,108, -101,68,97,116,97,0,98,116,67,111,108,108,105,115,105,111,110,83,104,97, -112,101,68,97,116,97,0,98,116,83,116,97,116,105,99,80,108,97,110,101, -83,104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,73,110, -116,101,114,110,97,108,83,104,97,112,101,68,97,116,97,0,98,116,80,111, -115,105,116,105,111,110,65,110,100,82,97,100,105,117,115,0,98,116,77,117, -108,116,105,83,112,104,101,114,101,83,104,97,112,101,68,97,116,97,0,98, -116,73,110,116,73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114, -116,73,110,116,73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114, -116,73,110,116,73,110,100,101,120,84,114,105,112,108,101,116,68,97,116,97, -0,98,116,67,104,97,114,73,110,100,101,120,84,114,105,112,108,101,116,68, -97,116,97,0,98,116,77,101,115,104,80,97,114,116,68,97,116,97,0,98, -116,83,116,114,105,100,105,110,103,77,101,115,104,73,110,116,101,114,102,97, -99,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108,101,77,101,115, -104,83,104,97,112,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108, -101,73,110,102,111,77,97,112,68,97,116,97,0,98,116,83,99,97,108,101, -100,84,114,105,97,110,103,108,101,77,101,115,104,83,104,97,112,101,68,97, -116,97,0,98,116,67,111,109,112,111,117,110,100,83,104,97,112,101,67,104, -105,108,100,68,97,116,97,0,98,116,67,111,109,112,111,117,110,100,83,104, -97,112,101,68,97,116,97,0,98,116,67,121,108,105,110,100,101,114,83,104, -97,112,101,68,97,116,97,0,98,116,67,97,112,115,117,108,101,83,104,97, +111,100,105,101,115,0,109,95,111,118,101,114,114,105,100,101,78,117,109,83, +111,108,118,101,114,73,116,101,114,97,116,105,111,110,115,0,109,95,98,114, +101,97,107,105,110,103,73,109,112,117,108,115,101,84,104,114,101,115,104,111, +108,100,0,109,95,105,115,69,110,97,98,108,101,100,0,109,95,116,121,112, +101,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,109,95,112,105, +118,111,116,73,110,65,0,109,95,112,105,118,111,116,73,110,66,0,109,95, +114,98,65,70,114,97,109,101,0,109,95,114,98,66,70,114,97,109,101,0, +109,95,117,115,101,82,101,102,101,114,101,110,99,101,70,114,97,109,101,65, +0,109,95,97,110,103,117,108,97,114,79,110,108,121,0,109,95,101,110,97, +98,108,101,65,110,103,117,108,97,114,77,111,116,111,114,0,109,95,109,111, +116,111,114,84,97,114,103,101,116,86,101,108,111,99,105,116,121,0,109,95, +109,97,120,77,111,116,111,114,73,109,112,117,108,115,101,0,109,95,108,111, +119,101,114,76,105,109,105,116,0,109,95,117,112,112,101,114,76,105,109,105, +116,0,109,95,108,105,109,105,116,83,111,102,116,110,101,115,115,0,109,95, +98,105,97,115,70,97,99,116,111,114,0,109,95,114,101,108,97,120,97,116, +105,111,110,70,97,99,116,111,114,0,109,95,115,119,105,110,103,83,112,97, +110,49,0,109,95,115,119,105,110,103,83,112,97,110,50,0,109,95,116,119, +105,115,116,83,112,97,110,0,109,95,100,97,109,112,105,110,103,0,109,95, +108,105,110,101,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95,108, +105,110,101,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,97,110, +103,117,108,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95,97,110, +103,117,108,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,117,115, +101,76,105,110,101,97,114,82,101,102,101,114,101,110,99,101,70,114,97,109, +101,65,0,109,95,117,115,101,79,102,102,115,101,116,70,111,114,67,111,110, +115,116,114,97,105,110,116,70,114,97,109,101,0,109,95,54,100,111,102,68, +97,116,97,0,109,95,115,112,114,105,110,103,69,110,97,98,108,101,100,91, +54,93,0,109,95,101,113,117,105,108,105,98,114,105,117,109,80,111,105,110, +116,91,54,93,0,109,95,115,112,114,105,110,103,83,116,105,102,102,110,101, +115,115,91,54,93,0,109,95,115,112,114,105,110,103,68,97,109,112,105,110, +103,91,54,93,0,109,95,108,105,110,101,97,114,83,116,105,102,102,110,101, +115,115,0,109,95,97,110,103,117,108,97,114,83,116,105,102,102,110,101,115, +115,0,109,95,118,111,108,117,109,101,83,116,105,102,102,110,101,115,115,0, +42,109,95,109,97,116,101,114,105,97,108,0,109,95,112,111,115,105,116,105, +111,110,0,109,95,112,114,101,118,105,111,117,115,80,111,115,105,116,105,111, +110,0,109,95,118,101,108,111,99,105,116,121,0,109,95,97,99,99,117,109, +117,108,97,116,101,100,70,111,114,99,101,0,109,95,110,111,114,109,97,108, +0,109,95,97,114,101,97,0,109,95,97,116,116,97,99,104,0,109,95,110, +111,100,101,73,110,100,105,99,101,115,91,50,93,0,109,95,114,101,115,116, +76,101,110,103,116,104,0,109,95,98,98,101,110,100,105,110,103,0,109,95, +110,111,100,101,73,110,100,105,99,101,115,91,51,93,0,109,95,114,101,115, +116,65,114,101,97,0,109,95,99,48,91,52,93,0,109,95,110,111,100,101, +73,110,100,105,99,101,115,91,52,93,0,109,95,114,101,115,116,86,111,108, +117,109,101,0,109,95,99,49,0,109,95,99,50,0,109,95,99,48,0,109, +95,108,111,99,97,108,70,114,97,109,101,0,42,109,95,114,105,103,105,100, +66,111,100,121,0,109,95,110,111,100,101,73,110,100,101,120,0,109,95,97, +101,114,111,77,111,100,101,108,0,109,95,98,97,117,109,103,97,114,116,101, +0,109,95,100,114,97,103,0,109,95,108,105,102,116,0,109,95,112,114,101, +115,115,117,114,101,0,109,95,118,111,108,117,109,101,0,109,95,100,121,110, +97,109,105,99,70,114,105,99,116,105,111,110,0,109,95,112,111,115,101,77, +97,116,99,104,0,109,95,114,105,103,105,100,67,111,110,116,97,99,116,72, +97,114,100,110,101,115,115,0,109,95,107,105,110,101,116,105,99,67,111,110, +116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,67, +111,110,116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,97,110,99, +104,111,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,82,105, +103,105,100,67,108,117,115,116,101,114,72,97,114,100,110,101,115,115,0,109, +95,115,111,102,116,75,105,110,101,116,105,99,67,108,117,115,116,101,114,72, +97,114,100,110,101,115,115,0,109,95,115,111,102,116,83,111,102,116,67,108, +117,115,116,101,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116, +82,105,103,105,100,67,108,117,115,116,101,114,73,109,112,117,108,115,101,83, +112,108,105,116,0,109,95,115,111,102,116,75,105,110,101,116,105,99,67,108, +117,115,116,101,114,73,109,112,117,108,115,101,83,112,108,105,116,0,109,95, +115,111,102,116,83,111,102,116,67,108,117,115,116,101,114,73,109,112,117,108, +115,101,83,112,108,105,116,0,109,95,109,97,120,86,111,108,117,109,101,0, +109,95,116,105,109,101,83,99,97,108,101,0,109,95,118,101,108,111,99,105, +116,121,73,116,101,114,97,116,105,111,110,115,0,109,95,112,111,115,105,116, +105,111,110,73,116,101,114,97,116,105,111,110,115,0,109,95,100,114,105,102, +116,73,116,101,114,97,116,105,111,110,115,0,109,95,99,108,117,115,116,101, +114,73,116,101,114,97,116,105,111,110,115,0,109,95,114,111,116,0,109,95, +115,99,97,108,101,0,109,95,97,113,113,0,109,95,99,111,109,0,42,109, +95,112,111,115,105,116,105,111,110,115,0,42,109,95,119,101,105,103,104,116, +115,0,109,95,110,117,109,80,111,115,105,116,105,111,110,115,0,109,95,110, +117,109,87,101,105,103,116,115,0,109,95,98,118,111,108,117,109,101,0,109, +95,98,102,114,97,109,101,0,109,95,102,114,97,109,101,120,102,111,114,109, +0,109,95,108,111,99,105,105,0,109,95,105,110,118,119,105,0,109,95,118, +105,109,112,117,108,115,101,115,91,50,93,0,109,95,100,105,109,112,117,108, +115,101,115,91,50,93,0,109,95,108,118,0,109,95,97,118,0,42,109,95, +102,114,97,109,101,114,101,102,115,0,42,109,95,110,111,100,101,73,110,100, +105,99,101,115,0,42,109,95,109,97,115,115,101,115,0,109,95,110,117,109, +70,114,97,109,101,82,101,102,115,0,109,95,110,117,109,78,111,100,101,115, +0,109,95,110,117,109,77,97,115,115,101,115,0,109,95,105,100,109,97,115, +115,0,109,95,105,109,97,115,115,0,109,95,110,118,105,109,112,117,108,115, +101,115,0,109,95,110,100,105,109,112,117,108,115,101,115,0,109,95,110,100, +97,109,112,105,110,103,0,109,95,108,100,97,109,112,105,110,103,0,109,95, +97,100,97,109,112,105,110,103,0,109,95,109,97,116,99,104,105,110,103,0, +109,95,109,97,120,83,101,108,102,67,111,108,108,105,115,105,111,110,73,109, +112,117,108,115,101,0,109,95,115,101,108,102,67,111,108,108,105,115,105,111, +110,73,109,112,117,108,115,101,70,97,99,116,111,114,0,109,95,99,111,110, +116,97,105,110,115,65,110,99,104,111,114,0,109,95,99,111,108,108,105,100, +101,0,109,95,99,108,117,115,116,101,114,73,110,100,101,120,0,42,109,95, +98,111,100,121,65,0,42,109,95,98,111,100,121,66,0,109,95,114,101,102, +115,91,50,93,0,109,95,99,102,109,0,109,95,101,114,112,0,109,95,115, +112,108,105,116,0,109,95,100,101,108,101,116,101,0,109,95,114,101,108,80, +111,115,105,116,105,111,110,91,50,93,0,109,95,98,111,100,121,65,116,121, +112,101,0,109,95,98,111,100,121,66,116,121,112,101,0,109,95,106,111,105, +110,116,84,121,112,101,0,42,109,95,112,111,115,101,0,42,42,109,95,109, +97,116,101,114,105,97,108,115,0,42,109,95,110,111,100,101,115,0,42,109, +95,108,105,110,107,115,0,42,109,95,102,97,99,101,115,0,42,109,95,116, +101,116,114,97,104,101,100,114,97,0,42,109,95,97,110,99,104,111,114,115, +0,42,109,95,99,108,117,115,116,101,114,115,0,42,109,95,106,111,105,110, +116,115,0,109,95,110,117,109,77,97,116,101,114,105,97,108,115,0,109,95, +110,117,109,76,105,110,107,115,0,109,95,110,117,109,70,97,99,101,115,0, +109,95,110,117,109,84,101,116,114,97,104,101,100,114,97,0,109,95,110,117, +109,65,110,99,104,111,114,115,0,109,95,110,117,109,67,108,117,115,116,101, +114,115,0,109,95,110,117,109,74,111,105,110,116,115,0,109,95,99,111,110, +102,105,103,0,84,89,80,69,72,0,0,0,99,104,97,114,0,117,99,104, +97,114,0,115,104,111,114,116,0,117,115,104,111,114,116,0,105,110,116,0, +108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116,0,100,111,117, +98,108,101,0,118,111,105,100,0,80,111,105,110,116,101,114,65,114,114,97, +121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101,109,0,76,105, +115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51,70,108,111,97, +116,68,97,116,97,0,98,116,86,101,99,116,111,114,51,68,111,117,98,108, +101,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120,51,70,108,111, +97,116,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120,51,68,111, +117,98,108,101,68,97,116,97,0,98,116,84,114,97,110,115,102,111,114,109, +70,108,111,97,116,68,97,116,97,0,98,116,84,114,97,110,115,102,111,114, +109,68,111,117,98,108,101,68,97,116,97,0,98,116,66,118,104,83,117,98, +116,114,101,101,73,110,102,111,68,97,116,97,0,98,116,79,112,116,105,109, +105,122,101,100,66,118,104,78,111,100,101,70,108,111,97,116,68,97,116,97, +0,98,116,79,112,116,105,109,105,122,101,100,66,118,104,78,111,100,101,68, +111,117,98,108,101,68,97,116,97,0,98,116,81,117,97,110,116,105,122,101, +100,66,118,104,78,111,100,101,68,97,116,97,0,98,116,81,117,97,110,116, +105,122,101,100,66,118,104,70,108,111,97,116,68,97,116,97,0,98,116,81, +117,97,110,116,105,122,101,100,66,118,104,68,111,117,98,108,101,68,97,116, +97,0,98,116,67,111,108,108,105,115,105,111,110,83,104,97,112,101,68,97, +116,97,0,98,116,83,116,97,116,105,99,80,108,97,110,101,83,104,97,112, +101,68,97,116,97,0,98,116,67,111,110,118,101,120,73,110,116,101,114,110, +97,108,83,104,97,112,101,68,97,116,97,0,98,116,80,111,115,105,116,105, +111,110,65,110,100,82,97,100,105,117,115,0,98,116,77,117,108,116,105,83, +112,104,101,114,101,83,104,97,112,101,68,97,116,97,0,98,116,73,110,116, +73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114,116,73,110,116, +73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114,116,73,110,116, +73,110,100,101,120,84,114,105,112,108,101,116,68,97,116,97,0,98,116,67, +104,97,114,73,110,100,101,120,84,114,105,112,108,101,116,68,97,116,97,0, +98,116,77,101,115,104,80,97,114,116,68,97,116,97,0,98,116,83,116,114, +105,100,105,110,103,77,101,115,104,73,110,116,101,114,102,97,99,101,68,97, +116,97,0,98,116,84,114,105,97,110,103,108,101,77,101,115,104,83,104,97, 112,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108,101,73,110,102, -111,68,97,116,97,0,98,116,71,73,109,112,97,99,116,77,101,115,104,83, -104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,72,117,108, -108,83,104,97,112,101,68,97,116,97,0,98,116,67,111,108,108,105,115,105, -111,110,79,98,106,101,99,116,68,111,117,98,108,101,68,97,116,97,0,98, -116,67,111,108,108,105,115,105,111,110,79,98,106,101,99,116,70,108,111,97, -116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,70,108,111, -97,116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,111, -117,98,108,101,68,97,116,97,0,98,116,67,111,110,115,116,114,97,105,110, -116,73,110,102,111,49,0,98,116,84,121,112,101,100,67,111,110,115,116,114, -97,105,110,116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121, -68,97,116,97,0,98,116,80,111,105,110,116,50,80,111,105,110,116,67,111, -110,115,116,114,97,105,110,116,70,108,111,97,116,68,97,116,97,0,98,116, -80,111,105,110,116,50,80,111,105,110,116,67,111,110,115,116,114,97,105,110, -116,68,111,117,98,108,101,68,97,116,97,0,98,116,72,105,110,103,101,67, -111,110,115,116,114,97,105,110,116,68,111,117,98,108,101,68,97,116,97,0, -98,116,72,105,110,103,101,67,111,110,115,116,114,97,105,110,116,70,108,111, -97,116,68,97,116,97,0,98,116,67,111,110,101,84,119,105,115,116,67,111, -110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,71,101,110,101,114, -105,99,54,68,111,102,67,111,110,115,116,114,97,105,110,116,68,97,116,97, -0,98,116,71,101,110,101,114,105,99,54,68,111,102,83,112,114,105,110,103, -67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,83,108,105, -100,101,114,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,83,111, -102,116,66,111,100,121,77,97,116,101,114,105,97,108,68,97,116,97,0,83, -111,102,116,66,111,100,121,78,111,100,101,68,97,116,97,0,83,111,102,116, -66,111,100,121,76,105,110,107,68,97,116,97,0,83,111,102,116,66,111,100, -121,70,97,99,101,68,97,116,97,0,83,111,102,116,66,111,100,121,84,101, -116,114,97,68,97,116,97,0,83,111,102,116,82,105,103,105,100,65,110,99, -104,111,114,68,97,116,97,0,83,111,102,116,66,111,100,121,67,111,110,102, -105,103,68,97,116,97,0,83,111,102,116,66,111,100,121,80,111,115,101,68, -97,116,97,0,83,111,102,116,66,111,100,121,67,108,117,115,116,101,114,68, -97,116,97,0,98,116,83,111,102,116,66,111,100,121,74,111,105,110,116,68, -97,116,97,0,98,116,83,111,102,116,66,111,100,121,70,108,111,97,116,68, -97,116,97,0,84,76,69,78,1,0,1,0,2,0,2,0,4,0,4,0, -4,0,4,0,8,0,0,0,12,0,36,0,8,0,16,0,32,0,48,0, -96,0,64,0,-128,0,20,0,48,0,80,0,16,0,84,0,-124,0,12,0, -52,0,52,0,20,0,64,0,4,0,4,0,8,0,4,0,32,0,28,0, -60,0,56,0,76,0,76,0,24,0,60,0,60,0,16,0,64,0,68,0, --56,1,-8,0,-32,1,-104,3,8,0,44,0,0,0,76,0,108,0,84,1, --44,0,-52,0,-12,0,84,1,-60,0,16,0,100,0,20,0,36,0,100,0, -92,0,104,0,-64,0,92,1,104,0,-92,1,83,84,82,67,61,0,0,0, -10,0,3,0,4,0,0,0,4,0,1,0,9,0,2,0,11,0,3,0, -10,0,3,0,10,0,4,0,10,0,5,0,12,0,2,0,9,0,6,0, -9,0,7,0,13,0,1,0,7,0,8,0,14,0,1,0,8,0,8,0, -15,0,1,0,13,0,9,0,16,0,1,0,14,0,9,0,17,0,2,0, -15,0,10,0,13,0,11,0,18,0,2,0,16,0,10,0,14,0,11,0, -19,0,4,0,4,0,12,0,4,0,13,0,2,0,14,0,2,0,15,0, -20,0,6,0,13,0,16,0,13,0,17,0,4,0,18,0,4,0,19,0, -4,0,20,0,0,0,21,0,21,0,6,0,14,0,16,0,14,0,17,0, -4,0,18,0,4,0,19,0,4,0,20,0,0,0,21,0,22,0,3,0, -2,0,14,0,2,0,15,0,4,0,22,0,23,0,12,0,13,0,23,0, -13,0,24,0,13,0,25,0,4,0,26,0,4,0,27,0,4,0,28,0, -4,0,29,0,20,0,30,0,22,0,31,0,19,0,32,0,4,0,33,0, -4,0,34,0,24,0,12,0,14,0,23,0,14,0,24,0,14,0,25,0, -4,0,26,0,4,0,27,0,4,0,28,0,4,0,29,0,21,0,30,0, -22,0,31,0,4,0,33,0,4,0,34,0,19,0,32,0,25,0,3,0, -0,0,35,0,4,0,36,0,0,0,37,0,26,0,5,0,25,0,38,0, -13,0,39,0,13,0,40,0,7,0,41,0,0,0,21,0,27,0,5,0, -25,0,38,0,13,0,39,0,13,0,42,0,7,0,43,0,4,0,44,0, -28,0,2,0,13,0,45,0,7,0,46,0,29,0,4,0,27,0,47,0, -28,0,48,0,4,0,49,0,0,0,37,0,30,0,1,0,4,0,50,0, -31,0,2,0,2,0,50,0,0,0,51,0,32,0,2,0,2,0,52,0, -0,0,51,0,33,0,2,0,0,0,52,0,0,0,53,0,34,0,8,0, -13,0,54,0,14,0,55,0,30,0,56,0,32,0,57,0,33,0,58,0, -31,0,59,0,4,0,60,0,4,0,61,0,35,0,4,0,34,0,62,0, -13,0,63,0,4,0,64,0,0,0,37,0,36,0,7,0,25,0,38,0, -35,0,65,0,23,0,66,0,24,0,67,0,37,0,68,0,7,0,43,0, -0,0,69,0,38,0,2,0,36,0,70,0,13,0,39,0,39,0,4,0, -17,0,71,0,25,0,72,0,4,0,73,0,7,0,74,0,40,0,4,0, -25,0,38,0,39,0,75,0,4,0,76,0,7,0,43,0,41,0,3,0, -27,0,47,0,4,0,77,0,0,0,37,0,42,0,3,0,27,0,47,0, -4,0,77,0,0,0,37,0,43,0,4,0,4,0,78,0,7,0,79,0, -7,0,80,0,7,0,81,0,37,0,14,0,4,0,82,0,4,0,83,0, -43,0,84,0,4,0,85,0,7,0,86,0,7,0,87,0,7,0,88,0, -7,0,89,0,7,0,90,0,4,0,91,0,4,0,92,0,4,0,93,0, -4,0,94,0,0,0,37,0,44,0,5,0,25,0,38,0,35,0,65,0, -13,0,39,0,7,0,43,0,4,0,95,0,45,0,5,0,27,0,47,0, -13,0,96,0,14,0,97,0,4,0,98,0,0,0,99,0,46,0,24,0, -9,0,100,0,9,0,101,0,25,0,102,0,0,0,35,0,18,0,103,0, -18,0,104,0,14,0,105,0,14,0,106,0,14,0,107,0,8,0,108,0, -8,0,109,0,8,0,110,0,8,0,111,0,8,0,112,0,8,0,113,0, -8,0,114,0,4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0, -4,0,119,0,4,0,120,0,4,0,121,0,0,0,37,0,47,0,23,0, -9,0,100,0,9,0,101,0,25,0,102,0,0,0,35,0,17,0,103,0, -17,0,104,0,13,0,105,0,13,0,106,0,13,0,107,0,7,0,108,0, -7,0,109,0,7,0,110,0,7,0,111,0,7,0,112,0,7,0,113,0, -7,0,114,0,4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0, -4,0,119,0,4,0,120,0,4,0,121,0,48,0,21,0,47,0,122,0, -15,0,123,0,13,0,124,0,13,0,125,0,13,0,126,0,13,0,127,0, -13,0,-128,0,13,0,-127,0,13,0,-126,0,13,0,-125,0,13,0,-124,0, -7,0,-123,0,7,0,-122,0,7,0,-121,0,7,0,-120,0,7,0,-119,0, -7,0,-118,0,7,0,-117,0,7,0,-116,0,7,0,-115,0,4,0,-114,0, -49,0,22,0,46,0,122,0,16,0,123,0,14,0,124,0,14,0,125,0, -14,0,126,0,14,0,127,0,14,0,-128,0,14,0,-127,0,14,0,-126,0, -14,0,-125,0,14,0,-124,0,8,0,-123,0,8,0,-122,0,8,0,-121,0, -8,0,-120,0,8,0,-119,0,8,0,-118,0,8,0,-117,0,8,0,-116,0, -8,0,-115,0,4,0,-114,0,0,0,37,0,50,0,2,0,4,0,-113,0, -4,0,-112,0,51,0,11,0,52,0,-111,0,52,0,-110,0,0,0,35,0, -4,0,-109,0,4,0,-108,0,4,0,-107,0,4,0,-106,0,7,0,-105,0, -7,0,-104,0,4,0,-103,0,0,0,-102,0,53,0,3,0,51,0,-101,0, -13,0,-100,0,13,0,-99,0,54,0,3,0,51,0,-101,0,14,0,-100,0, -14,0,-99,0,55,0,13,0,51,0,-101,0,18,0,-98,0,18,0,-97,0, -4,0,-96,0,4,0,-95,0,4,0,-94,0,7,0,-93,0,7,0,-92,0, -7,0,-91,0,7,0,-90,0,7,0,-89,0,7,0,-88,0,7,0,-87,0, -56,0,13,0,51,0,-101,0,17,0,-98,0,17,0,-97,0,4,0,-96,0, -4,0,-95,0,4,0,-94,0,7,0,-93,0,7,0,-92,0,7,0,-91,0, -7,0,-90,0,7,0,-89,0,7,0,-88,0,7,0,-87,0,57,0,11,0, -51,0,-101,0,17,0,-98,0,17,0,-97,0,7,0,-86,0,7,0,-85,0, -7,0,-84,0,7,0,-89,0,7,0,-88,0,7,0,-87,0,7,0,-83,0, -0,0,21,0,58,0,9,0,51,0,-101,0,17,0,-98,0,17,0,-97,0, -13,0,-82,0,13,0,-81,0,13,0,-80,0,13,0,-79,0,4,0,-78,0, -4,0,-77,0,59,0,5,0,58,0,-76,0,4,0,-75,0,7,0,-74,0, -7,0,-73,0,7,0,-72,0,60,0,9,0,51,0,-101,0,17,0,-98,0, -17,0,-97,0,7,0,-82,0,7,0,-81,0,7,0,-80,0,7,0,-79,0, -4,0,-78,0,4,0,-77,0,61,0,4,0,7,0,-71,0,7,0,-70,0, -7,0,-69,0,4,0,78,0,62,0,10,0,61,0,-68,0,13,0,-67,0, -13,0,-66,0,13,0,-65,0,13,0,-64,0,13,0,-63,0,7,0,-123,0, -7,0,-62,0,4,0,-61,0,4,0,53,0,63,0,4,0,61,0,-68,0, -4,0,-60,0,7,0,-59,0,4,0,-58,0,64,0,4,0,13,0,-63,0, -61,0,-68,0,4,0,-57,0,7,0,-56,0,65,0,7,0,13,0,-55,0, -61,0,-68,0,4,0,-54,0,7,0,-53,0,7,0,-52,0,7,0,-51,0, -4,0,53,0,66,0,6,0,15,0,-50,0,13,0,-52,0,13,0,-49,0, -52,0,-48,0,4,0,-47,0,7,0,-51,0,67,0,26,0,4,0,-46,0, -7,0,-45,0,7,0,-83,0,7,0,-44,0,7,0,-43,0,7,0,-42,0, -7,0,-41,0,7,0,-40,0,7,0,-39,0,7,0,-38,0,7,0,-37,0, -7,0,-36,0,7,0,-35,0,7,0,-34,0,7,0,-33,0,7,0,-32,0, -7,0,-31,0,7,0,-30,0,7,0,-29,0,7,0,-28,0,7,0,-27,0, -4,0,-26,0,4,0,-25,0,4,0,-24,0,4,0,-23,0,4,0,116,0, -68,0,12,0,15,0,-22,0,15,0,-21,0,15,0,-20,0,13,0,-19,0, -13,0,-18,0,7,0,-17,0,4,0,-16,0,4,0,-15,0,4,0,-14,0, -4,0,-13,0,7,0,-53,0,4,0,53,0,69,0,27,0,17,0,-12,0, -15,0,-11,0,15,0,-10,0,13,0,-19,0,13,0,-9,0,13,0,-8,0, -13,0,-7,0,13,0,-6,0,13,0,-5,0,4,0,-4,0,7,0,-3,0, -4,0,-2,0,4,0,-1,0,4,0,0,1,7,0,1,1,7,0,2,1, -4,0,3,1,4,0,4,1,7,0,5,1,7,0,6,1,7,0,7,1, -7,0,8,1,7,0,9,1,7,0,10,1,4,0,11,1,4,0,12,1, -4,0,13,1,70,0,12,0,9,0,14,1,9,0,15,1,13,0,16,1, -7,0,17,1,7,0,18,1,7,0,19,1,4,0,20,1,13,0,21,1, -4,0,22,1,4,0,23,1,4,0,24,1,4,0,53,0,71,0,19,0, -47,0,122,0,68,0,25,1,61,0,26,1,62,0,27,1,63,0,28,1, -64,0,29,1,65,0,30,1,66,0,31,1,69,0,32,1,70,0,33,1, -4,0,34,1,4,0,-1,0,4,0,35,1,4,0,36,1,4,0,37,1, -4,0,38,1,4,0,39,1,4,0,40,1,67,0,41,1,}; +111,77,97,112,68,97,116,97,0,98,116,83,99,97,108,101,100,84,114,105, +97,110,103,108,101,77,101,115,104,83,104,97,112,101,68,97,116,97,0,98, +116,67,111,109,112,111,117,110,100,83,104,97,112,101,67,104,105,108,100,68, +97,116,97,0,98,116,67,111,109,112,111,117,110,100,83,104,97,112,101,68, +97,116,97,0,98,116,67,121,108,105,110,100,101,114,83,104,97,112,101,68, +97,116,97,0,98,116,67,97,112,115,117,108,101,83,104,97,112,101,68,97, +116,97,0,98,116,84,114,105,97,110,103,108,101,73,110,102,111,68,97,116, +97,0,98,116,71,73,109,112,97,99,116,77,101,115,104,83,104,97,112,101, +68,97,116,97,0,98,116,67,111,110,118,101,120,72,117,108,108,83,104,97, +112,101,68,97,116,97,0,98,116,67,111,108,108,105,115,105,111,110,79,98, +106,101,99,116,68,111,117,98,108,101,68,97,116,97,0,98,116,67,111,108, +108,105,115,105,111,110,79,98,106,101,99,116,70,108,111,97,116,68,97,116, +97,0,98,116,82,105,103,105,100,66,111,100,121,70,108,111,97,116,68,97, +116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,111,117,98,108,101, +68,97,116,97,0,98,116,67,111,110,115,116,114,97,105,110,116,73,110,102, +111,49,0,98,116,84,121,112,101,100,67,111,110,115,116,114,97,105,110,116, +68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,97,116,97, +0,98,116,80,111,105,110,116,50,80,111,105,110,116,67,111,110,115,116,114, +97,105,110,116,70,108,111,97,116,68,97,116,97,0,98,116,80,111,105,110, +116,50,80,111,105,110,116,67,111,110,115,116,114,97,105,110,116,68,111,117, +98,108,101,68,97,116,97,0,98,116,72,105,110,103,101,67,111,110,115,116, +114,97,105,110,116,68,111,117,98,108,101,68,97,116,97,0,98,116,72,105, +110,103,101,67,111,110,115,116,114,97,105,110,116,70,108,111,97,116,68,97, +116,97,0,98,116,67,111,110,101,84,119,105,115,116,67,111,110,115,116,114, +97,105,110,116,68,97,116,97,0,98,116,71,101,110,101,114,105,99,54,68, +111,102,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,71, +101,110,101,114,105,99,54,68,111,102,83,112,114,105,110,103,67,111,110,115, +116,114,97,105,110,116,68,97,116,97,0,98,116,83,108,105,100,101,114,67, +111,110,115,116,114,97,105,110,116,68,97,116,97,0,83,111,102,116,66,111, +100,121,77,97,116,101,114,105,97,108,68,97,116,97,0,83,111,102,116,66, +111,100,121,78,111,100,101,68,97,116,97,0,83,111,102,116,66,111,100,121, +76,105,110,107,68,97,116,97,0,83,111,102,116,66,111,100,121,70,97,99, +101,68,97,116,97,0,83,111,102,116,66,111,100,121,84,101,116,114,97,68, +97,116,97,0,83,111,102,116,82,105,103,105,100,65,110,99,104,111,114,68, +97,116,97,0,83,111,102,116,66,111,100,121,67,111,110,102,105,103,68,97, +116,97,0,83,111,102,116,66,111,100,121,80,111,115,101,68,97,116,97,0, +83,111,102,116,66,111,100,121,67,108,117,115,116,101,114,68,97,116,97,0, +98,116,83,111,102,116,66,111,100,121,74,111,105,110,116,68,97,116,97,0, +98,116,83,111,102,116,66,111,100,121,70,108,111,97,116,68,97,116,97,0, +84,76,69,78,1,0,1,0,2,0,2,0,4,0,4,0,4,0,4,0, +8,0,0,0,12,0,36,0,8,0,16,0,32,0,48,0,96,0,64,0, +-128,0,20,0,48,0,80,0,16,0,84,0,-124,0,12,0,52,0,52,0, +20,0,64,0,4,0,4,0,8,0,4,0,32,0,28,0,60,0,56,0, +76,0,76,0,24,0,60,0,60,0,16,0,64,0,68,0,-56,1,-8,0, +-32,1,-104,3,8,0,52,0,0,0,84,0,116,0,92,1,-36,0,-44,0, +-4,0,92,1,-52,0,16,0,100,0,20,0,36,0,100,0,92,0,104,0, +-64,0,92,1,104,0,-92,1,83,84,82,67,61,0,0,0,10,0,3,0, +4,0,0,0,4,0,1,0,9,0,2,0,11,0,3,0,10,0,3,0, +10,0,4,0,10,0,5,0,12,0,2,0,9,0,6,0,9,0,7,0, +13,0,1,0,7,0,8,0,14,0,1,0,8,0,8,0,15,0,1,0, +13,0,9,0,16,0,1,0,14,0,9,0,17,0,2,0,15,0,10,0, +13,0,11,0,18,0,2,0,16,0,10,0,14,0,11,0,19,0,4,0, +4,0,12,0,4,0,13,0,2,0,14,0,2,0,15,0,20,0,6,0, +13,0,16,0,13,0,17,0,4,0,18,0,4,0,19,0,4,0,20,0, +0,0,21,0,21,0,6,0,14,0,16,0,14,0,17,0,4,0,18,0, +4,0,19,0,4,0,20,0,0,0,21,0,22,0,3,0,2,0,14,0, +2,0,15,0,4,0,22,0,23,0,12,0,13,0,23,0,13,0,24,0, +13,0,25,0,4,0,26,0,4,0,27,0,4,0,28,0,4,0,29,0, +20,0,30,0,22,0,31,0,19,0,32,0,4,0,33,0,4,0,34,0, +24,0,12,0,14,0,23,0,14,0,24,0,14,0,25,0,4,0,26,0, +4,0,27,0,4,0,28,0,4,0,29,0,21,0,30,0,22,0,31,0, +4,0,33,0,4,0,34,0,19,0,32,0,25,0,3,0,0,0,35,0, +4,0,36,0,0,0,37,0,26,0,5,0,25,0,38,0,13,0,39,0, +13,0,40,0,7,0,41,0,0,0,21,0,27,0,5,0,25,0,38,0, +13,0,39,0,13,0,42,0,7,0,43,0,4,0,44,0,28,0,2,0, +13,0,45,0,7,0,46,0,29,0,4,0,27,0,47,0,28,0,48,0, +4,0,49,0,0,0,37,0,30,0,1,0,4,0,50,0,31,0,2,0, +2,0,50,0,0,0,51,0,32,0,2,0,2,0,52,0,0,0,51,0, +33,0,2,0,0,0,52,0,0,0,53,0,34,0,8,0,13,0,54,0, +14,0,55,0,30,0,56,0,32,0,57,0,33,0,58,0,31,0,59,0, +4,0,60,0,4,0,61,0,35,0,4,0,34,0,62,0,13,0,63,0, +4,0,64,0,0,0,37,0,36,0,7,0,25,0,38,0,35,0,65,0, +23,0,66,0,24,0,67,0,37,0,68,0,7,0,43,0,0,0,69,0, +38,0,2,0,36,0,70,0,13,0,39,0,39,0,4,0,17,0,71,0, +25,0,72,0,4,0,73,0,7,0,74,0,40,0,4,0,25,0,38,0, +39,0,75,0,4,0,76,0,7,0,43,0,41,0,3,0,27,0,47,0, +4,0,77,0,0,0,37,0,42,0,3,0,27,0,47,0,4,0,77,0, +0,0,37,0,43,0,4,0,4,0,78,0,7,0,79,0,7,0,80,0, +7,0,81,0,37,0,14,0,4,0,82,0,4,0,83,0,43,0,84,0, +4,0,85,0,7,0,86,0,7,0,87,0,7,0,88,0,7,0,89,0, +7,0,90,0,4,0,91,0,4,0,92,0,4,0,93,0,4,0,94,0, +0,0,37,0,44,0,5,0,25,0,38,0,35,0,65,0,13,0,39,0, +7,0,43,0,4,0,95,0,45,0,5,0,27,0,47,0,13,0,96,0, +14,0,97,0,4,0,98,0,0,0,99,0,46,0,24,0,9,0,100,0, +9,0,101,0,25,0,102,0,0,0,35,0,18,0,103,0,18,0,104,0, +14,0,105,0,14,0,106,0,14,0,107,0,8,0,108,0,8,0,109,0, +8,0,110,0,8,0,111,0,8,0,112,0,8,0,113,0,8,0,114,0, +4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0,4,0,119,0, +4,0,120,0,4,0,121,0,0,0,37,0,47,0,23,0,9,0,100,0, +9,0,101,0,25,0,102,0,0,0,35,0,17,0,103,0,17,0,104,0, +13,0,105,0,13,0,106,0,13,0,107,0,7,0,108,0,7,0,109,0, +7,0,110,0,7,0,111,0,7,0,112,0,7,0,113,0,7,0,114,0, +4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0,4,0,119,0, +4,0,120,0,4,0,121,0,48,0,21,0,47,0,122,0,15,0,123,0, +13,0,124,0,13,0,125,0,13,0,126,0,13,0,127,0,13,0,-128,0, +13,0,-127,0,13,0,-126,0,13,0,-125,0,13,0,-124,0,7,0,-123,0, +7,0,-122,0,7,0,-121,0,7,0,-120,0,7,0,-119,0,7,0,-118,0, +7,0,-117,0,7,0,-116,0,7,0,-115,0,4,0,-114,0,49,0,22,0, +46,0,122,0,16,0,123,0,14,0,124,0,14,0,125,0,14,0,126,0, +14,0,127,0,14,0,-128,0,14,0,-127,0,14,0,-126,0,14,0,-125,0, +14,0,-124,0,8,0,-123,0,8,0,-122,0,8,0,-121,0,8,0,-120,0, +8,0,-119,0,8,0,-118,0,8,0,-117,0,8,0,-116,0,8,0,-115,0, +4,0,-114,0,0,0,37,0,50,0,2,0,4,0,-113,0,4,0,-112,0, +51,0,13,0,52,0,-111,0,52,0,-110,0,0,0,35,0,4,0,-109,0, +4,0,-108,0,4,0,-107,0,4,0,-106,0,7,0,-105,0,7,0,-104,0, +4,0,-103,0,4,0,-102,0,7,0,-101,0,4,0,-100,0,53,0,3,0, +51,0,-99,0,13,0,-98,0,13,0,-97,0,54,0,3,0,51,0,-99,0, +14,0,-98,0,14,0,-97,0,55,0,13,0,51,0,-99,0,18,0,-96,0, +18,0,-95,0,4,0,-94,0,4,0,-93,0,4,0,-92,0,7,0,-91,0, +7,0,-90,0,7,0,-89,0,7,0,-88,0,7,0,-87,0,7,0,-86,0, +7,0,-85,0,56,0,13,0,51,0,-99,0,17,0,-96,0,17,0,-95,0, +4,0,-94,0,4,0,-93,0,4,0,-92,0,7,0,-91,0,7,0,-90,0, +7,0,-89,0,7,0,-88,0,7,0,-87,0,7,0,-86,0,7,0,-85,0, +57,0,11,0,51,0,-99,0,17,0,-96,0,17,0,-95,0,7,0,-84,0, +7,0,-83,0,7,0,-82,0,7,0,-87,0,7,0,-86,0,7,0,-85,0, +7,0,-81,0,0,0,21,0,58,0,9,0,51,0,-99,0,17,0,-96,0, +17,0,-95,0,13,0,-80,0,13,0,-79,0,13,0,-78,0,13,0,-77,0, +4,0,-76,0,4,0,-75,0,59,0,5,0,58,0,-74,0,4,0,-73,0, +7,0,-72,0,7,0,-71,0,7,0,-70,0,60,0,9,0,51,0,-99,0, +17,0,-96,0,17,0,-95,0,7,0,-80,0,7,0,-79,0,7,0,-78,0, +7,0,-77,0,4,0,-76,0,4,0,-75,0,61,0,4,0,7,0,-69,0, +7,0,-68,0,7,0,-67,0,4,0,78,0,62,0,10,0,61,0,-66,0, +13,0,-65,0,13,0,-64,0,13,0,-63,0,13,0,-62,0,13,0,-61,0, +7,0,-123,0,7,0,-60,0,4,0,-59,0,4,0,53,0,63,0,4,0, +61,0,-66,0,4,0,-58,0,7,0,-57,0,4,0,-56,0,64,0,4,0, +13,0,-61,0,61,0,-66,0,4,0,-55,0,7,0,-54,0,65,0,7,0, +13,0,-53,0,61,0,-66,0,4,0,-52,0,7,0,-51,0,7,0,-50,0, +7,0,-49,0,4,0,53,0,66,0,6,0,15,0,-48,0,13,0,-50,0, +13,0,-47,0,52,0,-46,0,4,0,-45,0,7,0,-49,0,67,0,26,0, +4,0,-44,0,7,0,-43,0,7,0,-81,0,7,0,-42,0,7,0,-41,0, +7,0,-40,0,7,0,-39,0,7,0,-38,0,7,0,-37,0,7,0,-36,0, +7,0,-35,0,7,0,-34,0,7,0,-33,0,7,0,-32,0,7,0,-31,0, +7,0,-30,0,7,0,-29,0,7,0,-28,0,7,0,-27,0,7,0,-26,0, +7,0,-25,0,4,0,-24,0,4,0,-23,0,4,0,-22,0,4,0,-21,0, +4,0,116,0,68,0,12,0,15,0,-20,0,15,0,-19,0,15,0,-18,0, +13,0,-17,0,13,0,-16,0,7,0,-15,0,4,0,-14,0,4,0,-13,0, +4,0,-12,0,4,0,-11,0,7,0,-51,0,4,0,53,0,69,0,27,0, +17,0,-10,0,15,0,-9,0,15,0,-8,0,13,0,-17,0,13,0,-7,0, +13,0,-6,0,13,0,-5,0,13,0,-4,0,13,0,-3,0,4,0,-2,0, +7,0,-1,0,4,0,0,1,4,0,1,1,4,0,2,1,7,0,3,1, +7,0,4,1,4,0,5,1,4,0,6,1,7,0,7,1,7,0,8,1, +7,0,9,1,7,0,10,1,7,0,11,1,7,0,12,1,4,0,13,1, +4,0,14,1,4,0,15,1,70,0,12,0,9,0,16,1,9,0,17,1, +13,0,18,1,7,0,19,1,7,0,20,1,7,0,21,1,4,0,22,1, +13,0,23,1,4,0,24,1,4,0,25,1,4,0,26,1,4,0,53,0, +71,0,19,0,47,0,122,0,68,0,27,1,61,0,28,1,62,0,29,1, +63,0,30,1,64,0,31,1,65,0,32,1,66,0,33,1,69,0,34,1, +70,0,35,1,4,0,36,1,4,0,1,1,4,0,37,1,4,0,38,1, +4,0,39,1,4,0,40,1,4,0,41,1,4,0,42,1,67,0,43,1, +}; int sBulletDNAlen= sizeof(sBulletDNAstr); -unsigned char sBulletDNAstr64[]= { -83,68,78,65,78,65,77,69,42,1,0,0,109,95,115,105,122,101,0,109, + + char sBulletDNAstr64[]= { +83,68,78,65,78,65,77,69,44,1,0,0,109,95,115,105,122,101,0,109, 95,99,97,112,97,99,105,116,121,0,42,109,95,100,97,116,97,0,109,95, 99,111,108,108,105,115,105,111,110,83,104,97,112,101,115,0,109,95,99,111, 108,108,105,115,105,111,110,79,98,106,101,99,116,115,0,109,95,99,111,110, @@ -546,287 +551,291 @@ unsigned char sBulletDNAstr64[]= { 112,108,105,101,100,73,109,112,117,108,115,101,0,109,95,100,98,103,68,114, 97,119,83,105,122,101,0,109,95,100,105,115,97,98,108,101,67,111,108,108, 105,115,105,111,110,115,66,101,116,119,101,101,110,76,105,110,107,101,100,66, -111,100,105,101,115,0,109,95,112,97,100,52,91,52,93,0,109,95,116,121, -112,101,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,109,95,112, -105,118,111,116,73,110,65,0,109,95,112,105,118,111,116,73,110,66,0,109, -95,114,98,65,70,114,97,109,101,0,109,95,114,98,66,70,114,97,109,101, -0,109,95,117,115,101,82,101,102,101,114,101,110,99,101,70,114,97,109,101, -65,0,109,95,97,110,103,117,108,97,114,79,110,108,121,0,109,95,101,110, -97,98,108,101,65,110,103,117,108,97,114,77,111,116,111,114,0,109,95,109, -111,116,111,114,84,97,114,103,101,116,86,101,108,111,99,105,116,121,0,109, -95,109,97,120,77,111,116,111,114,73,109,112,117,108,115,101,0,109,95,108, -111,119,101,114,76,105,109,105,116,0,109,95,117,112,112,101,114,76,105,109, -105,116,0,109,95,108,105,109,105,116,83,111,102,116,110,101,115,115,0,109, -95,98,105,97,115,70,97,99,116,111,114,0,109,95,114,101,108,97,120,97, -116,105,111,110,70,97,99,116,111,114,0,109,95,115,119,105,110,103,83,112, -97,110,49,0,109,95,115,119,105,110,103,83,112,97,110,50,0,109,95,116, -119,105,115,116,83,112,97,110,0,109,95,100,97,109,112,105,110,103,0,109, -95,108,105,110,101,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95, -108,105,110,101,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,97, -110,103,117,108,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95,97, -110,103,117,108,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,117, -115,101,76,105,110,101,97,114,82,101,102,101,114,101,110,99,101,70,114,97, -109,101,65,0,109,95,117,115,101,79,102,102,115,101,116,70,111,114,67,111, -110,115,116,114,97,105,110,116,70,114,97,109,101,0,109,95,54,100,111,102, -68,97,116,97,0,109,95,115,112,114,105,110,103,69,110,97,98,108,101,100, -91,54,93,0,109,95,101,113,117,105,108,105,98,114,105,117,109,80,111,105, -110,116,91,54,93,0,109,95,115,112,114,105,110,103,83,116,105,102,102,110, -101,115,115,91,54,93,0,109,95,115,112,114,105,110,103,68,97,109,112,105, -110,103,91,54,93,0,109,95,108,105,110,101,97,114,83,116,105,102,102,110, -101,115,115,0,109,95,97,110,103,117,108,97,114,83,116,105,102,102,110,101, -115,115,0,109,95,118,111,108,117,109,101,83,116,105,102,102,110,101,115,115, -0,42,109,95,109,97,116,101,114,105,97,108,0,109,95,112,111,115,105,116, -105,111,110,0,109,95,112,114,101,118,105,111,117,115,80,111,115,105,116,105, -111,110,0,109,95,118,101,108,111,99,105,116,121,0,109,95,97,99,99,117, -109,117,108,97,116,101,100,70,111,114,99,101,0,109,95,110,111,114,109,97, -108,0,109,95,97,114,101,97,0,109,95,97,116,116,97,99,104,0,109,95, -110,111,100,101,73,110,100,105,99,101,115,91,50,93,0,109,95,114,101,115, -116,76,101,110,103,116,104,0,109,95,98,98,101,110,100,105,110,103,0,109, -95,110,111,100,101,73,110,100,105,99,101,115,91,51,93,0,109,95,114,101, -115,116,65,114,101,97,0,109,95,99,48,91,52,93,0,109,95,110,111,100, -101,73,110,100,105,99,101,115,91,52,93,0,109,95,114,101,115,116,86,111, -108,117,109,101,0,109,95,99,49,0,109,95,99,50,0,109,95,99,48,0, -109,95,108,111,99,97,108,70,114,97,109,101,0,42,109,95,114,105,103,105, -100,66,111,100,121,0,109,95,110,111,100,101,73,110,100,101,120,0,109,95, -97,101,114,111,77,111,100,101,108,0,109,95,98,97,117,109,103,97,114,116, -101,0,109,95,100,114,97,103,0,109,95,108,105,102,116,0,109,95,112,114, -101,115,115,117,114,101,0,109,95,118,111,108,117,109,101,0,109,95,100,121, -110,97,109,105,99,70,114,105,99,116,105,111,110,0,109,95,112,111,115,101, -77,97,116,99,104,0,109,95,114,105,103,105,100,67,111,110,116,97,99,116, -72,97,114,100,110,101,115,115,0,109,95,107,105,110,101,116,105,99,67,111, -110,116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116, -67,111,110,116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,97,110, -99,104,111,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,82, -105,103,105,100,67,108,117,115,116,101,114,72,97,114,100,110,101,115,115,0, -109,95,115,111,102,116,75,105,110,101,116,105,99,67,108,117,115,116,101,114, -72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,83,111,102,116,67, -108,117,115,116,101,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102, -116,82,105,103,105,100,67,108,117,115,116,101,114,73,109,112,117,108,115,101, -83,112,108,105,116,0,109,95,115,111,102,116,75,105,110,101,116,105,99,67, -108,117,115,116,101,114,73,109,112,117,108,115,101,83,112,108,105,116,0,109, -95,115,111,102,116,83,111,102,116,67,108,117,115,116,101,114,73,109,112,117, -108,115,101,83,112,108,105,116,0,109,95,109,97,120,86,111,108,117,109,101, -0,109,95,116,105,109,101,83,99,97,108,101,0,109,95,118,101,108,111,99, -105,116,121,73,116,101,114,97,116,105,111,110,115,0,109,95,112,111,115,105, -116,105,111,110,73,116,101,114,97,116,105,111,110,115,0,109,95,100,114,105, -102,116,73,116,101,114,97,116,105,111,110,115,0,109,95,99,108,117,115,116, -101,114,73,116,101,114,97,116,105,111,110,115,0,109,95,114,111,116,0,109, -95,115,99,97,108,101,0,109,95,97,113,113,0,109,95,99,111,109,0,42, -109,95,112,111,115,105,116,105,111,110,115,0,42,109,95,119,101,105,103,104, -116,115,0,109,95,110,117,109,80,111,115,105,116,105,111,110,115,0,109,95, -110,117,109,87,101,105,103,116,115,0,109,95,98,118,111,108,117,109,101,0, -109,95,98,102,114,97,109,101,0,109,95,102,114,97,109,101,120,102,111,114, -109,0,109,95,108,111,99,105,105,0,109,95,105,110,118,119,105,0,109,95, -118,105,109,112,117,108,115,101,115,91,50,93,0,109,95,100,105,109,112,117, -108,115,101,115,91,50,93,0,109,95,108,118,0,109,95,97,118,0,42,109, -95,102,114,97,109,101,114,101,102,115,0,42,109,95,110,111,100,101,73,110, -100,105,99,101,115,0,42,109,95,109,97,115,115,101,115,0,109,95,110,117, -109,70,114,97,109,101,82,101,102,115,0,109,95,110,117,109,78,111,100,101, -115,0,109,95,110,117,109,77,97,115,115,101,115,0,109,95,105,100,109,97, -115,115,0,109,95,105,109,97,115,115,0,109,95,110,118,105,109,112,117,108, -115,101,115,0,109,95,110,100,105,109,112,117,108,115,101,115,0,109,95,110, -100,97,109,112,105,110,103,0,109,95,108,100,97,109,112,105,110,103,0,109, -95,97,100,97,109,112,105,110,103,0,109,95,109,97,116,99,104,105,110,103, -0,109,95,109,97,120,83,101,108,102,67,111,108,108,105,115,105,111,110,73, -109,112,117,108,115,101,0,109,95,115,101,108,102,67,111,108,108,105,115,105, -111,110,73,109,112,117,108,115,101,70,97,99,116,111,114,0,109,95,99,111, -110,116,97,105,110,115,65,110,99,104,111,114,0,109,95,99,111,108,108,105, -100,101,0,109,95,99,108,117,115,116,101,114,73,110,100,101,120,0,42,109, -95,98,111,100,121,65,0,42,109,95,98,111,100,121,66,0,109,95,114,101, -102,115,91,50,93,0,109,95,99,102,109,0,109,95,101,114,112,0,109,95, -115,112,108,105,116,0,109,95,100,101,108,101,116,101,0,109,95,114,101,108, -80,111,115,105,116,105,111,110,91,50,93,0,109,95,98,111,100,121,65,116, -121,112,101,0,109,95,98,111,100,121,66,116,121,112,101,0,109,95,106,111, -105,110,116,84,121,112,101,0,42,109,95,112,111,115,101,0,42,42,109,95, -109,97,116,101,114,105,97,108,115,0,42,109,95,110,111,100,101,115,0,42, -109,95,108,105,110,107,115,0,42,109,95,102,97,99,101,115,0,42,109,95, -116,101,116,114,97,104,101,100,114,97,0,42,109,95,97,110,99,104,111,114, -115,0,42,109,95,99,108,117,115,116,101,114,115,0,42,109,95,106,111,105, -110,116,115,0,109,95,110,117,109,77,97,116,101,114,105,97,108,115,0,109, -95,110,117,109,76,105,110,107,115,0,109,95,110,117,109,70,97,99,101,115, -0,109,95,110,117,109,84,101,116,114,97,104,101,100,114,97,0,109,95,110, -117,109,65,110,99,104,111,114,115,0,109,95,110,117,109,67,108,117,115,116, -101,114,115,0,109,95,110,117,109,74,111,105,110,116,115,0,109,95,99,111, -110,102,105,103,0,0,0,0,84,89,80,69,72,0,0,0,99,104,97,114, -0,117,99,104,97,114,0,115,104,111,114,116,0,117,115,104,111,114,116,0, -105,110,116,0,108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116, -0,100,111,117,98,108,101,0,118,111,105,100,0,80,111,105,110,116,101,114, -65,114,114,97,121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101, -109,0,76,105,115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51, -70,108,111,97,116,68,97,116,97,0,98,116,86,101,99,116,111,114,51,68, -111,117,98,108,101,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120, -51,70,108,111,97,116,68,97,116,97,0,98,116,77,97,116,114,105,120,51, -120,51,68,111,117,98,108,101,68,97,116,97,0,98,116,84,114,97,110,115, -102,111,114,109,70,108,111,97,116,68,97,116,97,0,98,116,84,114,97,110, -115,102,111,114,109,68,111,117,98,108,101,68,97,116,97,0,98,116,66,118, -104,83,117,98,116,114,101,101,73,110,102,111,68,97,116,97,0,98,116,79, -112,116,105,109,105,122,101,100,66,118,104,78,111,100,101,70,108,111,97,116, -68,97,116,97,0,98,116,79,112,116,105,109,105,122,101,100,66,118,104,78, -111,100,101,68,111,117,98,108,101,68,97,116,97,0,98,116,81,117,97,110, -116,105,122,101,100,66,118,104,78,111,100,101,68,97,116,97,0,98,116,81, -117,97,110,116,105,122,101,100,66,118,104,70,108,111,97,116,68,97,116,97, -0,98,116,81,117,97,110,116,105,122,101,100,66,118,104,68,111,117,98,108, -101,68,97,116,97,0,98,116,67,111,108,108,105,115,105,111,110,83,104,97, -112,101,68,97,116,97,0,98,116,83,116,97,116,105,99,80,108,97,110,101, -83,104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,73,110, -116,101,114,110,97,108,83,104,97,112,101,68,97,116,97,0,98,116,80,111, -115,105,116,105,111,110,65,110,100,82,97,100,105,117,115,0,98,116,77,117, -108,116,105,83,112,104,101,114,101,83,104,97,112,101,68,97,116,97,0,98, -116,73,110,116,73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114, -116,73,110,116,73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114, -116,73,110,116,73,110,100,101,120,84,114,105,112,108,101,116,68,97,116,97, -0,98,116,67,104,97,114,73,110,100,101,120,84,114,105,112,108,101,116,68, -97,116,97,0,98,116,77,101,115,104,80,97,114,116,68,97,116,97,0,98, -116,83,116,114,105,100,105,110,103,77,101,115,104,73,110,116,101,114,102,97, -99,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108,101,77,101,115, -104,83,104,97,112,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108, -101,73,110,102,111,77,97,112,68,97,116,97,0,98,116,83,99,97,108,101, -100,84,114,105,97,110,103,108,101,77,101,115,104,83,104,97,112,101,68,97, -116,97,0,98,116,67,111,109,112,111,117,110,100,83,104,97,112,101,67,104, -105,108,100,68,97,116,97,0,98,116,67,111,109,112,111,117,110,100,83,104, -97,112,101,68,97,116,97,0,98,116,67,121,108,105,110,100,101,114,83,104, -97,112,101,68,97,116,97,0,98,116,67,97,112,115,117,108,101,83,104,97, +111,100,105,101,115,0,109,95,111,118,101,114,114,105,100,101,78,117,109,83, +111,108,118,101,114,73,116,101,114,97,116,105,111,110,115,0,109,95,98,114, +101,97,107,105,110,103,73,109,112,117,108,115,101,84,104,114,101,115,104,111, +108,100,0,109,95,105,115,69,110,97,98,108,101,100,0,109,95,116,121,112, +101,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,109,95,112,105, +118,111,116,73,110,65,0,109,95,112,105,118,111,116,73,110,66,0,109,95, +114,98,65,70,114,97,109,101,0,109,95,114,98,66,70,114,97,109,101,0, +109,95,117,115,101,82,101,102,101,114,101,110,99,101,70,114,97,109,101,65, +0,109,95,97,110,103,117,108,97,114,79,110,108,121,0,109,95,101,110,97, +98,108,101,65,110,103,117,108,97,114,77,111,116,111,114,0,109,95,109,111, +116,111,114,84,97,114,103,101,116,86,101,108,111,99,105,116,121,0,109,95, +109,97,120,77,111,116,111,114,73,109,112,117,108,115,101,0,109,95,108,111, +119,101,114,76,105,109,105,116,0,109,95,117,112,112,101,114,76,105,109,105, +116,0,109,95,108,105,109,105,116,83,111,102,116,110,101,115,115,0,109,95, +98,105,97,115,70,97,99,116,111,114,0,109,95,114,101,108,97,120,97,116, +105,111,110,70,97,99,116,111,114,0,109,95,115,119,105,110,103,83,112,97, +110,49,0,109,95,115,119,105,110,103,83,112,97,110,50,0,109,95,116,119, +105,115,116,83,112,97,110,0,109,95,100,97,109,112,105,110,103,0,109,95, +108,105,110,101,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95,108, +105,110,101,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,97,110, +103,117,108,97,114,85,112,112,101,114,76,105,109,105,116,0,109,95,97,110, +103,117,108,97,114,76,111,119,101,114,76,105,109,105,116,0,109,95,117,115, +101,76,105,110,101,97,114,82,101,102,101,114,101,110,99,101,70,114,97,109, +101,65,0,109,95,117,115,101,79,102,102,115,101,116,70,111,114,67,111,110, +115,116,114,97,105,110,116,70,114,97,109,101,0,109,95,54,100,111,102,68, +97,116,97,0,109,95,115,112,114,105,110,103,69,110,97,98,108,101,100,91, +54,93,0,109,95,101,113,117,105,108,105,98,114,105,117,109,80,111,105,110, +116,91,54,93,0,109,95,115,112,114,105,110,103,83,116,105,102,102,110,101, +115,115,91,54,93,0,109,95,115,112,114,105,110,103,68,97,109,112,105,110, +103,91,54,93,0,109,95,108,105,110,101,97,114,83,116,105,102,102,110,101, +115,115,0,109,95,97,110,103,117,108,97,114,83,116,105,102,102,110,101,115, +115,0,109,95,118,111,108,117,109,101,83,116,105,102,102,110,101,115,115,0, +42,109,95,109,97,116,101,114,105,97,108,0,109,95,112,111,115,105,116,105, +111,110,0,109,95,112,114,101,118,105,111,117,115,80,111,115,105,116,105,111, +110,0,109,95,118,101,108,111,99,105,116,121,0,109,95,97,99,99,117,109, +117,108,97,116,101,100,70,111,114,99,101,0,109,95,110,111,114,109,97,108, +0,109,95,97,114,101,97,0,109,95,97,116,116,97,99,104,0,109,95,110, +111,100,101,73,110,100,105,99,101,115,91,50,93,0,109,95,114,101,115,116, +76,101,110,103,116,104,0,109,95,98,98,101,110,100,105,110,103,0,109,95, +110,111,100,101,73,110,100,105,99,101,115,91,51,93,0,109,95,114,101,115, +116,65,114,101,97,0,109,95,99,48,91,52,93,0,109,95,110,111,100,101, +73,110,100,105,99,101,115,91,52,93,0,109,95,114,101,115,116,86,111,108, +117,109,101,0,109,95,99,49,0,109,95,99,50,0,109,95,99,48,0,109, +95,108,111,99,97,108,70,114,97,109,101,0,42,109,95,114,105,103,105,100, +66,111,100,121,0,109,95,110,111,100,101,73,110,100,101,120,0,109,95,97, +101,114,111,77,111,100,101,108,0,109,95,98,97,117,109,103,97,114,116,101, +0,109,95,100,114,97,103,0,109,95,108,105,102,116,0,109,95,112,114,101, +115,115,117,114,101,0,109,95,118,111,108,117,109,101,0,109,95,100,121,110, +97,109,105,99,70,114,105,99,116,105,111,110,0,109,95,112,111,115,101,77, +97,116,99,104,0,109,95,114,105,103,105,100,67,111,110,116,97,99,116,72, +97,114,100,110,101,115,115,0,109,95,107,105,110,101,116,105,99,67,111,110, +116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,67, +111,110,116,97,99,116,72,97,114,100,110,101,115,115,0,109,95,97,110,99, +104,111,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116,82,105, +103,105,100,67,108,117,115,116,101,114,72,97,114,100,110,101,115,115,0,109, +95,115,111,102,116,75,105,110,101,116,105,99,67,108,117,115,116,101,114,72, +97,114,100,110,101,115,115,0,109,95,115,111,102,116,83,111,102,116,67,108, +117,115,116,101,114,72,97,114,100,110,101,115,115,0,109,95,115,111,102,116, +82,105,103,105,100,67,108,117,115,116,101,114,73,109,112,117,108,115,101,83, +112,108,105,116,0,109,95,115,111,102,116,75,105,110,101,116,105,99,67,108, +117,115,116,101,114,73,109,112,117,108,115,101,83,112,108,105,116,0,109,95, +115,111,102,116,83,111,102,116,67,108,117,115,116,101,114,73,109,112,117,108, +115,101,83,112,108,105,116,0,109,95,109,97,120,86,111,108,117,109,101,0, +109,95,116,105,109,101,83,99,97,108,101,0,109,95,118,101,108,111,99,105, +116,121,73,116,101,114,97,116,105,111,110,115,0,109,95,112,111,115,105,116, +105,111,110,73,116,101,114,97,116,105,111,110,115,0,109,95,100,114,105,102, +116,73,116,101,114,97,116,105,111,110,115,0,109,95,99,108,117,115,116,101, +114,73,116,101,114,97,116,105,111,110,115,0,109,95,114,111,116,0,109,95, +115,99,97,108,101,0,109,95,97,113,113,0,109,95,99,111,109,0,42,109, +95,112,111,115,105,116,105,111,110,115,0,42,109,95,119,101,105,103,104,116, +115,0,109,95,110,117,109,80,111,115,105,116,105,111,110,115,0,109,95,110, +117,109,87,101,105,103,116,115,0,109,95,98,118,111,108,117,109,101,0,109, +95,98,102,114,97,109,101,0,109,95,102,114,97,109,101,120,102,111,114,109, +0,109,95,108,111,99,105,105,0,109,95,105,110,118,119,105,0,109,95,118, +105,109,112,117,108,115,101,115,91,50,93,0,109,95,100,105,109,112,117,108, +115,101,115,91,50,93,0,109,95,108,118,0,109,95,97,118,0,42,109,95, +102,114,97,109,101,114,101,102,115,0,42,109,95,110,111,100,101,73,110,100, +105,99,101,115,0,42,109,95,109,97,115,115,101,115,0,109,95,110,117,109, +70,114,97,109,101,82,101,102,115,0,109,95,110,117,109,78,111,100,101,115, +0,109,95,110,117,109,77,97,115,115,101,115,0,109,95,105,100,109,97,115, +115,0,109,95,105,109,97,115,115,0,109,95,110,118,105,109,112,117,108,115, +101,115,0,109,95,110,100,105,109,112,117,108,115,101,115,0,109,95,110,100, +97,109,112,105,110,103,0,109,95,108,100,97,109,112,105,110,103,0,109,95, +97,100,97,109,112,105,110,103,0,109,95,109,97,116,99,104,105,110,103,0, +109,95,109,97,120,83,101,108,102,67,111,108,108,105,115,105,111,110,73,109, +112,117,108,115,101,0,109,95,115,101,108,102,67,111,108,108,105,115,105,111, +110,73,109,112,117,108,115,101,70,97,99,116,111,114,0,109,95,99,111,110, +116,97,105,110,115,65,110,99,104,111,114,0,109,95,99,111,108,108,105,100, +101,0,109,95,99,108,117,115,116,101,114,73,110,100,101,120,0,42,109,95, +98,111,100,121,65,0,42,109,95,98,111,100,121,66,0,109,95,114,101,102, +115,91,50,93,0,109,95,99,102,109,0,109,95,101,114,112,0,109,95,115, +112,108,105,116,0,109,95,100,101,108,101,116,101,0,109,95,114,101,108,80, +111,115,105,116,105,111,110,91,50,93,0,109,95,98,111,100,121,65,116,121, +112,101,0,109,95,98,111,100,121,66,116,121,112,101,0,109,95,106,111,105, +110,116,84,121,112,101,0,42,109,95,112,111,115,101,0,42,42,109,95,109, +97,116,101,114,105,97,108,115,0,42,109,95,110,111,100,101,115,0,42,109, +95,108,105,110,107,115,0,42,109,95,102,97,99,101,115,0,42,109,95,116, +101,116,114,97,104,101,100,114,97,0,42,109,95,97,110,99,104,111,114,115, +0,42,109,95,99,108,117,115,116,101,114,115,0,42,109,95,106,111,105,110, +116,115,0,109,95,110,117,109,77,97,116,101,114,105,97,108,115,0,109,95, +110,117,109,76,105,110,107,115,0,109,95,110,117,109,70,97,99,101,115,0, +109,95,110,117,109,84,101,116,114,97,104,101,100,114,97,0,109,95,110,117, +109,65,110,99,104,111,114,115,0,109,95,110,117,109,67,108,117,115,116,101, +114,115,0,109,95,110,117,109,74,111,105,110,116,115,0,109,95,99,111,110, +102,105,103,0,84,89,80,69,72,0,0,0,99,104,97,114,0,117,99,104, +97,114,0,115,104,111,114,116,0,117,115,104,111,114,116,0,105,110,116,0, +108,111,110,103,0,117,108,111,110,103,0,102,108,111,97,116,0,100,111,117, +98,108,101,0,118,111,105,100,0,80,111,105,110,116,101,114,65,114,114,97, +121,0,98,116,80,104,121,115,105,99,115,83,121,115,116,101,109,0,76,105, +115,116,66,97,115,101,0,98,116,86,101,99,116,111,114,51,70,108,111,97, +116,68,97,116,97,0,98,116,86,101,99,116,111,114,51,68,111,117,98,108, +101,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120,51,70,108,111, +97,116,68,97,116,97,0,98,116,77,97,116,114,105,120,51,120,51,68,111, +117,98,108,101,68,97,116,97,0,98,116,84,114,97,110,115,102,111,114,109, +70,108,111,97,116,68,97,116,97,0,98,116,84,114,97,110,115,102,111,114, +109,68,111,117,98,108,101,68,97,116,97,0,98,116,66,118,104,83,117,98, +116,114,101,101,73,110,102,111,68,97,116,97,0,98,116,79,112,116,105,109, +105,122,101,100,66,118,104,78,111,100,101,70,108,111,97,116,68,97,116,97, +0,98,116,79,112,116,105,109,105,122,101,100,66,118,104,78,111,100,101,68, +111,117,98,108,101,68,97,116,97,0,98,116,81,117,97,110,116,105,122,101, +100,66,118,104,78,111,100,101,68,97,116,97,0,98,116,81,117,97,110,116, +105,122,101,100,66,118,104,70,108,111,97,116,68,97,116,97,0,98,116,81, +117,97,110,116,105,122,101,100,66,118,104,68,111,117,98,108,101,68,97,116, +97,0,98,116,67,111,108,108,105,115,105,111,110,83,104,97,112,101,68,97, +116,97,0,98,116,83,116,97,116,105,99,80,108,97,110,101,83,104,97,112, +101,68,97,116,97,0,98,116,67,111,110,118,101,120,73,110,116,101,114,110, +97,108,83,104,97,112,101,68,97,116,97,0,98,116,80,111,115,105,116,105, +111,110,65,110,100,82,97,100,105,117,115,0,98,116,77,117,108,116,105,83, +112,104,101,114,101,83,104,97,112,101,68,97,116,97,0,98,116,73,110,116, +73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114,116,73,110,116, +73,110,100,101,120,68,97,116,97,0,98,116,83,104,111,114,116,73,110,116, +73,110,100,101,120,84,114,105,112,108,101,116,68,97,116,97,0,98,116,67, +104,97,114,73,110,100,101,120,84,114,105,112,108,101,116,68,97,116,97,0, +98,116,77,101,115,104,80,97,114,116,68,97,116,97,0,98,116,83,116,114, +105,100,105,110,103,77,101,115,104,73,110,116,101,114,102,97,99,101,68,97, +116,97,0,98,116,84,114,105,97,110,103,108,101,77,101,115,104,83,104,97, 112,101,68,97,116,97,0,98,116,84,114,105,97,110,103,108,101,73,110,102, -111,68,97,116,97,0,98,116,71,73,109,112,97,99,116,77,101,115,104,83, -104,97,112,101,68,97,116,97,0,98,116,67,111,110,118,101,120,72,117,108, -108,83,104,97,112,101,68,97,116,97,0,98,116,67,111,108,108,105,115,105, -111,110,79,98,106,101,99,116,68,111,117,98,108,101,68,97,116,97,0,98, -116,67,111,108,108,105,115,105,111,110,79,98,106,101,99,116,70,108,111,97, -116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,70,108,111, -97,116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,111, -117,98,108,101,68,97,116,97,0,98,116,67,111,110,115,116,114,97,105,110, -116,73,110,102,111,49,0,98,116,84,121,112,101,100,67,111,110,115,116,114, -97,105,110,116,68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121, -68,97,116,97,0,98,116,80,111,105,110,116,50,80,111,105,110,116,67,111, -110,115,116,114,97,105,110,116,70,108,111,97,116,68,97,116,97,0,98,116, -80,111,105,110,116,50,80,111,105,110,116,67,111,110,115,116,114,97,105,110, -116,68,111,117,98,108,101,68,97,116,97,0,98,116,72,105,110,103,101,67, -111,110,115,116,114,97,105,110,116,68,111,117,98,108,101,68,97,116,97,0, -98,116,72,105,110,103,101,67,111,110,115,116,114,97,105,110,116,70,108,111, -97,116,68,97,116,97,0,98,116,67,111,110,101,84,119,105,115,116,67,111, -110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,71,101,110,101,114, -105,99,54,68,111,102,67,111,110,115,116,114,97,105,110,116,68,97,116,97, -0,98,116,71,101,110,101,114,105,99,54,68,111,102,83,112,114,105,110,103, -67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,83,108,105, -100,101,114,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,83,111, -102,116,66,111,100,121,77,97,116,101,114,105,97,108,68,97,116,97,0,83, -111,102,116,66,111,100,121,78,111,100,101,68,97,116,97,0,83,111,102,116, -66,111,100,121,76,105,110,107,68,97,116,97,0,83,111,102,116,66,111,100, -121,70,97,99,101,68,97,116,97,0,83,111,102,116,66,111,100,121,84,101, -116,114,97,68,97,116,97,0,83,111,102,116,82,105,103,105,100,65,110,99, -104,111,114,68,97,116,97,0,83,111,102,116,66,111,100,121,67,111,110,102, -105,103,68,97,116,97,0,83,111,102,116,66,111,100,121,80,111,115,101,68, -97,116,97,0,83,111,102,116,66,111,100,121,67,108,117,115,116,101,114,68, -97,116,97,0,98,116,83,111,102,116,66,111,100,121,74,111,105,110,116,68, -97,116,97,0,98,116,83,111,102,116,66,111,100,121,70,108,111,97,116,68, -97,116,97,0,84,76,69,78,1,0,1,0,2,0,2,0,4,0,4,0, -4,0,4,0,8,0,0,0,16,0,48,0,16,0,16,0,32,0,48,0, -96,0,64,0,-128,0,20,0,48,0,80,0,16,0,96,0,-112,0,16,0, -56,0,56,0,20,0,72,0,4,0,4,0,8,0,4,0,56,0,32,0, -80,0,72,0,96,0,80,0,32,0,64,0,64,0,16,0,72,0,80,0, --40,1,8,1,-16,1,-88,3,8,0,56,0,0,0,88,0,120,0,96,1, --32,0,-40,0,0,1,96,1,-48,0,16,0,104,0,24,0,40,0,104,0, -96,0,104,0,-56,0,104,1,112,0,-40,1,83,84,82,67,61,0,0,0, -10,0,3,0,4,0,0,0,4,0,1,0,9,0,2,0,11,0,3,0, -10,0,3,0,10,0,4,0,10,0,5,0,12,0,2,0,9,0,6,0, -9,0,7,0,13,0,1,0,7,0,8,0,14,0,1,0,8,0,8,0, -15,0,1,0,13,0,9,0,16,0,1,0,14,0,9,0,17,0,2,0, -15,0,10,0,13,0,11,0,18,0,2,0,16,0,10,0,14,0,11,0, -19,0,4,0,4,0,12,0,4,0,13,0,2,0,14,0,2,0,15,0, -20,0,6,0,13,0,16,0,13,0,17,0,4,0,18,0,4,0,19,0, -4,0,20,0,0,0,21,0,21,0,6,0,14,0,16,0,14,0,17,0, -4,0,18,0,4,0,19,0,4,0,20,0,0,0,21,0,22,0,3,0, -2,0,14,0,2,0,15,0,4,0,22,0,23,0,12,0,13,0,23,0, -13,0,24,0,13,0,25,0,4,0,26,0,4,0,27,0,4,0,28,0, -4,0,29,0,20,0,30,0,22,0,31,0,19,0,32,0,4,0,33,0, -4,0,34,0,24,0,12,0,14,0,23,0,14,0,24,0,14,0,25,0, -4,0,26,0,4,0,27,0,4,0,28,0,4,0,29,0,21,0,30,0, -22,0,31,0,4,0,33,0,4,0,34,0,19,0,32,0,25,0,3,0, -0,0,35,0,4,0,36,0,0,0,37,0,26,0,5,0,25,0,38,0, -13,0,39,0,13,0,40,0,7,0,41,0,0,0,21,0,27,0,5,0, -25,0,38,0,13,0,39,0,13,0,42,0,7,0,43,0,4,0,44,0, -28,0,2,0,13,0,45,0,7,0,46,0,29,0,4,0,27,0,47,0, -28,0,48,0,4,0,49,0,0,0,37,0,30,0,1,0,4,0,50,0, -31,0,2,0,2,0,50,0,0,0,51,0,32,0,2,0,2,0,52,0, -0,0,51,0,33,0,2,0,0,0,52,0,0,0,53,0,34,0,8,0, -13,0,54,0,14,0,55,0,30,0,56,0,32,0,57,0,33,0,58,0, -31,0,59,0,4,0,60,0,4,0,61,0,35,0,4,0,34,0,62,0, -13,0,63,0,4,0,64,0,0,0,37,0,36,0,7,0,25,0,38,0, -35,0,65,0,23,0,66,0,24,0,67,0,37,0,68,0,7,0,43,0, -0,0,69,0,38,0,2,0,36,0,70,0,13,0,39,0,39,0,4,0, -17,0,71,0,25,0,72,0,4,0,73,0,7,0,74,0,40,0,4,0, -25,0,38,0,39,0,75,0,4,0,76,0,7,0,43,0,41,0,3,0, -27,0,47,0,4,0,77,0,0,0,37,0,42,0,3,0,27,0,47,0, -4,0,77,0,0,0,37,0,43,0,4,0,4,0,78,0,7,0,79,0, -7,0,80,0,7,0,81,0,37,0,14,0,4,0,82,0,4,0,83,0, -43,0,84,0,4,0,85,0,7,0,86,0,7,0,87,0,7,0,88,0, -7,0,89,0,7,0,90,0,4,0,91,0,4,0,92,0,4,0,93,0, -4,0,94,0,0,0,37,0,44,0,5,0,25,0,38,0,35,0,65,0, -13,0,39,0,7,0,43,0,4,0,95,0,45,0,5,0,27,0,47,0, -13,0,96,0,14,0,97,0,4,0,98,0,0,0,99,0,46,0,24,0, -9,0,100,0,9,0,101,0,25,0,102,0,0,0,35,0,18,0,103,0, -18,0,104,0,14,0,105,0,14,0,106,0,14,0,107,0,8,0,108,0, -8,0,109,0,8,0,110,0,8,0,111,0,8,0,112,0,8,0,113,0, -8,0,114,0,4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0, -4,0,119,0,4,0,120,0,4,0,121,0,0,0,37,0,47,0,23,0, -9,0,100,0,9,0,101,0,25,0,102,0,0,0,35,0,17,0,103,0, -17,0,104,0,13,0,105,0,13,0,106,0,13,0,107,0,7,0,108,0, -7,0,109,0,7,0,110,0,7,0,111,0,7,0,112,0,7,0,113,0, -7,0,114,0,4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0, -4,0,119,0,4,0,120,0,4,0,121,0,48,0,21,0,47,0,122,0, -15,0,123,0,13,0,124,0,13,0,125,0,13,0,126,0,13,0,127,0, -13,0,-128,0,13,0,-127,0,13,0,-126,0,13,0,-125,0,13,0,-124,0, -7,0,-123,0,7,0,-122,0,7,0,-121,0,7,0,-120,0,7,0,-119,0, -7,0,-118,0,7,0,-117,0,7,0,-116,0,7,0,-115,0,4,0,-114,0, -49,0,22,0,46,0,122,0,16,0,123,0,14,0,124,0,14,0,125,0, -14,0,126,0,14,0,127,0,14,0,-128,0,14,0,-127,0,14,0,-126,0, -14,0,-125,0,14,0,-124,0,8,0,-123,0,8,0,-122,0,8,0,-121,0, -8,0,-120,0,8,0,-119,0,8,0,-118,0,8,0,-117,0,8,0,-116,0, -8,0,-115,0,4,0,-114,0,0,0,37,0,50,0,2,0,4,0,-113,0, -4,0,-112,0,51,0,11,0,52,0,-111,0,52,0,-110,0,0,0,35,0, -4,0,-109,0,4,0,-108,0,4,0,-107,0,4,0,-106,0,7,0,-105,0, -7,0,-104,0,4,0,-103,0,0,0,-102,0,53,0,3,0,51,0,-101,0, -13,0,-100,0,13,0,-99,0,54,0,3,0,51,0,-101,0,14,0,-100,0, -14,0,-99,0,55,0,13,0,51,0,-101,0,18,0,-98,0,18,0,-97,0, -4,0,-96,0,4,0,-95,0,4,0,-94,0,7,0,-93,0,7,0,-92,0, -7,0,-91,0,7,0,-90,0,7,0,-89,0,7,0,-88,0,7,0,-87,0, -56,0,13,0,51,0,-101,0,17,0,-98,0,17,0,-97,0,4,0,-96,0, -4,0,-95,0,4,0,-94,0,7,0,-93,0,7,0,-92,0,7,0,-91,0, -7,0,-90,0,7,0,-89,0,7,0,-88,0,7,0,-87,0,57,0,11,0, -51,0,-101,0,17,0,-98,0,17,0,-97,0,7,0,-86,0,7,0,-85,0, -7,0,-84,0,7,0,-89,0,7,0,-88,0,7,0,-87,0,7,0,-83,0, -0,0,21,0,58,0,9,0,51,0,-101,0,17,0,-98,0,17,0,-97,0, -13,0,-82,0,13,0,-81,0,13,0,-80,0,13,0,-79,0,4,0,-78,0, -4,0,-77,0,59,0,5,0,58,0,-76,0,4,0,-75,0,7,0,-74,0, -7,0,-73,0,7,0,-72,0,60,0,9,0,51,0,-101,0,17,0,-98,0, -17,0,-97,0,7,0,-82,0,7,0,-81,0,7,0,-80,0,7,0,-79,0, -4,0,-78,0,4,0,-77,0,61,0,4,0,7,0,-71,0,7,0,-70,0, -7,0,-69,0,4,0,78,0,62,0,10,0,61,0,-68,0,13,0,-67,0, -13,0,-66,0,13,0,-65,0,13,0,-64,0,13,0,-63,0,7,0,-123,0, -7,0,-62,0,4,0,-61,0,4,0,53,0,63,0,4,0,61,0,-68,0, -4,0,-60,0,7,0,-59,0,4,0,-58,0,64,0,4,0,13,0,-63,0, -61,0,-68,0,4,0,-57,0,7,0,-56,0,65,0,7,0,13,0,-55,0, -61,0,-68,0,4,0,-54,0,7,0,-53,0,7,0,-52,0,7,0,-51,0, -4,0,53,0,66,0,6,0,15,0,-50,0,13,0,-52,0,13,0,-49,0, -52,0,-48,0,4,0,-47,0,7,0,-51,0,67,0,26,0,4,0,-46,0, -7,0,-45,0,7,0,-83,0,7,0,-44,0,7,0,-43,0,7,0,-42,0, -7,0,-41,0,7,0,-40,0,7,0,-39,0,7,0,-38,0,7,0,-37,0, -7,0,-36,0,7,0,-35,0,7,0,-34,0,7,0,-33,0,7,0,-32,0, -7,0,-31,0,7,0,-30,0,7,0,-29,0,7,0,-28,0,7,0,-27,0, -4,0,-26,0,4,0,-25,0,4,0,-24,0,4,0,-23,0,4,0,116,0, -68,0,12,0,15,0,-22,0,15,0,-21,0,15,0,-20,0,13,0,-19,0, -13,0,-18,0,7,0,-17,0,4,0,-16,0,4,0,-15,0,4,0,-14,0, -4,0,-13,0,7,0,-53,0,4,0,53,0,69,0,27,0,17,0,-12,0, -15,0,-11,0,15,0,-10,0,13,0,-19,0,13,0,-9,0,13,0,-8,0, -13,0,-7,0,13,0,-6,0,13,0,-5,0,4,0,-4,0,7,0,-3,0, -4,0,-2,0,4,0,-1,0,4,0,0,1,7,0,1,1,7,0,2,1, -4,0,3,1,4,0,4,1,7,0,5,1,7,0,6,1,7,0,7,1, -7,0,8,1,7,0,9,1,7,0,10,1,4,0,11,1,4,0,12,1, -4,0,13,1,70,0,12,0,9,0,14,1,9,0,15,1,13,0,16,1, -7,0,17,1,7,0,18,1,7,0,19,1,4,0,20,1,13,0,21,1, -4,0,22,1,4,0,23,1,4,0,24,1,4,0,53,0,71,0,19,0, -47,0,122,0,68,0,25,1,61,0,26,1,62,0,27,1,63,0,28,1, -64,0,29,1,65,0,30,1,66,0,31,1,69,0,32,1,70,0,33,1, -4,0,34,1,4,0,-1,0,4,0,35,1,4,0,36,1,4,0,37,1, -4,0,38,1,4,0,39,1,4,0,40,1,67,0,41,1,}; +111,77,97,112,68,97,116,97,0,98,116,83,99,97,108,101,100,84,114,105, +97,110,103,108,101,77,101,115,104,83,104,97,112,101,68,97,116,97,0,98, +116,67,111,109,112,111,117,110,100,83,104,97,112,101,67,104,105,108,100,68, +97,116,97,0,98,116,67,111,109,112,111,117,110,100,83,104,97,112,101,68, +97,116,97,0,98,116,67,121,108,105,110,100,101,114,83,104,97,112,101,68, +97,116,97,0,98,116,67,97,112,115,117,108,101,83,104,97,112,101,68,97, +116,97,0,98,116,84,114,105,97,110,103,108,101,73,110,102,111,68,97,116, +97,0,98,116,71,73,109,112,97,99,116,77,101,115,104,83,104,97,112,101, +68,97,116,97,0,98,116,67,111,110,118,101,120,72,117,108,108,83,104,97, +112,101,68,97,116,97,0,98,116,67,111,108,108,105,115,105,111,110,79,98, +106,101,99,116,68,111,117,98,108,101,68,97,116,97,0,98,116,67,111,108, +108,105,115,105,111,110,79,98,106,101,99,116,70,108,111,97,116,68,97,116, +97,0,98,116,82,105,103,105,100,66,111,100,121,70,108,111,97,116,68,97, +116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,111,117,98,108,101, +68,97,116,97,0,98,116,67,111,110,115,116,114,97,105,110,116,73,110,102, +111,49,0,98,116,84,121,112,101,100,67,111,110,115,116,114,97,105,110,116, +68,97,116,97,0,98,116,82,105,103,105,100,66,111,100,121,68,97,116,97, +0,98,116,80,111,105,110,116,50,80,111,105,110,116,67,111,110,115,116,114, +97,105,110,116,70,108,111,97,116,68,97,116,97,0,98,116,80,111,105,110, +116,50,80,111,105,110,116,67,111,110,115,116,114,97,105,110,116,68,111,117, +98,108,101,68,97,116,97,0,98,116,72,105,110,103,101,67,111,110,115,116, +114,97,105,110,116,68,111,117,98,108,101,68,97,116,97,0,98,116,72,105, +110,103,101,67,111,110,115,116,114,97,105,110,116,70,108,111,97,116,68,97, +116,97,0,98,116,67,111,110,101,84,119,105,115,116,67,111,110,115,116,114, +97,105,110,116,68,97,116,97,0,98,116,71,101,110,101,114,105,99,54,68, +111,102,67,111,110,115,116,114,97,105,110,116,68,97,116,97,0,98,116,71, +101,110,101,114,105,99,54,68,111,102,83,112,114,105,110,103,67,111,110,115, +116,114,97,105,110,116,68,97,116,97,0,98,116,83,108,105,100,101,114,67, +111,110,115,116,114,97,105,110,116,68,97,116,97,0,83,111,102,116,66,111, +100,121,77,97,116,101,114,105,97,108,68,97,116,97,0,83,111,102,116,66, +111,100,121,78,111,100,101,68,97,116,97,0,83,111,102,116,66,111,100,121, +76,105,110,107,68,97,116,97,0,83,111,102,116,66,111,100,121,70,97,99, +101,68,97,116,97,0,83,111,102,116,66,111,100,121,84,101,116,114,97,68, +97,116,97,0,83,111,102,116,82,105,103,105,100,65,110,99,104,111,114,68, +97,116,97,0,83,111,102,116,66,111,100,121,67,111,110,102,105,103,68,97, +116,97,0,83,111,102,116,66,111,100,121,80,111,115,101,68,97,116,97,0, +83,111,102,116,66,111,100,121,67,108,117,115,116,101,114,68,97,116,97,0, +98,116,83,111,102,116,66,111,100,121,74,111,105,110,116,68,97,116,97,0, +98,116,83,111,102,116,66,111,100,121,70,108,111,97,116,68,97,116,97,0, +84,76,69,78,1,0,1,0,2,0,2,0,4,0,4,0,4,0,4,0, +8,0,0,0,16,0,48,0,16,0,16,0,32,0,48,0,96,0,64,0, +-128,0,20,0,48,0,80,0,16,0,96,0,-112,0,16,0,56,0,56,0, +20,0,72,0,4,0,4,0,8,0,4,0,56,0,32,0,80,0,72,0, +96,0,80,0,32,0,64,0,64,0,16,0,72,0,80,0,-40,1,8,1, +-16,1,-88,3,8,0,64,0,0,0,96,0,-128,0,104,1,-24,0,-32,0, +8,1,104,1,-40,0,16,0,104,0,24,0,40,0,104,0,96,0,104,0, +-56,0,104,1,112,0,-40,1,83,84,82,67,61,0,0,0,10,0,3,0, +4,0,0,0,4,0,1,0,9,0,2,0,11,0,3,0,10,0,3,0, +10,0,4,0,10,0,5,0,12,0,2,0,9,0,6,0,9,0,7,0, +13,0,1,0,7,0,8,0,14,0,1,0,8,0,8,0,15,0,1,0, +13,0,9,0,16,0,1,0,14,0,9,0,17,0,2,0,15,0,10,0, +13,0,11,0,18,0,2,0,16,0,10,0,14,0,11,0,19,0,4,0, +4,0,12,0,4,0,13,0,2,0,14,0,2,0,15,0,20,0,6,0, +13,0,16,0,13,0,17,0,4,0,18,0,4,0,19,0,4,0,20,0, +0,0,21,0,21,0,6,0,14,0,16,0,14,0,17,0,4,0,18,0, +4,0,19,0,4,0,20,0,0,0,21,0,22,0,3,0,2,0,14,0, +2,0,15,0,4,0,22,0,23,0,12,0,13,0,23,0,13,0,24,0, +13,0,25,0,4,0,26,0,4,0,27,0,4,0,28,0,4,0,29,0, +20,0,30,0,22,0,31,0,19,0,32,0,4,0,33,0,4,0,34,0, +24,0,12,0,14,0,23,0,14,0,24,0,14,0,25,0,4,0,26,0, +4,0,27,0,4,0,28,0,4,0,29,0,21,0,30,0,22,0,31,0, +4,0,33,0,4,0,34,0,19,0,32,0,25,0,3,0,0,0,35,0, +4,0,36,0,0,0,37,0,26,0,5,0,25,0,38,0,13,0,39,0, +13,0,40,0,7,0,41,0,0,0,21,0,27,0,5,0,25,0,38,0, +13,0,39,0,13,0,42,0,7,0,43,0,4,0,44,0,28,0,2,0, +13,0,45,0,7,0,46,0,29,0,4,0,27,0,47,0,28,0,48,0, +4,0,49,0,0,0,37,0,30,0,1,0,4,0,50,0,31,0,2,0, +2,0,50,0,0,0,51,0,32,0,2,0,2,0,52,0,0,0,51,0, +33,0,2,0,0,0,52,0,0,0,53,0,34,0,8,0,13,0,54,0, +14,0,55,0,30,0,56,0,32,0,57,0,33,0,58,0,31,0,59,0, +4,0,60,0,4,0,61,0,35,0,4,0,34,0,62,0,13,0,63,0, +4,0,64,0,0,0,37,0,36,0,7,0,25,0,38,0,35,0,65,0, +23,0,66,0,24,0,67,0,37,0,68,0,7,0,43,0,0,0,69,0, +38,0,2,0,36,0,70,0,13,0,39,0,39,0,4,0,17,0,71,0, +25,0,72,0,4,0,73,0,7,0,74,0,40,0,4,0,25,0,38,0, +39,0,75,0,4,0,76,0,7,0,43,0,41,0,3,0,27,0,47,0, +4,0,77,0,0,0,37,0,42,0,3,0,27,0,47,0,4,0,77,0, +0,0,37,0,43,0,4,0,4,0,78,0,7,0,79,0,7,0,80,0, +7,0,81,0,37,0,14,0,4,0,82,0,4,0,83,0,43,0,84,0, +4,0,85,0,7,0,86,0,7,0,87,0,7,0,88,0,7,0,89,0, +7,0,90,0,4,0,91,0,4,0,92,0,4,0,93,0,4,0,94,0, +0,0,37,0,44,0,5,0,25,0,38,0,35,0,65,0,13,0,39,0, +7,0,43,0,4,0,95,0,45,0,5,0,27,0,47,0,13,0,96,0, +14,0,97,0,4,0,98,0,0,0,99,0,46,0,24,0,9,0,100,0, +9,0,101,0,25,0,102,0,0,0,35,0,18,0,103,0,18,0,104,0, +14,0,105,0,14,0,106,0,14,0,107,0,8,0,108,0,8,0,109,0, +8,0,110,0,8,0,111,0,8,0,112,0,8,0,113,0,8,0,114,0, +4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0,4,0,119,0, +4,0,120,0,4,0,121,0,0,0,37,0,47,0,23,0,9,0,100,0, +9,0,101,0,25,0,102,0,0,0,35,0,17,0,103,0,17,0,104,0, +13,0,105,0,13,0,106,0,13,0,107,0,7,0,108,0,7,0,109,0, +7,0,110,0,7,0,111,0,7,0,112,0,7,0,113,0,7,0,114,0, +4,0,115,0,4,0,116,0,4,0,117,0,4,0,118,0,4,0,119,0, +4,0,120,0,4,0,121,0,48,0,21,0,47,0,122,0,15,0,123,0, +13,0,124,0,13,0,125,0,13,0,126,0,13,0,127,0,13,0,-128,0, +13,0,-127,0,13,0,-126,0,13,0,-125,0,13,0,-124,0,7,0,-123,0, +7,0,-122,0,7,0,-121,0,7,0,-120,0,7,0,-119,0,7,0,-118,0, +7,0,-117,0,7,0,-116,0,7,0,-115,0,4,0,-114,0,49,0,22,0, +46,0,122,0,16,0,123,0,14,0,124,0,14,0,125,0,14,0,126,0, +14,0,127,0,14,0,-128,0,14,0,-127,0,14,0,-126,0,14,0,-125,0, +14,0,-124,0,8,0,-123,0,8,0,-122,0,8,0,-121,0,8,0,-120,0, +8,0,-119,0,8,0,-118,0,8,0,-117,0,8,0,-116,0,8,0,-115,0, +4,0,-114,0,0,0,37,0,50,0,2,0,4,0,-113,0,4,0,-112,0, +51,0,13,0,52,0,-111,0,52,0,-110,0,0,0,35,0,4,0,-109,0, +4,0,-108,0,4,0,-107,0,4,0,-106,0,7,0,-105,0,7,0,-104,0, +4,0,-103,0,4,0,-102,0,7,0,-101,0,4,0,-100,0,53,0,3,0, +51,0,-99,0,13,0,-98,0,13,0,-97,0,54,0,3,0,51,0,-99,0, +14,0,-98,0,14,0,-97,0,55,0,13,0,51,0,-99,0,18,0,-96,0, +18,0,-95,0,4,0,-94,0,4,0,-93,0,4,0,-92,0,7,0,-91,0, +7,0,-90,0,7,0,-89,0,7,0,-88,0,7,0,-87,0,7,0,-86,0, +7,0,-85,0,56,0,13,0,51,0,-99,0,17,0,-96,0,17,0,-95,0, +4,0,-94,0,4,0,-93,0,4,0,-92,0,7,0,-91,0,7,0,-90,0, +7,0,-89,0,7,0,-88,0,7,0,-87,0,7,0,-86,0,7,0,-85,0, +57,0,11,0,51,0,-99,0,17,0,-96,0,17,0,-95,0,7,0,-84,0, +7,0,-83,0,7,0,-82,0,7,0,-87,0,7,0,-86,0,7,0,-85,0, +7,0,-81,0,0,0,21,0,58,0,9,0,51,0,-99,0,17,0,-96,0, +17,0,-95,0,13,0,-80,0,13,0,-79,0,13,0,-78,0,13,0,-77,0, +4,0,-76,0,4,0,-75,0,59,0,5,0,58,0,-74,0,4,0,-73,0, +7,0,-72,0,7,0,-71,0,7,0,-70,0,60,0,9,0,51,0,-99,0, +17,0,-96,0,17,0,-95,0,7,0,-80,0,7,0,-79,0,7,0,-78,0, +7,0,-77,0,4,0,-76,0,4,0,-75,0,61,0,4,0,7,0,-69,0, +7,0,-68,0,7,0,-67,0,4,0,78,0,62,0,10,0,61,0,-66,0, +13,0,-65,0,13,0,-64,0,13,0,-63,0,13,0,-62,0,13,0,-61,0, +7,0,-123,0,7,0,-60,0,4,0,-59,0,4,0,53,0,63,0,4,0, +61,0,-66,0,4,0,-58,0,7,0,-57,0,4,0,-56,0,64,0,4,0, +13,0,-61,0,61,0,-66,0,4,0,-55,0,7,0,-54,0,65,0,7,0, +13,0,-53,0,61,0,-66,0,4,0,-52,0,7,0,-51,0,7,0,-50,0, +7,0,-49,0,4,0,53,0,66,0,6,0,15,0,-48,0,13,0,-50,0, +13,0,-47,0,52,0,-46,0,4,0,-45,0,7,0,-49,0,67,0,26,0, +4,0,-44,0,7,0,-43,0,7,0,-81,0,7,0,-42,0,7,0,-41,0, +7,0,-40,0,7,0,-39,0,7,0,-38,0,7,0,-37,0,7,0,-36,0, +7,0,-35,0,7,0,-34,0,7,0,-33,0,7,0,-32,0,7,0,-31,0, +7,0,-30,0,7,0,-29,0,7,0,-28,0,7,0,-27,0,7,0,-26,0, +7,0,-25,0,4,0,-24,0,4,0,-23,0,4,0,-22,0,4,0,-21,0, +4,0,116,0,68,0,12,0,15,0,-20,0,15,0,-19,0,15,0,-18,0, +13,0,-17,0,13,0,-16,0,7,0,-15,0,4,0,-14,0,4,0,-13,0, +4,0,-12,0,4,0,-11,0,7,0,-51,0,4,0,53,0,69,0,27,0, +17,0,-10,0,15,0,-9,0,15,0,-8,0,13,0,-17,0,13,0,-7,0, +13,0,-6,0,13,0,-5,0,13,0,-4,0,13,0,-3,0,4,0,-2,0, +7,0,-1,0,4,0,0,1,4,0,1,1,4,0,2,1,7,0,3,1, +7,0,4,1,4,0,5,1,4,0,6,1,7,0,7,1,7,0,8,1, +7,0,9,1,7,0,10,1,7,0,11,1,7,0,12,1,4,0,13,1, +4,0,14,1,4,0,15,1,70,0,12,0,9,0,16,1,9,0,17,1, +13,0,18,1,7,0,19,1,7,0,20,1,7,0,21,1,4,0,22,1, +13,0,23,1,4,0,24,1,4,0,25,1,4,0,26,1,4,0,53,0, +71,0,19,0,47,0,122,0,68,0,27,1,61,0,28,1,62,0,29,1, +63,0,30,1,64,0,31,1,65,0,32,1,66,0,33,1,69,0,34,1, +70,0,35,1,4,0,36,1,4,0,1,1,4,0,37,1,4,0,38,1, +4,0,39,1,4,0,40,1,4,0,41,1,4,0,42,1,67,0,43,1, +}; int sBulletDNAlen64= sizeof(sBulletDNAstr64); diff --git a/extern/bullet2/src/LinearMath/btSerializer.h b/extern/bullet2/src/LinearMath/btSerializer.h index 52520d72b9e..76f3cf32f8e 100644 --- a/extern/bullet2/src/LinearMath/btSerializer.h +++ b/extern/bullet2/src/LinearMath/btSerializer.h @@ -28,9 +28,9 @@ subject to the following restrictions: ///only the 32bit versions for now -extern unsigned char sBulletDNAstr[]; +extern char sBulletDNAstr[]; extern int sBulletDNAlen; -extern unsigned char sBulletDNAstr64[]; +extern char sBulletDNAstr64[]; extern int sBulletDNAlen64; SIMD_FORCE_INLINE int btStrLen(const char* str) @@ -213,7 +213,7 @@ protected: int *intPtr=0; short *shtPtr=0; - char *cp = 0;int dataLen =0;long nr=0; + char *cp = 0;int dataLen =0; intPtr = (int*)m_dna; /* @@ -246,15 +246,7 @@ protected: while (*cp)cp++; cp++; } - { - nr= (long)cp; - // long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } + cp = btAlignPointer(cp,4); /* TYPE (4 bytes) @@ -281,15 +273,7 @@ protected: cp++; } - { - nr= (long)cp; - // long mask=3; - nr= ((nr+3)&~3)-nr; - while (nr--) - { - cp++; - } - } + cp = btAlignPointer(cp,4); /* @@ -453,8 +437,8 @@ public: buffer[9] = '2'; - buffer[10] = '7'; - buffer[11] = '8'; + buffer[10] = '8'; + buffer[11] = '0'; } diff --git a/extern/bullet2/src/LinearMath/btSimdMinMax.h b/extern/bullet2/src/LinearMath/btSimdMinMax.h deleted file mode 100644 index 75e83f3c53f..00000000000 --- a/extern/bullet2/src/LinearMath/btSimdMinMax.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/ - -This software is provided 'as-is', without any express or implied warranty. -In no event will the authors be held liable for any damages arising from the use of this software. -Permission is granted to anyone to use this software for any purpose, -including commercial applications, and to alter it and redistribute it freely, -subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. -3. This notice may not be removed or altered from any source distribution. -*/ - - - -#ifndef SIMD_MINMAX_H -#define SIMD_MINMAX_H -#include "btScalar.h" - -template <class T> -SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) { - return b < a ? b : a; -} - -template <class T> -SIMD_FORCE_INLINE const T& btMax(const T& a, const T& b) { - return a < b ? b : a; -} - -template <class T> -SIMD_FORCE_INLINE void btSetMin(T& a, const T& b) { - if (a > b) a = b; -} - -template <class T> -SIMD_FORCE_INLINE void btSetMax(T& a, const T& b) { - if (a < b) a = b; -} - -#endif diff --git a/extern/bullet2/src/LinearMath/btTransform.h b/extern/bullet2/src/LinearMath/btTransform.h index 187b09116cc..5e52d183acb 100644 --- a/extern/bullet2/src/LinearMath/btTransform.h +++ b/extern/bullet2/src/LinearMath/btTransform.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef btTransform_H -#define btTransform_H +#ifndef BT_TRANSFORM_H +#define BT_TRANSFORM_H #include "btMatrix3x3.h" @@ -298,7 +298,7 @@ SIMD_FORCE_INLINE void btTransform::deSerializeDouble(const btTransformDoubleDat } -#endif +#endif //BT_TRANSFORM_H diff --git a/extern/bullet2/src/LinearMath/btTransformUtil.h b/extern/bullet2/src/LinearMath/btTransformUtil.h index 626110ce4ee..2303c274275 100644 --- a/extern/bullet2/src/LinearMath/btTransformUtil.h +++ b/extern/bullet2/src/LinearMath/btTransformUtil.h @@ -13,8 +13,8 @@ subject to the following restrictions: */ -#ifndef SIMD_TRANSFORM_UTIL_H -#define SIMD_TRANSFORM_UTIL_H +#ifndef BT_TRANSFORM_UTIL_H +#define BT_TRANSFORM_UTIL_H #include "btTransform.h" #define ANGULAR_MOTION_THRESHOLD btScalar(0.5)*SIMD_HALF_PI @@ -224,5 +224,5 @@ public: }; -#endif //SIMD_TRANSFORM_UTIL_H +#endif //BT_TRANSFORM_UTIL_H diff --git a/extern/bullet2/src/LinearMath/btVector3.h b/extern/bullet2/src/LinearMath/btVector3.h index 068e87c94ab..d99b7c83ae3 100644 --- a/extern/bullet2/src/LinearMath/btVector3.h +++ b/extern/bullet2/src/LinearMath/btVector3.h @@ -14,8 +14,8 @@ subject to the following restrictions: -#ifndef SIMD__VECTOR3_H -#define SIMD__VECTOR3_H +#ifndef BT_VECTOR3_H +#define BT_VECTOR3_H #include "btScalar.h" @@ -763,4 +763,4 @@ SIMD_FORCE_INLINE void btVector3::deSerialize(const struct btVector3Data& dataIn } -#endif //SIMD__VECTOR3_H +#endif //BT_VECTOR3_H diff --git a/extern/bullet2/src/SConscript b/extern/bullet2/src/SConscript index cd94df257ec..8a3db17f6d1 100644 --- a/extern/bullet2/src/SConscript +++ b/extern/bullet2/src/SConscript @@ -21,25 +21,18 @@ elif sys.platform=='darwin': defs += ' NDEBUG' cflags += ['-O2','-pipe', '-fPIC', '-funsigned-char', '-ffast-math'] -linearmath_src = env.Glob("LinearMath/*.cpp") - -bulletdyn_src = env.Glob("BulletDynamics/Vehicle/*.cpp") + env.Glob("BulletDynamics/ConstraintSolver/*.cpp") + env.Glob("BulletDynamics/Dynamics/*.cpp") + env.Glob("BulletDynamics/Character/*.cpp") - -collision_broadphase_src = env.Glob("BulletCollision/BroadphaseCollision/*.cpp") -collision_dispatch_src = env.Glob("BulletCollision/CollisionDispatch/*.cpp") -collision_gimpact_src = env.Glob("BulletCollision/Gimpact/*.cpp") -collision_shapes_src = env.Glob("BulletCollision/CollisionShapes/*.cpp") -collision_narrowphase_src = env.Glob("BulletCollision/NarrowPhaseCollision/*.cpp") - -softbody_src = env.Glob("BulletSoftBody/*.cpp") +bullet2_src = env.Glob("LinearMath/*.cpp") +bullet2_src += env.Glob("BulletCollision/BroadphaseCollision/*.cpp") +bullet2_src += env.Glob("BulletCollision/CollisionDispatch/*.cpp") +bullet2_src += env.Glob("BulletCollision/Gimpact/*.cpp") +bullet2_src += env.Glob("BulletCollision/CollisionShapes/*.cpp") +bullet2_src += env.Glob("BulletCollision/NarrowPhaseCollision/*.cpp") +bullet2_src += env.Glob("BulletDynamics/Vehicle/*.cpp") +bullet2_src += env.Glob("BulletDynamics/ConstraintSolver/*.cpp") +bullet2_src += env.Glob("BulletDynamics/Dynamics/*.cpp") +bullet2_src += env.Glob("BulletDynamics/Character/*.cpp") +bullet2_src += env.Glob("BulletSoftBody/*.cpp") incs = '. BulletCollision BulletDynamics LinearMath BulletSoftBody' -env.BlenderLib ( libname = 'extern_bullet2linmath', sources=linearmath_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[20,137], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2dynamics', sources=bulletdyn_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[19,136], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2collision_broadphase', sources=collision_broadphase_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[25,145], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2collision_dispatch', sources=collision_dispatch_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[20,138], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2collision_gimpact', sources=collision_gimpact_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[20,138], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2collision_shapes', sources=collision_shapes_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[20,138], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2collision_narrowphase', sources=collision_narrowphase_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[20,138], compileflags=cflags ) -env.BlenderLib ( libname = 'extern_bullet2softbody', sources=softbody_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[30,135], compileflags=cflags ) +env.BlenderLib ( libname = 'extern_bullet2', sources=bullet2_src, includes=Split(incs), defines=Split(defs), libtype=['extern','player'], priority=[20,137], compileflags=cflags ) diff --git a/extern/bullet2/src/btBulletDynamicsCommon.h b/extern/bullet2/src/btBulletDynamicsCommon.h index db8b37989f5..ccfad19b87a 100644 --- a/extern/bullet2/src/btBulletDynamicsCommon.h +++ b/extern/bullet2/src/btBulletDynamicsCommon.h @@ -20,7 +20,6 @@ subject to the following restrictions: #include "btBulletCollisionCommon.h" #include "BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h" -#include "BulletDynamics/Dynamics/btContinuousDynamicsWorld.h" #include "BulletDynamics/Dynamics/btSimpleDynamicsWorld.h" #include "BulletDynamics/Dynamics/btRigidBody.h" diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt index 003c6c84f8f..a8c7eef89fa 100644 --- a/intern/cycles/blender/CMakeLists.txt +++ b/intern/cycles/blender/CMakeLists.txt @@ -22,6 +22,7 @@ set(SRC blender_camera.cpp blender_mesh.cpp blender_object.cpp + blender_particles.cpp blender_python.cpp blender_session.cpp blender_shader.cpp diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index cea3b0256bd..b70491a7b82 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -192,7 +192,7 @@ void BlenderSync::sync_background_light() /* Object */ -void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm, uint layer_flag, int motion) +void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm, uint layer_flag, int motion, int particle_id) { /* light is handled separately */ if(object_is_light(b_ob)) { @@ -270,6 +270,12 @@ void BlenderSync::sync_object(BL::Object b_parent, int b_index, BL::Object b_ob, object->visibility &= ~PATH_RAY_CAMERA; } + object->particle_id = particle_id; + + /* particle sync */ + if (object_use_particles(b_ob)) + sync_particles(object, b_ob); + object->tag_update(scene); } } @@ -292,54 +298,51 @@ void BlenderSync::sync_objects(BL::SpaceView3D b_v3d, int motion) /* object loop */ BL::Scene::objects_iterator b_ob; BL::Scene b_sce = b_scene; + int particle_offset = 0; for(; b_sce; b_sce = b_sce.background_set()) { for(b_sce.objects.begin(b_ob); b_ob != b_sce.objects.end(); ++b_ob) { bool hide = (render_layer.use_viewport_visibility)? b_ob->hide(): b_ob->hide_render(); uint ob_layer = get_layer(b_ob->layers()); + hide = hide || !(ob_layer & scene_layer); + + if(!hide) { + + int num_particles = object_count_particles(*b_ob); - if(!hide && (ob_layer & scene_layer)) { if(b_ob->is_duplicator()) { + hide = true; /* duplicators hidden by default */ + /* dupli objects */ object_create_duplilist(*b_ob, b_scene); BL::Object::dupli_list_iterator b_dup; - int b_index = 0; - for(b_ob->dupli_list.begin(b_dup); b_dup != b_ob->dupli_list.end(); ++b_dup) { Transform tfm = get_transform(b_dup->matrix()); BL::Object b_dup_ob = b_dup->object(); bool dup_hide = (b_v3d)? b_dup_ob.hide(): b_dup_ob.hide_render(); - if(!(b_dup->hide() || dup_hide)) - sync_object(*b_ob, b_index, b_dup_ob, tfm, ob_layer, motion); - - b_index++; + if(!(b_dup->hide() || dup_hide)) { + sync_object(*b_ob, b_dup->index(), b_dup_ob, tfm, ob_layer, motion, b_dup->particle_index() + particle_offset); + } } object_free_duplilist(*b_ob); - - hide = true; } /* check if we should render or hide particle emitter */ BL::Object::particle_systems_iterator b_psys; - bool render_emitter = false; - - for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) { - if(b_psys->settings().use_render_emitter()) { + for(b_ob->particle_systems.begin(b_psys); b_psys != b_ob->particle_systems.end(); ++b_psys) + if(b_psys->settings().use_render_emitter()) hide = false; - render_emitter = true; - } - else if(!render_emitter) - hide = true; - } if(!hide) { /* object itself */ Transform tfm = get_transform(b_ob->matrix_world()); - sync_object(*b_ob, 0, *b_ob, tfm, ob_layer, motion); + sync_object(*b_ob, 0, *b_ob, tfm, ob_layer, motion, 0); } + + particle_offset += num_particles; } } } diff --git a/intern/cycles/blender/blender_particles.cpp b/intern/cycles/blender/blender_particles.cpp new file mode 100644 index 00000000000..2b19009989a --- /dev/null +++ b/intern/cycles/blender/blender_particles.cpp @@ -0,0 +1,162 @@ +/* + * Copyright 2011, Blender Foundation. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "object.h" + +#include "mesh.h" +#include "blender_sync.h" +#include "blender_util.h" + +#include "util_foreach.h" + +CCL_NAMESPACE_BEGIN + +/* Utilities */ + + +/* Particles Sync */ + +bool BlenderSync::object_use_particles(BL::Object b_ob) +{ + /* Particle data is only needed for + * a) Billboard render mode if object's own material uses particle info + * b) object/group render mode if any dupli object's material uses particle info + * + * Note: Meshes have to be synced at this point! + */ + bool use_particles = false; + + BL::Object::particle_systems_iterator b_psys; + for (b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { + switch (b_psys->settings().render_type()) { + /* XXX not implemented yet! + * billboards/strands would become part of the mesh data (?), + * so the mesh attributes would store whether particle info is required. + */ + #if 0 + case BL::ParticleSettings::render_type_BILLBOARD: + case BL::ParticleSettings::render_type_PATH: { /* for strand rendering */ + BL::ID key = (BKE_object_is_modified(b_ob))? b_ob: b_ob.data(); + Mesh *mesh = mesh_map.find(key); + if (mesh) { + use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE); + } + break; + } + #endif + + case BL::ParticleSettings::render_type_OBJECT: { + BL::Object b_dupli_ob = b_psys->settings().dupli_object(); + if (b_dupli_ob) { + BL::ID key = (BKE_object_is_modified(b_dupli_ob))? b_dupli_ob: b_dupli_ob.data(); + Mesh *mesh = mesh_map.find(key); + if (mesh) { + use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE); + } + } + break; + } + + case BL::ParticleSettings::render_type_GROUP: { + BL::Group b_dupli_group = b_psys->settings().dupli_group(); + if (b_dupli_group) { + BL::Group::objects_iterator b_gob; + for (b_dupli_group.objects.begin(b_gob); b_gob != b_dupli_group.objects.end(); ++b_gob) { + BL::ID key = (BKE_object_is_modified(*b_gob))? *b_gob: b_gob->data(); + Mesh *mesh = mesh_map.find(key); + if (mesh) { + use_particles |= mesh->need_attribute(scene, ATTR_STD_PARTICLE); + } + } + } + break; + } + + default: + /* avoid compiler warning */ + break; + } + } + + return use_particles; +} + +static bool use_particle_system(BL::ParticleSystem b_psys) +{ + /* only use duplicator particles? disabled particle info for + * halo and billboard to reduce particle count. + * Probably not necessary since particles don't contain a huge amount + * of data compared to other textures. + */ + #if 0 + int render_type = b_psys->settings().render_type(); + return (render_type == BL::ParticleSettings::render_type_OBJECT + || render_type == BL::ParticleSettings::render_type_GROUP); + #endif + + return true; +} + +static bool use_particle(BL::Particle b_pa) +{ + return b_pa.is_exist() && b_pa.is_visible() && b_pa.alive_state()==BL::Particle::alive_state_ALIVE; +} + +int BlenderSync::object_count_particles(BL::Object b_ob) +{ + int tot = 0; + BL::Object::particle_systems_iterator b_psys; + for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { + if (use_particle_system(*b_psys)) { + BL::ParticleSystem::particles_iterator b_pa; + for(b_psys->particles.begin(b_pa); b_pa != b_psys->particles.end(); ++b_pa) { + if(use_particle(*b_pa)) + ++tot; + } + } + } + return tot; +} + +void BlenderSync::sync_particles(Object *ob, BL::Object b_ob) +{ + int tot = object_count_particles(b_ob); + + ob->particles.clear(); + ob->particles.reserve(tot); + + int index; + BL::Object::particle_systems_iterator b_psys; + for(b_ob.particle_systems.begin(b_psys); b_psys != b_ob.particle_systems.end(); ++b_psys) { + if (use_particle_system(*b_psys)) { + BL::ParticleSystem::particles_iterator b_pa; + for(b_psys->particles.begin(b_pa), index=0; b_pa != b_psys->particles.end(); ++b_pa, ++index) { + if(use_particle(*b_pa)) { + Particle pa; + + pa.age = b_scene.frame_current() - b_pa->birth_time(); + pa.lifetime = b_pa->lifetime(); + + ob->particles.push_back(pa); + } + } + } + } +} + +CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 130b73a2808..a7be0a8fb54 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -337,6 +337,10 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph node = new ObjectInfoNode(); break; } + case BL::ShaderNode::type_PARTICLE_INFO: { + node = new ParticleInfoNode(); + break; + } case BL::ShaderNode::type_TEX_IMAGE: { BL::ShaderNodeTexImage b_image_node(b_node); BL::Image b_image(b_image_node.image()); diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index bc6258d35ac..8c31c4b86ba 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -80,17 +80,20 @@ private: void sync_nodes(Shader *shader, BL::ShaderNodeTree b_ntree); Mesh *sync_mesh(BL::Object b_ob, bool object_updated); - void sync_object(BL::Object b_parent, int b_index, BL::Object b_object, Transform& tfm, uint layer_flag, int motion); + void sync_object(BL::Object b_parent, int b_index, BL::Object b_object, Transform& tfm, uint layer_flag, int motion, int particle_id); void sync_light(BL::Object b_parent, int b_index, BL::Object b_ob, Transform& tfm); void sync_background_light(); void sync_mesh_motion(BL::Object b_ob, Mesh *mesh, int motion); void sync_camera_motion(BL::Object b_ob, int motion); + void sync_particles(Object *ob, BL::Object b_ob); /* util */ void find_shader(BL::ID id, vector<uint>& used_shaders, int default_shader); bool BKE_object_is_modified(BL::Object b_ob); bool object_is_mesh(BL::Object b_ob); bool object_is_light(BL::Object b_ob); + bool object_use_particles(BL::Object b_ob); + int object_count_particles(BL::Object b_ob); /* variables */ BL::BlendData b_data; diff --git a/intern/cycles/kernel/kernel_object.h b/intern/cycles/kernel/kernel_object.h index 05c45c490d8..18e0b1e8a87 100644 --- a/intern/cycles/kernel/kernel_object.h +++ b/intern/cycles/kernel/kernel_object.h @@ -154,10 +154,35 @@ __device_inline float object_random_number(KernelGlobals *kg, int object) return f.z; } +__device_inline uint object_particle_id(KernelGlobals *kg, int object) +{ + if(object == ~0) + return 0.0f; + + int offset = object*OBJECT_SIZE + OBJECT_PROPERTIES; + float4 f = kernel_tex_fetch(__objects, offset); + return __float_as_int(f.w); +} + __device int shader_pass_id(KernelGlobals *kg, ShaderData *sd) { return kernel_tex_fetch(__shader_flag, (sd->shader & SHADER_MASK)*2 + 1); } +__device float particle_age(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset); + return f.x; +} + +__device float particle_lifetime(KernelGlobals *kg, int particle) +{ + int offset = particle*PARTICLE_SIZE; + float4 f = kernel_tex_fetch(__particles, offset); + return f.y; +} + + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/kernel_textures.h b/intern/cycles/kernel/kernel_textures.h index 482f886df3e..c1b8eed3dff 100644 --- a/intern/cycles/kernel/kernel_textures.h +++ b/intern/cycles/kernel/kernel_textures.h @@ -52,6 +52,9 @@ KERNEL_TEX(float4, texture_float4, __light_data) KERNEL_TEX(float2, texture_float2, __light_background_marginal_cdf) KERNEL_TEX(float2, texture_float2, __light_background_conditional_cdf) +/* particles */ +KERNEL_TEX(float4, texture_float4, __particles) + /* shaders */ KERNEL_TEX(uint4, texture_uint4, __svm_nodes) KERNEL_TEX(uint, texture_uint, __shader_flag) diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index 4fd57a5f2b3..77a800b0e67 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -33,6 +33,7 @@ CCL_NAMESPACE_BEGIN #define LIGHT_SIZE 4 #define FILTER_TABLE_SIZE 256 #define RAMP_TABLE_SIZE 256 +#define PARTICLE_SIZE 1 #define TIME_INVALID FLT_MAX /* device capabilities */ @@ -359,6 +360,7 @@ typedef enum AttributeStandard { ATTR_STD_POSITION_UNDISPLACED, ATTR_STD_MOTION_PRE, ATTR_STD_MOTION_POST, + ATTR_STD_PARTICLE, ATTR_STD_NUM, ATTR_STD_NOT_FOUND = ~0 diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 6a05639beb9..8901e5e9628 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -269,6 +269,9 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT case NODE_OBJECT_INFO: svm_node_object_info(kg, sd, stack, node.y, node.z); break; + case NODE_PARTICLE_INFO: + svm_node_particle_info(kg, sd, stack, node.y, node.z); + break; #endif case NODE_CONVERT: svm_node_convert(sd, stack, node.y, node.z, node.w); diff --git a/intern/cycles/kernel/svm/svm_geometry.h b/intern/cycles/kernel/svm/svm_geometry.h index dab19983946..88127b56474 100644 --- a/intern/cycles/kernel/svm/svm_geometry.h +++ b/intern/cycles/kernel/svm/svm_geometry.h @@ -94,5 +94,27 @@ __device void svm_node_object_info(KernelGlobals *kg, ShaderData *sd, float *sta stack_store_float(stack, out_offset, data); } +/* Particle Info */ + +__device void svm_node_particle_info(KernelGlobals *kg, ShaderData *sd, float *stack, uint type, uint out_offset) +{ + float data; + + switch(type) { + case NODE_INFO_PAR_AGE: { + uint particle_id = object_particle_id(kg, sd->object); + data = particle_age(kg, particle_id); + stack_store_float(stack, out_offset, data); + break; + } + case NODE_INFO_PAR_LIFETIME: { + uint particle_id = object_particle_id(kg, sd->object); + data = particle_lifetime(kg, particle_id); + stack_store_float(stack, out_offset, data); + break; + } + } +} + CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 97849736ef6..2d756d57f41 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -93,7 +93,8 @@ typedef enum NodeType { NODE_RGB_CURVES = 6000, NODE_MIN_MAX = 6100, NODE_LIGHT_FALLOFF = 6200, - NODE_OBJECT_INFO = 6300 + NODE_OBJECT_INFO = 6300, + NODE_PARTICLE_INFO = 6400 } NodeType; typedef enum NodeAttributeType { @@ -117,6 +118,11 @@ typedef enum NodeObjectInfo { NODE_INFO_OB_RANDOM } NodeObjectInfo; +typedef enum NodeParticleInfo { + NODE_INFO_PAR_AGE, + NODE_INFO_PAR_LIFETIME +} NodeParticleInfo; + typedef enum NodeLightPath { NODE_LP_camera = 0, NODE_LP_shadow, diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 16c6b07261a..1c9eeacddbe 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -1789,6 +1789,47 @@ void ObjectInfoNode::compile(OSLCompiler& compiler) compiler.add(this, "node_object_info"); } +/* Particle Info */ + +ParticleInfoNode::ParticleInfoNode() +: ShaderNode("particle_info") +{ + add_output("Age", SHADER_SOCKET_FLOAT); + add_output("Lifetime", SHADER_SOCKET_FLOAT); +} + +void ParticleInfoNode::attributes(AttributeRequestSet *attributes) +{ + if(!output("Age")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + if(!output("Lifetime")->links.empty()) + attributes->add(ATTR_STD_PARTICLE); + + ShaderNode::attributes(attributes); +} + +void ParticleInfoNode::compile(SVMCompiler& compiler) +{ + ShaderOutput *out; + + out = output("Age"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_AGE, out->stack_offset); + } + + out = output("Lifetime"); + if(!out->links.empty()) { + compiler.stack_assign(out); + compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LIFETIME, out->stack_offset); + } +} + +void ParticleInfoNode::compile(OSLCompiler& compiler) +{ + compiler.add(this, "node_particle_info"); +} + /* Value */ ValueNode::ValueNode() diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 2d0d58d1e94..650758a6113 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -290,6 +290,12 @@ public: SHADER_NODE_CLASS(ObjectInfoNode) }; +class ParticleInfoNode : public ShaderNode { +public: + SHADER_NODE_CLASS(ParticleInfoNode) + void attributes(AttributeRequestSet *attributes); +}; + class ValueNode : public ShaderNode { public: SHADER_NODE_CLASS(ValueNode) diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 5c7e48a38eb..259a0d25bcc 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -25,6 +25,7 @@ #include "util_foreach.h" #include "util_map.h" #include "util_progress.h" +#include "util_vector.h" CCL_NAMESPACE_BEGIN @@ -38,6 +39,7 @@ Object::Object() visibility = ~0; random_id = 0; pass_id = 0; + particle_id = 0; bounds = BoundBox::empty; motion.pre = transform_identity(); motion.post = transform_identity(); @@ -200,7 +202,7 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene memcpy(&objects[offset], &tfm, sizeof(float4)*3); memcpy(&objects[offset+3], &itfm, sizeof(float4)*3); - objects[offset+6] = make_float4(surface_area, pass_id, random_number, 0.0f); + objects[offset+6] = make_float4(surface_area, pass_id, random_number, __int_as_float(ob->particle_id)); if(need_motion == Scene::MOTION_PASS) { /* motion transformations, is world/object space depending if mesh @@ -246,6 +248,38 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene device->tex_alloc("__object_flag", dscene->object_flag); } +void ObjectManager::device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) +{ + /* count particles. + * adds one dummy particle at the beginning to avoid invalid lookups, + * in case a shader uses particle info without actual particle data. + */ + int num_particles = 1; + foreach(Object *ob, scene->objects) + num_particles += ob->particles.size(); + + float4 *particles = dscene->particles.resize(PARTICLE_SIZE*num_particles); + + /* dummy particle */ + particles[0] = make_float4(0.0f, 0.0f, 0.0f, 0.0f); + + int i = 1; + foreach(Object *ob, scene->objects) { + foreach(Particle &pa, ob->particles) { + /* pack in texture */ + int offset = i*PARTICLE_SIZE; + + particles[offset] = make_float4(pa.age, pa.lifetime, 0.0f, 0.0f); + + i++; + + if(progress.get_cancel()) return; + } + } + + device->tex_alloc("__particles", dscene->particles); +} + void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) { if(!need_update) @@ -271,6 +305,11 @@ void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *sc if(progress.get_cancel()) return; + progress.set_status("Updating Objects", "Copying Particles to device"); + device_update_particles(device, dscene, scene, progress); + + if(progress.get_cancel()) return; + need_update = false; } @@ -281,6 +320,9 @@ void ObjectManager::device_free(Device *device, DeviceScene *dscene) device->tex_free(dscene->object_flag); dscene->object_flag.clear(); + + device->tex_free(dscene->particles); + dscene->particles.clear(); } void ObjectManager::apply_static_transforms(Scene *scene, Progress& progress) diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index a3bd748a8a4..6d674731b07 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -35,6 +35,11 @@ struct Transform; /* Object */ +struct Particle { + float age; + float lifetime; +}; + class Object { public: Mesh *mesh; @@ -49,6 +54,9 @@ public: bool use_motion; bool use_holdout; + int particle_id; + vector<Particle> particles; + Object(); ~Object(); @@ -69,6 +77,7 @@ public: void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); void device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); + void device_update_particles(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); void device_free(Device *device, DeviceScene *dscene); void tag_update(Scene *scene); diff --git a/intern/cycles/render/scene.h b/intern/cycles/render/scene.h index 90bc47d5c8e..8b9944cb76e 100644 --- a/intern/cycles/render/scene.h +++ b/intern/cycles/render/scene.h @@ -82,6 +82,9 @@ public: device_vector<float2> light_background_marginal_cdf; device_vector<float2> light_background_conditional_cdf; + /* particles */ + device_vector<float4> particles; + /* shaders */ device_vector<uint4> svm_nodes; device_vector<uint> shader_flag; diff --git a/release/scripts/startup/bl_ui/properties_physics_cloth.py b/release/scripts/startup/bl_ui/properties_physics_cloth.py index 0240335c98f..33b977b5f04 100644 --- a/release/scripts/startup/bl_ui/properties_physics_cloth.py +++ b/release/scripts/startup/bl_ui/properties_physics_cloth.py @@ -117,10 +117,6 @@ class PHYSICS_PT_cloth_cache(PhysicButtonsPanel, Panel): bl_label = "Cloth Cache" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.cloth - def draw(self, context): md = context.cloth point_cache_ui(self, context, md.point_cache, cloth_panel_enabled(md), 'CLOTH') @@ -130,10 +126,6 @@ class PHYSICS_PT_cloth_collision(PhysicButtonsPanel, Panel): bl_label = "Cloth Collision" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.cloth - def draw_header(self, context): cloth = context.cloth.collision_settings @@ -173,10 +165,6 @@ class PHYSICS_PT_cloth_stiffness(PhysicButtonsPanel, Panel): bl_label = "Cloth Stiffness Scaling" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.cloth - def draw_header(self, context): cloth = context.cloth.settings @@ -209,10 +197,6 @@ class PHYSICS_PT_cloth_field_weights(PhysicButtonsPanel, Panel): bl_label = "Cloth Field Weights" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return (context.cloth) - def draw(self, context): cloth = context.cloth.settings effector_weights_ui(self, context, cloth.effector_weights) diff --git a/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py b/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py index 04696c793a6..db0794d8a8a 100644 --- a/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py +++ b/release/scripts/startup/bl_ui/properties_physics_dynamicpaint.py @@ -120,7 +120,8 @@ class PHYSICS_PT_dp_advanced_canvas(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint - return md and md.ui_type == 'CANVAS' and md.canvas_settings and md.canvas_settings.canvas_surfaces.active + rd = context.scene.render + return md and md.ui_type == 'CANVAS' and md.canvas_settings and md.canvas_settings.canvas_surfaces.active and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -194,10 +195,13 @@ class PHYSICS_PT_dp_canvas_output(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint + rd = context.scene.render if not (md and md.ui_type == 'CANVAS' and md.canvas_settings): return 0 surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active - return surface and not (surface.surface_format == 'VERTEX' and (surface.surface_type in {'DISPLACE', 'WAVE'})) + return (surface and + (not (surface.surface_format == 'VERTEX' and (surface.surface_type in {'DISPLACE', 'WAVE'}))) and + (not rd.use_game_engine)) def draw(self, context): layout = self.layout @@ -284,10 +288,11 @@ class PHYSICS_PT_dp_canvas_initial_color(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint + rd = context.scene.render if not (md and md.ui_type == 'CANVAS' and md.canvas_settings): return 0 surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active - return (surface and surface.surface_type == 'PAINT') + return (surface and surface.surface_type == 'PAINT') and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -318,10 +323,11 @@ class PHYSICS_PT_dp_effects(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint + rd = context.scene.render if not (md and md.ui_type == 'CANVAS' and md.canvas_settings): return False surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active - return (surface and surface.surface_type == 'PAINT') + return (surface and surface.surface_type == 'PAINT') and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -366,11 +372,13 @@ class PHYSICS_PT_dp_cache(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint + rd = context.scene.render return (md and md.ui_type == 'CANVAS' and md.canvas_settings and md.canvas_settings.canvas_surfaces.active and - md.canvas_settings.canvas_surfaces.active.is_cache_user) + md.canvas_settings.canvas_surfaces.active.is_cache_user and + (not rd.use_game_engine)) def draw(self, context): surface = context.dynamic_paint.canvas_settings.canvas_surfaces.active @@ -385,7 +393,8 @@ class PHYSICS_PT_dp_brush_source(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint - return md and md.ui_type == 'BRUSH' and md.brush_settings + rd = context.scene.render + return md and md.ui_type == 'BRUSH' and md.brush_settings and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -437,7 +446,8 @@ class PHYSICS_PT_dp_brush_velocity(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint - return md and md.ui_type == 'BRUSH' and md.brush_settings + rd = context.scene.render + return md and md.ui_type == 'BRUSH' and md.brush_settings and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -472,7 +482,8 @@ class PHYSICS_PT_dp_brush_wave(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.dynamic_paint - return md and md.ui_type == 'BRUSH' and md.brush_settings + rd = context.scene.render + return md and md.ui_type == 'BRUSH' and md.brush_settings and (not rd.use_game_engine) def draw(self, context): layout = self.layout diff --git a/release/scripts/startup/bl_ui/properties_physics_fluid.py b/release/scripts/startup/bl_ui/properties_physics_fluid.py index beb525bbd07..751f3e18acc 100644 --- a/release/scripts/startup/bl_ui/properties_physics_fluid.py +++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py @@ -192,13 +192,14 @@ class PHYSICS_PT_fluid(PhysicButtonsPanel, Panel): class PHYSICS_PT_domain_gravity(PhysicButtonsPanel, Panel): - bl_label = "Domain World" + bl_label = "Fluid World" bl_options = {'DEFAULT_CLOSED'} @classmethod def poll(cls, context): md = context.fluid - return md and md.settings and (md.settings.type == 'DOMAIN') + rd = context.scene.render + return md and md.settings and (md.settings.type == 'DOMAIN') and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -244,13 +245,14 @@ class PHYSICS_PT_domain_gravity(PhysicButtonsPanel, Panel): class PHYSICS_PT_domain_boundary(PhysicButtonsPanel, Panel): - bl_label = "Domain Boundary" + bl_label = "Fluid Boundary" bl_options = {'DEFAULT_CLOSED'} @classmethod def poll(cls, context): md = context.fluid - return md and md.settings and (md.settings.type == 'DOMAIN') + rd = context.scene.render + return md and md.settings and (md.settings.type == 'DOMAIN') and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -273,13 +275,14 @@ class PHYSICS_PT_domain_boundary(PhysicButtonsPanel, Panel): class PHYSICS_PT_domain_particles(PhysicButtonsPanel, Panel): - bl_label = "Domain Particles" + bl_label = "Fluid Particles" bl_options = {'DEFAULT_CLOSED'} @classmethod def poll(cls, context): md = context.fluid - return md and md.settings and (md.settings.type == 'DOMAIN') + rd = context.scene.render + return md and md.settings and (md.settings.type == 'DOMAIN') and (not rd.use_game_engine) def draw(self, context): layout = self.layout diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py b/release/scripts/startup/bl_ui/properties_physics_smoke.py index 012aefebb6e..1b333f1e505 100644 --- a/release/scripts/startup/bl_ui/properties_physics_smoke.py +++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py @@ -117,7 +117,8 @@ class PHYSICS_PT_smoke_groups(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.smoke - return md and (md.smoke_type == 'DOMAIN') + rd = context.scene.render + return md and (md.smoke_type == 'DOMAIN') and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -145,7 +146,8 @@ class PHYSICS_PT_smoke_highres(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.smoke - return md and (md.smoke_type == 'DOMAIN') + rd = context.scene.render + return md and (md.smoke_type == 'DOMAIN') and (not rd.use_game_engine) def draw_header(self, context): md = context.smoke.domain_settings @@ -182,7 +184,8 @@ class PHYSICS_PT_smoke_cache(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): md = context.smoke - return md and (md.smoke_type == 'DOMAIN') + rd = context.scene.render + return md and (md.smoke_type == 'DOMAIN') and (not rd.use_game_engine) def draw(self, context): layout = self.layout @@ -202,8 +205,9 @@ class PHYSICS_PT_smoke_field_weights(PhysicButtonsPanel, Panel): @classmethod def poll(cls, context): - smoke = context.smoke - return (smoke and smoke.smoke_type == 'DOMAIN') + md = context.smoke + rd = context.scene.render + return md and (md.smoke_type == 'DOMAIN') and (not rd.use_game_engine) def draw(self, context): domain = context.smoke.domain_settings diff --git a/release/scripts/startup/bl_ui/properties_physics_softbody.py b/release/scripts/startup/bl_ui/properties_physics_softbody.py index ea4180c891f..b043c1f9b68 100644 --- a/release/scripts/startup/bl_ui/properties_physics_softbody.py +++ b/release/scripts/startup/bl_ui/properties_physics_softbody.py @@ -72,10 +72,6 @@ class PHYSICS_PT_softbody_cache(PhysicButtonsPanel, Panel): bl_label = "Soft Body Cache" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.soft_body - def draw(self, context): md = context.soft_body point_cache_ui(self, context, md.point_cache, softbody_panel_enabled(md), 'SOFTBODY') @@ -85,10 +81,6 @@ class PHYSICS_PT_softbody_goal(PhysicButtonsPanel, Panel): bl_label = "Soft Body Goal" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.soft_body - def draw_header(self, context): softbody = context.soft_body.settings @@ -128,10 +120,6 @@ class PHYSICS_PT_softbody_edge(PhysicButtonsPanel, Panel): bl_label = "Soft Body Edges" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.soft_body - def draw_header(self, context): softbody = context.soft_body.settings @@ -181,10 +169,6 @@ class PHYSICS_PT_softbody_collision(PhysicButtonsPanel, Panel): bl_label = "Soft Body Self Collision" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.soft_body - def draw_header(self, context): softbody = context.soft_body.settings @@ -213,10 +197,6 @@ class PHYSICS_PT_softbody_solver(PhysicButtonsPanel, Panel): bl_label = "Soft Body Solver" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return context.soft_body - def draw(self, context): layout = self.layout @@ -249,10 +229,6 @@ class PHYSICS_PT_softbody_field_weights(PhysicButtonsPanel, Panel): bl_label = "Soft Body Field Weights" bl_options = {'DEFAULT_CLOSED'} - @classmethod - def poll(cls, context): - return (context.soft_body) - def draw(self, context): md = context.soft_body softbody = md.settings diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index eaaa1d8b62e..73a0d2d375b 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -527,6 +527,7 @@ struct ShadeResult; #define SH_NODE_BRIGHTCONTRAST 165 #define SH_NODE_LIGHT_FALLOFF 166 #define SH_NODE_OBJECT_INFO 167 +#define SH_NODE_PARTICLE_INFO 168 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index e2f17a1dd18..25723b8b0e8 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -205,5 +205,6 @@ void BKE_tracking_dopesheet_update(struct MovieTracking *tracking, int sort_meth #define TRACK_SORT_NAME 0 #define TRACK_SORT_LONGEST 1 #define TRACK_SORT_TOTAL 2 +#define TRACK_SORT_AVERAGE_ERROR 3 #endif diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index f73221066b1..701ce6c8299 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -75,7 +75,7 @@ /* --------------------- */ /* forward declarations */ -static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int level, int animated); +static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, int level, int animated); /* ******************************************************************** */ /* Animation Visualisation */ @@ -699,7 +699,7 @@ int where_on_path(Object *ob, float ctime, float vec[4], float dir[3], float qua /* ******************************************************************** */ /* Dupli-Geometry */ -static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int type, int animated) +static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], int lay, int index, int par_index, int type, int animated) { DupliObject *dob = MEM_callocN(sizeof(DupliObject), "dupliobject"); @@ -709,6 +709,7 @@ static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], i copy_m4_m4(dob->omat, ob->obmat); dob->origlay = ob->lay; dob->index = index; + dob->particle_index = par_index; dob->type = type; dob->animated = (type == OB_DUPLIGROUP) && animated; ob->lay = lay; @@ -716,7 +717,7 @@ static DupliObject *new_dupli_object(ListBase *lb, Object *ob, float mat[][4], i return dob; } -static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, int animated) +static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, int animated) { DupliObject *dob; Group *group; @@ -748,7 +749,7 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i mult_m4_m4m4(mat, ob->obmat, go->ob->obmat); } - dob = new_dupli_object(lb, go->ob, mat, ob->lay, 0, OB_DUPLIGROUP, animated); + dob = new_dupli_object(lb, go->ob, mat, ob->lay, 0, par_index, OB_DUPLIGROUP, animated); /* check the group instance and object layers match, also that the object visible flags are ok. */ if ((dob->origlay & group->layer) == 0 || @@ -763,14 +764,14 @@ static void group_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, i if (go->ob->transflag & OB_DUPLI) { copy_m4_m4(dob->ob->obmat, dob->mat); - object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, level + 1, animated); + object_duplilist_recursive(&group->id, scene, go->ob, lb, ob->obmat, par_index, level + 1, animated); copy_m4_m4(dob->ob->obmat, dob->omat); } } } } -static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, int animated) +static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int par_index, int level, int animated) { extern int enable_cu_speed; /* object.c */ Object copyob; @@ -818,7 +819,7 @@ static void frames_duplilist(ListBase *lb, Scene *scene, Object *ob, int level, BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */ BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra); - dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, OB_DUPLIFRAMES, animated); + dob = new_dupli_object(lb, ob, ob->obmat, ob->lay, scene->r.cfra, par_index, OB_DUPLIFRAMES, animated); copy_m4_m4(dob->omat, copyob.obmat); } } @@ -849,6 +850,7 @@ typedef struct vertexDupliData { Scene *scene; Object *ob, *par; float (*orco)[3]; + int par_index; } vertexDupliData; /* ------------- */ @@ -885,7 +887,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], origlay = vdd->ob->lay; - dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, OB_DUPLIVERTS, vdd->animated); + dob = new_dupli_object(vdd->lb, vdd->ob, obmat, vdd->par->lay, index, vdd->par_index, OB_DUPLIVERTS, vdd->animated); /* restore the original layer so that each dupli will have proper dob->origlay */ vdd->ob->lay = origlay; @@ -897,12 +899,12 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3], float tmpmat[4][4]; copy_m4_m4(tmpmat, vdd->ob->obmat); copy_m4_m4(vdd->ob->obmat, obmat); /* pretend we are really this mat */ - object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->level + 1, vdd->animated); + object_duplilist_recursive((ID *)vdd->id, vdd->scene, vdd->ob, vdd->lb, obmat, vdd->par_index, vdd->level + 1, vdd->animated); copy_m4_m4(vdd->ob->obmat, tmpmat); } } -static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int level, int animated) +static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, int level, int animated) { Object *ob, *ob_iter; Mesh *me = par->data; @@ -986,6 +988,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl vdd.scene = scene; vdd.par = par; copy_m4_m4(vdd.pmat, pmat); + vdd.par_index = par_index; /* mballs have a different dupli handling */ if (ob->type != OB_MBALL) ob->flag |= OB_DONE; /* doesnt render */ @@ -1024,7 +1027,7 @@ static void vertex_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, fl dm->release(dm); } -static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int level, int animated) +static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int par_index, int level, int animated) { Object *ob, *ob_iter; Base *base = NULL; @@ -1171,7 +1174,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa copy_m4_m4(tmat, obmat); mul_m4_m4m3(obmat, tmat, mat); - dob = new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIFACES, animated); + dob = new_dupli_object(lb, ob, obmat, par->lay, a, par_index, OB_DUPLIFACES, animated); if (G.rendering) { w = 1.0f / (float)mp->totloop; @@ -1194,7 +1197,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa float tmpmat[4][4]; copy_m4_m4(tmpmat, ob->obmat); copy_m4_m4(ob->obmat, obmat); /* pretend we are really this mat */ - object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, level + 1, animated); + object_duplilist_recursive((ID *)id, scene, ob, lb, ob->obmat, par_index, level + 1, animated); copy_m4_m4(ob->obmat, tmpmat); } } @@ -1214,7 +1217,7 @@ static void face_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, floa dm->release(dm); } -static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], ParticleSystem *psys, int level, int animated) +static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *par, float par_space_mat[][4], int UNUSED(par_index), ParticleSystem *psys, int level, int animated) { GroupObject *go; Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL; @@ -1228,7 +1231,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p float ctime, pa_time, scale = 1.0f; float tmat[4][4], mat[4][4], pamat[4][4], vec[3], size = 0.0; float (*obmat)[4], (*oldobmat)[4]; - int a, b, counter, hair = 0; + int a, b, counter, index, hair = 0; int totpart, totchild, totgroup = 0 /*, pa_num */; int no_draw_flag = PARS_UNEXIST; @@ -1342,6 +1345,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p else a = totpart; + index = 0; for (pa = psys->particles, counter = 0; a < totpart + totchild; a++, pa++, counter++) { if (a < totpart) { /* handle parent particle */ @@ -1437,7 +1441,7 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p else copy_m4_m4(mat, tmat); - dob = new_dupli_object(lb, go->ob, mat, par->lay, counter, OB_DUPLIPARTS, animated); + dob = new_dupli_object(lb, go->ob, mat, par->lay, counter, index, OB_DUPLIPARTS, animated); copy_m4_m4(dob->omat, obcopylist[b].obmat); if (G.rendering) psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); @@ -1479,11 +1483,14 @@ static void new_particle_duplilist(ListBase *lb, ID *id, Scene *scene, Object *p if (part->draw & PART_DRAW_GLOBAL_OB) add_v3_v3v3(mat[3], mat[3], vec); - dob = new_dupli_object(lb, ob, mat, ob->lay, counter, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated); + dob = new_dupli_object(lb, ob, mat, ob->lay, counter, index, GS(id->name) == ID_GR ? OB_DUPLIGROUP : OB_DUPLIPARTS, animated); copy_m4_m4(dob->omat, oldobmat); if (G.rendering) psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco); } + + /* only counts visible particles */ + ++index; } /* restore objects since they were changed in BKE_object_where_is_calc_time */ @@ -1530,7 +1537,7 @@ static Object *find_family_object(Object **obar, char *family, char ch) } -static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, int animated) +static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int par_index, int level, int animated) { Object *ob, *obar[256] = {NULL}; Curve *cu; @@ -1569,7 +1576,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i copy_m4_m4(obmat, par->obmat); copy_v3_v3(obmat[3], vec); - new_dupli_object(lb, ob, obmat, par->lay, a, OB_DUPLIVERTS, animated); + new_dupli_object(lb, ob, obmat, par->lay, a, par_index, OB_DUPLIVERTS, animated); } } @@ -1578,7 +1585,7 @@ static void font_duplilist(ListBase *lb, Scene *scene, Object *par, int level, i /* ------------- */ -static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int level, int animated) +static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBase *duplilist, float par_space_mat[][4], int par_index, int level, int animated) { if ((ob->transflag & OB_DUPLI) == 0) return; @@ -1598,31 +1605,31 @@ static void object_duplilist_recursive(ID *id, Scene *scene, Object *ob, ListBas if (ob->transflag & OB_DUPLIPARTS) { ParticleSystem *psys = ob->particlesystem.first; for (; psys; psys = psys->next) - new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, psys, level + 1, animated); + new_particle_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, psys, level + 1, animated); } else if (ob->transflag & OB_DUPLIVERTS) { if (ob->type == OB_MESH) { - vertex_duplilist(duplilist, id, scene, ob, par_space_mat, level + 1, animated); + vertex_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated); } else if (ob->type == OB_FONT) { if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ - font_duplilist(duplilist, scene, ob, level + 1, animated); + font_duplilist(duplilist, scene, ob, par_index, level + 1, animated); } } } else if (ob->transflag & OB_DUPLIFACES) { if (ob->type == OB_MESH) - face_duplilist(duplilist, id, scene, ob, par_space_mat, level + 1, animated); + face_duplilist(duplilist, id, scene, ob, par_space_mat, par_index, level + 1, animated); } else if (ob->transflag & OB_DUPLIFRAMES) { if (GS(id->name) == ID_SCE) { /* TODO - support dupligroups */ - frames_duplilist(duplilist, scene, ob, level + 1, animated); + frames_duplilist(duplilist, scene, ob, par_index, level + 1, animated); } } else if (ob->transflag & OB_DUPLIGROUP) { DupliObject *dob; - group_duplilist(duplilist, scene, ob, level + 1, animated); /* now recursive */ + group_duplilist(duplilist, scene, ob, par_index, level + 1, animated); /* now recursive */ if (level == 0) { for (dob = duplilist->first; dob; dob = dob->next) @@ -1638,7 +1645,7 @@ ListBase *object_duplilist(Scene *sce, Object *ob) { ListBase *duplilist = MEM_mallocN(sizeof(ListBase), "duplilist"); duplilist->first = duplilist->last = NULL; - object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0); + object_duplilist_recursive((ID *)sce, sce, ob, duplilist, NULL, 0, 0, 0); return duplilist; } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 84d6141b470..244d2888fc6 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -314,7 +314,7 @@ typedef struct MovieClipCache { /* cache for undistorted shot */ float principal[2]; float k1, k2, k3; - short undistoriton_used; + short undistortion_used; int proxy; short render_flag; @@ -627,7 +627,7 @@ static ImBuf *get_postprocessed_cached_frame(MovieClip *clip, MovieClipUser *use if (!check_undistortion_cache_flags(clip)) return NULL; } - else if (cache->postprocessed.undistoriton_used) + else if (cache->postprocessed.undistortion_used) return NULL; IMB_refImBuf(cache->postprocessed.ibuf); @@ -660,11 +660,11 @@ static ImBuf *put_postprocessed_frame_to_cache(MovieClip *clip, MovieClipUser *u if (need_undistortion_postprocess(user, flag)) { copy_v2_v2(cache->postprocessed.principal, camera->principal); copy_v3_v3(&cache->postprocessed.k1, &camera->k1); - cache->postprocessed.undistoriton_used = TRUE; + cache->postprocessed.undistortion_used = TRUE; postproc_ibuf = get_undistorted_ibuf(clip, NULL, ibuf); } else { - cache->postprocessed.undistoriton_used = FALSE; + cache->postprocessed.undistortion_used = FALSE; } if (postprocess_flag) { diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index ccec6320ac1..3e5f3f5b24c 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -1958,6 +1958,7 @@ static void registerShaderNodes(bNodeTreeType *ttype) register_node_type_sh_fresnel(ttype); register_node_type_sh_layer_weight(ttype); register_node_type_sh_tex_coord(ttype); + register_node_type_sh_particle_info(ttype); register_node_type_sh_background(ttype); register_node_type_sh_bsdf_diffuse(ttype); diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index a8a0d8f67cf..01e464e77a8 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -3371,6 +3371,17 @@ static int channels_longest_segment_sort(void *a, void *b) return 0; } +static int channels_average_error_sort(void *a, void *b) +{ + MovieTrackingDopesheetChannel *channel_a = a; + MovieTrackingDopesheetChannel *channel_b = b; + + if (channel_a->track->error > channel_b->track->error) + return 1; + else + return 0; +} + static int channels_alpha_inverse_sort(void *a, void *b) { if (channels_alpha_sort(a, b)) @@ -3395,6 +3406,17 @@ static int channels_longest_segment_inverse_sort(void *a, void *b) return 1; } +static int channels_average_error_inverse_sort(void *a, void *b) +{ + MovieTrackingDopesheetChannel *channel_a = a; + MovieTrackingDopesheetChannel *channel_b = b; + + if (channel_a->track->error < channel_b->track->error) + return 1; + else + return 0; +} + static void channels_segments_calc(MovieTrackingDopesheetChannel *channel) { MovieTrackingTrack *track = channel->track; @@ -3490,6 +3512,9 @@ static void tracking_dopesheet_sort(MovieTracking *tracking, int sort_method, i else if (sort_method == TRACK_SORT_TOTAL) { BLI_sortlist(&dopesheet->channels, channels_total_track_inverse_sort); } + else if (sort_method == TRACK_SORT_AVERAGE_ERROR) { + BLI_sortlist(&dopesheet->channels, channels_average_error_inverse_sort); + } } else { if (sort_method == TRACK_SORT_NAME) { @@ -3501,6 +3526,9 @@ static void tracking_dopesheet_sort(MovieTracking *tracking, int sort_method, i else if (sort_method == TRACK_SORT_TOTAL) { BLI_sortlist(&dopesheet->channels, channels_total_track_sort); } + else if (sort_method == TRACK_SORT_AVERAGE_ERROR) { + BLI_sortlist(&dopesheet->channels, channels_average_error_sort); + } } dopesheet->sort_method = sort_method; diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c index fa86f089387..89f018a1b76 100644 --- a/source/blender/editors/object/object_select.c +++ b/source/blender/editors/object/object_select.c @@ -708,10 +708,11 @@ void OBJECT_OT_select_grouped(wmOperatorType *ot) static int object_select_by_layer_exec(bContext *C, wmOperator *op) { unsigned int layernum; - short extend; + short extend, match; extend = RNA_boolean_get(op->ptr, "extend"); layernum = RNA_int_get(op->ptr, "layers"); + match = RNA_enum_get(op->ptr, "match"); if (extend == 0) { CTX_DATA_BEGIN (C, Base *, base, visible_bases) @@ -723,7 +724,14 @@ static int object_select_by_layer_exec(bContext *C, wmOperator *op) CTX_DATA_BEGIN (C, Base *, base, visible_bases) { - if (base->lay == (1 << (layernum - 1))) + int ok = 0; + + if (match == 1) /* exact */ + ok = (base->lay == (1 << (layernum - 1))); + else /* shared layers */ + ok = (base->lay & (1 << (layernum - 1))); + + if (ok) ED_base_object_select(base, BA_SELECT); } CTX_DATA_END; @@ -736,6 +744,12 @@ static int object_select_by_layer_exec(bContext *C, wmOperator *op) void OBJECT_OT_select_by_layer(wmOperatorType *ot) { + static EnumPropertyItem match_items[] = { + {1, "EXACT", 0, "Exact Match", ""}, + {2, "SHARED", 0, "Shared Layers", ""}, + {0, NULL, 0, NULL, NULL} + }; + /* identifiers */ ot->name = "Select by Layer"; ot->description = "Select all visible objects on a layer"; @@ -750,6 +764,7 @@ void OBJECT_OT_select_by_layer(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ + RNA_def_enum(ot->srna, "match", match_items, 0, "Match", ""); RNA_def_boolean(ot->srna, "extend", FALSE, "Extend", "Extend selection instead of deselecting everything first"); RNA_def_int(ot->srna, "layers", 1, 1, 20, "Layer", "", 1, 20); } diff --git a/source/blender/editors/space_clip/clip_dopesheet_ops.c b/source/blender/editors/space_clip/clip_dopesheet_ops.c index 4a390241629..499eae75a73 100644 --- a/source/blender/editors/space_clip/clip_dopesheet_ops.c +++ b/source/blender/editors/space_clip/clip_dopesheet_ops.c @@ -110,6 +110,10 @@ static int dopesheet_select_channel_exec(bContext *C, wmOperator *op) track->flag ^= TRACK_DOPE_SEL; else track->flag |= TRACK_DOPE_SEL; + + if (track->flag & TRACK_DOPE_SEL) { + tracking->act_track = track; + } } else if (!extend) track->flag &= ~TRACK_DOPE_SEL; diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c index bcda1d59555..504d96df072 100644 --- a/source/blender/editors/space_clip/clip_editor.c +++ b/source/blender/editors/space_clip/clip_editor.c @@ -522,6 +522,7 @@ typedef struct SpaceClipDrawContext { /* fields to check if cache is still valid */ int framenr, start_frame; + short render_size, render_flag; } SpaceClipDrawContext; int ED_space_clip_texture_buffer_supported(SpaceClip *sc) @@ -559,6 +560,8 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf) * so not changed image buffer pointer means unchanged image content */ need_rebind |= context->texture_ibuf != ibuf; need_rebind |= context->framenr != sc->user.framenr; + need_rebind |= context->render_size != sc->user.render_size; + need_rebind |= context->render_flag != sc->user.render_flag; need_rebind |= context->start_frame != clip->start_frame; if (need_rebind) { @@ -614,6 +617,8 @@ int ED_space_clip_load_movieclip_buffer(SpaceClip *sc, ImBuf *ibuf) context->image_width = ibuf->x; context->image_height = ibuf->y; context->framenr = sc->user.framenr; + context->render_size = sc->user.render_size; + context->render_flag = sc->user.render_flag; context->start_frame = clip->start_frame; } else { diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 44d7ec660f2..24d33b49db2 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -301,6 +301,15 @@ typedef struct DupliObject { short type; /* from Object.transflag */ char no_draw, animated; + + /* Lowest-level particle index. + * Note: This is needed for particle info in shaders. + * Otherwise dupli groups in particle systems would override the + * index value from higher dupli levels. Would be nice to have full generic access + * to all dupli levels somehow, but for now this should cover most use-cases. + */ + int particle_index; + int pad; } DupliObject; /* **************** OBJECT ********************* */ diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h index 8935268cb91..011bbcd442a 100644 --- a/source/blender/makesdna/DNA_space_types.h +++ b/source/blender/makesdna/DNA_space_types.h @@ -1063,6 +1063,7 @@ typedef enum eSpaceClip_Dopesheet_Sort { SC_DOPE_SORT_NAME = 0, SC_DOPE_SORT_LONGEST, SC_DOPE_SORT_TOTAL, + SC_DOPE_SORT_AVERAGE_ERROR, } eSpaceClip_Dopesheet_Sort; /* SpaceClip->dope_flag */ diff --git a/source/blender/makesrna/intern/rna_nodetree_types.h b/source/blender/makesrna/intern/rna_nodetree_types.h index ba6e40d3254..62c3051727d 100644 --- a/source/blender/makesrna/intern/rna_nodetree_types.h +++ b/source/blender/makesrna/intern/rna_nodetree_types.h @@ -80,6 +80,7 @@ DefNode( ShaderNode, SH_NODE_NEW_GEOMETRY, 0, "NE DefNode( ShaderNode, SH_NODE_LIGHT_PATH, 0, "LIGHT_PATH", LightPath, "Light Path", "" ) DefNode( ShaderNode, SH_NODE_LIGHT_FALLOFF, 0, "LIGHT_FALLOFF", LightFalloff, "Light Falloff", "" ) DefNode( ShaderNode, SH_NODE_OBJECT_INFO, 0, "OBJECT_INFO", ObjectInfo, "Object Info", "" ) +DefNode( ShaderNode, SH_NODE_PARTICLE_INFO, 0, "PARTICLE_INFO", ParticleInfo, "Particle Info", "" ) DefNode( ShaderNode, SH_NODE_TEX_IMAGE, def_sh_tex_image, "TEX_IMAGE", TexImage, "Image Texture", "" ) DefNode( ShaderNode, SH_NODE_TEX_ENVIRONMENT, def_sh_tex_environment, "TEX_ENVIRONMENT", TexEnvironment, "Environment Texture","" ) DefNode( ShaderNode, SH_NODE_TEX_SKY, def_sh_tex_sky, "TEX_SKY", TexSky, "Sky Texture", "" ) diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 7e3b368aa64..0399a8ee60d 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -2545,6 +2545,16 @@ static void rna_def_dupli_object(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE); RNA_def_property_ui_text(prop, "Hide", "Don't show dupli object in viewport or render"); + prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "index"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Index", "Index in the lowest-level dupli list"); + + prop = RNA_def_property(srna, "particle_index", PROP_INT, PROP_NONE); + RNA_def_property_int_sdna(prop, NULL, "particle_index"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Particle Index", "Index in the lowest-level particle dupli list"); + /* TODO: DupliObject has more properties that can be wrapped */ } diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 6755f7b7e78..cafe8ebefad 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2999,6 +2999,7 @@ static void rna_def_space_clip(BlenderRNA *brna) {SC_DOPE_SORT_NAME, "NAME", 0, "Name", "Sort channels by their names"}, {SC_DOPE_SORT_LONGEST, "LONGEST", 0, "Longest", "Sort channels by longest tracked segment"}, {SC_DOPE_SORT_TOTAL, "TOTAL", 0, "Total", "Sort channels by overall amount of tracked segments"}, + {SC_DOPE_SORT_AVERAGE_ERROR, "AVERAGE_ERROR", 0, "Average Error", "Sort channels by average reprojection error of tracks after solve"}, {0, NULL, 0, NULL, NULL} }; diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index dcbe52c3531..aaa96fc4d95 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -293,6 +293,20 @@ static void rna_trackingObject_tracks_begin(CollectionPropertyIterator *iter, Po } } +static PointerRNA rna_trackingObject_reconstruction_get(PointerRNA *ptr) +{ + MovieTrackingObject *object = (MovieTrackingObject* )ptr->data; + + if (object->flag & TRACKING_OBJECT_CAMERA) { + MovieClip *clip = (MovieClip*)ptr->id.data; + + return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingReconstruction, &clip->tracking.reconstruction); + } + else { + return rna_pointer_inherit_refine(ptr, &RNA_MovieTrackingReconstruction, &object->reconstruction); + } +} + static PointerRNA rna_tracking_active_object_get(PointerRNA *ptr) { MovieClip *clip = (MovieClip*)ptr->id.data; @@ -1312,6 +1326,7 @@ static void rna_def_trackingObject(BlenderRNA *brna) /* reconstruction */ prop = RNA_def_property(srna, "reconstruction", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "MovieTrackingReconstruction"); + RNA_def_property_pointer_funcs(prop, "rna_trackingObject_reconstruction_get", NULL, NULL, NULL); /* scale */ prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE); diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index 43c3c652bbc..6d88f64b5d5 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -161,6 +161,7 @@ set(SRC shader/nodes/node_shader_light_path.c shader/nodes/node_shader_light_falloff.c shader/nodes/node_shader_object_info.c + shader/nodes/node_shader_particle_info.c shader/nodes/node_shader_mix_shader.c shader/nodes/node_shader_add_shader.c shader/nodes/node_shader_output_lamp.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index dd6d25380b4..6b000181953 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -78,6 +78,7 @@ void register_node_type_sh_object_info(struct bNodeTreeType *ttype); void register_node_type_sh_fresnel(struct bNodeTreeType *ttype); void register_node_type_sh_layer_weight(struct bNodeTreeType *ttype); void register_node_type_sh_tex_coord(struct bNodeTreeType *ttype); +void register_node_type_sh_particle_info(struct bNodeTreeType *ttype); void register_node_type_sh_background(struct bNodeTreeType *ttype); void register_node_type_sh_bsdf_diffuse(struct bNodeTreeType *ttype); diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c new file mode 100644 index 00000000000..6456742e22b --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c @@ -0,0 +1,48 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +static bNodeSocketTemplate outputs[] = { + { SOCK_FLOAT, 0, "Age" }, + { SOCK_FLOAT, 0, "Lifetime" }, + { -1, 0, "" } +}; + +/* node type definition */ +void register_node_type_sh_particle_info(bNodeTreeType *ttype) +{ + static bNodeType ntype; + + node_type_base(ttype, &ntype, SH_NODE_PARTICLE_INFO, "Particle Info", NODE_CLASS_INPUT, 0); + node_type_compatibility(&ntype, NODE_NEW_SHADING); + node_type_socket_templates(&ntype, NULL, outputs); + node_type_size(&ntype, 150, 60, 200); + + nodeRegisterType(ttype, &ntype); +} + |