Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 28, 2011, 7:15:14 AM (13 years ago)
Author:
rgrieder
Message:

Merged kicklib2 branch back to trunk (includes former branches ois_update, mac_osx and kicklib).

Notes for updating

Linux:
You don't need an extra package for CEGUILua and Tolua, it's already shipped with CEGUI.
However you do need to make sure that the OgreRenderer is installed too with CEGUI 0.7 (may be a separate package).
Also, Orxonox now recognises if you install the CgProgramManager (a separate package available on newer Ubuntu on Debian systems).

Windows:
Download the new dependency packages versioned 6.0 and use these. If you have problems with that or if you don't like the in game console problem mentioned below, you can download the new 4.3 version of the packages (only available for Visual Studio 2005/2008).

Key new features:

  • *Support for Mac OS X*
  • Visual Studio 2010 support
  • Bullet library update to 2.77
  • OIS library update to 1.3
  • Support for CEGUI 0.7 —> Support for Arch Linux and even SuSE
  • Improved install target
  • Compiles now with GCC 4.6
  • Ogre Cg Shader plugin activated for Linux if available
  • And of course lots of bug fixes

There are also some regressions:

  • No support for CEGUI 0.5, Ogre 1.4 and boost 1.35 - 1.39 any more
  • In game console is not working in main menu for CEGUI 0.7
  • Tolua (just the C lib, not the application) and CEGUILua libraries are no longer in our repository. —> You will need to get these as well when compiling Orxonox
  • And of course lots of new bugs we don't yet know about
Location:
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch
Files:
25 edited
6 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp

    r5781 r8351  
    3838        btScalar timeOfImpact = btScalar(1.);
    3939        btScalar depth = btScalar(0.);
    40 //      output.m_distance = btScalar(1e30);
     40//      output.m_distance = btScalar(BT_LARGE_FLOAT);
    4141        //move sphere into triangle space
    4242        btTransform     sphereInTr = transformB.inverseTimes(transformA);
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h

    r5781 r8351  
    3535        virtual ~SphereTriangleDetector() {};
    3636
     37        bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold);
     38
    3739private:
    3840
    39         bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold);
     41       
    4042        bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p );
    4143        bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal);
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp

    r5781 r8351  
    6262
    6363        btDiscreteCollisionDetectorInterface::ClosestPointInput input;
    64         input.m_maximumDistanceSquared = 1e30f;
     64        input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
    6565        input.m_transformA = body0->getWorldTransform();
    6666        input.m_transformB = body1->getWorldTransform();
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp

    r5781 r8351  
    1 
    21/*
    32 * Box-Box collision detection re-distributed under the ZLib license with permission from Russell L. Smith
     
    213212        } else
    214213        {
    215                 a=1e30f;
     214                a=BT_LARGE_FLOAT;
    216215        }
    217216    cx = a*(cx + q*(p[n*2-2]+p[0]));
     
    268267{
    269268  const btScalar fudge_factor = btScalar(1.05);
    270   btVector3 p,pp,normalC;
     269  btVector3 p,pp,normalC(0.f,0.f,0.f);
    271270  const btScalar *normalR = 0;
    272271  btScalar A[3],B[3],R11,R12,R13,R21,R22,R23,R31,R32,R33,
     
    334333#define TST(expr1,expr2,n1,n2,n3,cc) \
    335334  s2 = btFabs(expr1) - (expr2); \
    336   if (s2 > 0) return 0; \
     335  if (s2 > SIMD_EPSILON) return 0; \
    337336  l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \
    338   if (l > 0) { \
     337  if (l > SIMD_EPSILON) { \
    339338    s2 /= l; \
    340339    if (s2*fudge_factor > s) { \
     
    346345    } \
    347346  }
     347
     348  btScalar fudge2 (1.0e-5f);
     349
     350  Q11 += fudge2;
     351  Q12 += fudge2;
     352  Q13 += fudge2;
     353
     354  Q21 += fudge2;
     355  Q22 += fudge2;
     356  Q23 += fudge2;
     357
     358  Q31 += fudge2;
     359  Q32 += fudge2;
     360  Q33 += fudge2;
    348361
    349362  // separating axis = u1 x (v1,v2,v3)
     
    425438#else
    426439                output.addContactPoint(-normal,pb,-*depth);
     440
    427441#endif //
    428442                *return_code = code;
     
    594608
    595609  if (cnum <= maxc) {
     610
     611          if (code<4)
     612          {
    596613    // we have less contacts than we need, so we use them all
    597     for (j=0; j < cnum; j++) {
    598 
    599                 //AddContactPoint...
    600 
    601                 //dContactGeom *con = CONTACT(contact,skip*j);
    602       //for (i=0; i<3; i++) con->pos[i] = point[j*3+i] + pa[i];
    603       //con->depth = dep[j];
    604 
     614    for (j=0; j < cnum; j++)
     615        {
    605616                btVector3 pointInWorld;
    606617                for (i=0; i<3; i++)
     
    609620
    610621    }
     622          } else
     623          {
     624                  // we have less contacts than we need, so we use them all
     625                for (j=0; j < cnum; j++)
     626                {
     627                        btVector3 pointInWorld;
     628                        for (i=0; i<3; i++)
     629                                pointInWorld[i] = point[j*3+i] + pa[i]-normal[i]*dep[j];
     630                                //pointInWorld[i] = point[j*3+i] + pa[i];
     631                        output.addContactPoint(-normal,pointInWorld,-dep[j]);
     632                }
     633          }
    611634  }
    612635  else {
     
    633656                for (i=0; i<3; i++)
    634657                        posInWorld[i] = point[iret[j]*3+i] + pa[i];
    635                 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]);
     658                if (code<4)
     659           {
     660                        output.addContactPoint(-normal,posInWorld,-dep[iret[j]]);
     661                } else
     662                {
     663                        output.addContactPoint(-normal,posInWorld-normal*dep[iret[j]],-dep[iret[j]]);
     664                }
    636665    }
    637666    cnum = maxc;
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp

    r5781 r8351  
    3535
    3636btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration):
    37         m_count(0),
    38         m_useIslands(true),
    39         m_staticWarningReported(false),
     37m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD),
    4038        m_collisionConfiguration(collisionConfiguration)
    4139{
     
    8078        btCollisionObject* body1 = (btCollisionObject*)b1;
    8179
    82         //test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold'
    83         //btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()));
    84         btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold());
     80        //optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
     81       
     82        btScalar contactBreakingThreshold =  (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ?
     83                btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold))
     84                : gContactBreakingThreshold ;
    8585
    8686        btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold());
     
    170170
    171171#ifdef BT_DEBUG
    172         if (!m_staticWarningReported)
     172        if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED))
    173173        {
    174174                //broadphase filtering already deals with this
     
    176176                        (body1->isStaticObject() || body1->isKinematicObject()))
    177177                {
    178                         m_staticWarningReported = true;
     178                        m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED;
    179179                        printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
    180180                }
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h

    r5781 r8351  
    4343class btCollisionDispatcher : public btDispatcher
    4444{
    45         int m_count;
     45        int             m_dispatcherFlags;
    4646       
    4747        btAlignedObjectArray<btPersistentManifold*>     m_manifoldsPtr;
    4848
    49         bool m_useIslands;
    50 
    51         bool    m_staticWarningReported;
    52        
    5349        btManifoldResult        m_defaultManifoldResult;
    5450
     
    6056
    6157        btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
    62        
    6358
    6459        btCollisionConfiguration*       m_collisionConfiguration;
     
    6661
    6762public:
     63
     64        enum DispatcherFlags
     65        {
     66                CD_STATIC_STATIC_REPORTED = 1,
     67                CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2
     68        };
     69
     70        int     getDispatcherFlags() const
     71        {
     72                return m_dispatcherFlags;
     73        }
     74
     75        void    setDispatcherFlags(int flags)
     76        {
     77        (void) flags;
     78                m_dispatcherFlags = 0;
     79        }
    6880
    6981        ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp

    r5781 r8351  
    1616
    1717#include "btCollisionObject.h"
     18#include "LinearMath/btSerializer.h"
    1819
    1920btCollisionObject::btCollisionObject()
    2021        :       m_anisotropicFriction(1.f,1.f,1.f),
    2122        m_hasAnisotropicFriction(false),
    22         m_contactProcessingThreshold(1e30f),
     23        m_contactProcessingThreshold(BT_LARGE_FLOAT),
    2324                m_broadphaseHandle(0),
    2425                m_collisionShape(0),
     26                m_extensionPointer(0),
    2527                m_rootCollisionShape(0),
    2628                m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
     
    3133                m_friction(btScalar(0.5)),
    3234                m_restitution(btScalar(0.)),
     35                m_internalType(CO_COLLISION_OBJECT),
    3336                m_userObjectPointer(0),
    34                 m_internalType(CO_COLLISION_OBJECT),
    3537                m_hitFraction(btScalar(1.)),
    3638                m_ccdSweptSphereRadius(btScalar(0.)),
     
    3840                m_checkCollideWith(false)
    3941{
    40        
     42        m_worldTransform.setIdentity();
    4143}
    4244
     
    6567}
    6668
     69const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
     70{
     71
     72        btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
     73
     74        m_worldTransform.serialize(dataOut->m_worldTransform);
     75        m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform);
     76        m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity);
     77        m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity);
     78        m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction);
     79        dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction;
     80        dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
     81        dataOut->m_broadphaseHandle = 0;
     82        dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
     83        dataOut->m_rootCollisionShape = 0;//@todo
     84        dataOut->m_collisionFlags = m_collisionFlags;
     85        dataOut->m_islandTag1 = m_islandTag1;
     86        dataOut->m_companionId = m_companionId;
     87        dataOut->m_activationState1 = m_activationState1;
     88        dataOut->m_activationState1 = m_activationState1;
     89        dataOut->m_deactivationTime = m_deactivationTime;
     90        dataOut->m_friction = m_friction;
     91        dataOut->m_restitution = m_restitution;
     92        dataOut->m_internalType = m_internalType;
     93       
     94        char* name = (char*) serializer->findNameForPointer(this);
     95        dataOut->m_name = (char*)serializer->getUniquePointer(name);
     96        if (dataOut->m_name)
     97        {
     98                serializer->serializeName(name);
     99        }
     100        dataOut->m_hitFraction = m_hitFraction;
     101        dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
     102        dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
     103        dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
     104        dataOut->m_checkCollideWith = m_checkCollideWith;
     105
     106        return btCollisionObjectDataName;
     107}
    67108
    68109
     110void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const
     111{
     112        int len = calculateSerializeBufferSize();
     113        btChunk* chunk = serializer->allocate(len,1);
     114        const char* structType = serialize(chunk->m_oldPtr, serializer);
     115        serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this);
     116}
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h

    r5781 r8351  
    2828struct  btBroadphaseProxy;
    2929class   btCollisionShape;
     30struct btCollisionShapeData;
    3031#include "LinearMath/btMotionState.h"
    3132#include "LinearMath/btAlignedAllocator.h"
    3233#include "LinearMath/btAlignedObjectArray.h"
    3334
    34 
    3535typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
     36
     37#ifdef BT_USE_DOUBLE_PRECISION
     38#define btCollisionObjectData btCollisionObjectDoubleData
     39#define btCollisionObjectDataName "btCollisionObjectDoubleData"
     40#else
     41#define btCollisionObjectData btCollisionObjectFloatData
     42#define btCollisionObjectDataName "btCollisionObjectFloatData"
     43#endif
    3644
    3745
     
    5462        btVector3       m_interpolationAngularVelocity;
    5563       
    56         btVector3               m_anisotropicFriction;
    57         bool                            m_hasAnisotropicFriction;
    58         btScalar                m_contactProcessingThreshold;   
     64        btVector3       m_anisotropicFriction;
     65        int                     m_hasAnisotropicFriction;
     66        btScalar        m_contactProcessingThreshold;   
    5967
    6068        btBroadphaseProxy*              m_broadphaseHandle;
    6169        btCollisionShape*               m_collisionShape;
     70        ///m_extensionPointer is used by some internal low-level Bullet extensions.
     71        void*                                   m_extensionPointer;
    6272       
    6373        ///m_rootCollisionShape is temporarily used to store the original collision shape
     
    7787        btScalar                m_restitution;
    7888
    79         ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
    80         void*                   m_userObjectPointer;
    81 
    8289        ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
    8390        ///do not assign your own m_internalType unless you write a new dynamics object class.
    8491        int                             m_internalType;
    8592
     93        ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
     94        void*                   m_userObjectPointer;
     95
    8696        ///time of impact calculation
    8797        btScalar                m_hitFraction;
     
    94104       
    95105        /// If some object should have elaborate collision filtering by sub-classes
    96         bool                    m_checkCollideWith;
    97 
    98         char    m_pad[7];
     106        int                     m_checkCollideWith;
    99107
    100108        virtual bool    checkCollideWithOverride(btCollisionObject* /* co */)
     
    113121                CF_NO_CONTACT_RESPONSE = 4,
    114122                CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
    115                 CF_CHARACTER_OBJECT = 16
     123                CF_CHARACTER_OBJECT = 16,
     124                CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
     125                CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
    116126        };
    117127
     
    119129        {
    120130                CO_COLLISION_OBJECT =1,
    121                 CO_RIGID_BODY,
     131                CO_RIGID_BODY=2,
    122132                ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter
    123133                ///It is useful for collision sensors, explosion objects, character controller etc.
    124                 CO_GHOST_OBJECT,
    125                 CO_SOFT_BODY,
    126                 CO_HF_FLUID
     134                CO_GHOST_OBJECT=4,
     135                CO_SOFT_BODY=8,
     136                CO_HF_FLUID=16,
     137                CO_USER_TYPE=32
    127138        };
    128139
     
    144155        bool    hasAnisotropicFriction() const
    145156        {
    146                 return m_hasAnisotropicFriction;
     157                return m_hasAnisotropicFriction!=0;
    147158        }
    148159
     
    214225        }
    215226
     227        ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions.
     228        ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
     229        void*           internalGetExtensionPointer() const
     230        {
     231                return m_extensionPointer;
     232        }
     233        ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions
     234        ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
     235        void    internalSetExtensionPointer(void* pointer)
     236        {
     237                m_extensionPointer = pointer;
     238        }
     239
    216240        SIMD_FORCE_INLINE       int     getActivationState() const { return m_activationState1;}
    217241       
     
    394418        void    setCcdMotionThreshold(btScalar ccdMotionThreshold)
    395419        {
    396                 m_ccdMotionThreshold = ccdMotionThreshold*ccdMotionThreshold;
     420                m_ccdMotionThreshold = ccdMotionThreshold;
    397421        }
    398422
     
    417441                return true;
    418442        }
     443
     444        virtual int     calculateSerializeBufferSize()  const;
     445
     446        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     447        virtual const char*     serialize(void* dataBuffer, class btSerializer* serializer) const;
     448
     449        virtual void serializeSingleObject(class btSerializer* serializer) const;
     450
    419451};
    420452
     453///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     454struct  btCollisionObjectDoubleData
     455{
     456        void                                    *m_broadphaseHandle;
     457        void                                    *m_collisionShape;
     458        btCollisionShapeData    *m_rootCollisionShape;
     459        char                                    *m_name;
     460
     461        btTransformDoubleData   m_worldTransform;
     462        btTransformDoubleData   m_interpolationWorldTransform;
     463        btVector3DoubleData             m_interpolationLinearVelocity;
     464        btVector3DoubleData             m_interpolationAngularVelocity;
     465        btVector3DoubleData             m_anisotropicFriction;
     466        double                                  m_contactProcessingThreshold;   
     467        double                                  m_deactivationTime;
     468        double                                  m_friction;
     469        double                                  m_restitution;
     470        double                                  m_hitFraction;
     471        double                                  m_ccdSweptSphereRadius;
     472        double                                  m_ccdMotionThreshold;
     473
     474        int                                             m_hasAnisotropicFriction;
     475        int                                             m_collisionFlags;
     476        int                                             m_islandTag1;
     477        int                                             m_companionId;
     478        int                                             m_activationState1;
     479        int                                             m_internalType;
     480        int                                             m_checkCollideWith;
     481
     482        char    m_padding[4];
     483};
     484
     485///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     486struct  btCollisionObjectFloatData
     487{
     488        void                                    *m_broadphaseHandle;
     489        void                                    *m_collisionShape;
     490        btCollisionShapeData    *m_rootCollisionShape;
     491        char                                    *m_name;
     492
     493        btTransformFloatData    m_worldTransform;
     494        btTransformFloatData    m_interpolationWorldTransform;
     495        btVector3FloatData              m_interpolationLinearVelocity;
     496        btVector3FloatData              m_interpolationAngularVelocity;
     497        btVector3FloatData              m_anisotropicFriction;
     498        float                                   m_contactProcessingThreshold;   
     499        float                                   m_deactivationTime;
     500        float                                   m_friction;
     501        float                                   m_restitution;
     502        float                                   m_hitFraction;
     503        float                                   m_ccdSweptSphereRadius;
     504        float                                   m_ccdMotionThreshold;
     505
     506        int                                             m_hasAnisotropicFriction;
     507        int                                             m_collisionFlags;
     508        int                                             m_islandTag1;
     509        int                                             m_companionId;
     510        int                                             m_activationState1;
     511        int                                             m_internalType;
     512        int                                             m_checkCollideWith;
     513};
     514
     515
     516
     517SIMD_FORCE_INLINE       int     btCollisionObject::calculateSerializeBufferSize() const
     518{
     519        return sizeof(btCollisionObjectData);
     520}
     521
     522
     523
    421524#endif //COLLISION_OBJECT_H
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp

    r5781 r8351  
    2727#include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
    2828#include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
    29 
     29#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
    3030#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
    3131#include "LinearMath/btAabbUtil2.h"
    3232#include "LinearMath/btQuickprof.h"
    3333#include "LinearMath/btStackAlloc.h"
     34#include "LinearMath/btSerializer.h"
    3435
    3536//#define USE_BRUTEFORCE_RAYBROADPHASE 1
     
    4344
    4445
     46///for debug drawing
     47
     48//for debug rendering
     49#include "BulletCollision/CollisionShapes/btBoxShape.h"
     50#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
     51#include "BulletCollision/CollisionShapes/btCompoundShape.h"
     52#include "BulletCollision/CollisionShapes/btConeShape.h"
     53#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
     54#include "BulletCollision/CollisionShapes/btCylinderShape.h"
     55#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
     56#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
     57#include "BulletCollision/CollisionShapes/btSphereShape.h"
     58#include "BulletCollision/CollisionShapes/btTriangleCallback.h"
     59#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
     60#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
     61
     62
     63
    4564btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration)
    4665:m_dispatcher1(dispatcher),
    4766m_broadphasePairCache(pairCache),
    48 m_debugDrawer(0)
     67m_debugDrawer(0),
     68m_forceUpdateAllAabbs(true)
    4969{
    5070        m_stackAlloc = collisionConfiguration->getStackAllocator();
     
    89109{
    90110
     111        btAssert(collisionObject);
     112
    91113        //check that the object isn't already added
    92                 btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());
    93 
    94                 m_collisionObjects.push_back(collisionObject);
    95 
    96                 //calculate new AABB
    97                 btTransform trans = collisionObject->getWorldTransform();
    98 
    99                 btVector3       minAabb;
    100                 btVector3       maxAabb;
    101                 collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb);
    102 
    103                 int type = collisionObject->getCollisionShape()->getShapeType();
    104                 collisionObject->setBroadphaseHandle( getBroadphase()->createProxy(
    105                         minAabb,
    106                         maxAabb,
    107                         type,
    108                         collisionObject,
    109                         collisionFilterGroup,
    110                         collisionFilterMask,
    111                         m_dispatcher1,0
    112                         ))      ;
     114        btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());
     115
     116        m_collisionObjects.push_back(collisionObject);
     117
     118        //calculate new AABB
     119        btTransform trans = collisionObject->getWorldTransform();
     120
     121        btVector3       minAabb;
     122        btVector3       maxAabb;
     123        collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb);
     124
     125        int type = collisionObject->getCollisionShape()->getShapeType();
     126        collisionObject->setBroadphaseHandle( getBroadphase()->createProxy(
     127                minAabb,
     128                maxAabb,
     129                type,
     130                collisionObject,
     131                collisionFilterGroup,
     132                collisionFilterMask,
     133                m_dispatcher1,0
     134                ))      ;
    113135
    114136
     
    163185
    164186                //only update aabb of active objects
    165                 if (colObj->isActive())
     187                if (m_forceUpdateAllAabbs || colObj->isActive())
    166188                {
    167189                        updateSingleAabb(colObj);
     
    226248
    227249void    btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
    228                                           btCollisionObject* collisionObject,
    229                                           const btCollisionShape* collisionShape,
    230                                           const btTransform& colObjWorldTransform,
    231                                           RayResultCallback& resultCallback)
     250                                                                                btCollisionObject* collisionObject,
     251                                                                                const btCollisionShape* collisionShape,
     252                                                                                const btTransform& colObjWorldTransform,
     253                                                                                RayResultCallback& resultCallback)
    232254{
    233255        btSphereShape pointShape(btScalar(0.0));
     
    237259        if (collisionShape->isConvex())
    238260        {
    239 //              BT_PROFILE("rayTestConvex");
     261                //              BT_PROFILE("rayTestConvex");
    240262                btConvexCast::CastResult castResult;
    241263                castResult.m_fraction = resultCallback.m_closestHitFraction;
     
    266288                                        btCollisionWorld::LocalRayResult localRayResult
    267289                                                (
    268                                                         collisionObject,
    269                                                         0,
    270                                                         castResult.m_normal,
    271                                                         castResult.m_fraction
     290                                                collisionObject,
     291                                                0,
     292                                                castResult.m_normal,
     293                                                castResult.m_fraction
    272294                                                );
    273295
     
    281303                if (collisionShape->isConcave())
    282304                {
    283 //                      BT_PROFILE("rayTestConcave");
     305                        //                      BT_PROFILE("rayTestConcave");
    284306                        if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
    285307                        {
     
    297319                                        btTriangleMeshShape*    m_triangleMesh;
    298320
     321                                        btTransform m_colObjWorldTransform;
     322
    299323                                        BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
    300                                                 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*    triangleMesh):
    301                   //@BP Mod
    302                                                 btTriangleRaycastCallback(from,to, resultCallback->m_flags),
    303                                                         m_resultCallback(resultCallback),
    304                                                         m_collisionObject(collisionObject),
    305                                                         m_triangleMesh(triangleMesh)
    306                                                 {
    307                                                 }
     324                                                btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*    triangleMesh,const btTransform& colObjWorldTransform):
     325                                        //@BP Mod
     326                                        btTriangleRaycastCallback(from,to, resultCallback->m_flags),
     327                                                m_resultCallback(resultCallback),
     328                                                m_collisionObject(collisionObject),
     329                                                m_triangleMesh(triangleMesh),
     330                                                m_colObjWorldTransform(colObjWorldTransform)
     331                                        {
     332                                        }
    308333
    309334
     
    314339                                                shapeInfo.m_triangleIndex = triangleIndex;
    315340
     341                                                btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal;
     342
    316343                                                btCollisionWorld::LocalRayResult rayResult
    317                                                 (m_collisionObject,
     344                                                        (m_collisionObject,
    318345                                                        &shapeInfo,
    319                                                         hitNormalLocal,
     346                                                        hitNormalWorld,
    320347                                                        hitFraction);
    321348
    322                                                 bool    normalInWorldSpace = false;
     349                                                bool    normalInWorldSpace = true;
    323350                                                return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace);
    324351                                        }
     
    326353                                };
    327354
    328                                 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh);
     355                                BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh,colObjWorldTransform);
    329356                                rcb.m_hitFraction = resultCallback.m_closestHitFraction;
    330357                                triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
     
    347374                                        btConcaveShape* m_triangleMesh;
    348375
     376                                        btTransform m_colObjWorldTransform;
     377
    349378                                        BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
    350                                                 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh):
    351                   //@BP Mod
    352                   btTriangleRaycastCallback(from,to, resultCallback->m_flags),
    353                                                         m_resultCallback(resultCallback),
    354                                                         m_collisionObject(collisionObject),
    355                                                         m_triangleMesh(triangleMesh)
    356                                                 {
    357                                                 }
     379                                                btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& colObjWorldTransform):
     380                                        //@BP Mod
     381                                        btTriangleRaycastCallback(from,to, resultCallback->m_flags),
     382                                                m_resultCallback(resultCallback),
     383                                                m_collisionObject(collisionObject),
     384                                                m_triangleMesh(triangleMesh),
     385                                                m_colObjWorldTransform(colObjWorldTransform)
     386                                        {
     387                                        }
    358388
    359389
     
    364394                                                shapeInfo.m_triangleIndex = triangleIndex;
    365395
     396                                                btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal;
     397
    366398                                                btCollisionWorld::LocalRayResult rayResult
    367                                                 (m_collisionObject,
     399                                                        (m_collisionObject,
    368400                                                        &shapeInfo,
    369                                                         hitNormalLocal,
     401                                                        hitNormalWorld,
    370402                                                        hitFraction);
    371403
    372                                                 bool    normalInWorldSpace = false;
     404                                                bool    normalInWorldSpace = true;
    373405                                                return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace);
    374 
    375 
    376406                                        }
    377407
     
    379409
    380410
    381                                 BridgeTriangleRaycastCallback   rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape);
     411                                BridgeTriangleRaycastCallback   rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
    382412                                rcb.m_hitFraction = resultCallback.m_closestHitFraction;
    383413
     
    390420                        }
    391421                } else {
    392 //                      BT_PROFILE("rayTestCompound");
     422                        //                      BT_PROFILE("rayTestCompound");
    393423                        ///@todo: use AABB tree or other BVH acceleration structure, see btDbvt
    394424                        if (collisionShape->isCompound())
     
    404434                                        btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape();
    405435                                        collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
     436                    struct LocalInfoAdder2 : public RayResultCallback {
     437                                                RayResultCallback* m_userCallback;
     438                                                int m_i;
     439                        LocalInfoAdder2 (int i, RayResultCallback *user)
     440                                                        : m_userCallback(user),
     441                                                        m_i(i)
     442                                                {
     443                                                        m_closestHitFraction = m_userCallback->m_closestHitFraction;
     444                                                }
     445                                                virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b)
     446                            {
     447                                    btCollisionWorld::LocalShapeInfo    shapeInfo;
     448                                    shapeInfo.m_shapePart = -1;
     449                                    shapeInfo.m_triangleIndex = m_i;
     450                                    if (r.m_localShapeInfo == NULL)
     451                                        r.m_localShapeInfo = &shapeInfo;
     452
     453                                                                        const btScalar result = m_userCallback->addSingleResult(r, b);
     454                                                                        m_closestHitFraction = m_userCallback->m_closestHitFraction;
     455                                                                        return result;
     456                            }
     457                    };
     458
     459                    LocalInfoAdder2 my_cb(i, &resultCallback);
     460
    406461                                        rayTestSingle(rayFromTrans,rayToTrans,
    407462                                                collisionObject,
    408463                                                childCollisionShape,
    409464                                                childWorldTrans,
    410                                                 resultCallback);
     465                                                my_cb);
    411466                                        // restore
    412467                                        collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
     
    418473
    419474void    btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
    420                                           btCollisionObject* collisionObject,
    421                                           const btCollisionShape* collisionShape,
    422                                           const btTransform& colObjWorldTransform,
    423                                           ConvexResultCallback& resultCallback, btScalar allowedPenetration)
     475                                                                                        btCollisionObject* collisionObject,
     476                                                                                        const btCollisionShape* collisionShape,
     477                                                                                        const btTransform& colObjWorldTransform,
     478                                                                                        ConvexResultCallback& resultCallback, btScalar allowedPenetration)
    424479{
    425480        if (collisionShape->isConvex())
     
    433488                btVoronoiSimplexSolver  simplexSolver;
    434489                btGjkEpaPenetrationDepthSolver  gjkEpaPenetrationSolver;
    435                
     490
    436491                btContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver);
    437492                //btGjkConvexCast convexCaster2(castShape,convexShape,&simplexSolver);
     
    439494
    440495                btConvexCast* castPtr = &convexCaster1;
    441        
    442        
    443                
     496
     497
     498
    444499                if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
    445500                {
     
    451506                                        castResult.m_normal.normalize();
    452507                                        btCollisionWorld::LocalConvexResult localConvexResult
    453                                                                 (
    454                                                                         collisionObject,
    455                                                                         0,
    456                                                                         castResult.m_normal,
    457                                                                         castResult.m_hitPoint,
    458                                                                         castResult.m_fraction
    459                                                                 );
     508                                                (
     509                                                collisionObject,
     510                                                0,
     511                                                castResult.m_normal,
     512                                                castResult.m_hitPoint,
     513                                                castResult.m_fraction
     514                                                );
    460515
    461516                                        bool normalInWorldSpace = true;
     
    487542                                        BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
    488543                                                btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld):
    489                                                 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
    490                                                         m_resultCallback(resultCallback),
    491                                                         m_collisionObject(collisionObject),
    492                                                         m_triangleMesh(triangleMesh)
    493                                                 {
    494                                                 }
     544                                        btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
     545                                                m_resultCallback(resultCallback),
     546                                                m_collisionObject(collisionObject),
     547                                                m_triangleMesh(triangleMesh)
     548                                        {
     549                                        }
    495550
    496551
     
    504559
    505560                                                        btCollisionWorld::LocalConvexResult convexResult
    506                                                         (m_collisionObject,
     561                                                                (m_collisionObject,
    507562                                                                &shapeInfo,
    508563                                                                hitNormalLocal,
     
    544599                                        BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
    545600                                                btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape*      triangleMesh, const btTransform& triangleToWorld):
    546                                                 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
    547                                                         m_resultCallback(resultCallback),
    548                                                         m_collisionObject(collisionObject),
    549                                                         m_triangleMesh(triangleMesh)
    550                                                 {
    551                                                 }
     601                                        btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
     602                                                m_resultCallback(resultCallback),
     603                                                m_collisionObject(collisionObject),
     604                                                m_triangleMesh(triangleMesh)
     605                                        {
     606                                        }
    552607
    553608
     
    561616
    562617                                                        btCollisionWorld::LocalConvexResult convexResult
    563                                                         (m_collisionObject,
     618                                                                (m_collisionObject,
    564619                                                                &shapeInfo,
    565620                                                                hitNormalLocal,
     
    604659                                        btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape();
    605660                                        collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
     661                    struct      LocalInfoAdder : public ConvexResultCallback {
     662                            ConvexResultCallback* m_userCallback;
     663                                                        int m_i;
     664
     665                            LocalInfoAdder (int i, ConvexResultCallback *user)
     666                                                                : m_userCallback(user), m_i(i)
     667                                                        {
     668                                                                m_closestHitFraction = m_userCallback->m_closestHitFraction;
     669                                                        }
     670                            virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult&      r,      bool b)
     671                            {
     672                                    btCollisionWorld::LocalShapeInfo    shapeInfo;
     673                                    shapeInfo.m_shapePart = -1;
     674                                    shapeInfo.m_triangleIndex = m_i;
     675                                    if (r.m_localShapeInfo == NULL)
     676                                        r.m_localShapeInfo = &shapeInfo;
     677                                                                        const btScalar result = m_userCallback->addSingleResult(r, b);
     678                                                                        m_closestHitFraction = m_userCallback->m_closestHitFraction;
     679                                                                        return result;
     680                                   
     681                            }
     682                    };
     683
     684                    LocalInfoAdder my_cb(i, &resultCallback);
     685                                       
     686
    606687                                        objectQuerySingle(castShape, convexFromTrans,convexToTrans,
    607688                                                collisionObject,
    608689                                                childCollisionShape,
    609690                                                childWorldTrans,
    610                                                 resultCallback, allowedPenetration);
     691                                                my_cb, allowedPenetration);
    611692                                        // restore
    612693                                        collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
     
    631712
    632713        btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback)
    633         :m_rayFromWorld(rayFromWorld),
    634         m_rayToWorld(rayToWorld),
    635         m_world(world),
    636         m_resultCallback(resultCallback)
     714                :m_rayFromWorld(rayFromWorld),
     715                m_rayToWorld(rayToWorld),
     716                m_world(world),
     717                m_resultCallback(resultCallback)
    637718        {
    638719                m_rayFromTrans.setIdentity();
     
    644725
    645726                rayDir.normalize ();
    646                 ///what about division by zero? --> just set rayDirection[i] to INF/1e30
    647                 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
    648                 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
    649                 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
     727                ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT
     728                m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0];
     729                m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1];
     730                m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2];
    650731                m_signs[0] = m_rayDirectionInverse[0] < 0.0;
    651732                m_signs[1] = m_rayDirectionInverse[1] < 0.0;
     
    656737        }
    657738
    658        
     739
    659740
    660741        virtual bool    process(const btBroadphaseProxy* proxy)
     
    687768                                m_world->rayTestSingle(m_rayFromTrans,m_rayToTrans,
    688769                                        collisionObject,
    689                                                 collisionObject->getCollisionShape(),
    690                                                 collisionObject->getWorldTransform(),
    691                                                 m_resultCallback);
     770                                        collisionObject->getCollisionShape(),
     771                                        collisionObject->getWorldTransform(),
     772                                        m_resultCallback);
    692773                        }
    693774                }
     
    698779void    btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const
    699780{
    700         BT_PROFILE("rayTest");
     781        //BT_PROFILE("rayTest");
    701782        /// use the broadphase to accelerate the search for objects, based on their aabb
    702783        /// and for each object with ray-aabb overlap, perform an exact ray test
     
    737818                btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin()-m_convexFromTrans.getOrigin());
    738819                btVector3 rayDir = unnormalizedRayDir.normalized();
    739                 ///what about division by zero? --> just set rayDirection[i] to INF/1e30
    740                 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
    741                 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
    742                 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
     820                ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT
     821                m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0];
     822                m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1];
     823                m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2];
    743824                m_signs[0] = m_rayDirectionInverse[0] < 0.0;
    744825                m_signs[1] = m_rayDirectionInverse[1] < 0.0;
     
    761842                        //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
    762843                        m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans,
    763                                         collisionObject,
    764                                                 collisionObject->getCollisionShape(),
    765                                                 collisionObject->getWorldTransform(),
    766                                                 m_resultCallback,
    767                                                 m_allowedCcdPenetration);
    768                 }
    769                
     844                                collisionObject,
     845                                collisionObject->getCollisionShape(),
     846                                collisionObject->getWorldTransform(),
     847                                m_resultCallback,
     848                                m_allowedCcdPenetration);
     849                }
     850
    770851                return true;
    771852        }
     
    782863        /// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical
    783864
    784        
     865
    785866
    786867        btTransform     convexFromTrans,convexToTrans;
     
    825906                                objectQuerySingle(castShape, convexFromTrans,convexToTrans,
    826907                                        collisionObject,
    827                                                 collisionObject->getCollisionShape(),
    828                                                 collisionObject->getWorldTransform(),
    829                                                 resultCallback,
    830                                                 allowedCcdPenetration);
     908                                        collisionObject->getCollisionShape(),
     909                                        collisionObject->getWorldTransform(),
     910                                        resultCallback,
     911                                        allowedCcdPenetration);
    831912                        }
    832913                }
     
    834915#endif //USE_BRUTEFORCE_RAYBROADPHASE
    835916}
     917
     918
     919
     920struct btBridgedManifoldResult : public btManifoldResult
     921{
     922
     923        btCollisionWorld::ContactResultCallback&        m_resultCallback;
     924
     925        btBridgedManifoldResult( btCollisionObject* obj0,btCollisionObject* obj1,btCollisionWorld::ContactResultCallback& resultCallback )
     926                :btManifoldResult(obj0,obj1),
     927                m_resultCallback(resultCallback)
     928        {
     929        }
     930
     931        virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
     932        {
     933                bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
     934                btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
     935                btVector3 localA;
     936                btVector3 localB;
     937                if (isSwapped)
     938                {
     939                        localA = m_rootTransB.invXform(pointA );
     940                        localB = m_rootTransA.invXform(pointInWorld);
     941                } else
     942                {
     943                        localA = m_rootTransA.invXform(pointA );
     944                        localB = m_rootTransB.invXform(pointInWorld);
     945                }
     946               
     947                btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
     948                newPt.m_positionWorldOnA = pointA;
     949                newPt.m_positionWorldOnB = pointInWorld;
     950               
     951           //BP mod, store contact triangles.
     952                if (isSwapped)
     953                {
     954                        newPt.m_partId0 = m_partId1;
     955                        newPt.m_partId1 = m_partId0;
     956                        newPt.m_index0  = m_index1;
     957                        newPt.m_index1  = m_index0;
     958                } else
     959                {
     960                        newPt.m_partId0 = m_partId0;
     961                        newPt.m_partId1 = m_partId1;
     962                        newPt.m_index0  = m_index0;
     963                        newPt.m_index1  = m_index1;
     964                }
     965
     966                //experimental feature info, for per-triangle material etc.
     967                btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
     968                btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
     969                m_resultCallback.addSingleResult(newPt,obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1);
     970
     971        }
     972       
     973};
     974
     975
     976
     977struct btSingleContactCallback : public btBroadphaseAabbCallback
     978{
     979
     980        btCollisionObject* m_collisionObject;
     981        btCollisionWorld*       m_world;
     982        btCollisionWorld::ContactResultCallback&        m_resultCallback;
     983       
     984       
     985        btSingleContactCallback(btCollisionObject* collisionObject, btCollisionWorld* world,btCollisionWorld::ContactResultCallback& resultCallback)
     986                :m_collisionObject(collisionObject),
     987                m_world(world),
     988                m_resultCallback(resultCallback)
     989        {
     990        }
     991
     992        virtual bool    process(const btBroadphaseProxy* proxy)
     993        {
     994                btCollisionObject*      collisionObject = (btCollisionObject*)proxy->m_clientObject;
     995                if (collisionObject == m_collisionObject)
     996                        return true;
     997
     998                //only perform raycast if filterMask matches
     999                if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle()))
     1000                {
     1001                        btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(m_collisionObject,collisionObject);
     1002                        if (algorithm)
     1003                        {
     1004                                btBridgedManifoldResult contactPointResult(m_collisionObject,collisionObject, m_resultCallback);
     1005                                //discrete collision detection query
     1006                                algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult);
     1007
     1008                                algorithm->~btCollisionAlgorithm();
     1009                                m_world->getDispatcher()->freeCollisionAlgorithm(algorithm);
     1010                        }
     1011                }
     1012                return true;
     1013        }
     1014};
     1015
     1016
     1017///contactTest performs a discrete collision test against all objects in the btCollisionWorld, and calls the resultCallback.
     1018///it reports one or more contact points for every overlapping object (including the one with deepest penetration)
     1019void    btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCallback& resultCallback)
     1020{
     1021        btVector3 aabbMin,aabbMax;
     1022        colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax);
     1023        btSingleContactCallback contactCB(colObj,this,resultCallback);
     1024       
     1025        m_broadphasePairCache->aabbTest(aabbMin,aabbMax,contactCB);
     1026}
     1027
     1028
     1029///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected.
     1030///it reports one or more contact points (including the one with deepest penetration)
     1031void    btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback)
     1032{
     1033        btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(colObjA,colObjB);
     1034        if (algorithm)
     1035        {
     1036                btBridgedManifoldResult contactPointResult(colObjA,colObjB, resultCallback);
     1037                //discrete collision detection query
     1038                algorithm->processCollision(colObjA,colObjB, getDispatchInfo(),&contactPointResult);
     1039
     1040                algorithm->~btCollisionAlgorithm();
     1041                getDispatcher()->freeCollisionAlgorithm(algorithm);
     1042        }
     1043
     1044}
     1045
     1046
     1047
     1048
     1049class DebugDrawcallback : public btTriangleCallback, public btInternalTriangleIndexCallback
     1050{
     1051        btIDebugDraw*   m_debugDrawer;
     1052        btVector3       m_color;
     1053        btTransform     m_worldTrans;
     1054
     1055public:
     1056
     1057        DebugDrawcallback(btIDebugDraw* debugDrawer,const btTransform& worldTrans,const btVector3& color) :
     1058          m_debugDrawer(debugDrawer),
     1059                  m_color(color),
     1060                  m_worldTrans(worldTrans)
     1061          {
     1062          }
     1063
     1064          virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int  triangleIndex)
     1065          {
     1066                  processTriangle(triangle,partId,triangleIndex);
     1067          }
     1068
     1069          virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
     1070          {
     1071                  (void)partId;
     1072                  (void)triangleIndex;
     1073
     1074                  btVector3 wv0,wv1,wv2;
     1075                  wv0 = m_worldTrans*triangle[0];
     1076                  wv1 = m_worldTrans*triangle[1];
     1077                  wv2 = m_worldTrans*triangle[2];
     1078                  btVector3 center = (wv0+wv1+wv2)*btScalar(1./3.);
     1079
     1080                  btVector3 normal = (wv1-wv0).cross(wv2-wv0);
     1081                  normal.normalize();
     1082                  btVector3 normalColor(1,1,0);
     1083                  m_debugDrawer->drawLine(center,center+normal,normalColor);
     1084
     1085
     1086
     1087                 
     1088                  m_debugDrawer->drawLine(wv0,wv1,m_color);
     1089                  m_debugDrawer->drawLine(wv1,wv2,m_color);
     1090                  m_debugDrawer->drawLine(wv2,wv0,m_color);
     1091          }
     1092};
     1093
     1094
     1095void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
     1096{
     1097        // Draw a small simplex at the center of the object
     1098        getDebugDrawer()->drawTransform(worldTransform,1);
     1099
     1100        if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
     1101        {
     1102                const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
     1103                for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--)
     1104                {
     1105                        btTransform childTrans = compoundShape->getChildTransform(i);
     1106                        const btCollisionShape* colShape = compoundShape->getChildShape(i);
     1107                        debugDrawObject(worldTransform*childTrans,colShape,color);
     1108                }
     1109
     1110        } else
     1111        {
     1112                switch (shape->getShapeType())
     1113                {
     1114
     1115                case BOX_SHAPE_PROXYTYPE:
     1116                        {
     1117                                const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
     1118                                btVector3 halfExtents = boxShape->getHalfExtentsWithMargin();
     1119                                getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color);
     1120                                break;
     1121                        }
     1122
     1123                case SPHERE_SHAPE_PROXYTYPE:
     1124                        {
     1125                                const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
     1126                                btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
     1127
     1128                                getDebugDrawer()->drawSphere(radius, worldTransform, color);
     1129                                break;
     1130                        }
     1131                case MULTI_SPHERE_SHAPE_PROXYTYPE:
     1132                        {
     1133                                const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
     1134
     1135                                btTransform childTransform;
     1136                                childTransform.setIdentity();
     1137
     1138                                for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
     1139                                {
     1140                                        childTransform.setOrigin(multiSphereShape->getSpherePosition(i));
     1141                                        getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color);
     1142                                }
     1143
     1144                                break;
     1145                        }
     1146                case CAPSULE_SHAPE_PROXYTYPE:
     1147                        {
     1148                                const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
     1149
     1150                                btScalar radius = capsuleShape->getRadius();
     1151                                btScalar halfHeight = capsuleShape->getHalfHeight();
     1152
     1153                                int upAxis = capsuleShape->getUpAxis();
     1154
     1155
     1156                                btVector3 capStart(0.f,0.f,0.f);
     1157                                capStart[upAxis] = -halfHeight;
     1158
     1159                                btVector3 capEnd(0.f,0.f,0.f);
     1160                                capEnd[upAxis] = halfHeight;
     1161
     1162                                // Draw the ends
     1163                                {
     1164
     1165                                        btTransform childTransform = worldTransform;
     1166                                        childTransform.getOrigin() = worldTransform * capStart;
     1167                                        getDebugDrawer()->drawSphere(radius, childTransform, color);
     1168                                }
     1169
     1170                                {
     1171                                        btTransform childTransform = worldTransform;
     1172                                        childTransform.getOrigin() = worldTransform * capEnd;
     1173                                        getDebugDrawer()->drawSphere(radius, childTransform, color);
     1174                                }
     1175
     1176                                // Draw some additional lines
     1177                                btVector3 start = worldTransform.getOrigin();
     1178
     1179
     1180                                capStart[(upAxis+1)%3] = radius;
     1181                                capEnd[(upAxis+1)%3] = radius;
     1182                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
     1183                                capStart[(upAxis+1)%3] = -radius;
     1184                                capEnd[(upAxis+1)%3] = -radius;
     1185                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
     1186
     1187                                capStart[(upAxis+1)%3] = 0.f;
     1188                                capEnd[(upAxis+1)%3] = 0.f;
     1189
     1190                                capStart[(upAxis+2)%3] = radius;
     1191                                capEnd[(upAxis+2)%3] = radius;
     1192                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
     1193                                capStart[(upAxis+2)%3] = -radius;
     1194                                capEnd[(upAxis+2)%3] = -radius;
     1195                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);
     1196
     1197
     1198                                break;
     1199                        }
     1200                case CONE_SHAPE_PROXYTYPE:
     1201                        {
     1202                                const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
     1203                                btScalar radius = coneShape->getRadius();//+coneShape->getMargin();
     1204                                btScalar height = coneShape->getHeight();//+coneShape->getMargin();
     1205                                btVector3 start = worldTransform.getOrigin();
     1206
     1207                                int upAxis= coneShape->getConeUpIndex();
     1208
     1209
     1210                                btVector3       offsetHeight(0,0,0);
     1211                                offsetHeight[upAxis] = height * btScalar(0.5);
     1212                                btVector3       offsetRadius(0,0,0);
     1213                                offsetRadius[(upAxis+1)%3] = radius;
     1214                                btVector3       offset2Radius(0,0,0);
     1215                                offset2Radius[(upAxis+2)%3] = radius;
     1216
     1217                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
     1218                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
     1219                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color);
     1220                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color);
     1221
     1222                                // Drawing the base of the cone
     1223                                btVector3 yaxis(0,0,0);
     1224                                yaxis[upAxis] = btScalar(1.0);
     1225                                btVector3 xaxis(0,0,0);
     1226                                xaxis[(upAxis+1)%3] = btScalar(1.0);
     1227                                getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,10.0);
     1228                break;
     1229
     1230                        }
     1231                case CYLINDER_SHAPE_PROXYTYPE:
     1232                        {
     1233                                const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
     1234                                int upAxis = cylinder->getUpAxis();
     1235                                btScalar radius = cylinder->getRadius();
     1236                                btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
     1237                                btVector3 start = worldTransform.getOrigin();
     1238                                btVector3       offsetHeight(0,0,0);
     1239                                offsetHeight[upAxis] = halfHeight;
     1240                                btVector3       offsetRadius(0,0,0);
     1241                                offsetRadius[(upAxis+1)%3] = radius;
     1242                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);
     1243                                getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);
     1244
     1245                                // Drawing top and bottom caps of the cylinder
     1246                                btVector3 yaxis(0,0,0);
     1247                                yaxis[upAxis] = btScalar(1.0);
     1248                                btVector3 xaxis(0,0,0);
     1249                                xaxis[(upAxis+1)%3] = btScalar(1.0);
     1250                                getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0));
     1251                                getDebugDrawer()->drawArc(start+worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0));
     1252                                break;
     1253                        }
     1254
     1255                case STATIC_PLANE_PROXYTYPE:
     1256                        {
     1257                                const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
     1258                                btScalar planeConst = staticPlaneShape->getPlaneConstant();
     1259                                const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
     1260                                btVector3 planeOrigin = planeNormal * planeConst;
     1261                                btVector3 vec0,vec1;
     1262                                btPlaneSpace1(planeNormal,vec0,vec1);
     1263                                btScalar vecLen = 100.f;
     1264                                btVector3 pt0 = planeOrigin + vec0*vecLen;
     1265                                btVector3 pt1 = planeOrigin - vec0*vecLen;
     1266                                btVector3 pt2 = planeOrigin + vec1*vecLen;
     1267                                btVector3 pt3 = planeOrigin - vec1*vecLen;
     1268                                getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color);
     1269                                getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color);
     1270                                break;
     1271
     1272                        }
     1273                default:
     1274                        {
     1275
     1276                                if (shape->isConcave())
     1277                                {
     1278                                        btConcaveShape* concaveMesh = (btConcaveShape*) shape;
     1279
     1280                                        ///@todo pass camera, for some culling? no -> we are not a graphics lib
     1281                                        btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     1282                                        btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
     1283
     1284                                        DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
     1285                                        concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
     1286
     1287                                }
     1288
     1289                                if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
     1290                                {
     1291                                        btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
     1292                                        //todo: pass camera for some culling                   
     1293                                        btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     1294                                        btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
     1295                                        //DebugDrawcallback drawCallback;
     1296                                        DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
     1297                                        convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
     1298                                }
     1299
     1300
     1301                                /// for polyhedral shapes
     1302                                if (shape->isPolyhedral())
     1303                                {
     1304                                        btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
     1305
     1306                                        int i;
     1307                                        for (i=0;i<polyshape->getNumEdges();i++)
     1308                                        {
     1309                                                btVector3 a,b;
     1310                                                polyshape->getEdge(i,a,b);
     1311                                                btVector3 wa = worldTransform * a;
     1312                                                btVector3 wb = worldTransform * b;
     1313                                                getDebugDrawer()->drawLine(wa,wb,color);
     1314
     1315                                        }
     1316
     1317
     1318                                }
     1319                        }
     1320                }
     1321        }
     1322}
     1323
     1324
     1325void    btCollisionWorld::debugDrawWorld()
     1326{
     1327        if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
     1328        {
     1329                int numManifolds = getDispatcher()->getNumManifolds();
     1330                btVector3 color(0,0,0);
     1331                for (int i=0;i<numManifolds;i++)
     1332                {
     1333                        btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
     1334                        //btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
     1335                        //btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
     1336
     1337                        int numContacts = contactManifold->getNumContacts();
     1338                        for (int j=0;j<numContacts;j++)
     1339                        {
     1340                                btManifoldPoint& cp = contactManifold->getContactPoint(j);
     1341                                getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color);
     1342                        }
     1343                }
     1344        }
     1345
     1346        if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb))
     1347        {
     1348                int i;
     1349
     1350                for (  i=0;i<m_collisionObjects.size();i++)
     1351                {
     1352                        btCollisionObject* colObj = m_collisionObjects[i];
     1353                        if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
     1354                        {
     1355                                if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)
     1356                                {
     1357                                        btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.));
     1358                                        switch(colObj->getActivationState())
     1359                                        {
     1360                                        case  ACTIVE_TAG:
     1361                                                color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break;
     1362                                        case ISLAND_SLEEPING:
     1363                                                color =  btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break;
     1364                                        case WANTS_DEACTIVATION:
     1365                                                color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break;
     1366                                        case DISABLE_DEACTIVATION:
     1367                                                color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break;
     1368                                        case DISABLE_SIMULATION:
     1369                                                color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break;
     1370                                        default:
     1371                                                {
     1372                                                        color = btVector3(btScalar(1),btScalar(0.),btScalar(0.));
     1373                                                }
     1374                                        };
     1375
     1376                                        debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
     1377                                }
     1378                                if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
     1379                                {
     1380                                        btVector3 minAabb,maxAabb;
     1381                                        btVector3 colorvec(1,0,0);
     1382                                        colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
     1383                                        m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
     1384                                }
     1385                        }
     1386
     1387                }
     1388        }
     1389}
     1390
     1391
     1392void    btCollisionWorld::serializeCollisionObjects(btSerializer* serializer)
     1393{
     1394        int i;
     1395        //serialize all collision objects
     1396        for (i=0;i<m_collisionObjects.size();i++)
     1397        {
     1398                btCollisionObject* colObj = m_collisionObjects[i];
     1399                if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT)
     1400                {
     1401                        colObj->serializeSingleObject(serializer);
     1402                }
     1403        }
     1404
     1405        ///keep track of shapes already serialized
     1406        btHashMap<btHashPtr,btCollisionShape*>  serializedShapes;
     1407
     1408        for (i=0;i<m_collisionObjects.size();i++)
     1409        {
     1410                btCollisionObject* colObj = m_collisionObjects[i];
     1411                btCollisionShape* shape = colObj->getCollisionShape();
     1412
     1413                if (!serializedShapes.find(shape))
     1414                {
     1415                        serializedShapes.insert(shape,shape);
     1416                        shape->serializeSingleShape(serializer);
     1417                }
     1418        }
     1419
     1420}
     1421
     1422
     1423void    btCollisionWorld::serialize(btSerializer* serializer)
     1424{
     1425
     1426        serializer->startSerialization();
     1427       
     1428        serializeCollisionObjects(serializer);
     1429       
     1430        serializer->finishSerialization();
     1431}
     1432
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h

    r5781 r8351  
    2323 * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ).
    2424 *
     25 * The main documentation is Bullet_User_Manual.pdf, included in the source code distribution.
    2526 * There is the Physics Forum for feedback and general Collision Detection and Physics discussions.
    2627 * Please visit http://www.bulletphysics.com
     
    3031 * @subsection step1 Step 1: Download
    3132 * You can download the Bullet Physics Library from the Google Code repository: http://code.google.com/p/bullet/downloads/list
     33 *
    3234 * @subsection step2 Step 2: Building
    33  * Bullet comes with autogenerated Project Files for Microsoft Visual Studio 6, 7, 7.1 and 8.
    34  * The main Workspace/Solution is located in Bullet/msvc/8/wksbullet.sln (replace 8 with your version).
    35  *
    36  * Under other platforms, like Linux or Mac OS-X, Bullet can be build using either using make, cmake, http://www.cmake.org , or jam, http://www.perforce.com/jam/jam.html . cmake can autogenerate Xcode, KDevelop, MSVC and other build systems. just run cmake . in the root of Bullet.
    37  * So if you are not using MSVC or cmake, you can run ./autogen.sh ./configure to create both Makefile and Jamfile and then run make or jam.
    38  * Jam is a build system that can build the library, demos and also autogenerate the MSVC Project Files.
    39  * If you don't have jam installed, you can make jam from the included jam-2.5 sources, or download jam from ftp://ftp.perforce.com/jam
     35 * Bullet main build system for all platforms is cmake, you can download http://www.cmake.org
     36 * cmake can autogenerate projectfiles for Microsoft Visual Studio, Apple Xcode, KDevelop and Unix Makefiles.
     37 * The easiest is to run the CMake cmake-gui graphical user interface and choose the options and generate projectfiles.
     38 * You can also use cmake in the command-line. Here are some examples for various platforms:
     39 * cmake . -G "Visual Studio 9 2008"
     40 * cmake . -G Xcode
     41 * cmake . -G "Unix Makefiles"
     42 * Although cmake is recommended, you can also use autotools for UNIX: ./autogen.sh ./configure to create a Makefile and then run make.
    4043 *
    4144 * @subsection step3 Step 3: Testing demos
     
    5457 *
    5558 * @section copyright Copyright
    56  * Copyright (C) 2005-2008 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon
    57  * Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, John McCutchan, Nathanael Presson, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky,
    58  * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren, Marten Svanfeldt.
     59 * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf
    5960 *
    6061 */
    61 
    62 
    6362 
    6463 
     
    7170class btConvexShape;
    7271class btBroadphaseInterface;
     72class btSerializer;
     73
    7374#include "LinearMath/btVector3.h"
    7475#include "LinearMath/btTransform.h"
     
    8283{
    8384
    84 
    8585       
    8686protected:
    8787
    8888        btAlignedObjectArray<btCollisionObject*>        m_collisionObjects;
    89 
    9089       
    9190        btDispatcher*   m_dispatcher1;
     
    9998        btIDebugDraw*   m_debugDrawer;
    10099
    101 
    102        
     100        ///m_forceUpdateAllAabbs can be set to false as an optimization to only update active object AABBs
     101        ///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB)
     102        bool m_forceUpdateAllAabbs;
     103
     104        void    serializeCollisionObjects(btSerializer* serializer);
     105
    103106public:
    104107
     
    142145
    143146        virtual void    updateAabbs();
    144 
    145147       
    146148        virtual void    setDebugDrawer(btIDebugDraw*    debugDrawer)
     
    153155                return m_debugDrawer;
    154156        }
     157
     158        virtual void    debugDrawWorld();
     159
     160        virtual void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
    155161
    156162
     
    161167                int     m_shapePart;
    162168                int     m_triangleIndex;
    163 
    164169               
    165170                //const btCollisionShape*       m_shapeTemp;
     
    239244                btVector3       m_hitNormalWorld;
    240245                btVector3       m_hitPointWorld;
    241 
    242246                       
    243247                virtual btScalar        addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace)
     
    245249                        //caller already does the filter on the m_closestHitFraction
    246250                        btAssert(rayResult.m_hitFraction <= m_closestHitFraction);
    247 
    248251                       
    249252                        m_closestHitFraction = rayResult.m_hitFraction;
     
    262265        };
    263266
     267        struct  AllHitsRayResultCallback : public RayResultCallback
     268        {
     269                AllHitsRayResultCallback(const btVector3&       rayFromWorld,const btVector3&   rayToWorld)
     270                :m_rayFromWorld(rayFromWorld),
     271                m_rayToWorld(rayToWorld)
     272                {
     273                }
     274
     275                btAlignedObjectArray<btCollisionObject*>                m_collisionObjects;
     276
     277                btVector3       m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
     278                btVector3       m_rayToWorld;
     279
     280                btAlignedObjectArray<btVector3> m_hitNormalWorld;
     281                btAlignedObjectArray<btVector3> m_hitPointWorld;
     282                btAlignedObjectArray<btScalar> m_hitFractions;
     283                       
     284                virtual btScalar        addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace)
     285                {
     286                        m_collisionObject = rayResult.m_collisionObject;
     287                        m_collisionObjects.push_back(rayResult.m_collisionObject);
     288                        btVector3 hitNormalWorld;
     289                        if (normalInWorldSpace)
     290                        {
     291                                hitNormalWorld = rayResult.m_hitNormalLocal;
     292                        } else
     293                        {
     294                                ///need to transform normal into worldspace
     295                                hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;
     296                        }
     297                        m_hitNormalWorld.push_back(hitNormalWorld);
     298                        btVector3 hitPointWorld;
     299                        hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);
     300                        m_hitPointWorld.push_back(hitPointWorld);
     301                        m_hitFractions.push_back(rayResult.m_hitFraction);
     302                        return m_closestHitFraction;
     303                }
     304        };
     305
    264306
    265307        struct LocalConvexResult
     
    292334                short int       m_collisionFilterGroup;
    293335                short int       m_collisionFilterMask;
    294 
    295336               
    296337                ConvexResultCallback()
     
    304345                {
    305346                }
    306 
    307347               
    308348                bool    hasHit() const
     
    310350                        return (m_closestHitFraction < btScalar(1.));
    311351                }
    312 
    313352
    314353               
     
    339378                btVector3       m_hitPointWorld;
    340379                btCollisionObject*      m_hitCollisionObject;
    341 
    342380               
    343381                virtual btScalar        addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace)
     
    345383//caller already does the filter on the m_closestHitFraction
    346384                        btAssert(convexResult.m_hitFraction <= m_closestHitFraction);
    347 
    348385                                               
    349386                        m_closestHitFraction = convexResult.m_hitFraction;
     
    362399        };
    363400
     401        ///ContactResultCallback is used to report contact points
     402        struct  ContactResultCallback
     403        {
     404                short int       m_collisionFilterGroup;
     405                short int       m_collisionFilterMask;
     406               
     407                ContactResultCallback()
     408                        :m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
     409                        m_collisionFilterMask(btBroadphaseProxy::AllFilter)
     410                {
     411                }
     412
     413                virtual ~ContactResultCallback()
     414                {
     415                }
     416               
     417                virtual bool needsCollision(btBroadphaseProxy* proxy0) const
     418                {
     419                        bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
     420                        collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);
     421                        return collides;
     422                }
     423
     424                virtual btScalar        addSingleResult(btManifoldPoint& cp,    const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) = 0;
     425        };
     426
     427
     428
    364429        int     getNumCollisionObjects() const
    365430        {
     
    369434        /// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback
    370435        /// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
    371         void    rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;
    372 
    373         // convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback
    374         // This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
     436        virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;
     437
     438        /// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback
     439        /// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
    375440        void    convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback,  btScalar allowedCcdPenetration = btScalar(0.)) const;
     441
     442        ///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback.
     443        ///it reports one or more contact points for every overlapping object (including the one with deepest penetration)
     444        void    contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback);
     445
     446        ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected.
     447        ///it reports one or more contact points (including the one with deepest penetration)
     448        void    contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback);
    376449
    377450
     
    392465                                          ConvexResultCallback& resultCallback, btScalar        allowedPenetration);
    393466
    394         void    addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);
     467        virtual void    addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);
    395468
    396469        btCollisionObjectArray& getCollisionObjectArray()
     
    405478
    406479
    407         void    removeCollisionObject(btCollisionObject* collisionObject);
     480        virtual void    removeCollisionObject(btCollisionObject* collisionObject);
    408481
    409482        virtual void    performDiscreteCollisionDetection();
     
    418491                return m_dispatchInfo;
    419492        }
     493       
     494        bool    getForceUpdateAllAabbs() const
     495        {
     496                return m_forceUpdateAllAabbs;
     497        }
     498        void setForceUpdateAllAabbs( bool forceUpdateAllAabbs)
     499        {
     500                m_forceUpdateAllAabbs = forceUpdateAllAabbs;
     501        }
     502
     503        ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo)
     504        virtual void    serialize(btSerializer* serializer);
    420505
    421506};
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

    r5781 r8351  
    115115        void    ProcessChildShape(btCollisionShape* childShape,int index)
    116116        {
    117                
     117                btAssert(index>=0);
    118118                btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
     119                btAssert(index<compoundShape->getNumChildShapes());
    119120
    120121
     
    142143                        if (!m_childCollisionAlgorithms[index])
    143144                                m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold);
     145
     146                        ///detect swapping case
     147                        if (m_resultOut->getBody0Internal() == m_compoundColObj)
     148                        {
     149                                m_resultOut->setShapeIdentifiersA(-1,index);
     150                        } else
     151                        {
     152                                m_resultOut->setShapeIdentifiersB(-1,index);
     153                        }
    144154
    145155                        m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut);
     
    258268                int i;
    259269                btManifoldArray manifoldArray;
    260 
     270        btCollisionShape* childShape = 0;
     271        btTransform     orgTrans;
     272        btTransform     orgInterpolationTrans;
     273        btTransform     newChildWorldTrans;
     274        btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;       
     275       
    261276                for (i=0;i<numChildren;i++)
    262277                {
    263278                        if (m_childCollisionAlgorithms[i])
    264279                        {
    265                                 btCollisionShape* childShape = compoundShape->getChildShape(i);
     280                                childShape = compoundShape->getChildShape(i);
    266281                        //if not longer overlapping, remove the algorithm
    267                                 btTransform     orgTrans = colObj->getWorldTransform();
    268                                 btTransform     orgInterpolationTrans = colObj->getInterpolationWorldTransform();
     282                orgTrans = colObj->getWorldTransform();
     283                orgInterpolationTrans = colObj->getInterpolationWorldTransform();
    269284                                const btTransform& childTrans = compoundShape->getChildTransform(i);
    270                                 btTransform     newChildWorldTrans = orgTrans*childTrans ;
     285                newChildWorldTrans = orgTrans*childTrans ;
    271286
    272287                                //perform an AABB check first
    273                                 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
    274288                                childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
    275289                                otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1);
     
    281295                                        m_childCollisionAlgorithms[i] = 0;
    282296                                }
    283 
    284297                        }
    285                        
    286                 }
    287 
    288                
    289 
     298                }
    290299        }
    291300}
     
    312321        int numChildren = m_childCollisionAlgorithms.size();
    313322        int i;
     323    btTransform orgTrans;
     324    btScalar frac;
    314325        for (i=0;i<numChildren;i++)
    315326        {
     
    318329
    319330                //backup
    320                 btTransform     orgTrans = colObj->getWorldTransform();
     331        orgTrans = colObj->getWorldTransform();
    321332       
    322333                const btTransform& childTrans = compoundShape->getChildTransform(i);
     
    326337                btCollisionShape* tmpShape = colObj->getCollisionShape();
    327338                colObj->internalSetTemporaryCollisionShape( childShape );
    328                 btScalar frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
     339        frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
    329340                if (frac<hitFraction)
    330341                {
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp

    r5781 r8351  
    9696        if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
    9797        {
    98                 btVector3 color(255,255,0);
     98                btVector3 color(1,1,0);
    9999                btTransform& tr = ob->getWorldTransform();
    100100                m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
     
    122122               
    123123                btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr);
    124                 ///this should use the btDispatcher, so the actual registered algorithm is used
    125                 //              btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
    126 
    127                 m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex);
    128         //      cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
    129 //              cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
     124
     125                if (m_resultOut->getBody0Internal() == m_triBody)
     126                {
     127                        m_resultOut->setShapeIdentifiersA(partId,triangleIndex);
     128                }
     129                else
     130                {
     131                        m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
     132                }
     133       
    130134                colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
    131135                colAlgo->~btCollisionAlgorithm();
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp

    r5781 r8351  
    1414*/
    1515
     16///Specialized capsule-capsule collision algorithm has been added for Bullet 2.75 release to increase ragdoll performance
     17///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums
     18///with reproduction case
     19//define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1
     20
    1621#include "btConvexConvexAlgorithm.h"
    1722
     
    2126#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
    2227#include "BulletCollision/CollisionShapes/btConvexShape.h"
     28#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
     29
     30
    2331#include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
    2432#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
     
    4452
    4553
    46 
     54///////////
     55
     56
     57
     58static SIMD_FORCE_INLINE void segmentsClosestPoints(
     59        btVector3& ptsVector,
     60        btVector3& offsetA,
     61        btVector3& offsetB,
     62        btScalar& tA, btScalar& tB,
     63        const btVector3& translation,
     64        const btVector3& dirA, btScalar hlenA,
     65        const btVector3& dirB, btScalar hlenB )
     66{
     67        // compute the parameters of the closest points on each line segment
     68
     69        btScalar dirA_dot_dirB = btDot(dirA,dirB);
     70        btScalar dirA_dot_trans = btDot(dirA,translation);
     71        btScalar dirB_dot_trans = btDot(dirB,translation);
     72
     73        btScalar denom = 1.0f - dirA_dot_dirB * dirA_dot_dirB;
     74
     75        if ( denom == 0.0f ) {
     76                tA = 0.0f;
     77        } else {
     78                tA = ( dirA_dot_trans - dirB_dot_trans * dirA_dot_dirB ) / denom;
     79                if ( tA < -hlenA )
     80                        tA = -hlenA;
     81                else if ( tA > hlenA )
     82                        tA = hlenA;
     83        }
     84
     85        tB = tA * dirA_dot_dirB - dirB_dot_trans;
     86
     87        if ( tB < -hlenB ) {
     88                tB = -hlenB;
     89                tA = tB * dirA_dot_dirB + dirA_dot_trans;
     90
     91                if ( tA < -hlenA )
     92                        tA = -hlenA;
     93                else if ( tA > hlenA )
     94                        tA = hlenA;
     95        } else if ( tB > hlenB ) {
     96                tB = hlenB;
     97                tA = tB * dirA_dot_dirB + dirA_dot_trans;
     98
     99                if ( tA < -hlenA )
     100                        tA = -hlenA;
     101                else if ( tA > hlenA )
     102                        tA = hlenA;
     103        }
     104
     105        // compute the closest points relative to segment centers.
     106
     107        offsetA = dirA * tA;
     108        offsetB = dirB * tB;
     109
     110        ptsVector = translation - offsetA + offsetB;
     111}
     112
     113
     114static SIMD_FORCE_INLINE btScalar capsuleCapsuleDistance(
     115        btVector3& normalOnB,
     116        btVector3& pointOnB,
     117        btScalar capsuleLengthA,
     118        btScalar        capsuleRadiusA,
     119        btScalar capsuleLengthB,
     120        btScalar        capsuleRadiusB,
     121        int capsuleAxisA,
     122        int capsuleAxisB,
     123        const btTransform& transformA,
     124        const btTransform& transformB,
     125        btScalar distanceThreshold )
     126{
     127        btVector3 directionA = transformA.getBasis().getColumn(capsuleAxisA);
     128        btVector3 translationA = transformA.getOrigin();
     129        btVector3 directionB = transformB.getBasis().getColumn(capsuleAxisB);
     130        btVector3 translationB = transformB.getOrigin();
     131
     132        // translation between centers
     133
     134        btVector3 translation = translationB - translationA;
     135
     136        // compute the closest points of the capsule line segments
     137
     138        btVector3 ptsVector;           // the vector between the closest points
     139       
     140        btVector3 offsetA, offsetB;    // offsets from segment centers to their closest points
     141        btScalar tA, tB;              // parameters on line segment
     142
     143        segmentsClosestPoints( ptsVector, offsetA, offsetB, tA, tB, translation,
     144                                                   directionA, capsuleLengthA, directionB, capsuleLengthB );
     145
     146        btScalar distance = ptsVector.length() - capsuleRadiusA - capsuleRadiusB;
     147
     148        if ( distance > distanceThreshold )
     149                return distance;
     150
     151        btScalar lenSqr = ptsVector.length2();
     152        if (lenSqr<= (SIMD_EPSILON*SIMD_EPSILON))
     153        {
     154                //degenerate case where 2 capsules are likely at the same location: take a vector tangential to 'directionA'
     155                btVector3 q;
     156                btPlaneSpace1(directionA,normalOnB,q);
     157        } else
     158        {
     159                // compute the contact normal
     160                normalOnB = ptsVector*-btRecipSqrt(lenSqr);
     161        }
     162        pointOnB = transformB.getOrigin()+offsetB + normalOnB * capsuleRadiusB;
     163
     164        return distance;
     165}
     166
     167
     168
     169
     170
     171
     172
     173//////////
    47174
    48175
     
    70197m_lowLevelOfDetail(false),
    71198#ifdef USE_SEPDISTANCE_UTIL2
    72 ,m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(),
     199m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(),
    73200                          (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()),
    74201#endif
     
    112239                m_transformA(transformA),
    113240                m_transformB(transformB),
     241                m_unPerturbedTransform(unPerturbedTransform),
    114242                m_perturbA(perturbA),
    115                 m_unPerturbedTransform(unPerturbedTransform),
    116243                m_debugDrawer(debugDrawer)
    117244        {
     
    156283extern btScalar gContactBreakingThreshold;
    157284
     285
    158286//
    159287// Convex-Convex collision algorithm
     
    177305        btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape());
    178306
     307        btVector3  normalOnB;
     308                btVector3  pointOnBWorld;
     309#ifndef BT_DISABLE_CAPSULE_CAPSULE_COLLIDER
     310        if ((min0->getShapeType() == CAPSULE_SHAPE_PROXYTYPE) && (min1->getShapeType() == CAPSULE_SHAPE_PROXYTYPE))
     311        {
     312                btCapsuleShape* capsuleA = (btCapsuleShape*) min0;
     313                btCapsuleShape* capsuleB = (btCapsuleShape*) min1;
     314                btVector3 localScalingA = capsuleA->getLocalScaling();
     315                btVector3 localScalingB = capsuleB->getLocalScaling();
     316               
     317                btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
     318
     319                btScalar dist = capsuleCapsuleDistance(normalOnB,       pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(),
     320                        capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(),
     321                        body0->getWorldTransform(),body1->getWorldTransform(),threshold);
     322
     323                if (dist<threshold)
     324                {
     325                        btAssert(normalOnB.length2()>=(SIMD_EPSILON*SIMD_EPSILON));
     326                        resultOut->addContactPoint(normalOnB,pointOnBWorld,dist);       
     327                }
     328                resultOut->refreshContactPoints();
     329                return;
     330        }
     331#endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER
     332
     333
    179334#ifdef USE_SEPDISTANCE_UTIL2
    180         m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform());
     335        if (dispatchInfo.m_useConvexConservativeDistanceUtil)
     336        {
     337                m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform());
     338        }
     339
    181340        if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f)
    182341#endif //USE_SEPDISTANCE_UTIL2
     
    195354        if (dispatchInfo.m_useConvexConservativeDistanceUtil)
    196355        {
    197                 input.m_maximumDistanceSquared = 1e30f;
     356                input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
    198357        } else
    199358#endif //USE_SEPDISTANCE_UTIL2
    200359        {
    201                 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
     360                if (dispatchInfo.m_convexMaxDistanceUseCPT)
     361                {
     362                        input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold();
     363                } else
     364                {
     365                        input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
     366                }
    202367                input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
    203368        }
     
    208373
    209374        gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
    210         btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold;
    211 
    212         //now perturbe directions to get multiple contact points
    213         btVector3 v0,v1;
    214         btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized();
    215         btPlaneSpace1(sepNormalWorldSpace,v0,v1);
     375
     376       
     377
     378#ifdef USE_SEPDISTANCE_UTIL2
     379        btScalar sepDist = 0.f;
     380        if (dispatchInfo.m_useConvexConservativeDistanceUtil)
     381        {
     382                sepDist = gjkPairDetector.getCachedSeparatingDistance();
     383                if (sepDist>SIMD_EPSILON)
     384                {
     385                        sepDist += dispatchInfo.m_convexConservativeDistanceThreshold;
     386                        //now perturbe directions to get multiple contact points
     387                       
     388                }
     389        }
     390#endif //USE_SEPDISTANCE_UTIL2
     391
    216392        //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
    217393       
    218394        //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points
    219         if (resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)
     395        if (m_numPerturbationIterations && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)
    220396        {
    221397               
    222398                int i;
     399                btVector3 v0,v1;
     400                btVector3 sepNormalWorldSpace;
     401       
     402                sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized();
     403                btPlaneSpace1(sepNormalWorldSpace,v0,v1);
     404
    223405
    224406                bool perturbeA = true;
     
    250432                for ( i=0;i<m_numPerturbationIterations;i++)
    251433                {
     434                        if (v0.length2()>SIMD_EPSILON)
     435                        {
    252436                        btQuaternion perturbeRot(v0,perturbeAngle);
    253437                        btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
     
    273457                        btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw);
    274458                        gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw);
     459                        }
    275460                       
    276                        
    277461                }
    278462        }
     
    281465
    282466#ifdef USE_SEPDISTANCE_UTIL2
    283         if (dispatchInfo.m_useConvexConservativeDistanceUtil)
     467        if (dispatchInfo.m_useConvexConservativeDistanceUtil && (sepDist>SIMD_EPSILON))
    284468        {
    285469                m_sepDistance.initSeparatingDistance(gjkPairDetector.getCachedSeparatingAxis(),sepDist,body0->getWorldTransform(),body1->getWorldTransform());
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h

    r5781 r8351  
    3232///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util
    3333///for certain pairs that have a small size ratio
    34 ///#define USE_SEPDISTANCE_UTIL2 1
     34
     35//#define USE_SEPDISTANCE_UTIL2 1
    3536
    3637///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects.
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp

    r5781 r8351  
    103103        btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
    104104
    105     bool hasCollision = false;
     105   
    106106        const btVector3& planeNormal = planeShape->getPlaneNormal();
    107         const btScalar& planeConstant = planeShape->getPlaneConstant();
     107        //const btScalar& planeConstant = planeShape->getPlaneConstant();
    108108
    109109        //first perform a collision query with the non-perturbated collision objects
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h

    r5781 r8351  
    6161                       
    6262                CreateFunc()
    63                         : m_numPerturbationIterations(3),
    64                         m_minimumPointsPerturbationThreshold(3)
     63                        : m_numPerturbationIterations(1),
     64                        m_minimumPointsPerturbationThreshold(1)
    6565                {
    6666                }
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp

    r5781 r8351  
    4646        void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16);
    4747        m_simplexSolver = new (mem)btVoronoiSimplexSolver();
    48        
    49 #define USE_EPA 1
    50 #ifdef USE_EPA
    51         mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
    52         m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;
    53 #else
    54         mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);
    55         m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;
    56 #endif//USE_EPA
    57        
    58 
     48
     49        if (constructionInfo.m_useEpaPenetrationAlgorithm)
     50        {
     51                mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
     52                m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;
     53        }else
     54        {
     55                mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);
     56                m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;
     57        }
     58       
    5959        //default CreationFunctions, filling the m_doubleDispatch table
    6060        mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16);
     
    103103        int sl = sizeof(btConvexSeparatingDistanceUtil);
    104104        sl = sizeof(btGjkPairDetector);
    105         int     collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2);
     105        int     collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
     106        collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
    106107        collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
    107108
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h

    r5781 r8351  
    2828        int                                     m_defaultMaxPersistentManifoldPoolSize;
    2929        int                                     m_defaultMaxCollisionAlgorithmPoolSize;
     30        int                                     m_customCollisionAlgorithmMaxElementSize;
    3031        int                                     m_defaultStackAllocatorSize;
     32        int                                     m_useEpaPenetrationAlgorithm;
    3133
    3234        btDefaultCollisionConstructionInfo()
     
    3638                m_defaultMaxPersistentManifoldPoolSize(4096),
    3739                m_defaultMaxCollisionAlgorithmPoolSize(4096),
    38                 m_defaultStackAllocatorSize(0)
     40                m_customCollisionAlgorithmMaxElementSize(0),
     41                m_defaultStackAllocatorSize(0),
     42                m_useEpaPenetrationAlgorithm(true)
    3943        {
    4044        }
     
    109113        }
    110114
     115        virtual btVoronoiSimplexSolver* getSimplexSolver()
     116        {
     117                return m_simplexSolver;
     118        }
     119
    111120
    112121        virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1);
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btGhostObject.h

    r5781 r8351  
    161161        }
    162162
    163         virtual void    removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0,btDispatcher* dispatcher)
     163        virtual void    removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/)
    164164        {
    165165                btAssert(0);
     
    173173
    174174#endif
     175
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp

    r5781 r8351  
    4848                m_body0(body0),
    4949                m_body1(body1)
     50#ifdef DEBUG_PART_INDEX
     51                ,m_partId0(-1),
     52        m_partId1(-1),
     53        m_index0(-1),
     54        m_index1(-1)
     55#endif //DEBUG_PART_INDEX
    5056{
    5157        m_rootTransA = body0->getWorldTransform();
     
    8995
    9096   //BP mod, store contact triangles.
    91    newPt.m_partId0 = m_partId0;
    92    newPt.m_partId1 = m_partId1;
    93    newPt.m_index0  = m_index0;
    94    newPt.m_index1  = m_index1;
     97        if (isSwapped)
     98        {
     99                newPt.m_partId0 = m_partId1;
     100                newPt.m_partId1 = m_partId0;
     101                newPt.m_index0  = m_index1;
     102                newPt.m_index1  = m_index0;
     103        } else
     104        {
     105                newPt.m_partId0 = m_partId0;
     106                newPt.m_partId1 = m_partId1;
     107                newPt.m_index0  = m_index0;
     108                newPt.m_index1  = m_index1;
     109        }
    95110        //printf("depth=%f\n",depth);
    96111        ///@todo, check this for any side effects
     
    113128                btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
    114129                btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
    115                 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);
     130                (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1);
    116131        }
    117132
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h

    r5781 r8351  
    2929extern ContactAddedCallback             gContactAddedCallback;
    3030
     31//#define DEBUG_PART_INDEX 1
    3132
    3233
     
    3435class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
    3536{
     37protected:
     38
    3639        btPersistentManifold* m_manifoldPtr;
    3740
     
    5154
    5255        btManifoldResult()
     56#ifdef DEBUG_PART_INDEX
     57                :
     58        m_partId0(-1),
     59        m_partId1(-1),
     60        m_index0(-1),
     61        m_index1(-1)
     62#endif //DEBUG_PART_INDEX
    5363        {
    5464        }
     
    7282        }
    7383
    74         virtual void setShapeIdentifiers(int partId0,int index0,        int partId1,int index1)
     84        virtual void setShapeIdentifiersA(int partId0,int index0)
    7585        {
    76                         m_partId0=partId0;
    77                         m_partId1=partId1;
    78                         m_index0=index0;
    79                         m_index1=index1;               
     86                m_partId0=partId0;
     87                m_index0=index0;
     88        }
     89
     90        virtual void setShapeIdentifiersB(      int partId1,int index1)
     91        {
     92                m_partId1=partId1;
     93                m_index1=index1;
    8094        }
    8195
     
    100114        }
    101115
     116        const btCollisionObject* getBody0Internal() const
     117        {
     118                return m_body0;
     119        }
    102120
     121        const btCollisionObject* getBody1Internal() const
     122        {
     123                return m_body1;
     124        }
     125       
    103126};
    104127
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp

    r5781 r8351  
     1
    12/*
    23Bullet Continuous Collision Detection and Physics Library
     
    4546       
    4647        {
     48                btOverlappingPairCache* pairCachePtr = colWorld->getPairCache();
     49                const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs();
     50                btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr();
    4751               
    48                 for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++)
    49                 {
    50                         btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr();
     52                for (int i=0;i<numOverlappingPairs;i++)
     53                {
    5154                        const btBroadphasePair& collisionPair = pairPtr[i];
    5255                        btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
     
    6467}
    6568
    66 
     69#ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION
     70void   btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
     71{
     72
     73        // put the index into m_controllers into m_tag   
     74        int index = 0;
     75        {
     76
     77                int i;
     78                for (i=0;i<colWorld->getCollisionObjectArray().size(); i++)
     79                {
     80                        btCollisionObject*   collisionObject= colWorld->getCollisionObjectArray()[i];
     81                        //Adding filtering here
     82                        if (!collisionObject->isStaticOrKinematicObject())
     83                        {
     84                                collisionObject->setIslandTag(index++);
     85                        }
     86                        collisionObject->setCompanionId(-1);
     87                        collisionObject->setHitFraction(btScalar(1.));
     88                }
     89        }
     90        // do the union find
     91
     92        initUnionFind( index );
     93
     94        findUnions(dispatcher,colWorld);
     95}
     96
     97void   btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
     98{
     99        // put the islandId ('find' value) into m_tag   
     100        {
     101                int index = 0;
     102                int i;
     103                for (i=0;i<colWorld->getCollisionObjectArray().size();i++)
     104                {
     105                        btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i];
     106                        if (!collisionObject->isStaticOrKinematicObject())
     107                        {
     108                                collisionObject->setIslandTag( m_unionFind.find(index) );
     109                                //Set the correct object offset in Collision Object Array
     110                                m_unionFind.getElement(index).m_sz = i;
     111                                collisionObject->setCompanionId(-1);
     112                                index++;
     113                        } else
     114                        {
     115                                collisionObject->setIslandTag(-1);
     116                                collisionObject->setCompanionId(-2);
     117                        }
     118                }
     119        }
     120}
     121
     122
     123#else //STATIC_SIMULATION_ISLAND_OPTIMIZATION
    67124void    btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
    68125{
    69        
     126
    70127        initUnionFind( int (colWorld->getCollisionObjectArray().size()));
    71        
     128
    72129        // put the index into m_controllers into m_tag 
    73130        {
    74                
     131
    75132                int index = 0;
    76133                int i;
     
    82139                        collisionObject->setHitFraction(btScalar(1.));
    83140                        index++;
    84                        
     141
    85142                }
    86143        }
    87144        // do the union find
    88        
     145
    89146        findUnions(dispatcher,colWorld);
    90        
    91 
    92        
    93 }
    94 
    95 
    96 
     147}
    97148
    98149void    btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
     
    100151        // put the islandId ('find' value) into m_tag   
    101152        {
    102                
    103                
     153
     154
    104155                int index = 0;
    105156                int i;
     
    120171        }
    121172}
     173
     174#endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION
    122175
    123176inline  int     getIslandId(const btPersistentManifold* lhs)
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp

    r5781 r8351  
    6060       
    6161        btDiscreteCollisionDetectorInterface::ClosestPointInput input;
    62         input.m_maximumDistanceSquared = btScalar(1e30);///@todo: tighter bounds
     62        input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds
    6363        input.m_transformA = sphereObj->getWorldTransform();
    6464        input.m_transformB = triObj->getWorldTransform();
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp

    r5781 r8351  
    7171        {
    7272                m_elements[i].m_id = find(i);
     73#ifndef STATIC_SIMULATION_ISLAND_OPTIMIZATION
    7374                m_elements[i].m_sz = i;
     75#endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION
    7476        }
    7577       
     
    7981
    8082}
    81 
  • code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h

    r5781 r8351  
    1919#include "LinearMath/btAlignedObjectArray.h"
    2020
    21         #define USE_PATH_COMPRESSION 1
     21#define USE_PATH_COMPRESSION 1
     22
     23///see for discussion of static island optimizations by Vroonsh here: http://code.google.com/p/bullet/issues/detail?id=406
     24#define STATIC_SIMULATION_ISLAND_OPTIMIZATION 1
    2225
    2326struct  btElement
     
    107110       
    108111                #ifdef USE_PATH_COMPRESSION
    109                                 //
    110                                 m_elements[x].m_id = m_elements[m_elements[x].m_id].m_id;
    111                 #endif //
     112                                const btElement* elementPtr = &m_elements[m_elements[x].m_id];
     113                                m_elements[x].m_id = elementPtr->m_id;
     114                                x = elementPtr->m_id;                   
     115                #else//
    112116                                x = m_elements[x].m_id;
     117                #endif         
    113118                                //btAssert(x < m_N);
    114119                                //btAssert(x >= 0);
Note: See TracChangeset for help on using the changeset viewer.