Changeset 8393 for code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
- Timestamp:
- May 3, 2011, 5:07:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
r8351 r8393 36 36 #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" 37 37 #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" 38 #include "BulletDynamics/ConstraintSolver/btContactConstraint.h" 39 38 40 39 41 #include "LinearMath/btIDebugDraw.h" … … 46 48 47 49 #include "LinearMath/btSerializer.h" 50 51 #if 0 52 btAlignedObjectArray<btVector3> debugContacts; 53 btAlignedObjectArray<btVector3> debugNormals; 54 int startHit=2; 55 int firstHit=startHit; 56 #endif 48 57 49 58 … … 315 324 dispatchInfo.m_debugDraw = getDebugDrawer(); 316 325 326 317 327 ///perform collision detection 318 328 performDiscreteCollisionDetection(); 329 330 if (getDispatchInfo().m_useContinuous) 331 addSpeculativeContacts(timeStep); 332 319 333 320 334 calculateSimulationIslands(); … … 746 760 class btClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback 747 761 { 762 public: 763 748 764 btCollisionObject* m_me; 749 765 btScalar m_allowedPenetration; 750 766 btOverlappingPairCache* m_pairCache; 751 767 btDispatcher* m_dispatcher; 752 753 768 754 769 public: … … 798 813 if (m_dispatcher->needsResponse(m_me,otherObj)) 799 814 { 815 #if 0 800 816 ///don't do CCD when there are already contact points (touching contact/penetration) 801 817 btAlignedObjectArray<btPersistentManifold*> manifoldArray; … … 815 831 } 816 832 } 817 } 818 return true; 833 #endif 834 return true; 835 } 836 837 return false; 819 838 } 820 839 … … 825 844 int gNumClampedCcdMotions=0; 826 845 827 //#include "stdio.h"828 846 void btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep) 829 847 { … … 837 855 if (body->isActive() && (!body->isStaticOrKinematicObject())) 838 856 { 857 858 body->predictIntegratedTransform(timeStep, predictedTrans); 859 860 btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); 861 862 863 864 if (getDispatchInfo().m_useContinuous && body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion) 865 { 866 BT_PROFILE("CCD motion clamping"); 867 if (body->getCollisionShape()->isConvex()) 868 { 869 gNumClampedCcdMotions++; 870 #ifdef USE_STATIC_ONLY 871 class StaticOnlyCallback : public btClosestNotMeConvexResultCallback 872 { 873 public: 874 875 StaticOnlyCallback (btCollisionObject* me,const btVector3& fromA,const btVector3& toA,btOverlappingPairCache* pairCache,btDispatcher* dispatcher) : 876 btClosestNotMeConvexResultCallback(me,fromA,toA,pairCache,dispatcher) 877 { 878 } 879 880 virtual bool needsCollision(btBroadphaseProxy* proxy0) const 881 { 882 btCollisionObject* otherObj = (btCollisionObject*) proxy0->m_clientObject; 883 if (!otherObj->isStaticOrKinematicObject()) 884 return false; 885 return btClosestNotMeConvexResultCallback::needsCollision(proxy0); 886 } 887 }; 888 889 StaticOnlyCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher()); 890 #else 891 btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher()); 892 #endif 893 //btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 894 btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 895 sweepResults.m_allowedPenetration=getDispatchInfo().m_allowedCcdPenetration; 896 897 sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup; 898 sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask; 899 btTransform modifiedPredictedTrans = predictedTrans; 900 modifiedPredictedTrans.setBasis(body->getWorldTransform().getBasis()); 901 902 convexSweepTest(&tmpSphere,body->getWorldTransform(),modifiedPredictedTrans,sweepResults); 903 if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f)) 904 { 905 906 //printf("clamped integration to hit fraction = %f\n",fraction); 907 body->setHitFraction(sweepResults.m_closestHitFraction); 908 body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans); 909 body->setHitFraction(0.f); 910 body->proceedToTransform( predictedTrans); 911 912 #if 0 913 btVector3 linVel = body->getLinearVelocity(); 914 915 btScalar maxSpeed = body->getCcdMotionThreshold()/getSolverInfo().m_timeStep; 916 btScalar maxSpeedSqr = maxSpeed*maxSpeed; 917 if (linVel.length2()>maxSpeedSqr) 918 { 919 linVel.normalize(); 920 linVel*= maxSpeed; 921 body->setLinearVelocity(linVel); 922 btScalar ms2 = body->getLinearVelocity().length2(); 923 body->predictIntegratedTransform(timeStep, predictedTrans); 924 925 btScalar sm2 = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); 926 btScalar smt = body->getCcdSquareMotionThreshold(); 927 printf("sm2=%f\n",sm2); 928 } 929 #else 930 //response between two dynamic objects without friction, assuming 0 penetration depth 931 btScalar appliedImpulse = 0.f; 932 btScalar depth = 0.f; 933 appliedImpulse = resolveSingleCollision(body,sweepResults.m_hitCollisionObject,sweepResults.m_hitPointWorld,sweepResults.m_hitNormalWorld,getSolverInfo(), depth); 934 935 936 #endif 937 938 continue; 939 } 940 } 941 } 942 943 944 body->proceedToTransform( predictedTrans); 945 } 946 } 947 } 948 949 void btDiscreteDynamicsWorld::addSpeculativeContacts(btScalar timeStep) 950 { 951 BT_PROFILE("addSpeculativeContacts"); 952 btTransform predictedTrans; 953 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 954 { 955 btRigidBody* body = m_nonStaticRigidBodies[i]; 956 body->setHitFraction(1.f); 957 958 if (body->isActive() && (!body->isStaticOrKinematicObject())) 959 { 839 960 body->predictIntegratedTransform(timeStep, predictedTrans); 840 961 btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); … … 842 963 if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion) 843 964 { 844 BT_PROFILE(" CCD motion clamping");965 BT_PROFILE("search speculative contacts"); 845 966 if (body->getCollisionShape()->isConvex()) 846 967 { … … 853 974 sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup; 854 975 sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask; 855 856 convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults); 976 btTransform modifiedPredictedTrans; 977 modifiedPredictedTrans = predictedTrans; 978 modifiedPredictedTrans.setBasis(body->getWorldTransform().getBasis()); 979 980 convexSweepTest(&tmpSphere,body->getWorldTransform(),modifiedPredictedTrans,sweepResults); 857 981 if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f)) 858 982 { 859 body->setHitFraction(sweepResults.m_closestHitFraction); 860 body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans); 861 body->setHitFraction(0.f); 862 // printf("clamped integration to hit fraction = %f\n",fraction); 983 btBroadphaseProxy* proxy0 = body->getBroadphaseHandle(); 984 btBroadphaseProxy* proxy1 = sweepResults.m_hitCollisionObject->getBroadphaseHandle(); 985 btBroadphasePair* pair = sweepResults.m_pairCache->findPair(proxy0,proxy1); 986 if (pair) 987 { 988 if (pair->m_algorithm) 989 { 990 btManifoldArray contacts; 991 pair->m_algorithm->getAllContactManifolds(contacts); 992 if (contacts.size()) 993 { 994 btManifoldResult result(body,sweepResults.m_hitCollisionObject); 995 result.setPersistentManifold(contacts[0]); 996 997 btVector3 vec = (modifiedPredictedTrans.getOrigin()-body->getWorldTransform().getOrigin()); 998 vec*=sweepResults.m_closestHitFraction; 999 1000 btScalar lenSqr = vec.length2(); 1001 btScalar depth = 0.f; 1002 btVector3 pointWorld = sweepResults.m_hitPointWorld; 1003 if (lenSqr>SIMD_EPSILON) 1004 { 1005 depth = btSqrt(lenSqr); 1006 pointWorld -= vec; 1007 vec /= depth; 1008 } 1009 1010 if (contacts[0]->getBody0()==body) 1011 { 1012 result.addContactPoint(sweepResults.m_hitNormalWorld,pointWorld,depth); 1013 #if 0 1014 debugContacts.push_back(sweepResults.m_hitPointWorld);//sweepResults.m_hitPointWorld); 1015 debugNormals.push_back(sweepResults.m_hitNormalWorld); 1016 #endif 1017 } else 1018 { 1019 //swapped 1020 result.addContactPoint(-sweepResults.m_hitNormalWorld,pointWorld,depth); 1021 //sweepResults.m_hitPointWorld,depth); 1022 1023 #if 0 1024 if (1)//firstHit==1) 1025 { 1026 firstHit=0; 1027 debugNormals.push_back(sweepResults.m_hitNormalWorld); 1028 debugContacts.push_back(pointWorld);//sweepResults.m_hitPointWorld); 1029 debugNormals.push_back(sweepResults.m_hitNormalWorld); 1030 debugContacts.push_back(sweepResults.m_hitPointWorld); 1031 } 1032 firstHit--; 1033 #endif 1034 } 1035 } 1036 1037 } else 1038 { 1039 //no algorithm, use dispatcher to create one 1040 1041 } 1042 1043 1044 } else 1045 { 1046 //add an overlapping pair 1047 //printf("pair missing\n"); 1048 1049 } 863 1050 } 864 1051 } 865 1052 } 866 1053 867 body->proceedToTransform( predictedTrans);868 1054 } 869 1055 } … … 1010 1196 } 1011 1197 break; 1198 case D6_SPRING_CONSTRAINT_TYPE: 1012 1199 case D6_CONSTRAINT_TYPE: 1013 1200 {
Note: See TracChangeset
for help on using the changeset viewer.