Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 3, 2011, 5:07:42 AM (13 years ago)
Author:
rgrieder
Message:

Updated Bullet from v2.77 to v2.78.
(I'm not going to make a branch for that since the update from 2.74 to 2.77 hasn't been tested that much either).

You will HAVE to do a complete RECOMPILE! I tested with MSVC and MinGW and they both threw linker errors at me.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp

    r8351 r8393  
    3636#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"
    3737#include "BulletDynamics/ConstraintSolver/btSliderConstraint.h"
     38#include "BulletDynamics/ConstraintSolver/btContactConstraint.h"
     39
    3840
    3941#include "LinearMath/btIDebugDraw.h"
     
    4648
    4749#include "LinearMath/btSerializer.h"
     50
     51#if 0
     52btAlignedObjectArray<btVector3> debugContacts;
     53btAlignedObjectArray<btVector3> debugNormals;
     54int startHit=2;
     55int firstHit=startHit;
     56#endif
    4857
    4958
     
    315324        dispatchInfo.m_debugDraw = getDebugDrawer();
    316325
     326
    317327        ///perform collision detection
    318328        performDiscreteCollisionDetection();
     329
     330        if (getDispatchInfo().m_useContinuous)
     331                addSpeculativeContacts(timeStep);
     332
    319333
    320334        calculateSimulationIslands();
     
    746760class btClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback
    747761{
     762public:
     763
    748764        btCollisionObject* m_me;
    749765        btScalar m_allowedPenetration;
    750766        btOverlappingPairCache* m_pairCache;
    751767        btDispatcher* m_dispatcher;
    752 
    753768
    754769public:
     
    798813                if (m_dispatcher->needsResponse(m_me,otherObj))
    799814                {
     815#if 0
    800816                        ///don't do CCD when there are already contact points (touching contact/penetration)
    801817                        btAlignedObjectArray<btPersistentManifold*> manifoldArray;
     
    815831                                }
    816832                        }
    817                 }
    818                 return true;
     833#endif
     834                        return true;
     835                }
     836
     837                return false;
    819838        }
    820839
     
    825844int gNumClampedCcdMotions=0;
    826845
    827 //#include "stdio.h"
    828846void    btDiscreteDynamicsWorld::integrateTransforms(btScalar timeStep)
    829847{
     
    837855                if (body->isActive() && (!body->isStaticOrKinematicObject()))
    838856                {
     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
     949void    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                {
    839960                        body->predictIntegratedTransform(timeStep, predictedTrans);
    840961                        btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2();
     
    842963                        if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion)
    843964                        {
    844                                 BT_PROFILE("CCD motion clamping");
     965                                BT_PROFILE("search speculative contacts");
    845966                                if (body->getCollisionShape()->isConvex())
    846967                                {
     
    853974                                        sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup;
    854975                                        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);
    857981                                        if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f))
    858982                                        {
    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                                                }
    8631050                                        }
    8641051                                }
    8651052                        }
    8661053                       
    867                         body->proceedToTransform( predictedTrans);
    8681054                }
    8691055        }
     
    10101196                        }
    10111197                        break;
     1198                case D6_SPRING_CONSTRAINT_TYPE:
    10121199                case D6_CONSTRAINT_TYPE:
    10131200                        {
Note: See TracChangeset for help on using the changeset viewer.