Changeset 8393 for code/trunk/src/external/bullet/BulletDynamics/Dynamics
- Timestamp:
- May 3, 2011, 5:07:42 AM (14 years ago)
- Location:
- code/trunk/src/external/bullet/BulletDynamics/Dynamics
- Files:
-
- 7 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 { -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
r8351 r8393 63 63 virtual void integrateTransforms(btScalar timeStep); 64 64 65 virtual void addSpeculativeContacts(btScalar timeStep); 66 65 67 virtual void calculateSimulationIslands(); 66 68 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDynamicsWorld.h
r8351 r8393 33 33 BT_SIMPLE_DYNAMICS_WORLD=1, 34 34 BT_DISCRETE_DYNAMICS_WORLD=2, 35 BT_CONTINUOUS_DYNAMICS_WORLD=3 35 BT_CONTINUOUS_DYNAMICS_WORLD=3, 36 BT_SOFT_RIGID_DYNAMICS_WORLD=4 36 37 }; 37 38 … … 86 87 87 88 virtual void addRigidBody(btRigidBody* body) = 0; 89 90 virtual void addRigidBody(btRigidBody* body, short group, short mask) = 0; 88 91 89 92 virtual void removeRigidBody(btRigidBody* body) = 0; -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btRigidBody.cpp
r8351 r8393 52 52 m_totalForce.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); 53 53 m_totalTorque.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)), 54 m_linearDamping = btScalar(0.);55 m_angularDamping = btScalar(0.5); 54 setDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping); 55 56 56 m_linearSleepingThreshold = constructionInfo.m_linearSleepingThreshold; 57 57 m_angularSleepingThreshold = constructionInfo.m_angularSleepingThreshold; … … 85 85 86 86 setMassProps(constructionInfo.m_mass, constructionInfo.m_localInertia); 87 setDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping);88 87 updateInertiaTensor(); 89 88 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btRigidBody.h
r8351 r8393 14 14 */ 15 15 16 #ifndef RIGIDBODY_H17 #define RIGIDBODY_H16 #ifndef BT_RIGIDBODY_H 17 #define BT_RIGIDBODY_H 18 18 19 19 #include "LinearMath/btAlignedObjectArray.h" … … 90 90 91 91 int m_debugBodyId; 92 92 93 93 94 94 protected: … … 271 271 } 272 272 273 const btVector3& getTotalForce() 273 const btVector3& getTotalForce() const 274 274 { 275 275 return m_totalForce; 276 276 }; 277 277 278 const btVector3& getTotalTorque() 278 const btVector3& getTotalTorque() const 279 279 { 280 280 return m_totalTorque; … … 505 505 } 506 506 507 int getNumConstraintRefs() 507 int getNumConstraintRefs() const 508 508 { 509 509 return m_constraintRefs.size(); … … 618 618 619 619 void internalWritebackVelocity(btScalar timeStep); 620 620 621 621 622 … … 687 688 688 689 689 #endif 690 690 #endif //BT_RIGIDBODY_H 691 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
r8351 r8393 79 79 infoGlobal.m_timeStep = timeStep; 80 80 m_constraintSolver->prepareSolve(0,numManifolds); 81 m_constraintSolver->solveGroup( 0,0,manifoldPtr, numManifolds,0,0,infoGlobal,m_debugDrawer, m_stackAlloc,m_dispatcher1);81 m_constraintSolver->solveGroup(&getCollisionObjectArray()[0],getNumCollisionObjects(),manifoldPtr, numManifolds,0,0,infoGlobal,m_debugDrawer, m_stackAlloc,m_dispatcher1); 82 82 m_constraintSolver->allSolved(infoGlobal,m_debugDrawer, m_stackAlloc); 83 83 } … … 155 155 } 156 156 } 157 158 void btSimpleDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask) 159 { 160 body->setGravity(m_gravity); 161 162 if (body->getCollisionShape()) 163 { 164 addCollisionObject(body,group,mask); 165 } 166 } 167 168 169 void btSimpleDynamicsWorld::debugDrawWorld() 170 { 171 172 } 173 174 void btSimpleDynamicsWorld::addAction(btActionInterface* action) 175 { 176 177 } 178 179 void btSimpleDynamicsWorld::removeAction(btActionInterface* action) 180 { 181 182 } 183 157 184 158 185 void btSimpleDynamicsWorld::updateAabbs() -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
r8351 r8393 57 57 virtual void addRigidBody(btRigidBody* body); 58 58 59 virtual void addRigidBody(btRigidBody* body, short group, short mask); 60 59 61 virtual void removeRigidBody(btRigidBody* body); 62 63 virtual void debugDrawWorld(); 64 65 virtual void addAction(btActionInterface* action); 66 67 virtual void removeAction(btActionInterface* action); 60 68 61 69 ///removeCollisionObject will first check if it is a rigid body, if so call removeRigidBody otherwise call btCollisionWorld::removeCollisionObject
Note: See TracChangeset
for help on using the changeset viewer.