Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 21, 2011, 6:58:23 PM (13 years ago)
Author:
rgrieder
Message:

Merged revisions 7978 - 8096 from kicklib to kicklib2.

Location:
code/branches/kicklib2
Files:
1 deleted
130 edited
11 copied

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2

  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h

    r5781 r8284  
    151151       
    152152        virtual void    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
     153        virtual void    aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
     154
    153155       
    154156        void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const;
     
    281283                        {
    282284                                rayCallback.process(getHandle(m_pEdges[axis][i].m_handle));
     285                        }
     286                }
     287        }
     288}
     289
     290template <typename BP_FP_INT_TYPE>
     291void    btAxisSweep3Internal<BP_FP_INT_TYPE>::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
     292{
     293        if (m_raycastAccelerator)
     294        {
     295                m_raycastAccelerator->aabbTest(aabbMin,aabbMax,callback);
     296        } else
     297        {
     298                //choose axis?
     299                BP_FP_INT_TYPE axis = 0;
     300                //for each proxy
     301                for (BP_FP_INT_TYPE i=1;i<m_numHandles*2+1;i++)
     302                {
     303                        if (m_pEdges[axis][i].IsMax())
     304                        {
     305                                Handle* handle = getHandle(m_pEdges[axis][i].m_handle);
     306                                if (TestAabbAgainstAabb2(aabbMin,aabbMax,handle->m_aabbMin,handle->m_aabbMax))
     307                                {
     308                                        callback.process(handle);
     309                                }
    283310                        }
    284311                }
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h

    r5781 r8284  
    2727
    2828
    29 struct  btBroadphaseRayCallback
     29struct  btBroadphaseAabbCallback
     30{
     31        virtual ~btBroadphaseAabbCallback() {}
     32        virtual bool    process(const btBroadphaseProxy* proxy) = 0;
     33};
     34
     35
     36struct  btBroadphaseRayCallback : public btBroadphaseAabbCallback
    3037{
    3138        ///added some cached data to accelerate ray-AABB tests
     
    3542
    3643        virtual ~btBroadphaseRayCallback() {}
    37         virtual bool    process(const btBroadphaseProxy* proxy) = 0;
    3844};
    3945
     
    5561        virtual void    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0;
    5662
     63        virtual void    aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) = 0;
     64
    5765        ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
    5866        virtual void    calculateOverlappingPairs(btDispatcher* dispatcher)=0;
     
    6674
    6775        ///reset broadphase internal structures, to ensure determinism/reproducability
    68         virtual void resetPool(btDispatcher* dispatcher) {};
     76        virtual void resetPool(btDispatcher* dispatcher) { (void) dispatcher; };
    6977
    7078        virtual void    printStats() = 0;
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h

    r5781 r8284  
    4747        MINKOWSKI_SUM_SHAPE_PROXYTYPE,
    4848        MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
     49        BOX_2D_SHAPE_PROXYTYPE,
     50        CONVEX_2D_SHAPE_PROXYTYPE,
    4951        CUSTOM_CONVEX_SHAPE_TYPE,
    5052//concave shapes
     
    140142        }
    141143
     144        static SIMD_FORCE_INLINE bool   isNonMoving(int proxyType)
     145        {
     146                return (isConcave(proxyType) && !(proxyType==GIMPACT_SHAPE_PROXYTYPE));
     147        }
     148
    142149        static SIMD_FORCE_INLINE bool   isConcave(int proxyType)
    143150        {
     
    149156                return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
    150157        }
     158
     159        static SIMD_FORCE_INLINE bool   isSoftBody(int proxyType)
     160        {
     161                return (proxyType == SOFTBODY_SHAPE_PROXYTYPE);
     162        }
     163
    151164        static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
    152165        {
    153166                return (proxyType == STATIC_PLANE_PROXYTYPE);
    154167        }
     168
     169        static SIMD_FORCE_INLINE bool isConvex2d(int proxyType)
     170        {
     171                return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE);
     172        }
     173
    155174       
    156175}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp

    r5781 r8284  
    6262        {
    6363                getmaxdepth(node->childs[0],depth+1,maxdepth);
    64                 getmaxdepth(node->childs[0],depth+1,maxdepth);
     64                getmaxdepth(node->childs[1],depth+1,maxdepth);
    6565        } else maxdepth=btMax(maxdepth,depth);
    6666}
     
    239239        for(int i=0,ni=leaves.size();i<ni;++i)
    240240        {
    241                 if(dot(axis,leaves[i]->volume.Center()-org)<0)
     241                if(btDot(axis,leaves[i]->volume.Center()-org)<0)
    242242                        left.push_back(leaves[i]);
    243243                else
     
    320320                                for(int j=0;j<3;++j)
    321321                                {
    322                                         ++splitcount[j][dot(x,axis[j])>0?1:0];
     322                                        ++splitcount[j][btDot(x,axis[j])>0?1:0];
    323323                                }
    324324                        }
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvt.h

    r5781 r8284  
    3333
    3434// Template implementation of ICollide
    35 #ifdef WIN32
     35#ifdef _WIN32
    3636#if (defined (_MSC_VER) && _MSC_VER >= 1400)
    3737#define DBVT_USE_TEMPLATE               1
     
    5858
    5959//SSE gives errors on a MSVC 7.1
    60 #ifdef BT_USE_SSE
     60#if defined (BT_USE_SSE) && defined (_WIN32)
    6161#define DBVT_SELECT_IMPL                DBVT_IMPL_SSE
    6262#define DBVT_MERGE_IMPL                 DBVT_IMPL_SSE
     
    9393
    9494#if DBVT_USE_MEMMOVE
    95 #ifndef __CELLOS_LV2__
     95#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__)
    9696#include <memory.h>
    9797#endif
     
    485485                pi=btVector3(mi.x(),mi.y(),mi.z());break;
    486486        }
    487         if((dot(n,px)+o)<0)             return(-1);
    488         if((dot(n,pi)+o)>=0)    return(+1);
     487        if((btDot(n,px)+o)<0)           return(-1);
     488        if((btDot(n,pi)+o)>=0)  return(+1);
    489489        return(0);
    490490}
     
    497497                b[(signs>>1)&1]->y(),
    498498                b[(signs>>2)&1]->z());
    499         return(dot(p,v));
     499        return(btDot(p,v));
    500500}
    501501
     
    948948                                                                DBVT_IPOLICY) const
    949949{
     950        (void) rayTo;
    950951        DBVT_CHECKTYPE
    951952        if(root)
     
    962963                {
    963964                        const btDbvtNode*       node=stack[--depth];
    964                         bounds[0] = node->volume.Mins()+aabbMin;
    965                         bounds[1] = node->volume.Maxs()+aabbMax;
     965                        bounds[0] = node->volume.Mins()-aabbMax;
     966                        bounds[1] = node->volume.Maxs()-aabbMin;
    966967                        btScalar tmin=1.f,lambda_min=0.f;
    967968                        unsigned int result1=false;
     
    10011002                        rayDir.normalize ();
    10021003
    1003                         ///what about division by zero? --> just set rayDirection[i] to INF/1e30
     1004                        ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT
    10041005                        btVector3 rayDirectionInverse;
    1005                         rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
    1006                         rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
    1007                         rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
     1006                        rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0];
     1007                        rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1];
     1008                        rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2];
    10081009                        unsigned int signs[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
    10091010
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2007 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516///btDbvtBroadphase implementation by Nathanael Presson
    1617
     
    124125        m_needcleanup           =       true;
    125126        m_releasepaircache      =       (paircache!=0)?false:true;
    126         m_prediction            =       1/(btScalar)2;
     127        m_prediction            =       0;
    127128        m_stageCurrent          =       0;
    128129        m_fixedleft                     =       0;
     
    250251}
    251252
     253
     254struct  BroadphaseAabbTester : btDbvt::ICollide
     255{
     256        btBroadphaseAabbCallback& m_aabbCallback;
     257        BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback)
     258                :m_aabbCallback(orgCallback)
     259        {
     260        }
     261        void                                    Process(const btDbvtNode* leaf)
     262        {
     263                btDbvtProxy*    proxy=(btDbvtProxy*)leaf->data;
     264                m_aabbCallback.process(proxy);
     265        }
     266};     
     267
     268void    btDbvtBroadphase::aabbTest(const btVector3& aabbMin,const btVector3& aabbMax,btBroadphaseAabbCallback& aabbCallback)
     269{
     270        BroadphaseAabbTester callback(aabbCallback);
     271
     272        const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(aabbMin,aabbMax);
     273                //process all children, that overlap with  the given AABB bounds
     274        m_sets[0].collideTV(m_sets[0].m_root,bounds,callback);
     275        m_sets[1].collideTV(m_sets[1].m_root,bounds,callback);
     276
     277}
     278
     279
     280
    252281//
    253282void                                                    btDbvtBroadphase::setAabb(              btBroadphaseProxy* absproxy,
     
    315344                }       
    316345        }
     346}
     347
     348
     349//
     350void                                                    btDbvtBroadphase::setAabbForceUpdate(           btBroadphaseProxy* absproxy,
     351                                                                                                                  const btVector3& aabbMin,
     352                                                                                                                  const btVector3& aabbMax,
     353                                                                                                                  btDispatcher* /*dispatcher*/)
     354{
     355        btDbvtProxy*                                            proxy=(btDbvtProxy*)absproxy;
     356        ATTRIBUTE_ALIGNED16(btDbvtVolume)       aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
     357        bool    docollide=false;
     358        if(proxy->stage==STAGECOUNT)
     359        {/* fixed -> dynamic set        */
     360                m_sets[1].remove(proxy->leaf);
     361                proxy->leaf=m_sets[0].insert(aabb,proxy);
     362                docollide=true;
     363        }
     364        else
     365        {/* dynamic set                         */
     366                ++m_updates_call;
     367                /* Teleporting                  */
     368                m_sets[0].update(proxy->leaf,aabb);
     369                ++m_updates_done;
     370                docollide=true;
     371        }
     372        listremove(proxy,m_stageRoots[proxy->stage]);
     373        proxy->m_aabbMin = aabbMin;
     374        proxy->m_aabbMax = aabbMax;
     375        proxy->stage    =       m_stageCurrent;
     376        listappend(proxy,m_stageRoots[m_stageCurrent]);
     377        if(docollide)
     378        {
     379                m_needcleanup=true;
     380                if(!m_deferedcollide)
     381                {
     382                        btDbvtTreeCollider      collider(this);
     383                        m_sets[1].collideTTpersistentStack(m_sets[1].m_root,proxy->leaf,collider);
     384                        m_sets[0].collideTTpersistentStack(m_sets[0].m_root,proxy->leaf,collider);
     385                }
     386        }       
    317387}
    318388
     
    572642                m_deferedcollide        =       false;
    573643                m_needcleanup           =       true;
    574                 m_prediction            =       1/(btScalar)2;
    575644                m_stageCurrent          =       0;
    576645                m_fixedleft                     =       0;
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2007 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516///btDbvtBroadphase implementation by Nathanael Presson
    1617#ifndef BT_DBVT_BROADPHASE_H
     
    102103        void                                                    collide(btDispatcher* dispatcher);
    103104        void                                                    optimize();
    104         /* btBroadphaseInterface Implementation */
     105       
     106        /* btBroadphaseInterface Implementation */
    105107        btBroadphaseProxy*                              createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
    106         void                                                    destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
    107         void                                                    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
    108         virtual void    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
     108        virtual void                                    destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
     109        virtual void                                    setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
     110        virtual void                                    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
     111        virtual void                                    aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
    109112
    110         virtual void    getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
    111         void                                                    calculateOverlappingPairs(btDispatcher* dispatcher);
    112         btOverlappingPairCache*                 getOverlappingPairCache();
    113         const btOverlappingPairCache*   getOverlappingPairCache() const;
    114         void                                                    getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
    115         void                                                    printStats();
    116         static void                                             benchmark(btBroadphaseInterface*);
     113        virtual void                                    getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
     114        virtual void                                    calculateOverlappingPairs(btDispatcher* dispatcher);
     115        virtual btOverlappingPairCache* getOverlappingPairCache();
     116        virtual const btOverlappingPairCache*   getOverlappingPairCache() const;
     117        virtual void                                    getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
     118        virtual void                                    printStats();
    117119
    118 
    119         void    performDeferredRemoval(btDispatcher* dispatcher);
    120120
    121121        ///reset broadphase internal structures, to ensure determinism/reproducability
    122122        virtual void resetPool(btDispatcher* dispatcher);
    123123
     124        void    performDeferredRemoval(btDispatcher* dispatcher);
     125       
     126        void    setVelocityPrediction(btScalar prediction)
     127        {
     128                m_prediction = prediction;
     129        }
     130        btScalar getVelocityPrediction() const
     131        {
     132                return m_prediction;
     133        }
     134
     135        ///this setAabbForceUpdate is similar to setAabb but always forces the aabb update.
     136        ///it is not part of the btBroadphaseInterface but specific to btDbvtBroadphase.
     137        ///it bypasses certain optimizations that prevent aabb updates (when the aabb shrinks), see
     138        ///http://code.google.com/p/bullet/issues/detail?id=223
     139        void                                                    setAabbForceUpdate(             btBroadphaseProxy* absproxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* /*dispatcher*/);
     140
     141        static void                                             benchmark(btBroadphaseInterface*);
     142
     143
    124144};
    125145
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btDispatcher.h

    r5781 r8284  
    4747                m_useEpa(true),
    4848                m_allowedCcdPenetration(btScalar(0.04)),
    49                 m_useConvexConservativeDistanceUtil(true),
     49                m_useConvexConservativeDistanceUtil(false),
    5050                m_convexConservativeDistanceThreshold(0.0f),
     51                m_convexMaxDistanceUseCPT(false),
    5152                m_stackAllocator(0)
    5253        {
     
    6566        bool            m_useConvexConservativeDistanceUtil;
    6667        btScalar        m_convexConservativeDistanceThreshold;
     68        bool            m_convexMaxDistanceUseCPT;
    6769        btStackAlloc*   m_stackAllocator;
    6870};
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h

    r5781 r8284  
    134134        virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
    135135        {
    136                 aabbMin.setValue(-1e30f,-1e30f,-1e30f);
    137                 aabbMax.setValue(1e30f,1e30f,1e30f);
     136                aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
     137                aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
    138138        }
    139139
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp

    r5781 r8284  
    241241        int count = m_overlappingPairArray.size();
    242242        int oldCapacity = m_overlappingPairArray.capacity();
    243         void* mem = &m_overlappingPairArray.expand();
     243        void* mem = &m_overlappingPairArray.expandNonInitializing();
    244244
    245245        //this is where we add an actual pair, so also call the 'ghost'
     
    468468                return 0;
    469469       
    470         void* mem = &m_overlappingPairArray.expand();
     470        void* mem = &m_overlappingPairArray.expandNonInitializing();
    471471        btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1);
    472472       
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h

    r5781 r8284  
    458458        virtual void    sortOverlappingPairs(btDispatcher* dispatcher)
    459459        {
     460        (void) dispatcher;
    460461        }
    461462
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp

    r5781 r8284  
    1818#include "LinearMath/btAabbUtil2.h"
    1919#include "LinearMath/btIDebugDraw.h"
     20#include "LinearMath/btSerializer.h"
    2021
    2122#define RAYAABB2
     
    7980btVector3 color[4]=
    8081{
    81         btVector3(255,0,0),
    82         btVector3(0,255,0),
    83         btVector3(0,0,255),
    84         btVector3(0,255,255)
     82        btVector3(1,0,0),
     83        btVector3(0,1,0),
     84        btVector3(0,0,1),
     85        btVector3(0,1,1)
    8586};
    8687#endif //DEBUG_PATCH_COLORS
     
    475476        ///what about division by zero? --> just set rayDirection[i] to 1.0
    476477        btVector3 rayDirectionInverse;
    477         rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];
    478         rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];
    479         rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];
     478        rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0];
     479        rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1];
     480        rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2];
    480481        unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};
    481482#endif
     
    494495                bounds[1] = rootNode->m_aabbMaxOrg;
    495496                /* Add box cast extents */
    496                 bounds[0] += aabbMin;
    497                 bounds[1] += aabbMax;
     497                bounds[0] -= aabbMax;
     498                bounds[1] -= aabbMin;
    498499
    499500                aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg);
     
    562563        lambda_max = rayDirection.dot(rayTarget-raySource);
    563564        ///what about division by zero? --> just set rayDirection[i] to 1.0
    564         rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDirection[0];
    565         rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDirection[1];
    566         rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDirection[2];
     565        rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0];
     566        rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[1];
     567        rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[2];
    567568        unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0};
    568569#endif
     
    618619                        bounds[1] = unQuantize(rootNode->m_quantizedAabbMax);
    619620                        /* Add box cast extents */
    620                         bounds[0] += aabbMin;
    621                         bounds[1] += aabbMax;
     621                        bounds[0] -= aabbMax;
     622                        bounds[1] -= aabbMin;
    622623                        btVector3 normal;
    623624#if 0
     
    831832}
    832833
    833 unsigned btQuantizedBvh::calculateSerializeBufferSize()
     834unsigned btQuantizedBvh::calculateSerializeBufferSize() const
    834835{
    835836        unsigned baseSize = sizeof(btQuantizedBvh) + getAlignmentSerializationPadding();
     
    842843}
    843844
    844 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian)
     845bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) const
    845846{
    846847        btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
     
    11441145}
    11451146
    1146 
    1147 
    1148 
     1147void btQuantizedBvh::deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData)
     1148{
     1149        m_bvhAabbMax.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMax);
     1150        m_bvhAabbMin.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMin);
     1151        m_bvhQuantization.deSerializeFloat(quantizedBvhFloatData.m_bvhQuantization);
     1152
     1153        m_curNodeIndex = quantizedBvhFloatData.m_curNodeIndex;
     1154        m_useQuantization = quantizedBvhFloatData.m_useQuantization!=0;
     1155       
     1156        {
     1157                int numElem = quantizedBvhFloatData.m_numContiguousLeafNodes;
     1158                m_contiguousNodes.resize(numElem);
     1159
     1160                if (numElem)
     1161                {
     1162                        btOptimizedBvhNodeFloatData* memPtr = quantizedBvhFloatData.m_contiguousNodesPtr;
     1163
     1164                        for (int i=0;i<numElem;i++,memPtr++)
     1165                        {
     1166                                m_contiguousNodes[i].m_aabbMaxOrg.deSerializeFloat(memPtr->m_aabbMaxOrg);
     1167                                m_contiguousNodes[i].m_aabbMinOrg.deSerializeFloat(memPtr->m_aabbMinOrg);
     1168                                m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex;
     1169                                m_contiguousNodes[i].m_subPart = memPtr->m_subPart;
     1170                                m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex;
     1171                        }
     1172                }
     1173        }
     1174
     1175        {
     1176                int numElem = quantizedBvhFloatData.m_numQuantizedContiguousNodes;
     1177                m_quantizedContiguousNodes.resize(numElem);
     1178               
     1179                if (numElem)
     1180                {
     1181                        btQuantizedBvhNodeData* memPtr = quantizedBvhFloatData.m_quantizedContiguousNodesPtr;
     1182                        for (int i=0;i<numElem;i++,memPtr++)
     1183                        {
     1184                                m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex;
     1185                                m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0];
     1186                                m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
     1187                                m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
     1188                                m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
     1189                                m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
     1190                                m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
     1191                        }
     1192                }
     1193        }
     1194
     1195        m_traversalMode = btTraversalMode(quantizedBvhFloatData.m_traversalMode);
     1196       
     1197        {
     1198                int numElem = quantizedBvhFloatData.m_numSubtreeHeaders;
     1199                m_SubtreeHeaders.resize(numElem);
     1200                if (numElem)
     1201                {
     1202                        btBvhSubtreeInfoData* memPtr = quantizedBvhFloatData.m_subTreeInfoPtr;
     1203                        for (int i=0;i<numElem;i++,memPtr++)
     1204                        {
     1205                                m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ;
     1206                                m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
     1207                                m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
     1208                                m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
     1209                                m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
     1210                                m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
     1211                                m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex;
     1212                                m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize;
     1213                        }
     1214                }
     1215        }
     1216}
     1217
     1218void btQuantizedBvh::deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData)
     1219{
     1220        m_bvhAabbMax.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMax);
     1221        m_bvhAabbMin.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMin);
     1222        m_bvhQuantization.deSerializeDouble(quantizedBvhDoubleData.m_bvhQuantization);
     1223
     1224        m_curNodeIndex = quantizedBvhDoubleData.m_curNodeIndex;
     1225        m_useQuantization = quantizedBvhDoubleData.m_useQuantization!=0;
     1226       
     1227        {
     1228                int numElem = quantizedBvhDoubleData.m_numContiguousLeafNodes;
     1229                m_contiguousNodes.resize(numElem);
     1230
     1231                if (numElem)
     1232                {
     1233                        btOptimizedBvhNodeDoubleData* memPtr = quantizedBvhDoubleData.m_contiguousNodesPtr;
     1234
     1235                        for (int i=0;i<numElem;i++,memPtr++)
     1236                        {
     1237                                m_contiguousNodes[i].m_aabbMaxOrg.deSerializeDouble(memPtr->m_aabbMaxOrg);
     1238                                m_contiguousNodes[i].m_aabbMinOrg.deSerializeDouble(memPtr->m_aabbMinOrg);
     1239                                m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex;
     1240                                m_contiguousNodes[i].m_subPart = memPtr->m_subPart;
     1241                                m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex;
     1242                        }
     1243                }
     1244        }
     1245
     1246        {
     1247                int numElem = quantizedBvhDoubleData.m_numQuantizedContiguousNodes;
     1248                m_quantizedContiguousNodes.resize(numElem);
     1249               
     1250                if (numElem)
     1251                {
     1252                        btQuantizedBvhNodeData* memPtr = quantizedBvhDoubleData.m_quantizedContiguousNodesPtr;
     1253                        for (int i=0;i<numElem;i++,memPtr++)
     1254                        {
     1255                                m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex;
     1256                                m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0];
     1257                                m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
     1258                                m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
     1259                                m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
     1260                                m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
     1261                                m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
     1262                        }
     1263                }
     1264        }
     1265
     1266        m_traversalMode = btTraversalMode(quantizedBvhDoubleData.m_traversalMode);
     1267       
     1268        {
     1269                int numElem = quantizedBvhDoubleData.m_numSubtreeHeaders;
     1270                m_SubtreeHeaders.resize(numElem);
     1271                if (numElem)
     1272                {
     1273                        btBvhSubtreeInfoData* memPtr = quantizedBvhDoubleData.m_subTreeInfoPtr;
     1274                        for (int i=0;i<numElem;i++,memPtr++)
     1275                        {
     1276                                m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ;
     1277                                m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
     1278                                m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
     1279                                m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
     1280                                m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
     1281                                m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
     1282                                m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex;
     1283                                m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize;
     1284                        }
     1285                }
     1286        }
     1287
     1288}
     1289
     1290
     1291
     1292///fills the dataBuffer and returns the struct name (and 0 on failure)
     1293const char*     btQuantizedBvh::serialize(void* dataBuffer, btSerializer* serializer) const
     1294{
     1295        btQuantizedBvhData* quantizedData = (btQuantizedBvhData*)dataBuffer;
     1296       
     1297        m_bvhAabbMax.serialize(quantizedData->m_bvhAabbMax);
     1298        m_bvhAabbMin.serialize(quantizedData->m_bvhAabbMin);
     1299        m_bvhQuantization.serialize(quantizedData->m_bvhQuantization);
     1300
     1301        quantizedData->m_curNodeIndex = m_curNodeIndex;
     1302        quantizedData->m_useQuantization = m_useQuantization;
     1303       
     1304        quantizedData->m_numContiguousLeafNodes = m_contiguousNodes.size();
     1305        quantizedData->m_contiguousNodesPtr = (btOptimizedBvhNodeData*) (m_contiguousNodes.size() ? serializer->getUniquePointer((void*)&m_contiguousNodes[0]) : 0);
     1306        if (quantizedData->m_contiguousNodesPtr)
     1307        {
     1308                int sz = sizeof(btOptimizedBvhNodeData);
     1309                int numElem = m_contiguousNodes.size();
     1310                btChunk* chunk = serializer->allocate(sz,numElem);
     1311                btOptimizedBvhNodeData* memPtr = (btOptimizedBvhNodeData*)chunk->m_oldPtr;
     1312                for (int i=0;i<numElem;i++,memPtr++)
     1313                {
     1314                        m_contiguousNodes[i].m_aabbMaxOrg.serialize(memPtr->m_aabbMaxOrg);
     1315                        m_contiguousNodes[i].m_aabbMinOrg.serialize(memPtr->m_aabbMinOrg);
     1316                        memPtr->m_escapeIndex = m_contiguousNodes[i].m_escapeIndex;
     1317                        memPtr->m_subPart = m_contiguousNodes[i].m_subPart;
     1318                        memPtr->m_triangleIndex = m_contiguousNodes[i].m_triangleIndex;
     1319                }
     1320                serializer->finalizeChunk(chunk,"btOptimizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_contiguousNodes[0]);
     1321        }
     1322
     1323        quantizedData->m_numQuantizedContiguousNodes = m_quantizedContiguousNodes.size();
     1324//      printf("quantizedData->m_numQuantizedContiguousNodes=%d\n",quantizedData->m_numQuantizedContiguousNodes);
     1325        quantizedData->m_quantizedContiguousNodesPtr =(btQuantizedBvhNodeData*) (m_quantizedContiguousNodes.size() ? serializer->getUniquePointer((void*)&m_quantizedContiguousNodes[0]) : 0);
     1326        if (quantizedData->m_quantizedContiguousNodesPtr)
     1327        {
     1328                int sz = sizeof(btQuantizedBvhNodeData);
     1329                int numElem = m_quantizedContiguousNodes.size();
     1330                btChunk* chunk = serializer->allocate(sz,numElem);
     1331                btQuantizedBvhNodeData* memPtr = (btQuantizedBvhNodeData*)chunk->m_oldPtr;
     1332                for (int i=0;i<numElem;i++,memPtr++)
     1333                {
     1334                        memPtr->m_escapeIndexOrTriangleIndex = m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex;
     1335                        memPtr->m_quantizedAabbMax[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[0];
     1336                        memPtr->m_quantizedAabbMax[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[1];
     1337                        memPtr->m_quantizedAabbMax[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[2];
     1338                        memPtr->m_quantizedAabbMin[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[0];
     1339                        memPtr->m_quantizedAabbMin[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[1];
     1340                        memPtr->m_quantizedAabbMin[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[2];
     1341                }
     1342                serializer->finalizeChunk(chunk,"btQuantizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_quantizedContiguousNodes[0]);
     1343        }
     1344
     1345        quantizedData->m_traversalMode = int(m_traversalMode);
     1346        quantizedData->m_numSubtreeHeaders = m_SubtreeHeaders.size();
     1347
     1348        quantizedData->m_subTreeInfoPtr = (btBvhSubtreeInfoData*) (m_SubtreeHeaders.size() ? serializer->getUniquePointer((void*)&m_SubtreeHeaders[0]) : 0);
     1349        if (quantizedData->m_subTreeInfoPtr)
     1350        {
     1351                int sz = sizeof(btBvhSubtreeInfoData);
     1352                int numElem = m_SubtreeHeaders.size();
     1353                btChunk* chunk = serializer->allocate(sz,numElem);
     1354                btBvhSubtreeInfoData* memPtr = (btBvhSubtreeInfoData*)chunk->m_oldPtr;
     1355                for (int i=0;i<numElem;i++,memPtr++)
     1356                {
     1357                        memPtr->m_quantizedAabbMax[0] = m_SubtreeHeaders[i].m_quantizedAabbMax[0];
     1358                        memPtr->m_quantizedAabbMax[1] = m_SubtreeHeaders[i].m_quantizedAabbMax[1];
     1359                        memPtr->m_quantizedAabbMax[2] = m_SubtreeHeaders[i].m_quantizedAabbMax[2];
     1360                        memPtr->m_quantizedAabbMin[0] = m_SubtreeHeaders[i].m_quantizedAabbMin[0];
     1361                        memPtr->m_quantizedAabbMin[1] = m_SubtreeHeaders[i].m_quantizedAabbMin[1];
     1362                        memPtr->m_quantizedAabbMin[2] = m_SubtreeHeaders[i].m_quantizedAabbMin[2];
     1363
     1364                        memPtr->m_rootNodeIndex = m_SubtreeHeaders[i].m_rootNodeIndex;
     1365                        memPtr->m_subtreeSize = m_SubtreeHeaders[i].m_subtreeSize;
     1366                }
     1367                serializer->finalizeChunk(chunk,"btBvhSubtreeInfoData",BT_ARRAY_CODE,(void*)&m_SubtreeHeaders[0]);
     1368        }
     1369        return btQuantizedBvhDataName;
     1370}
     1371
     1372
     1373
     1374
     1375
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h

    r5781 r8284  
    1717#define QUANTIZED_BVH_H
    1818
     19class btSerializer;
     20
    1921//#define DEBUG_CHECK_DEQUANTIZATION 1
    2022#ifdef DEBUG_CHECK_DEQUANTIZATION
     
    2931#include "LinearMath/btVector3.h"
    3032#include "LinearMath/btAlignedAllocator.h"
     33
     34#ifdef BT_USE_DOUBLE_PRECISION
     35#define btQuantizedBvhData btQuantizedBvhDoubleData
     36#define btOptimizedBvhNodeData btOptimizedBvhNodeDoubleData
     37#define btQuantizedBvhDataName "btQuantizedBvhDoubleData"
     38#else
     39#define btQuantizedBvhData btQuantizedBvhFloatData
     40#define btOptimizedBvhNodeData btOptimizedBvhNodeFloatData
     41#define btQuantizedBvhDataName "btQuantizedBvhFloatData"
     42#endif
     43
    3144
    3245
     
    191204
    192205        //This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray
    193         int m_subtreeHeaderCount;
     206        mutable int m_subtreeHeaderCount;
    194207
    195208       
     
    444457        }
    445458
     459////////////////////////////////////////////////////////////////////
    446460
    447461        /////Calculate space needed to store BVH for serialization
    448         unsigned calculateSerializeBufferSize();
     462        unsigned calculateSerializeBufferSize() const;
    449463
    450464        /// Data buffer MUST be 16 byte aligned
    451         virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian);
     465        virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const;
    452466
    453467        ///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place'
     
    455469
    456470        static unsigned int getAlignmentSerializationPadding();
     471//////////////////////////////////////////////////////////////////////
     472
     473       
     474        virtual int     calculateSerializeBufferSizeNew() const;
     475
     476        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     477        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     478
     479        virtual void deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData);
     480
     481        virtual void deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData);
     482
     483
     484////////////////////////////////////////////////////////////////////
    457485
    458486        SIMD_FORCE_INLINE bool isQuantized()
     
    471499
    472500
     501struct  btBvhSubtreeInfoData
     502{
     503        int                     m_rootNodeIndex;
     504        int                     m_subtreeSize;
     505        unsigned short m_quantizedAabbMin[3];
     506        unsigned short m_quantizedAabbMax[3];
     507};
     508
     509struct btOptimizedBvhNodeFloatData
     510{
     511        btVector3FloatData      m_aabbMinOrg;
     512        btVector3FloatData      m_aabbMaxOrg;
     513        int     m_escapeIndex;
     514        int     m_subPart;
     515        int     m_triangleIndex;
     516        char m_pad[4];
     517};
     518
     519struct btOptimizedBvhNodeDoubleData
     520{
     521        btVector3DoubleData     m_aabbMinOrg;
     522        btVector3DoubleData     m_aabbMaxOrg;
     523        int     m_escapeIndex;
     524        int     m_subPart;
     525        int     m_triangleIndex;
     526        char    m_pad[4];
     527};
     528
     529
     530struct btQuantizedBvhNodeData
     531{
     532        unsigned short m_quantizedAabbMin[3];
     533        unsigned short m_quantizedAabbMax[3];
     534        int     m_escapeIndexOrTriangleIndex;
     535};
     536
     537struct  btQuantizedBvhFloatData
     538{
     539        btVector3FloatData                      m_bvhAabbMin;
     540        btVector3FloatData                      m_bvhAabbMax;
     541        btVector3FloatData                      m_bvhQuantization;
     542        int                                     m_curNodeIndex;
     543        int                                     m_useQuantization;
     544        int                                     m_numContiguousLeafNodes;
     545        int                                     m_numQuantizedContiguousNodes;
     546        btOptimizedBvhNodeFloatData     *m_contiguousNodesPtr;
     547        btQuantizedBvhNodeData          *m_quantizedContiguousNodesPtr;
     548        btBvhSubtreeInfoData    *m_subTreeInfoPtr;
     549        int                                     m_traversalMode;
     550        int                                     m_numSubtreeHeaders;
     551       
     552};
     553
     554struct  btQuantizedBvhDoubleData
     555{
     556        btVector3DoubleData                     m_bvhAabbMin;
     557        btVector3DoubleData                     m_bvhAabbMax;
     558        btVector3DoubleData                     m_bvhQuantization;
     559        int                                                     m_curNodeIndex;
     560        int                                                     m_useQuantization;
     561        int                                                     m_numContiguousLeafNodes;
     562        int                                                     m_numQuantizedContiguousNodes;
     563        btOptimizedBvhNodeDoubleData    *m_contiguousNodesPtr;
     564        btQuantizedBvhNodeData                  *m_quantizedContiguousNodesPtr;
     565
     566        int                                                     m_traversalMode;
     567        int                                                     m_numSubtreeHeaders;
     568        btBvhSubtreeInfoData            *m_subTreeInfoPtr;
     569};
     570
     571
     572SIMD_FORCE_INLINE       int     btQuantizedBvh::calculateSerializeBufferSizeNew() const
     573{
     574        return sizeof(btQuantizedBvhData);
     575}
     576
     577
     578
    473579#endif //QUANTIZED_BVH_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp

    r5781 r8284  
    2121#include "LinearMath/btTransform.h"
    2222#include "LinearMath/btMatrix3x3.h"
     23#include "LinearMath/btAabbUtil2.h"
     24
    2325#include <new>
    2426
     
    163165                }
    164166                rayCallback.process(proxy);
     167        }
     168}
     169
     170
     171void    btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
     172{
     173        for (int i=0; i <= m_LastHandleIndex; i++)
     174        {
     175                btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
     176                if(!proxy->m_clientObject)
     177                {
     178                        continue;
     179                }
     180                if (TestAabbAgainstAabb2(aabbMin,aabbMax,proxy->m_aabbMin,proxy->m_aabbMax))
     181                {
     182                        callback.process(proxy);
     183                }
    165184        }
    166185}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h

    r5781 r8284  
    137137
    138138        virtual void    rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
     139        virtual void    aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
    139140               
    140141        btOverlappingPairCache* getOverlappingPairCache()
     
    154155        virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
    155156        {
    156                 aabbMin.setValue(-1e30f,-1e30f,-1e30f);
    157                 aabbMax.setValue(1e30f,1e30f,1e30f);
     157                aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
     158                aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
    158159        }
    159160
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CMakeLists.txt

    r5929 r8284  
    66        BroadphaseCollision/btBroadphaseProxy.cpp
    77        BroadphaseCollision/btCollisionAlgorithm.cpp
     8        BroadphaseCollision/btDbvt.cpp
     9        BroadphaseCollision/btDbvtBroadphase.cpp
    810        BroadphaseCollision/btDispatcher.cpp
    9         BroadphaseCollision/btDbvtBroadphase.cpp
    10         BroadphaseCollision/btDbvt.cpp
    1111        BroadphaseCollision/btMultiSapBroadphase.cpp
    1212        BroadphaseCollision/btOverlappingPairCache.cpp
     
    1515
    1616        CollisionDispatch/btActivatingCollisionAlgorithm.cpp
     17        CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
     18        CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp
     19        CollisionDispatch/btBoxBoxDetector.cpp
    1720        CollisionDispatch/btCollisionDispatcher.cpp
    1821        CollisionDispatch/btCollisionObject.cpp
     
    2023        CollisionDispatch/btCompoundCollisionAlgorithm.cpp
    2124        CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
     25        CollisionDispatch/btConvexConvexAlgorithm.cpp
     26        CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
     27        CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp
    2228        CollisionDispatch/btDefaultCollisionConfiguration.cpp
    23         CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
    24         CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
    25         CollisionDispatch/btBoxBoxDetector.cpp
     29        CollisionDispatch/btEmptyCollisionAlgorithm.cpp
    2630        CollisionDispatch/btGhostObject.cpp
    27         CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
    28         CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
    29         CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
    30         CollisionDispatch/btConvexConvexAlgorithm.cpp
    31         CollisionDispatch/btEmptyCollisionAlgorithm.cpp
     31        CollisionDispatch/btInternalEdgeUtility.cpp
     32        CollisionDispatch/btInternalEdgeUtility.h
    3233        CollisionDispatch/btManifoldResult.cpp
    3334        CollisionDispatch/btSimulationIslandManager.cpp
     35        CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
     36        CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
     37        CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
    3438        CollisionDispatch/btUnionFind.cpp
    3539        CollisionDispatch/SphereTriangleDetector.cpp
    3640
    3741        CollisionShapes/btBoxShape.cpp
     42        CollisionShapes/btBox2dShape.cpp
    3843        CollisionShapes/btBvhTriangleMeshShape.cpp
    3944        CollisionShapes/btCapsuleShape.cpp
     
    4348        CollisionShapes/btConeShape.cpp
    4449        CollisionShapes/btConvexHullShape.cpp
     50        CollisionShapes/btConvexInternalShape.cpp
    4551        CollisionShapes/btConvexPointCloudShape.cpp
    4652        CollisionShapes/btConvexShape.cpp
    47         CollisionShapes/btConvexInternalShape.cpp
     53        CollisionShapes/btConvex2dShape.cpp
    4854        CollisionShapes/btConvexTriangleMeshShape.cpp
    4955        CollisionShapes/btCylinderShape.cpp
     
    5662        CollisionShapes/btPolyhedralConvexShape.cpp
    5763        CollisionShapes/btScaledBvhTriangleMeshShape.cpp
    58         CollisionShapes/btTetrahedronShape.cpp
     64        CollisionShapes/btShapeHull.cpp
    5965        CollisionShapes/btSphereShape.cpp
    60         CollisionShapes/btShapeHull.cpp
    6166        CollisionShapes/btStaticPlaneShape.cpp
    6267        CollisionShapes/btStridingMeshInterface.cpp
     68        CollisionShapes/btTetrahedronShape.cpp
     69        CollisionShapes/btTriangleBuffer.cpp
    6370        CollisionShapes/btTriangleCallback.cpp
    64         CollisionShapes/btTriangleBuffer.cpp
    6571        CollisionShapes/btTriangleIndexVertexArray.cpp
    6672        CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
     
    6975        CollisionShapes/btUniformScalingShape.cpp
    7076
    71         Gimpact/btContactProcessing.cpp
    72         Gimpact/btGImpactShape.cpp
    73         Gimpact/btGImpactBvh.cpp
    74         Gimpact/btGenericPoolAllocator.cpp
    75         Gimpact/btGImpactCollisionAlgorithm.cpp
    76         Gimpact/btTriangleShapeEx.cpp
    77         Gimpact/btGImpactQuantizedBvh.cpp
    78 
    7977        NarrowPhaseCollision/btContinuousConvexCollision.cpp
     78        NarrowPhaseCollision/btConvexCast.cpp
     79        NarrowPhaseCollision/btGjkConvexCast.cpp
    8080        NarrowPhaseCollision/btGjkEpa2.cpp
    8181        NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp
    82         NarrowPhaseCollision/btConvexCast.cpp
    83         NarrowPhaseCollision/btGjkConvexCast.cpp
    8482        NarrowPhaseCollision/btGjkPairDetector.cpp
    8583        NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
     
    9189COMPILATION_END
    9290
    93 COMPILATION_BEGIN BulletGImpactCompilation.cpp
    94         Gimpact/gim_contact.cpp
    95         Gimpact/gim_memory.cpp
    96         Gimpact/gim_tri_collision.cpp
    97         Gimpact/gim_box_set.cpp
    98 COMPILATION_END
    99 
    10091        # Headers
    10192        BroadphaseCollision/btAxisSweep3.h
     
    10394        BroadphaseCollision/btBroadphaseProxy.h
    10495        BroadphaseCollision/btCollisionAlgorithm.h
     96        BroadphaseCollision/btDbvt.h
     97        BroadphaseCollision/btDbvtBroadphase.h
    10598        BroadphaseCollision/btDispatcher.h
    106         BroadphaseCollision/btDbvtBroadphase.h
    107         BroadphaseCollision/btDbvt.h
    10899        BroadphaseCollision/btMultiSapBroadphase.h
    109100        BroadphaseCollision/btOverlappingPairCache.h
     
    113104
    114105        CollisionDispatch/btActivatingCollisionAlgorithm.h
     106        CollisionDispatch/btBoxBoxCollisionAlgorithm.h
     107        CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h
     108        CollisionDispatch/btBoxBoxDetector.h
    115109        CollisionDispatch/btCollisionConfiguration.h
    116110        CollisionDispatch/btCollisionCreateFunc.h
     
    120114        CollisionDispatch/btCompoundCollisionAlgorithm.h
    121115        CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
     116        CollisionDispatch/btConvexConvexAlgorithm.h
     117        CollisionDispatch/btConvex2dConvex2dAlgorithm.h
     118        CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
    122119        CollisionDispatch/btDefaultCollisionConfiguration.h
    123         CollisionDispatch/btSphereSphereCollisionAlgorithm.h
    124         CollisionDispatch/btBoxBoxCollisionAlgorithm.h
    125         CollisionDispatch/btBoxBoxDetector.h
     120        CollisionDispatch/btEmptyCollisionAlgorithm.h
    126121        CollisionDispatch/btGhostObject.h
    127         CollisionDispatch/btSphereBoxCollisionAlgorithm.h
    128         CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
    129         CollisionDispatch/btSphereTriangleCollisionAlgorithm.h
    130         CollisionDispatch/btConvexConvexAlgorithm.h
    131         CollisionDispatch/btEmptyCollisionAlgorithm.h
    132122        CollisionDispatch/btManifoldResult.h
    133123        CollisionDispatch/btSimulationIslandManager.h
     124        CollisionDispatch/btSphereBoxCollisionAlgorithm.h
     125        CollisionDispatch/btSphereSphereCollisionAlgorithm.h
     126        CollisionDispatch/btSphereTriangleCollisionAlgorithm.h
    134127        CollisionDispatch/btUnionFind.h
    135128        CollisionDispatch/SphereTriangleDetector.h
    136129
    137130        CollisionShapes/btBoxShape.h
     131        CollisionShapes/btBox2dShape.h
    138132        CollisionShapes/btBvhTriangleMeshShape.h
    139133        CollisionShapes/btCapsuleShape.h
    140         CollisionShapes/btCollisionMargin
     134        CollisionShapes/btCollisionMargin.h
    141135        CollisionShapes/btCollisionShape.h
    142136        CollisionShapes/btCompoundShape.h
     
    144138        CollisionShapes/btConeShape.h
    145139        CollisionShapes/btConvexHullShape.h
     140        CollisionShapes/btConvexInternalShape.h
    146141        CollisionShapes/btConvexPointCloudShape.h
    147142        CollisionShapes/btConvexShape.h
    148         CollisionShapes/btConvexInternalShape.h
     143        CollisionShapes/btConvex2dShape.h
    149144        CollisionShapes/btConvexTriangleMeshShape.h
    150145        CollisionShapes/btCylinderShape.h
    151146        CollisionShapes/btEmptyShape.h
    152147        CollisionShapes/btHeightfieldTerrainShape.h
     148        CollisionShapes/btMaterial.h
    153149        CollisionShapes/btMinkowskiSumShape.h
    154         CollisionShapes/btMaterial.h
    155150        CollisionShapes/btMultimaterialTriangleMeshShape.h
    156151        CollisionShapes/btMultiSphereShape.h
     
    158153        CollisionShapes/btPolyhedralConvexShape.h
    159154        CollisionShapes/btScaledBvhTriangleMeshShape.h
    160         CollisionShapes/btTetrahedronShape.h
     155        CollisionShapes/btShapeHull.h
    161156        CollisionShapes/btSphereShape.h
    162         CollisionShapes/btShapeHull.h
    163157        CollisionShapes/btStaticPlaneShape.h
    164158        CollisionShapes/btStridingMeshInterface.h
     159        CollisionShapes/btTetrahedronShape.h
     160        CollisionShapes/btTriangleBuffer.h
    165161        CollisionShapes/btTriangleCallback.h
    166         CollisionShapes/btTriangleBuffer.h
    167162        CollisionShapes/btTriangleIndexVertexArray.h
    168163        CollisionShapes/btTriangleIndexVertexMaterialArray.h
     164        CollisionShapes/btTriangleInfoMap.h
    169165        CollisionShapes/btTriangleMesh.h
    170166        CollisionShapes/btTriangleMeshShape.h
     167        CollisionShapes/btTriangleShape.h
    171168        CollisionShapes/btUniformScalingShape.h
    172 
    173         Gimpact/btGImpactShape.h
    174         Gimpact/gim_contact.h
    175         Gimpact/btGImpactBvh.h
    176         Gimpact/btGenericPoolAllocator.h
    177         Gimpact/gim_memory.h
    178         Gimpact/btGImpactCollisionAlgorithm.h
    179         Gimpact/btTriangleShapeEx.h
    180         Gimpact/gim_tri_collision.h
    181         Gimpact/btGImpactQuantizedBvh.h
    182         Gimpact/gim_box_set.h
    183169
    184170        NarrowPhaseCollision/btContinuousConvexCollision.h
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h

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

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btGhostObject.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp

    r5781 r8284  
     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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp

    r5781 r8284  
    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/branches/kicklib2/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h

    r5781 r8284  
    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);
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
    15 
    1615#include "btBoxShape.h"
    1716
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    4242        const btVector3& getHalfExtentsWithoutMargin() const
    4343        {
    44                 return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
     44                return m_implicitShapeDimensions;//scaling is included, margin is not
    4545        }
    4646       
     
    313313};
    314314
     315
    315316#endif //OBB_BOX_MINKOWSKI_H
    316317
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1818#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
    1919#include "BulletCollision/CollisionShapes/btOptimizedBvh.h"
     20#include "LinearMath/btSerializer.h"
    2021
    2122///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
     
    2425:btTriangleMeshShape(meshInterface),
    2526m_bvh(0),
     27m_triangleInfoMap(0),
    2628m_useQuantizedAabbCompression(useQuantizedAabbCompression),
    2729m_ownsBvh(false)
     
    3133#ifndef DISABLE_BVH
    3234
    33         btVector3 bvhAabbMin,bvhAabbMax;
    34         if(meshInterface->hasPremadeAabb())
    35         {
    36                 meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);
    37         }
    38         else
    39         {
    40                 meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);
    41         }
    42        
    4335        if (buildBvh)
    4436        {
    45                 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
    46                 m_bvh = new (mem) btOptimizedBvh();
    47                 m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
    48                 m_ownsBvh = true;
     37                buildOptimizedBvh();
    4938        }
    5039
     
    5645:btTriangleMeshShape(meshInterface),
    5746m_bvh(0),
     47m_triangleInfoMap(0),
    5848m_useQuantizedAabbCompression(useQuantizedAabbCompression),
    5949m_ownsBvh(false)
     
    344334   {
    345335      btTriangleMeshShape::setLocalScaling(scaling);
    346       if (m_ownsBvh)
    347       {
    348          m_bvh->~btOptimizedBvh();
    349          btAlignedFree(m_bvh);
    350       }
    351       ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
    352       void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
    353       m_bvh = new(mem) btOptimizedBvh();
    354       //rebuild the bvh...
    355       m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
    356       m_ownsBvh = true;
     336          buildOptimizedBvh();
    357337   }
     338}
     339
     340void   btBvhTriangleMeshShape::buildOptimizedBvh()
     341{
     342        if (m_ownsBvh)
     343        {
     344                m_bvh->~btOptimizedBvh();
     345                btAlignedFree(m_bvh);
     346        }
     347        ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
     348        void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
     349        m_bvh = new(mem) btOptimizedBvh();
     350        //rebuild the bvh...
     351        m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
     352        m_ownsBvh = true;
    358353}
    359354
     
    373368
    374369
     370
     371///fills the dataBuffer and returns the struct name (and 0 on failure)
     372const char*     btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const
     373{
     374        btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer;
     375
     376        btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer);
     377
     378        m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer);
     379
     380        trimeshData->m_collisionMargin = float(m_collisionMargin);
     381
     382       
     383
     384        if (m_bvh && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_BVH))
     385        {
     386                void* chunk = serializer->findPointer(m_bvh);
     387                if (chunk)
     388                {
     389#ifdef BT_USE_DOUBLE_PRECISION
     390                        trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk;
     391                        trimeshData->m_quantizedFloatBvh = 0;
     392#else
     393                        trimeshData->m_quantizedFloatBvh  = (btQuantizedBvhData*)chunk;
     394                        trimeshData->m_quantizedDoubleBvh= 0;
     395#endif //BT_USE_DOUBLE_PRECISION
     396                } else
     397                {
     398
     399#ifdef BT_USE_DOUBLE_PRECISION
     400                        trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh);
     401                        trimeshData->m_quantizedFloatBvh = 0;
     402#else
     403                        trimeshData->m_quantizedFloatBvh  = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh);
     404                        trimeshData->m_quantizedDoubleBvh= 0;
     405#endif //BT_USE_DOUBLE_PRECISION
     406       
     407                        int sz = m_bvh->calculateSerializeBufferSizeNew();
     408                        btChunk* chunk = serializer->allocate(sz,1);
     409                        const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
     410                        serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,m_bvh);
     411                }
     412        } else
     413        {
     414                trimeshData->m_quantizedFloatBvh = 0;
     415                trimeshData->m_quantizedDoubleBvh = 0;
     416        }
     417
     418       
     419
     420        if (m_triangleInfoMap && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_TRIANGLEINFOMAP))
     421        {
     422                void* chunk = serializer->findPointer(m_triangleInfoMap);
     423                if (chunk)
     424                {
     425                        trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)chunk;
     426                } else
     427                {
     428                        trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)serializer->getUniquePointer(m_triangleInfoMap);
     429                        int sz = m_triangleInfoMap->calculateSerializeBufferSize();
     430                        btChunk* chunk = serializer->allocate(sz,1);
     431                        const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer);
     432                        serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,m_triangleInfoMap);
     433                }
     434        } else
     435        {
     436                trimeshData->m_triangleInfoMap = 0;
     437        }
     438
     439        return "btTriangleMeshShapeData";
     440}
     441
     442void    btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const
     443{
     444        if (m_bvh)
     445        {
     446                int len = m_bvh->calculateSerializeBufferSizeNew(); //make sure not to use calculateSerializeBufferSize because it is used for in-place
     447                btChunk* chunk = serializer->allocate(len,1);
     448                const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
     449                serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,(void*)m_bvh);
     450        }
     451}
     452
     453void    btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const
     454{
     455        if (m_triangleInfoMap)
     456        {
     457                int len = m_triangleInfoMap->calculateSerializeBufferSize();
     458                btChunk* chunk = serializer->allocate(len,1);
     459                const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer);
     460                serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,(void*)m_triangleInfoMap);
     461        }
     462}
     463
     464
     465
     466
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2020#include "btOptimizedBvh.h"
    2121#include "LinearMath/btAlignedAllocator.h"
    22 
     22#include "btTriangleInfoMap.h"
    2323
    2424///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage.
     
    3030
    3131        btOptimizedBvh* m_bvh;
     32        btTriangleInfoMap*      m_triangleInfoMap;
     33
    3234        bool m_useQuantizedAabbCompression;
    3335        bool m_ownsBvh;
     
    3840        BT_DECLARE_ALIGNED_ALLOCATOR();
    3941
    40         btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};
     42        btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_triangleInfoMap(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};
    4143        btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
    4244
     
    7476        }
    7577
     78        void    setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));
    7679
    77         void    setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));
     80        void    buildOptimizedBvh();
    7881
    7982        bool    usesQuantizedAabbCompression() const
     
    8184                return  m_useQuantizedAabbCompression;
    8285        }
     86
     87        void    setTriangleInfoMap(btTriangleInfoMap* triangleInfoMap)
     88        {
     89                m_triangleInfoMap = triangleInfoMap;
     90        }
     91
     92        const btTriangleInfoMap*        getTriangleInfoMap() const
     93        {
     94                return m_triangleInfoMap;
     95        }
     96       
     97        btTriangleInfoMap*      getTriangleInfoMap()
     98        {
     99                return m_triangleInfoMap;
     100        }
     101
     102        virtual int     calculateSerializeBufferSize() const;
     103
     104        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     105        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     106
     107        virtual void    serializeSingleBvh(btSerializer* serializer) const;
     108
     109        virtual void    serializeSingleTriangleInfoMap(btSerializer* serializer) const;
     110
     111};
     112
     113///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     114struct  btTriangleMeshShapeData
     115{
     116        btCollisionShapeData    m_collisionShapeData;
     117
     118        btStridingMeshInterfaceData m_meshInterface;
     119
     120        btQuantizedBvhFloatData         *m_quantizedFloatBvh;
     121        btQuantizedBvhDoubleData        *m_quantizedDoubleBvh;
     122
     123        btTriangleInfoMapData   *m_triangleInfoMap;
     124       
     125        float   m_collisionMargin;
     126
     127        char m_pad3[4];
     128       
     129};
     130
     131
     132SIMD_FORCE_INLINE       int     btBvhTriangleMeshShape::calculateSerializeBufferSize() const
     133{
     134        return sizeof(btTriangleMeshShapeData);
    83135}
    84 ;
     136
     137
    85138
    86139#endif //BVH_TRIANGLE_MESH_SHAPE_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    3333        btVector3 supVec(0,0,0);
    3434
    35         btScalar maxDot(btScalar(-1e30));
     35        btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    3636
    3737        btVector3 vec = vec0;
     
    8989        for (int j=0;j<numVectors;j++)
    9090        {
    91                 btScalar maxDot(btScalar(-1e30));
     91                btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    9292                const btVector3& vec = vectors[j];
    9393
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    4444        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
    4545       
     46        virtual void setMargin(btScalar collisionMargin)
     47        {
     48                //correct the m_implicitShapeDimensions for the margin
     49                btVector3 oldMargin(getMargin(),getMargin(),getMargin());
     50                btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
     51               
     52                btConvexInternalShape::setMargin(collisionMargin);
     53                btVector3 newMargin(getMargin(),getMargin(),getMargin());
     54                m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
     55
     56        }
     57
    4658        virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
    4759        {
     
    7789                return m_implicitShapeDimensions[m_upAxis];
    7890        }
     91
     92        virtual void    setLocalScaling(const btVector3& scaling)
     93        {
     94                btVector3 oldMargin(getMargin(),getMargin(),getMargin());
     95                btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
     96                btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
     97
     98                btConvexInternalShape::setLocalScaling(scaling);
     99
     100                m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
     101
     102        }
     103
     104        virtual int     calculateSerializeBufferSize() const;
     105
     106        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     107        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     108
    79109
    80110};
     
    114144};
    115145
     146///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     147struct  btCapsuleShapeData
     148{
     149        btConvexInternalShapeData       m_convexInternalShapeData;
    116150
     151        int     m_upAxis;
     152
     153        char    m_padding[4];
     154};
     155
     156SIMD_FORCE_INLINE       int     btCapsuleShape::calculateSerializeBufferSize() const
     157{
     158        return sizeof(btCapsuleShapeData);
     159}
     160
     161        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     162SIMD_FORCE_INLINE       const char*     btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const
     163{
     164        btCapsuleShapeData* shapeData = (btCapsuleShapeData*) dataBuffer;
     165       
     166        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
     167
     168        shapeData->m_upAxis = m_upAxis;
     169       
     170        return "btCapsuleShapeData";
     171}
    117172
    118173#endif //BT_CAPSULE_SHAPE_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCollisionMargin.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
    15 
    1615#include "BulletCollision/CollisionShapes/btCollisionShape.h"
    17 
    18 
    19 btScalar gContactThresholdFactor=btScalar(0.02);
    20 
     16#include "LinearMath/btSerializer.h"
    2117
    2218/*
     
    4642}
    4743
    48 btScalar        btCollisionShape::getContactBreakingThreshold() const
     44
     45btScalar        btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const
    4946{
    50         return getAngularMotionDisc() * gContactThresholdFactor;
     47        return getAngularMotionDisc() * defaultContactThreshold;
    5148}
     49
    5250btScalar        btCollisionShape::getAngularMotionDisc() const
    5351{
     
    9795        temporalAabbMax += angularMotion3d;
    9896}
     97
     98///fills the dataBuffer and returns the struct name (and 0 on failure)
     99const char*     btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const
     100{
     101        btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer;
     102        char* name = (char*) serializer->findNameForPointer(this);
     103        shapeData->m_name = (char*)serializer->getUniquePointer(name);
     104        if (shapeData->m_name)
     105        {
     106                serializer->serializeName(name);
     107        }
     108        shapeData->m_shapeType = m_shapeType;
     109        //shapeData->m_padding//??
     110        return "btCollisionShapeData";
     111}
     112
     113void    btCollisionShape::serializeSingleShape(btSerializer* serializer) const
     114{
     115        int len = calculateSerializeBufferSize();
     116        btChunk* chunk = serializer->allocate(len,1);
     117        const char* structType = serialize(chunk->m_oldPtr, serializer);
     118        serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this);
     119}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2121#include "LinearMath/btMatrix3x3.h"
    2222#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
     23class btSerializer;
     24
    2325
    2426///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
     
    4749        virtual btScalar        getAngularMotionDisc() const;
    4850
    49         virtual btScalar        getContactBreakingThreshold() const;
     51        virtual btScalar        getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
    5052
    5153
     
    5456        void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
    5557
    56 #ifndef __SPU__
     58
    5759
    5860        SIMD_FORCE_INLINE bool  isPolyhedral() const
     
    6163        }
    6264
     65        SIMD_FORCE_INLINE bool  isConvex2d() const
     66        {
     67                return btBroadphaseProxy::isConvex2d(getShapeType());
     68        }
     69
    6370        SIMD_FORCE_INLINE bool  isConvex() const
    6471        {
    6572                return btBroadphaseProxy::isConvex(getShapeType());
     73        }
     74        SIMD_FORCE_INLINE bool  isNonMoving() const
     75        {
     76                return btBroadphaseProxy::isNonMoving(getShapeType());
    6677        }
    6778        SIMD_FORCE_INLINE bool  isConcave() const
     
    7485        }
    7586
     87        SIMD_FORCE_INLINE bool  isSoftBody() const
     88        {
     89                return btBroadphaseProxy::isSoftBody(getShapeType());
     90        }
     91
    7692        ///isInfinite is used to catch simulation error (aabb check)
    7793        SIMD_FORCE_INLINE bool isInfinite() const
     
    8096        }
    8197
    82        
     98#ifndef __SPU__
    8399        virtual void    setLocalScaling(const btVector3& scaling) =0;
    84100        virtual const btVector3& getLocalScaling() const =0;
     
    107123        }
    108124
     125        virtual int     calculateSerializeBufferSize() const;
     126
     127        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     128        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     129
     130        virtual void    serializeSingleShape(btSerializer* serializer) const;
     131
    109132};     
     133
     134///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     135struct  btCollisionShapeData
     136{
     137        char    *m_name;
     138        int             m_shapeType;
     139        char    m_padding[4];
     140};
     141
     142SIMD_FORCE_INLINE       int     btCollisionShape::calculateSerializeBufferSize() const
     143{
     144        return sizeof(btCollisionShapeData);
     145}
     146
     147
    110148
    111149#endif //COLLISION_SHAPE_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1717#include "btCollisionShape.h"
    1818#include "BulletCollision/BroadphaseCollision/btDbvt.h"
     19#include "LinearMath/btSerializer.h"
    1920
    2021btCompoundShape::btCompoundShape(bool enableDynamicAabbTree)
    21 : m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
    22 m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
     22: m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)),
     23m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)),
     24m_dynamicAabbTree(0),
     25m_updateRevision(1),
    2326m_collisionMargin(btScalar(0.)),
    24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
    25 m_dynamicAabbTree(0),
    26 m_updateRevision(1)
     27m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
    2728{
    2829        m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
     
    5253        //m_childShapes.push_back(shape);
    5354        btCompoundShapeChild child;
     55        child.m_node = 0;
    5456        child.m_transform = localTransform;
    5557        child.m_childShape = shape;
     
    9496                m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax);
    9597                ATTRIBUTE_ALIGNED16(btDbvtVolume)       bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
    96                 int index = m_children.size()-1;
     98                //int index = m_children.size()-1;
    9799                m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds);
    98100        }
     
    110112        }
    111113        m_children.swap(childShapeIndex,m_children.size()-1);
     114    if (m_dynamicAabbTree)
     115                m_children[childShapeIndex].m_node->dataAsInt = childShapeIndex;
    112116        m_children.pop_back();
    113117
     
    125129                if(m_children[i].m_childShape == shape)
    126130                {
    127                         m_children.swap(i,m_children.size()-1);
    128                         m_children.pop_back();
    129                         //remove it from the m_dynamicAabbTree too
    130                         //@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm
    131                         //so effectively, removeChildShape is broken at the moment
    132                         //m_dynamicAabbTree->remove(m_aabbProxies[i]);
    133                         //m_aabbProxies.swap(i,m_children.size()-1);
    134                         //m_aabbProxies.pop_back();
     131                        removeChildShapeByIndex(i);
    135132                }
    136133        }
     
    146143        // Brute force, it iterates over all the shapes left.
    147144
    148         m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
    149         m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
     145        m_localAabbMin = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     146        m_localAabbMax = btVector3(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
    150147
    151148        //extend the local aabbMin/aabbMax
     
    224221        for (k = 0; k < n; k++)
    225222        {
     223                btAssert(masses[k]>0);
    226224                center += m_children[k].m_transform.getOrigin() * masses[k];
    227225                totalMass += masses[k];
    228226        }
     227
     228        btAssert(totalMass>0);
     229
    229230        center /= totalMass;
    230231        principal.setOrigin(center);
     
    272273
    273274
     275void btCompoundShape::setLocalScaling(const btVector3& scaling)
     276{
     277
     278        for(int i = 0; i < m_children.size(); i++)
     279        {
     280                btTransform childTrans = getChildTransform(i);
     281                btVector3 childScale = m_children[i].m_childShape->getLocalScaling();
     282//              childScale = childScale * (childTrans.getBasis() * scaling);
     283                childScale = childScale * scaling / m_localScaling;
     284                m_children[i].m_childShape->setLocalScaling(childScale);
     285                childTrans.setOrigin((childTrans.getOrigin())*scaling);
     286                updateChildTransform(i, childTrans);
     287                recalculateLocalAabb();
     288        }
     289        m_localScaling = scaling;
     290}
     291
     292
     293void btCompoundShape::createAabbTreeFromChildren()
     294{
     295    if ( !m_dynamicAabbTree )
     296    {
     297        void* mem = btAlignedAlloc(sizeof(btDbvt),16);
     298        m_dynamicAabbTree = new(mem) btDbvt();
     299        btAssert(mem==m_dynamicAabbTree);
     300
     301        for ( int index = 0; index < m_children.size(); index++ )
     302        {
     303            btCompoundShapeChild &child = m_children[index];
     304
     305            //extend the local aabbMin/aabbMax
     306            btVector3 localAabbMin,localAabbMax;
     307            child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax);
     308
     309            const btDbvtVolume  bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
     310            child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
     311        }
     312    }
     313}
     314
     315
     316///fills the dataBuffer and returns the struct name (and 0 on failure)
     317const char*     btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const
     318{
     319
     320        btCompoundShapeData* shapeData = (btCompoundShapeData*) dataBuffer;
     321        btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer);
     322
     323        shapeData->m_collisionMargin = float(m_collisionMargin);
     324        shapeData->m_numChildShapes = m_children.size();
     325        shapeData->m_childShapePtr = 0;
     326        if (shapeData->m_numChildShapes)
     327        {
     328                btChunk* chunk = serializer->allocate(sizeof(btCompoundShapeChildData),shapeData->m_numChildShapes);
     329                btCompoundShapeChildData* memPtr = (btCompoundShapeChildData*)chunk->m_oldPtr;
     330                shapeData->m_childShapePtr = (btCompoundShapeChildData*)serializer->getUniquePointer(memPtr);
     331
     332                for (int i=0;i<shapeData->m_numChildShapes;i++,memPtr++)
     333                {
     334                        memPtr->m_childMargin = float(m_children[i].m_childMargin);
     335                        memPtr->m_childShape = (btCollisionShapeData*)serializer->getUniquePointer(m_children[i].m_childShape);
     336                        //don't serialize shapes that already have been serialized
     337                        if (!serializer->findPointer(m_children[i].m_childShape))
     338                        {
     339                                btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(),1);
     340                                const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr,serializer);
     341                                serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,m_children[i].m_childShape);
     342                        }
     343
     344                        memPtr->m_childShapeType = m_children[i].m_childShapeType;
     345                        m_children[i].m_transform.serializeFloat(memPtr->m_transform);
     346                }
     347                serializer->finalizeChunk(chunk,"btCompoundShapeChildData",BT_ARRAY_CODE,chunk->m_oldPtr);
     348        }
     349        return "btCompoundShapeData";
     350}
     351
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    6363        int                                                             m_updateRevision;
    6464
     65        btScalar        m_collisionMargin;
     66
     67protected:
     68        btVector3       m_localScaling;
     69
    6570public:
    6671        BT_DECLARE_ALIGNED_ALLOCATOR();
     
    117122        virtual void recalculateLocalAabb();
    118123
    119         virtual void    setLocalScaling(const btVector3& scaling)
    120         {
    121                 m_localScaling = scaling;
    122         }
     124        virtual void    setLocalScaling(const btVector3& scaling);
     125
    123126        virtual const btVector3& getLocalScaling() const
    124127        {
     
    141144        }
    142145
    143         //this is optional, but should make collision queries faster, by culling non-overlapping nodes
    144         void    createAabbTreeFromChildren();
    145146
    146147        btDbvt*                                                 getDynamicAabbTree()
     
    148149                return m_dynamicAabbTree;
    149150        }
     151
     152        void createAabbTreeFromChildren();
    150153
    151154        ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia
     
    161164        }
    162165
    163 private:
    164         btScalar        m_collisionMargin;
    165 protected:
    166         btVector3       m_localScaling;
    167 
    168 };
     166        virtual int     calculateSerializeBufferSize() const;
     167
     168        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     169        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     170
     171
     172};
     173
     174///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     175struct btCompoundShapeChildData
     176{
     177        btTransformFloatData    m_transform;
     178        btCollisionShapeData    *m_childShape;
     179        int                                             m_childShapeType;
     180        float                                   m_childMargin;
     181};
     182
     183///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     184struct  btCompoundShapeData
     185{
     186        btCollisionShapeData            m_collisionShapeData;
     187
     188        btCompoundShapeChildData        *m_childShapePtr;
     189
     190        int                                                     m_numChildShapes;
     191
     192        float   m_collisionMargin;
     193
     194};
     195
     196
     197SIMD_FORCE_INLINE       int     btCompoundShape::calculateSerializeBufferSize() const
     198{
     199        return sizeof(btCompoundShapeData);
     200}
     201
     202
     203
     204
    169205
    170206
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.cpp

    r5781 r8284  
    1 
    21/*
    32Bullet Continuous Collision Detection and Physics Library
    4 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    54
    65This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516#include "btConvexHullShape.h"
    1617#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
    1718
    1819#include "LinearMath/btQuaternion.h"
    19 
    20 
    21 
    22 btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexShape ()
     20#include "LinearMath/btSerializer.h"
     21
     22btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexAabbCachingShape ()
    2323{
    2424        m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
    2525        m_unscaledPoints.resize(numPoints);
    2626
    27         unsigned char* pointsBaseAddress = (unsigned char*)points;
     27        unsigned char* pointsAddress = (unsigned char*)points;
    2828
    2929        for (int i=0;i<numPoints;i++)
    3030        {
    31                 btVector3* point = (btVector3*)(pointsBaseAddress + i*stride);
    32                 m_unscaledPoints[i] = point[0];
     31                btScalar* point = (btScalar*)pointsAddress;
     32                m_unscaledPoints[i] = btVector3(point[0], point[1], point[2]);
     33                pointsAddress += stride;
    3334        }
    3435
     
    5253}
    5354
    54 btVector3       btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
     55btVector3       btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
    5556{
    5657        btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
    57         btScalar newDot,maxDot = btScalar(-1e30);
    58 
    59         btVector3 vec = vec0;
    60         btScalar lenSqr = vec.length2();
    61         if (lenSqr < btScalar(0.0001))
    62         {
    63                 vec.setValue(1,0,0);
    64         } else
    65         {
    66                 btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
    67                 vec *= rlen;
    68         }
    69 
     58        btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
    7059
    7160        for (int i=0;i<m_unscaledPoints.size();i++)
     
    9079                for (int i=0;i<numVectors;i++)
    9180                {
    92                         supportVerticesOut[i][3] = btScalar(-1e30);
     81                        supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
    9382                }
    9483        }
     
    186175}
    187176
     177///fills the dataBuffer and returns the struct name (and 0 on failure)
     178const char*     btConvexHullShape::serialize(void* dataBuffer, btSerializer* serializer) const
     179{
     180        //int szc = sizeof(btConvexHullShapeData);
     181        btConvexHullShapeData* shapeData = (btConvexHullShapeData*) dataBuffer;
     182        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
     183
     184        int numElem = m_unscaledPoints.size();
     185        shapeData->m_numUnscaledPoints = numElem;
     186#ifdef BT_USE_DOUBLE_PRECISION
     187        shapeData->m_unscaledPointsFloatPtr = 0;
     188        shapeData->m_unscaledPointsDoublePtr = numElem ? (btVector3Data*)serializer->getUniquePointer((void*)&m_unscaledPoints[0]):  0;
     189#else
     190        shapeData->m_unscaledPointsFloatPtr = numElem ? (btVector3Data*)serializer->getUniquePointer((void*)&m_unscaledPoints[0]):  0;
     191        shapeData->m_unscaledPointsDoublePtr = 0;
     192#endif
     193       
     194        if (numElem)
     195        {
     196                int sz = sizeof(btVector3Data);
     197        //      int sz2 = sizeof(btVector3DoubleData);
     198        //      int sz3 = sizeof(btVector3FloatData);
     199                btChunk* chunk = serializer->allocate(sz,numElem);
     200                btVector3Data* memPtr = (btVector3Data*)chunk->m_oldPtr;
     201                for (int i=0;i<numElem;i++,memPtr++)
     202                {
     203                        m_unscaledPoints[i].serialize(*memPtr);
     204                }
     205                serializer->finalizeChunk(chunk,btVector3DataName,BT_ARRAY_CODE,(void*)&m_unscaledPoints[0]);
     206        }
     207       
     208        return "btConvexHullShapeData";
     209}
     210
     211
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2121#include "LinearMath/btAlignedObjectArray.h"
    2222
     23
    2324///The btConvexHullShape implements an implicit convex hull of an array of vertices.
    2425///Bullet provides a general and fast collision detector for convex shapes based on GJK and EPA using localGetSupportingVertex.
    25 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
     26ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexAabbCachingShape
    2627{
    2728        btAlignedObjectArray<btVector3> m_unscaledPoints;
     
    8990        virtual void    setLocalScaling(const btVector3& scaling);
    9091
     92        virtual int     calculateSerializeBufferSize() const;
     93
     94        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     95        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     96
    9197};
     98
     99///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     100struct  btConvexHullShapeData
     101{
     102        btConvexInternalShapeData       m_convexInternalShapeData;
     103
     104        btVector3FloatData      *m_unscaledPointsFloatPtr;
     105        btVector3DoubleData     *m_unscaledPointsDoublePtr;
     106
     107        int             m_numUnscaledPoints;
     108        char m_padding3[4];
     109
     110};
     111
     112
     113SIMD_FORCE_INLINE       int     btConvexHullShape::calculateSerializeBufferSize() const
     114{
     115        return sizeof(btConvexHullShapeData);
     116}
    92117
    93118
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    3535void    btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const
    3636{
    37 
     37#ifndef __SPU__
     38        //use localGetSupportingVertexWithoutMargin?
    3839        btScalar margin = getMargin();
    3940        for (int i=0;i<3;i++)
     
    5051                minAabb[i] = tmp[i]-margin;
    5152        }
     53#endif
    5254}
    5355
     
    8082
    8183
     84btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape()
     85        :       btConvexInternalShape(),
     86m_localAabbMin(1,1,1),
     87m_localAabbMax(-1,-1,-1),
     88m_isLocalAabbValid(false)
     89{
     90}
     91
     92
     93void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
     94{
     95        getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin());
     96}
     97
     98void    btConvexInternalAabbCachingShape::setLocalScaling(const btVector3& scaling)
     99{
     100        btConvexInternalShape::setLocalScaling(scaling);
     101        recalcLocalAabb();
     102}
     103
     104
     105void    btConvexInternalAabbCachingShape::recalcLocalAabb()
     106{
     107        m_isLocalAabbValid = true;
     108       
     109        #if 1
     110        static const btVector3 _directions[] =
     111        {
     112                btVector3( 1.,  0.,  0.),
     113                btVector3( 0.,  1.,  0.),
     114                btVector3( 0.,  0.,  1.),
     115                btVector3( -1., 0.,  0.),
     116                btVector3( 0., -1.,  0.),
     117                btVector3( 0.,  0., -1.)
     118        };
     119       
     120        btVector3 _supporting[] =
     121        {
     122                btVector3( 0., 0., 0.),
     123                btVector3( 0., 0., 0.),
     124                btVector3( 0., 0., 0.),
     125                btVector3( 0., 0., 0.),
     126                btVector3( 0., 0., 0.),
     127                btVector3( 0., 0., 0.)
     128        };
     129       
     130        batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
     131       
     132        for ( int i = 0; i < 3; ++i )
     133        {
     134                m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin;
     135                m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin;
     136        }
     137       
     138        #else
     139
     140        for (int i=0;i<3;i++)
     141        {
     142                btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.));
     143                vec[i] = btScalar(1.);
     144                btVector3 tmp = localGetSupportingVertex(vec);
     145                m_localAabbMax[i] = tmp[i]+m_collisionMargin;
     146                vec[i] = btScalar(-1.);
     147                tmp = localGetSupportingVertex(vec);
     148                m_localAabbMin[i] = tmp[i]-m_collisionMargin;
     149        }
     150        #endif
     151}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h

    r5781 r8284  
     1/*
     2Bullet Continuous Collision Detection and Physics Library
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
     4
     5This software is provided 'as-is', without any express or implied warranty.
     6In no event will the authors be held liable for any damages arising from the use of this software.
     7Permission is granted to anyone to use this software for any purpose,
     8including commercial applications, and to alter it and redistribute it freely,
     9subject to the following restrictions:
     10
     111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
     122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
     133. This notice may not be removed or altered from any source distribution.
     14*/
    115
    216#ifndef BT_CONVEX_INTERNAL_SHAPE_H
     
    418
    519#include "btConvexShape.h"
     20#include "LinearMath/btAabbUtil2.h"
     21
    622
    723///The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
     
    3652        {
    3753                return m_implicitShapeDimensions;
     54        }
     55
     56        ///warning: use setImplicitShapeDimensions with care
     57        ///changing a collision shape while the body is in the world is not recommended,
     58        ///it is best to remove the body from the world, then make the change, and re-add it
     59        ///alternatively flush the contact points, see documentation for 'cleanProxyFromPairs'
     60        void    setImplicitShapeDimensions(const btVector3& dimensions)
     61        {
     62                m_implicitShapeDimensions = dimensions;
    3863        }
    3964
     
    86111        }
    87112
     113        virtual int     calculateSerializeBufferSize() const;
     114
     115        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     116        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
    88117
    89118       
    90119};
    91120
     121///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     122struct  btConvexInternalShapeData
     123{
     124        btCollisionShapeData    m_collisionShapeData;
     125
     126        btVector3FloatData      m_localScaling;
     127
     128        btVector3FloatData      m_implicitShapeDimensions;
     129       
     130        float                   m_collisionMargin;
     131
     132        int     m_padding;
     133
     134};
     135
     136
     137
     138SIMD_FORCE_INLINE       int     btConvexInternalShape::calculateSerializeBufferSize() const
     139{
     140        return sizeof(btConvexInternalShapeData);
     141}
     142
     143///fills the dataBuffer and returns the struct name (and 0 on failure)
     144SIMD_FORCE_INLINE       const char*     btConvexInternalShape::serialize(void* dataBuffer, btSerializer* serializer) const
     145{
     146        btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer;
     147        btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer);
     148
     149        m_implicitShapeDimensions.serializeFloat(shapeData->m_implicitShapeDimensions);
     150        m_localScaling.serializeFloat(shapeData->m_localScaling);
     151        shapeData->m_collisionMargin = float(m_collisionMargin);
     152
     153        return "btConvexInternalShapeData";
     154}
     155
     156
     157
     158
     159///btConvexInternalAabbCachingShape adds local aabb caching for convex shapes, to avoid expensive bounding box calculations
     160class btConvexInternalAabbCachingShape : public btConvexInternalShape
     161{
     162        btVector3       m_localAabbMin;
     163        btVector3       m_localAabbMax;
     164        bool            m_isLocalAabbValid;
     165       
     166protected:
     167                                       
     168        btConvexInternalAabbCachingShape();
     169       
     170        void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax)
     171        {
     172                m_isLocalAabbValid = true;
     173                m_localAabbMin = aabbMin;
     174                m_localAabbMax = aabbMax;
     175        }
     176
     177        inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const
     178        {
     179                btAssert(m_isLocalAabbValid);
     180                aabbMin = m_localAabbMin;
     181                aabbMax = m_localAabbMax;
     182        }
     183
     184        inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
     185        {
     186
     187                //lazy evaluation of local aabb
     188                btAssert(m_isLocalAabbValid);
     189                btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax);
     190        }
     191               
     192public:
     193               
     194        virtual void    setLocalScaling(const btVector3& scaling);
     195
     196        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
     197
     198        void    recalcLocalAabb();
     199
     200};
    92201
    93202#endif //BT_CONVEX_INTERNAL_SHAPE_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516#include "btConvexPointCloudShape.h"
    1617#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
     
    2829{
    2930        btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
    30         btScalar newDot,maxDot = btScalar(-1e30);
     31        btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
    3132
    3233        btVector3 vec = vec0;
     
    6364                for (int i=0;i<numVectors;i++)
    6465                {
    65                         supportVerticesOut[i][3] = btScalar(-1e30);
     66                        supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
    6667                }
    6768        }
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2222
    2323///The btConvexPointCloudShape implements an implicit convex hull of an array of vertices.
    24 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape
     24ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexAabbCachingShape
    2525{
    2626        btVector3* m_unscaledPoints;
     
    2929public:
    3030        BT_DECLARE_ALIGNED_ALLOCATOR();
     31
     32        btConvexPointCloudShape()
     33        {
     34                m_localScaling.setValue(1.f,1.f,1.f);
     35                m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
     36                m_unscaledPoints = 0;
     37                m_numPoints = 0;
     38        }
    3139
    3240        btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true)
     
    4149        }
    4250
    43         void setPoints (btVector3* points, int numPoints, bool computeAabb = true)
     51        void setPoints (btVector3* points, int numPoints, bool computeAabb = true,const btVector3& localScaling=btVector3(1.f,1.f,1.f))
    4452        {
    4553                m_unscaledPoints = points;
    4654                m_numPoints = numPoints;
     55                m_localScaling = localScaling;
    4756
    4857                if (computeAabb)
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2222#include "btConvexPointCloudShape.h"
    2323
     24///not supported on IBM SDK, until we fix the alignment of btVector3
     25#if defined (__CELLOS_LV2__) && defined (__SPU__)
     26#include <spu_intrinsics.h>
     27static inline vec_float4 vec_dot3( vec_float4 vec0, vec_float4 vec1 )
     28{
     29    vec_float4 result;
     30    result = spu_mul( vec0, vec1 );
     31    result = spu_madd( spu_rlqwbyte( vec0, 4 ), spu_rlqwbyte( vec1, 4 ), result );
     32    return spu_madd( spu_rlqwbyte( vec0, 8 ), spu_rlqwbyte( vec1, 8 ), result );
     33}
     34#endif //__SPU__
     35
    2436btConvexShape::btConvexShape ()
    2537{
     
    3345
    3446
    35 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling)
    36 {
    37         btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
    38         btScalar newDot,maxDot = btScalar(-1e30);
    39 
    40         btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());
    41         btVector3 vec = vec0;
    42         btScalar lenSqr = vec.length2();
    43         if (lenSqr < btScalar(0.0001))
    44         {
    45                 vec.setValue(1,0,0);
    46         } else {
    47                 btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
    48                 vec *= rlen;
    49         }
    50 
     47static btVector3 convexHullSupport (const btVector3& localDirOrg, const btVector3* points, int numPoints, const btVector3& localScaling)
     48{       
     49
     50        btVector3 vec = localDirOrg * localScaling;
     51
     52#if defined (__CELLOS_LV2__) && defined (__SPU__)
     53
     54        btVector3 localDir = vec;
     55
     56        vec_float4 v_distMax = {-FLT_MAX,0,0,0};
     57        vec_int4 v_idxMax = {-999,0,0,0};
     58        int v=0;
     59        int numverts = numPoints;
     60
     61        for(;v<(int)numverts-4;v+=4) {
     62                vec_float4 p0 = vec_dot3(points[v  ].get128(),localDir.get128());
     63                vec_float4 p1 = vec_dot3(points[v+1].get128(),localDir.get128());
     64                vec_float4 p2 = vec_dot3(points[v+2].get128(),localDir.get128());
     65                vec_float4 p3 = vec_dot3(points[v+3].get128(),localDir.get128());
     66                const vec_int4 i0 = {v  ,0,0,0};
     67                const vec_int4 i1 = {v+1,0,0,0};
     68                const vec_int4 i2 = {v+2,0,0,0};
     69                const vec_int4 i3 = {v+3,0,0,0};
     70                vec_uint4  retGt01 = spu_cmpgt(p0,p1);
     71                vec_float4 pmax01 = spu_sel(p1,p0,retGt01);
     72                vec_int4   imax01 = spu_sel(i1,i0,retGt01);
     73                vec_uint4  retGt23 = spu_cmpgt(p2,p3);
     74                vec_float4 pmax23 = spu_sel(p3,p2,retGt23);
     75                vec_int4   imax23 = spu_sel(i3,i2,retGt23);
     76                vec_uint4  retGt0123 = spu_cmpgt(pmax01,pmax23);
     77                vec_float4 pmax0123 = spu_sel(pmax23,pmax01,retGt0123);
     78                vec_int4   imax0123 = spu_sel(imax23,imax01,retGt0123);
     79                vec_uint4  retGtMax = spu_cmpgt(v_distMax,pmax0123);
     80                v_distMax = spu_sel(pmax0123,v_distMax,retGtMax);
     81                v_idxMax = spu_sel(imax0123,v_idxMax,retGtMax);
     82        }
     83        for(;v<(int)numverts;v++) {
     84                vec_float4 p = vec_dot3(points[v].get128(),localDir.get128());
     85                const vec_int4 i = {v,0,0,0};
     86                vec_uint4  retGtMax = spu_cmpgt(v_distMax,p);
     87                v_distMax = spu_sel(p,v_distMax,retGtMax);
     88                v_idxMax = spu_sel(i,v_idxMax,retGtMax);
     89        }
     90        int ptIndex = spu_extract(v_idxMax,0);
     91        const btVector3& supVec= points[ptIndex] * localScaling;
     92        return supVec;
     93#else
     94
     95        btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
     96        int ptIndex = -1;
    5197
    5298        for (int i=0;i<numPoints;i++)
    5399        {
    54                 btVector3 vtx = points[i] * localScaling;
    55 
    56                 newDot = vec.dot(vtx);
     100
     101                newDot = vec.dot(points[i]);
    57102                if (newDot > maxDot)
    58103                {
    59104                        maxDot = newDot;
    60                         supVec = vtx;
    61                 }
    62         }
    63         return btVector3(supVec.getX(),supVec.getY(),supVec.getZ());
     105                        ptIndex = i;
     106                }
     107        }
     108        btAssert(ptIndex >= 0);
     109        btVector3 supVec = points[ptIndex] * localScaling;
     110        return supVec;
     111#endif //__SPU__
    64112}
    65113
     
    161209                btVector3 supVec(0,0,0);
    162210
    163                 btScalar maxDot(btScalar(-1e30));
     211                btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    164212
    165213                btVector3 vec = vec0;
     
    293341        return btScalar(0.0f);
    294342}
    295 
     343#ifndef __SPU__
    296344void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
    297345{
     
    361409        case CONVEX_HULL_SHAPE_PROXYTYPE:
    362410        {
    363                 btPolyhedralConvexShape* convexHullShape = (btPolyhedralConvexShape*)this;
     411                btPolyhedralConvexAabbCachingShape* convexHullShape = (btPolyhedralConvexAabbCachingShape*)this;
    364412                btScalar margin = convexHullShape->getMarginNonVirtual();
    365413                convexHullShape->getNonvirtualAabb (t, aabbMin, aabbMax, margin);
     
    378426        btAssert (0);
    379427}
     428
     429#endif //__SPU__
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516#include "btConvexTriangleMeshShape.h"
    1617#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
     
    2122
    2223btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface, bool calcAabb)
    23 : btPolyhedralConvexShape(), m_stridingMesh(meshInterface)
     24: btPolyhedralConvexAabbCachingShape(), m_stridingMesh(meshInterface)
    2425{
    2526        m_shapeType = CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE;
     
    4445        LocalSupportVertexCallback(const btVector3& supportVecLocal)
    4546                : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)),
    46                 m_maxDot(btScalar(-1e30)),
     47                m_maxDot(btScalar(-BT_LARGE_FLOAT)),
    4748                m_supportVecLocal(supportVecLocal)
    4849        {
     
    9293
    9394        LocalSupportVertexCallback      supportCallback(vec);
    94         btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     95        btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    9596        m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
    9697        supVec = supportCallback.GetSupportVertexLocal();
     
    105106                for (int i=0;i<numVectors;i++)
    106107                {
    107                         supportVerticesOut[i][3] = btScalar(-1e30);
     108                        supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
    108109                }
    109110        }
     
    116117                const btVector3& vec = vectors[j];
    117118                LocalSupportVertexCallback      supportCallback(vec);
    118                 btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     119                btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    119120                m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax);
    120121                supportVerticesOut[j] = supportCallback.GetSupportVertexLocal();
     
    298299
    299300   CenterCallback centerCallback;
    300    btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     301   btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    301302   m_stridingMesh->InternalProcessAllTriangles(&centerCallback, -aabbMax, aabbMax);
    302303   btVector3 center = centerCallback.getCenter();
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h

    r5781 r8284  
     1/*
     2Bullet Continuous Collision Detection and Physics Library
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
     4
     5This software is provided 'as-is', without any express or implied warranty.
     6In no event will the authors be held liable for any damages arising from the use of this software.
     7Permission is granted to anyone to use this software for any purpose,
     8including commercial applications, and to alter it and redistribute it freely,
     9subject to the following restrictions:
     10
     111. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
     122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
     133. This notice may not be removed or altered from any source distribution.
     14*/
    115#ifndef CONVEX_TRIANGLEMESH_SHAPE_H
    216#define CONVEX_TRIANGLEMESH_SHAPE_H
     
    923/// The btConvexTriangleMeshShape is a convex hull of a triangle mesh, but the performance is not as good as btConvexHullShape.
    1024/// A small benefit of this class is that it uses the btStridingMeshInterface, so you can avoid the duplication of the triangle mesh data. Nevertheless, most users should use the much better performing btConvexHullShape instead.
    11 class btConvexTriangleMeshShape : public btPolyhedralConvexShape
     25class btConvexTriangleMeshShape : public btPolyhedralConvexAabbCachingShape
    1226{
    1327
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516#include "btCylinderShape.h"
    1617
    1718btCylinderShape::btCylinderShape (const btVector3& halfExtents)
    18 :btBoxShape(halfExtents),
     19:btConvexInternalShape(),
    1920m_upAxis(1)
    2021{
     22        btVector3 margin(getMargin(),getMargin(),getMargin());
     23        m_implicitShapeDimensions = (halfExtents * m_localScaling) - margin;
    2124        m_shapeType = CYLINDER_SHAPE_PROXYTYPE;
    22         recalcLocalAabb();
    2325}
    2426
     
    2830{
    2931        m_upAxis = 0;
    30         recalcLocalAabb();
     32
    3133}
    3234
     
    3638{
    3739        m_upAxis = 2;
    38         recalcLocalAabb();
     40
    3941}
    4042
    4143void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
    4244{
    43         //skip the box 'getAabb'
    44         btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax);
     45        btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax);
     46}
     47
     48void    btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
     49{
     50        //approximation of box shape, todo: implement cylinder shape inertia before people notice ;-)
     51        btVector3 halfExtents = getHalfExtentsWithMargin();
     52
     53        btScalar lx=btScalar(2.)*(halfExtents.x());
     54        btScalar ly=btScalar(2.)*(halfExtents.y());
     55        btScalar lz=btScalar(2.)*(halfExtents.z());
     56
     57        inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
     58                                        mass/(btScalar(12.0)) * (lx*lx + lz*lz),
     59                                        mass/(btScalar(12.0)) * (lx*lx + ly*ly));
     60
    4561}
    4662
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2222
    2323/// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis.
    24 class btCylinderShape : public btBoxShape
     24class btCylinderShape : public btConvexInternalShape
    2525
    2626{
     
    3131
    3232public:
     33
     34        btVector3 getHalfExtentsWithMargin() const
     35        {
     36                btVector3 halfExtents = getHalfExtentsWithoutMargin();
     37                btVector3 margin(getMargin(),getMargin(),getMargin());
     38                halfExtents += margin;
     39                return halfExtents;
     40        }
     41       
     42        const btVector3& getHalfExtentsWithoutMargin() const
     43        {
     44                return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
     45        }
     46
    3347        btCylinderShape (const btVector3& halfExtents);
    3448       
    35         ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
    3649        void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
    3750
     51        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
     52
    3853        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
    3954
    4055        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
     56
     57        virtual void setMargin(btScalar collisionMargin)
     58        {
     59                //correct the m_implicitShapeDimensions for the margin
     60                btVector3 oldMargin(getMargin(),getMargin(),getMargin());
     61                btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
     62               
     63                btConvexInternalShape::setMargin(collisionMargin);
     64                btVector3 newMargin(getMargin(),getMargin(),getMargin());
     65                m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
     66
     67        }
    4168
    4269        virtual btVector3       localGetSupportingVertex(const btVector3& vec) const
     
    74101        }
    75102
     103        virtual void    setLocalScaling(const btVector3& scaling)
     104        {
     105                btVector3 oldMargin(getMargin(),getMargin(),getMargin());
     106                btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
     107                btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
     108
     109                btConvexInternalShape::setLocalScaling(scaling);
     110
     111                m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
     112
     113        }
     114
    76115        //debugging
    77116        virtual const char*     getName()const
     
    80119        }
    81120
    82 
     121        virtual int     calculateSerializeBufferSize() const;
     122
     123        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     124        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
    83125
    84126};
     
    113155        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
    114156
    115         virtual int     getUpAxis() const
    116         {
    117                 return 2;
    118         }
    119157                //debugging
    120158        virtual const char*     getName()const
     
    130168};
    131169
     170///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     171struct  btCylinderShapeData
     172{
     173        btConvexInternalShapeData       m_convexInternalShapeData;
     174
     175        int     m_upAxis;
     176
     177        char    m_padding[4];
     178};
     179
     180SIMD_FORCE_INLINE       int     btCylinderShape::calculateSerializeBufferSize() const
     181{
     182        return sizeof(btCylinderShapeData);
     183}
     184
     185        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     186SIMD_FORCE_INLINE       const char*     btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const
     187{
     188        btCylinderShapeData* shapeData = (btCylinderShapeData*) dataBuffer;
     189       
     190        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
     191
     192        shapeData->m_upAxis = m_upAxis;
     193       
     194        return "btCylinderShapeData";
     195}
     196
     197
    132198
    133199#endif //CYLINDER_MINKOWSKI_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMaterial.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2008 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    3333
    3434#endif // MATERIAL_H
     35
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516
    1617#include "btMinkowskiSumShape.h"
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1414*/
    1515
     16
     17
    1618#include "btMultiSphereShape.h"
    1719#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
    1820#include "LinearMath/btQuaternion.h"
     21#include "LinearMath/btSerializer.h"
    1922
    20 btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres)
    21 :btConvexInternalShape (), m_inertiaHalfExtents(inertiaHalfExtents)
     23btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres)
     24:btConvexInternalAabbCachingShape ()
    2225{
    2326        m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE;
    24         btScalar startMargin = btScalar(1e30);
     27        //btScalar startMargin = btScalar(BT_LARGE_FLOAT);
    2528
    26         m_numSpheres = numSpheres;
    27         for (int i=0;i<m_numSpheres;i++)
     29        m_localPositionArray.resize(numSpheres);
     30        m_radiArray.resize(numSpheres);
     31        for (int i=0;i<numSpheres;i++)
    2832        {
    29                 m_localPositions[i] = positions[i];
    30                 m_radi[i] = radi[i];
    31                 if (radi[i] < startMargin)
    32                         startMargin = radi[i];
     33                m_localPositionArray[i] = positions[i];
     34                m_radiArray[i] = radi[i];
     35               
    3336        }
    34         setMargin(startMargin);
     37
     38        recalcLocalAabb();
    3539
    3640}
    37 
    38 
    3941
    4042 
     
    4446        btVector3 supVec(0,0,0);
    4547
    46         btScalar maxDot(btScalar(-1e30));
     48        btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    4749
    4850
     
    6163        btScalar newDot;
    6264
    63         const btVector3* pos = &m_localPositions[0];
    64         const btScalar* rad = &m_radi[0];
     65        const btVector3* pos = &m_localPositionArray[0];
     66        const btScalar* rad = &m_radiArray[0];
     67        int numSpheres = m_localPositionArray.size();
    6568
    66         for (i=0;i<m_numSpheres;i++)
     69        for (i=0;i<numSpheres;i++)
    6770        {
    6871                vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
     
    8689        for (int j=0;j<numVectors;j++)
    8790        {
    88                 btScalar maxDot(btScalar(-1e30));
     91                btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    8992
    9093                const btVector3& vec = vectors[j];
     
    9396                btScalar newDot;
    9497
    95                 const btVector3* pos = &m_localPositions[0];
    96                 const btScalar* rad = &m_radi[0];
    97 
    98                 for (int i=0;i<m_numSpheres;i++)
     98                const btVector3* pos = &m_localPositionArray[0];
     99                const btScalar* rad = &m_radiArray[0];
     100                int numSpheres = m_localPositionArray.size();
     101                for (int i=0;i<numSpheres;i++)
    99102                {
    100103                        vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
     
    122125        //as an approximation, take the inertia of the box that bounds the spheres
    123126
    124         btTransform ident;
    125         ident.setIdentity();
    126 //      btVector3 aabbMin,aabbMax;
     127        btVector3 localAabbMin,localAabbMax;
     128        getCachedLocalAabb(localAabbMin,localAabbMax);
     129        btVector3 halfExtents = (localAabbMax-localAabbMin)*btScalar(0.5);
    127130
    128 //      getAabb(ident,aabbMin,aabbMax);
     131        btScalar lx=btScalar(2.)*(halfExtents.x());
     132        btScalar ly=btScalar(2.)*(halfExtents.y());
     133        btScalar lz=btScalar(2.)*(halfExtents.z());
    129134
    130         btVector3 halfExtents = m_inertiaHalfExtents;//(aabbMax - aabbMin)* btScalar(0.5);
    131 
    132         btScalar margin = CONVEX_DISTANCE_MARGIN;
    133 
    134         btScalar lx=btScalar(2.)*(halfExtents[0]+margin);
    135         btScalar ly=btScalar(2.)*(halfExtents[1]+margin);
    136         btScalar lz=btScalar(2.)*(halfExtents[2]+margin);
    137         const btScalar x2 = lx*lx;
    138         const btScalar y2 = ly*ly;
    139         const btScalar z2 = lz*lz;
    140         const btScalar scaledmass = mass * btScalar(.08333333);
    141 
    142         inertia[0] = scaledmass * (y2+z2);
    143         inertia[1] = scaledmass * (x2+z2);
    144         inertia[2] = scaledmass * (x2+y2);
     135        inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
     136                                        mass/(btScalar(12.0)) * (lx*lx + lz*lz),
     137                                        mass/(btScalar(12.0)) * (lx*lx + ly*ly));
    145138
    146139}
    147140
    148141
     142///fills the dataBuffer and returns the struct name (and 0 on failure)
     143const char*     btMultiSphereShape::serialize(void* dataBuffer, btSerializer* serializer) const
     144{
     145        btMultiSphereShapeData* shapeData = (btMultiSphereShapeData*) dataBuffer;
     146        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
    149147
     148        int numElem = m_localPositionArray.size();
     149        shapeData->m_localPositionArrayPtr = numElem ? (btPositionAndRadius*)serializer->getUniquePointer((void*)&m_localPositionArray[0]):  0;
     150       
     151        shapeData->m_localPositionArraySize = numElem;
     152        if (numElem)
     153        {
     154                btChunk* chunk = serializer->allocate(sizeof(btPositionAndRadius),numElem);
     155                btPositionAndRadius* memPtr = (btPositionAndRadius*)chunk->m_oldPtr;
     156                for (int i=0;i<numElem;i++,memPtr++)
     157                {
     158                        m_localPositionArray[i].serializeFloat(memPtr->m_pos);
     159                        memPtr->m_radius = float(m_radiArray[i]);
     160                }
     161                serializer->finalizeChunk(chunk,"btPositionAndRadius",BT_ARRAY_CODE,(void*)&m_localPositionArray[0]);
     162        }
     163       
     164        return "btMultiSphereShapeData";
     165}
     166
     167
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1919#include "btConvexInternalShape.h"
    2020#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
    21 
    22 #define MAX_NUM_SPHERES 5
    23 
    24 ///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes.
    25 ///It is possible to animate the spheres for deformation.
    26 class btMultiSphereShape : public btConvexInternalShape
    27 
    28 {
    29        
    30         btVector3 m_localPositions[MAX_NUM_SPHERES];
    31         btScalar  m_radi[MAX_NUM_SPHERES];
    32         btVector3       m_inertiaHalfExtents;
    33 
    34         int m_numSpheres;
    35        
     21#include "LinearMath/btAlignedObjectArray.h"
     22#include "LinearMath/btAabbUtil2.h"
    3623
    3724
    3825
     26///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes.
     27///It is possible to animate the spheres for deformation, but call 'recalcLocalAabb' after changing any sphere position/radius
     28class btMultiSphereShape : public btConvexInternalAabbCachingShape
     29{
     30       
     31        btAlignedObjectArray<btVector3> m_localPositionArray;
     32        btAlignedObjectArray<btScalar>  m_radiArray;
     33       
    3934public:
    40         btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres);
     35        btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres);
    4136
    4237        ///CollisionShape Interface
     
    5045        int     getSphereCount() const
    5146        {
    52                 return m_numSpheres;
     47                return m_localPositionArray.size();
    5348        }
    5449
    5550        const btVector3&        getSpherePosition(int index) const
    5651        {
    57                 return m_localPositions[index];
     52                return m_localPositionArray[index];
    5853        }
    5954
    6055        btScalar        getSphereRadius(int index) const
    6156        {
    62                 return m_radi[index];
     57                return m_radiArray[index];
    6358        }
    6459
     
    6964        }
    7065
     66        virtual int     calculateSerializeBufferSize() const;
     67
     68        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     69        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     70
     71
    7172};
    7273
    7374
     75struct  btPositionAndRadius
     76{
     77        btVector3FloatData      m_pos;
     78        float           m_radius;
     79};
     80
     81struct  btMultiSphereShapeData
     82{
     83        btConvexInternalShapeData       m_convexInternalShapeData;
     84
     85        btPositionAndRadius     *m_localPositionArrayPtr;
     86        int                             m_localPositionArraySize;
     87        char    m_padding[4];
     88};
     89
     90
     91
     92SIMD_FORCE_INLINE       int     btMultiSphereShape::calculateSerializeBufferSize() const
     93{
     94        return sizeof(btMultiSphereShapeData);
     95}
     96
     97
     98
    7499#endif //MULTI_SPHERE_MINKOWSKI_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2008 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2008 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    3838            m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
    3939
    40             btVector3 m_triangle[3];
    4140            const unsigned char *vertexbase;
    4241            int numverts;
     
    7271            m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE;
    7372
    74             btVector3 m_triangle[3];
    7573            const unsigned char *vertexbase;
    7674            int numverts;
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1414*/
    1515
     16
    1617#include "btOptimizedBvh.h"
    1718#include "btStridingMeshInterface.h"
     
    5657                        btOptimizedBvhNode node;
    5758                        btVector3       aabbMin,aabbMax;
    58                         aabbMin.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
    59                         aabbMax.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
     59                        aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     60                        aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
    6061                        aabbMin.setMin(triangle[0]);
    6162                        aabbMax.setMax(triangle[0]);
     
    104105                        btQuantizedBvhNode node;
    105106                        btVector3       aabbMin,aabbMax;
    106                         aabbMin.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
    107                         aabbMax.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
     107                        aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     108                        aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
    108109                        aabbMin.setMin(triangle[0]);
    109110                        aabbMax.setMax(triangle[0]);
     
    168169                NodeTriangleCallback    callback(m_leafNodes);
    169170
    170                 btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
    171                 btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     171                btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
     172                btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    172173
    173174                triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax);
     
    337338
    338339                               
    339                                 aabbMin.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
    340                                 aabbMax.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
     340                                aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     341                                aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
    341342                                aabbMin.setMin(triangleVerts[0]);
    342343                                aabbMax.setMax(triangleVerts[0]);
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
     16///Contains contributions from Disney Studio's
    1517
    1618#ifndef OPTIMIZED_BVH_H
     
    4648
    4749        /// Data buffer MUST be 16 byte aligned
    48         virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian)
     50        virtual bool serializeInPlace(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const
    4951        {
    5052                return btQuantizedBvh::serialize(o_alignedDataBuffer,i_dataBufferSize,i_swapEndian);
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1616#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
    1717
    18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(),
    19 m_localAabbMin(1,1,1),
    20 m_localAabbMax(-1,-1,-1),
    21 m_isLocalAabbValid(false),
    22 m_optionalHull(0)
     18btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape()
    2319{
    2420
     
    2824btVector3       btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
    2925{
     26
     27
     28        btVector3 supVec(0,0,0);
     29#ifndef __SPU__
    3030        int i;
    31         btVector3 supVec(0,0,0);
    32 
    33         btScalar maxDot(btScalar(-1e30));
     31        btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    3432
    3533        btVector3 vec = vec0;
     
    5856        }
    5957
     58       
     59#endif //__SPU__
    6060        return supVec;
     61}
    6162
    62 }
     63
    6364
    6465void    btPolyhedralConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
    6566{
     67#ifndef __SPU__
    6668        int i;
    6769
     
    7173        for (i=0;i<numVectors;i++)
    7274        {
    73                 supportVerticesOut[i][3] = btScalar(-1e30);
     75                supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT);
    7476        }
    7577
     
    9193                }
    9294        }
     95#endif //__SPU__
    9396}
    9497
     
    97100void    btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
    98101{
     102#ifndef __SPU__
    99103        //not yet, return box inertia
    100104
     
    116120
    117121        inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2));
    118 
     122#endif //__SPU__
    119123}
    120124
    121125
    122126
    123 void btPolyhedralConvexShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
    124 {
    125         getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin());
    126 }
    127 
    128 
    129 
    130 void    btPolyhedralConvexShape::setLocalScaling(const btVector3& scaling)
     127void    btPolyhedralConvexAabbCachingShape::setLocalScaling(const btVector3& scaling)
    131128{
    132129        btConvexInternalShape::setLocalScaling(scaling);
     
    134131}
    135132
    136 void    btPolyhedralConvexShape::recalcLocalAabb()
     133btPolyhedralConvexAabbCachingShape::btPolyhedralConvexAabbCachingShape()
     134:btPolyhedralConvexShape(),
     135m_localAabbMin(1,1,1),
     136m_localAabbMax(-1,-1,-1),
     137m_isLocalAabbValid(false)
     138{
     139}
     140
     141void btPolyhedralConvexAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
     142{
     143        getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin());
     144}
     145
     146void    btPolyhedralConvexAabbCachingShape::recalcLocalAabb()
    137147{
    138148        m_isLocalAabbValid = true;
     
    182192}
    183193
    184 
    185 
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1818
    1919#include "LinearMath/btMatrix3x3.h"
    20 #include "LinearMath/btAabbUtil2.h"
    2120#include "btConvexInternalShape.h"
    2221
     
    2726
    2827protected:
    29         btVector3       m_localAabbMin;
    30         btVector3       m_localAabbMax;
    31         bool            m_isLocalAabbValid;
    32 
     28       
    3329public:
    3430
     
    3935        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
    4036        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
    41 
    4237       
    4338        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
     39       
     40       
     41        virtual int     getNumVertices() const = 0 ;
     42        virtual int getNumEdges() const = 0;
     43        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0;
     44        virtual void getVertex(int i,btVector3& vtx) const = 0;
     45        virtual int     getNumPlanes() const = 0;
     46        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0;
     47//      virtual int getIndex(int i) const = 0 ;
    4448
     49        virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0;
     50       
     51};
     52
     53
     54///The btPolyhedralConvexAabbCachingShape adds aabb caching to the btPolyhedralConvexShape
     55class btPolyhedralConvexAabbCachingShape : public btPolyhedralConvexShape
     56{
     57
     58        btVector3       m_localAabbMin;
     59        btVector3       m_localAabbMax;
     60        bool            m_isLocalAabbValid;
     61               
     62protected:
    4563
    4664        void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax)
     
    5876        }
    5977
     78public:
     79
     80        btPolyhedralConvexAabbCachingShape();
     81       
    6082        inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
    6183        {
     
    6688        }
    6789
    68        
     90        virtual void    setLocalScaling(const btVector3& scaling);
     91
    6992        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
    7093
    71         virtual void    setLocalScaling(const btVector3& scaling);
    72 
    7394        void    recalcLocalAabb();
    74 
    75         virtual int     getNumVertices() const = 0 ;
    76         virtual int getNumEdges() const = 0;
    77         virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0;
    78         virtual void getVertex(int i,btVector3& vtx) const = 0;
    79         virtual int     getNumPlanes() const = 0;
    80         virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0;
    81 //      virtual int getIndex(int i) const = 0 ;
    82 
    83         virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0;
    84        
    85         /// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
    86         class   Hull*   m_optionalHull;
    8795
    8896};
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2008 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516
    1617#include "btScaledBvhTriangleMeshShape.h"
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2008 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.cpp

    r5781 r8284  
    11/*
    2 btbtShapeHull implemented by John McCutchan.
    3 
    42Bullet Continuous Collision Detection and Physics Library
    5 Copyright (c) 2003-2008 Erwin Coumans  http://bulletphysics.com
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    64
    75This software is provided 'as-is', without any express or implied warranty.
    86In no event will the authors be held liable for any damages arising from the use of this software.
    9 Permission is granted to anyone to use this software for any purpose,
    10 including commercial applications, and to alter it and redistribute it freely,
     7Permission is granted to anyone to use this software for any purpose, 
     8including commercial applications, and to alter it and redistribute it freely, 
    119subject to the following restrictions:
    1210
     
    1614*/
    1715
     16//btShapeHull was implemented by John McCutchan.
     17
     18
    1819#include "btShapeHull.h"
    1920#include "LinearMath/btConvexHull.h"
    2021
    2122#define NUM_UNITSPHERE_POINTS 42
    22 
    23 static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
    24 {
    25         btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
    26         btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
    27         btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
    28         btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
    29         btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
    30         btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
    31         btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
    32         btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
    33         btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
    34         btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
    35         btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
    36         btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
    37         btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
    38         btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
    39         btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
    40         btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
    41         btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
    42         btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
    43         btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
    44         btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
    45         btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
    46         btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
    47         btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
    48         btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
    49         btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
    50         btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
    51         btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
    52         btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
    53         btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
    54         btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
    55         btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
    56         btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
    57         btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
    58         btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
    59         btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
    60         btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
    61         btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
    62         btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
    63         btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
    64         btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
    65         btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
    66         btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
    67 };
    6823
    6924btShapeHull::btShapeHull (const btConvexShape* shape)
     
    9348                                btVector3 norm;
    9449                                m_shape->getPreferredPenetrationDirection(i,norm);
    95                                 btUnitSpherePoints[numSampleDirections] = norm;
     50                                getUnitSpherePoints()[numSampleDirections] = norm;
    9651                                numSampleDirections++;
    9752                        }
     
    10358        for (i = 0; i < numSampleDirections; i++)
    10459        {
    105                 supportPoints[i] = m_shape->localGetSupportingVertex(btUnitSpherePoints[i]);
     60                supportPoints[i] = m_shape->localGetSupportingVertex(getUnitSpherePoints()[i]);
    10661        }
    10762
     
    163118}
    164119
     120
     121btVector3* btShapeHull::getUnitSpherePoints()
     122{
     123        static btVector3 sUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
     124        {
     125                btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
     126                btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
     127                btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
     128                btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
     129                btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
     130                btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
     131                btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
     132                btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
     133                btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
     134                btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
     135                btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
     136                btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
     137                btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
     138                btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
     139                btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
     140                btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
     141                btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
     142                btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
     143                btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
     144                btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
     145                btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
     146                btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
     147                btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
     148                btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
     149                btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
     150                btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
     151                btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
     152                btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
     153                btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
     154                btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
     155                btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
     156                btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
     157                btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
     158                btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
     159                btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
     160                btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
     161                btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
     162                btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
     163                btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
     164                btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
     165                btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
     166                btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
     167        };
     168        return sUnitSpherePoints;
     169}
     170
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.h

    r5781 r8284  
    11/*
    2 btShapeHull implemented by John McCutchan.
    3 
    42Bullet Continuous Collision Detection and Physics Library
    5 Copyright (c) 2003-2008 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    64
    75This software is provided 'as-is', without any express or implied warranty.
    86In no event will the authors be held liable for any damages arising from the use of this software.
    9 Permission is granted to anyone to use this software for any purpose,
    10 including commercial applications, and to alter it and redistribute it freely,
     7Permission is granted to anyone to use this software for any purpose, 
     8including commercial applications, and to alter it and redistribute it freely, 
    119subject to the following restrictions:
    1210
     
    15133. This notice may not be removed or altered from any source distribution.
    1614*/
     15
     16///btShapeHull implemented by John McCutchan.
    1717
    1818#ifndef _SHAPE_HULL_H
     
    2828class btShapeHull
    2929{
     30protected:
     31
     32        btAlignedObjectArray<btVector3> m_vertices;
     33        btAlignedObjectArray<unsigned int> m_indices;
     34        unsigned int m_numIndices;
     35        const btConvexShape* m_shape;
     36
     37        static btVector3* getUnitSpherePoints();
     38
    3039public:
    3140        btShapeHull (const btConvexShape* shape);
     
    4655                return &m_indices[0];
    4756        }
    48 
    49 protected:
    50         btAlignedObjectArray<btVector3> m_vertices;
    51         btAlignedObjectArray<unsigned int> m_indices;
    52         unsigned int m_numIndices;
    53         const btConvexShape* m_shape;
    5457};
    5558
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
    15 
    1615#ifndef SPHERE_MINKOWSKI_H
    1716#define SPHERE_MINKOWSKI_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    3939        (void)t;
    4040        /*
    41         btVector3 infvec (btScalar(1e30),btScalar(1e30),btScalar(1e30));
     41        btVector3 infvec (btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    4242
    4343        btVector3 center = m_planeNormal*m_planeConstant;
     
    4848        */
    4949
    50         aabbMin.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
    51         aabbMax.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     50        aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
     51        aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    5252
    5353}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2121
    2222///The btStaticPlaneShape simulates an infinite non-moving (static) collision plane.
    23 class btStaticPlaneShape : public btConcaveShape
     23ATTRIBUTE_ALIGNED16(class) btStaticPlaneShape : public btConcaveShape
    2424{
    2525protected:
     
    5959        virtual const char*     getName()const {return "STATICPLANE";}
    6060
     61        virtual int     calculateSerializeBufferSize() const;
     62
     63        ///fills the dataBuffer and returns the struct name (and 0 on failure)
     64        virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     65
    6166
    6267};
    6368
     69///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     70struct  btStaticPlaneShapeData
     71{
     72        btCollisionShapeData    m_collisionShapeData;
     73
     74        btVector3FloatData      m_localScaling;
     75        btVector3FloatData      m_planeNormal;
     76        float                   m_planeConstant;
     77        char    m_pad[4];
     78};
     79
     80
     81SIMD_FORCE_INLINE       int     btStaticPlaneShape::calculateSerializeBufferSize() const
     82{
     83        return sizeof(btStaticPlaneShapeData);
     84}
     85
     86///fills the dataBuffer and returns the struct name (and 0 on failure)
     87SIMD_FORCE_INLINE       const char*     btStaticPlaneShape::serialize(void* dataBuffer, btSerializer* serializer) const
     88{
     89        btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*) dataBuffer;
     90        btCollisionShape::serialize(&planeData->m_collisionShapeData,serializer);
     91
     92        m_localScaling.serializeFloat(planeData->m_localScaling);
     93        m_planeNormal.serializeFloat(planeData->m_planeNormal);
     94        planeData->m_planeConstant = float(m_planeConstant);
     95               
     96        return "btStaticPlaneShapeData";
     97}
     98
     99
    64100#endif //STATIC_PLANE_SHAPE_H
     101
     102
     103
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1515
    1616#include "btStridingMeshInterface.h"
     17#include "LinearMath/btSerializer.h"
    1718
    1819btStridingMeshInterface::~btStridingMeshInterface()
     
    3637        int gfxindex;
    3738        btVector3 triangle[3];
    38         btScalar* graphicsbase;
    3939
    4040        btVector3 meshScaling = getScaling();
     
    4646                numtotalphysicsverts+=numtriangles*3; //upper bound
    4747
    48                 switch (gfxindextype)
     48                ///unlike that developers want to pass in double-precision meshes in single-precision Bullet build
     49                ///so disable this feature by default
     50                ///see patch http://code.google.com/p/bullet/issues/detail?id=213
     51
     52                switch (type)
    4953                {
    50                 case PHY_INTEGER:
     54                case PHY_FLOAT:
     55                 {
     56
     57                         float* graphicsbase;
     58
     59                         switch (gfxindextype)
     60                         {
     61                         case PHY_INTEGER:
     62                                 {
     63                                         for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
     64                                         {
     65                                                 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
     66                                                 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
     67                                                 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
     68                                                 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
     69                                                 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),    graphicsbase[2]*meshScaling.getZ());
     70                                                 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
     71                                                 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),    graphicsbase[2]*meshScaling.getZ());
     72                                                 callback->internalProcessTriangleIndex(triangle,part,gfxindex);
     73                                         }
     74                                         break;
     75                                 }
     76                         case PHY_SHORT:
     77                                 {
     78                                         for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
     79                                         {
     80                                                 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
     81                                                 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
     82                                                 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
     83                                                 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
     84                                                 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),    graphicsbase[2]*meshScaling.getZ());
     85                                                 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
     86                                                 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),    graphicsbase[2]*meshScaling.getZ());
     87                                                 callback->internalProcessTriangleIndex(triangle,part,gfxindex);
     88                                         }
     89                                         break;
     90                                 }
     91                         default:
     92                                 btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
     93                         }
     94                         break;
     95                 }
     96
     97                case PHY_DOUBLE:
    5198                        {
    52                                 for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
    53                                 {
    54                                         unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
    55                                         graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
    56                                         triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
    57                                         graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
    58                                         triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),     graphicsbase[2]*meshScaling.getZ());
    59                                         graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride);
    60                                         triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),     graphicsbase[2]*meshScaling.getZ());
    61                                         callback->internalProcessTriangleIndex(triangle,part,gfxindex);
    62                                 }
    63                                 break;
    64                         }
    65                 case PHY_SHORT:
    66                         {
    67                                 for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
    68                                 {
    69                                         unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
    70                                         graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride);
    71                                         triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
    72                                         graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride);
    73                                         triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),     graphicsbase[2]*meshScaling.getZ());
    74                                         graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride);
    75                                         triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),     graphicsbase[2]*meshScaling.getZ());
    76                                         callback->internalProcessTriangleIndex(triangle,part,gfxindex);
     99                                double* graphicsbase;
     100
     101                                switch (gfxindextype)
     102                                {
     103                                case PHY_INTEGER:
     104                                        {
     105                                                for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
     106                                                {
     107                                                        unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
     108                                                        graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
     109                                                        triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
     110                                                        graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
     111                                                        triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),  (btScalar)graphicsbase[2]*meshScaling.getZ());
     112                                                        graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
     113                                                        triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),  (btScalar)graphicsbase[2]*meshScaling.getZ());
     114                                                        callback->internalProcessTriangleIndex(triangle,part,gfxindex);
     115                                                }
     116                                                break;
     117                                        }
     118                                case PHY_SHORT:
     119                                        {
     120                                                for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
     121                                                {
     122                                                        unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
     123                                                        graphicsbase = (double*)(vertexbase+tri_indices[0]*stride);
     124                                                        triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ());
     125                                                        graphicsbase = (double*)(vertexbase+tri_indices[1]*stride);
     126                                                        triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),  (btScalar)graphicsbase[2]*meshScaling.getZ());
     127                                                        graphicsbase = (double*)(vertexbase+tri_indices[2]*stride);
     128                                                        triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),  (btScalar)graphicsbase[2]*meshScaling.getZ());
     129                                                        callback->internalProcessTriangleIndex(triangle,part,gfxindex);
     130                                                }
     131                                                break;
     132                                        }
     133                                default:
     134                                        btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
    77135                                }
    78136                                break;
    79137                        }
    80138                default:
    81                         btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
     139                        btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE));
    82140                }
    83141
     
    96154                AabbCalculationCallback()
    97155                {
    98                         m_aabbMin.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
    99                         m_aabbMax.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
     156                        m_aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
     157                        m_aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
    100158                }
    101159
     
    114172        };
    115173
    116                 //first calculate the total aabb for all triangles
     174        //first calculate the total aabb for all triangles
    117175        AabbCalculationCallback aabbCallback;
    118         aabbMin.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
    119         aabbMax.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     176        aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
     177        aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    120178        InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax);
    121179
     
    123181        aabbMax = aabbCallback.m_aabbMax;
    124182}
     183
     184
     185
     186///fills the dataBuffer and returns the struct name (and 0 on failure)
     187const char*     btStridingMeshInterface::serialize(void* dataBuffer, btSerializer* serializer) const
     188{
     189        btStridingMeshInterfaceData* trimeshData = (btStridingMeshInterfaceData*) dataBuffer;
     190
     191        trimeshData->m_numMeshParts = getNumSubParts();
     192
     193        //void* uniquePtr = 0;
     194
     195        trimeshData->m_meshPartsPtr = 0;
     196
     197        if (trimeshData->m_numMeshParts)
     198        {
     199                btChunk* chunk = serializer->allocate(sizeof(btMeshPartData),trimeshData->m_numMeshParts);
     200                btMeshPartData* memPtr = (btMeshPartData*)chunk->m_oldPtr;
     201                trimeshData->m_meshPartsPtr = (btMeshPartData *)serializer->getUniquePointer(memPtr);
     202
     203
     204        //      int numtotalphysicsverts = 0;
     205                int part,graphicssubparts = getNumSubParts();
     206                const unsigned char * vertexbase;
     207                const unsigned char * indexbase;
     208                int indexstride;
     209                PHY_ScalarType type;
     210                PHY_ScalarType gfxindextype;
     211                int stride,numverts,numtriangles;
     212                int gfxindex;
     213        //      btVector3 triangle[3];
     214
     215                btVector3 meshScaling = getScaling();
     216
     217                ///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
     218                for (part=0;part<graphicssubparts ;part++,memPtr++)
     219                {
     220                        getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
     221                        memPtr->m_numTriangles = numtriangles;//indices = 3*numtriangles
     222                        memPtr->m_numVertices = numverts;
     223                        memPtr->m_indices16 = 0;
     224                        memPtr->m_indices32 = 0;
     225                        memPtr->m_3indices16 = 0;
     226                        memPtr->m_vertices3f = 0;
     227                        memPtr->m_vertices3d = 0;
     228
     229                        switch (gfxindextype)
     230                        {
     231                        case PHY_INTEGER:
     232                                {
     233                                        int numindices = numtriangles*3;
     234                               
     235                                        if (numindices)
     236                                        {
     237                                                btChunk* chunk = serializer->allocate(sizeof(btIntIndexData),numindices);
     238                                                btIntIndexData* tmpIndices = (btIntIndexData*)chunk->m_oldPtr;
     239                                                memPtr->m_indices32 = (btIntIndexData*)serializer->getUniquePointer(tmpIndices);
     240                                                for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
     241                                                {
     242                                                        unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride);
     243                                                        tmpIndices[gfxindex*3].m_value = tri_indices[0];
     244                                                        tmpIndices[gfxindex*3+1].m_value = tri_indices[1];
     245                                                        tmpIndices[gfxindex*3+2].m_value = tri_indices[2];
     246                                                }
     247                                                serializer->finalizeChunk(chunk,"btIntIndexData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr);
     248                                        }
     249                                        break;
     250                                }
     251                        case PHY_SHORT:
     252                                {
     253                                        if (numtriangles)
     254                                        {
     255                                                btChunk* chunk = serializer->allocate(sizeof(btShortIntIndexTripletData),numtriangles);
     256                                                btShortIntIndexTripletData* tmpIndices = (btShortIntIndexTripletData*)chunk->m_oldPtr;
     257                                                memPtr->m_3indices16 = (btShortIntIndexTripletData*) serializer->getUniquePointer(tmpIndices);
     258                                                for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
     259                                                {
     260                                                        unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride);
     261                                                        tmpIndices[gfxindex].m_values[0] = tri_indices[0];
     262                                                        tmpIndices[gfxindex].m_values[1] = tri_indices[1];
     263                                                        tmpIndices[gfxindex].m_values[2] = tri_indices[2];
     264                                                }
     265                                                serializer->finalizeChunk(chunk,"btShortIntIndexTripletData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr);
     266                                        }
     267                                        break;
     268                                }
     269                        default:
     270                                {
     271                                        btAssert(0);
     272                                        //unknown index type
     273                                }
     274                        }
     275
     276                        switch (type)
     277                        {
     278                        case PHY_FLOAT:
     279                         {
     280                                 float* graphicsbase;
     281
     282                                 if (numverts)
     283                                 {
     284                                         btChunk* chunk = serializer->allocate(sizeof(btVector3FloatData),numverts);
     285                                         btVector3FloatData* tmpVertices = (btVector3FloatData*) chunk->m_oldPtr;
     286                                         memPtr->m_vertices3f = (btVector3FloatData *)serializer->getUniquePointer(tmpVertices);
     287                                         for (int i=0;i<numverts;i++)
     288                                         {
     289                                                 graphicsbase = (float*)(vertexbase+i*stride);
     290                                                 tmpVertices[i].m_floats[0] = graphicsbase[0];
     291                                                 tmpVertices[i].m_floats[1] = graphicsbase[1];
     292                                                 tmpVertices[i].m_floats[2] = graphicsbase[2];
     293                                         }
     294                                         serializer->finalizeChunk(chunk,"btVector3FloatData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr);
     295                                 }
     296                                 break;
     297                                }
     298
     299                        case PHY_DOUBLE:
     300                                {
     301                                        if (numverts)
     302                                        {
     303                                                btChunk* chunk = serializer->allocate(sizeof(btVector3DoubleData),numverts);
     304                                                btVector3DoubleData* tmpVertices = (btVector3DoubleData*) chunk->m_oldPtr;
     305                                                memPtr->m_vertices3d = (btVector3DoubleData *) serializer->getUniquePointer(tmpVertices);
     306                                                for (int i=0;i<numverts;i++)
     307                                         {
     308                                                 double* graphicsbase = (double*)(vertexbase+i*stride);//for now convert to float, might leave it at double
     309                                                 tmpVertices[i].m_floats[0] = graphicsbase[0];
     310                                                 tmpVertices[i].m_floats[1] = graphicsbase[1];
     311                                                 tmpVertices[i].m_floats[2] = graphicsbase[2];
     312                                         }
     313                                                serializer->finalizeChunk(chunk,"btVector3DoubleData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr);
     314                                        }
     315                                        break;
     316                                }
     317
     318                        default:
     319                                btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE));
     320                        }
     321
     322                        unLockReadOnlyVertexBase(part);
     323                }
     324
     325                serializer->finalizeChunk(chunk,"btMeshPartData",BT_ARRAY_CODE,chunk->m_oldPtr);
     326        }
     327
     328
     329        m_scaling.serializeFloat(trimeshData->m_scaling);
     330        return "btStridingMeshInterfaceData";
     331}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2020#include "btTriangleCallback.h"
    2121#include "btConcaveShape.h"
     22
     23
    2224
    2325
     
    9092                }
    9193
    92        
     94                virtual int     calculateSerializeBufferSize() const;
     95
     96                ///fills the dataBuffer and returns the struct name (and 0 on failure)
     97                virtual const char*     serialize(void* dataBuffer, btSerializer* serializer) const;
     98
    9399
    94100};
    95101
     102struct  btIntIndexData
     103{
     104        int     m_value;
     105};
     106
     107struct  btShortIntIndexData
     108{
     109        short m_value;
     110        char m_pad[2];
     111};
     112
     113struct  btShortIntIndexTripletData
     114{
     115        short   m_values[3];
     116        char    m_pad[2];
     117};
     118
     119///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     120struct  btMeshPartData
     121{
     122        btVector3FloatData                      *m_vertices3f;
     123        btVector3DoubleData                     *m_vertices3d;
     124
     125        btIntIndexData                          *m_indices32;
     126        btShortIntIndexTripletData      *m_3indices16;
     127
     128        btShortIntIndexData                     *m_indices16;//backwards compatibility
     129
     130        int                     m_numTriangles;//length of m_indices = m_numTriangles
     131        int                     m_numVertices;
     132};
     133
     134
     135///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
     136struct  btStridingMeshInterfaceData
     137{
     138        btMeshPartData  *m_meshPartsPtr;
     139        btVector3FloatData      m_scaling;
     140        int     m_numMeshParts;
     141        char m_padding[4];
     142};
     143
     144
     145
     146
     147SIMD_FORCE_INLINE       int     btStridingMeshInterface::calculateSerializeBufferSize() const
     148{
     149        return sizeof(btStridingMeshInterfaceData);
     150}
     151
     152
     153
    96154#endif //STRIDING_MESHINTERFACE_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp

    r5781 r8284  
    1 
    21/*
    32Bullet Continuous Collision Detection and Physics Library
    4 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    54
    65This software is provided 'as-is', without any express or implied warranty.
     
    14133. This notice may not be removed or altered from any source distribution.
    1514*/
     15
    1616#include "btTetrahedronShape.h"
    1717#include "LinearMath/btMatrix3x3.h"
    1818
    19 btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexShape (),
    20 m_numVertices(0)
    21 {
    22         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
    23 }
    24 
    25 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexShape (),
    26 m_numVertices(0)
    27 {
    28         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
    29         addVertex(pt0);
    30 }
    31 
    32 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexShape (),
     19btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexAabbCachingShape (),
     20m_numVertices(0)
     21{
     22        m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
     23}
     24
     25btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexAabbCachingShape (),
     26m_numVertices(0)
     27{
     28        m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
     29        addVertex(pt0);
     30}
     31
     32btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexAabbCachingShape (),
    3333m_numVertices(0)
    3434{
     
    3838}
    3939
    40 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexShape (),
     40btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexAabbCachingShape (),
    4141m_numVertices(0)
    4242{
     
    4747}
    4848
    49 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexShape (),
     49btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexAabbCachingShape (),
    5050m_numVertices(0)
    5151{
     
    5858
    5959
     60void btBU_Simplex1to4::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
     61{
     62#if 1
     63        btPolyhedralConvexAabbCachingShape::getAabb(t,aabbMin,aabbMax);
     64#else
     65        aabbMin.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
     66        aabbMax.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
     67
     68        //just transform the vertices in worldspace, and take their AABB
     69        for (int i=0;i<m_numVertices;i++)
     70        {
     71                btVector3 worldVertex = t(m_vertices[i]);
     72                aabbMin.setMin(worldVertex);
     73                aabbMax.setMax(worldVertex);
     74        }
     75#endif
     76}
     77
     78
    6079
    6180
     
    6483{
    6584        m_vertices[m_numVertices++] = pt;
    66 
    6785        recalcLocalAabb();
    6886}
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2323
    2424///The btBU_Simplex1to4 implements tetrahedron, triangle, line, vertex collision shapes. In most cases it is better to use btConvexHullShape instead.
    25 class btBU_Simplex1to4 : public btPolyhedralConvexShape
     25class btBU_Simplex1to4 : public btPolyhedralConvexAabbCachingShape
    2626{
    2727protected:
     
    4444        }
    4545       
    46 
     46        virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
    4747
    4848        void addVertex(const btVector3& pt);
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
    66In no event will the authors be held liable for any damages arising from the use of this software.
    7 Permission is granted to anyone to use this software for any purpose,
    8 including commercial applications, and to alter it and redistribute it freely,
     7Permission is granted to anyone to use this software for any purpose, 
     8including commercial applications, and to alter it and redistribute it freely, 
    99subject to the following restrictions:
    1010
     
    4545        numverts = mesh.m_numVertices;
    4646        (*vertexbase) = (unsigned char *) mesh.m_vertexBase;
    47         #ifdef BT_USE_DOUBLE_PRECISION
    48         type = PHY_DOUBLE;
    49         #else
    50         type = PHY_FLOAT;
    51         #endif
     47
     48   type = mesh.m_vertexType;
     49
    5250        vertexStride = mesh.m_vertexStride;
    5351
     
    6563        numverts = mesh.m_numVertices;
    6664        (*vertexbase) = (const unsigned char *)mesh.m_vertexBase;
    67         #ifdef BT_USE_DOUBLE_PRECISION
    68         type = PHY_DOUBLE;
    69         #else
    70         type = PHY_FLOAT;
    71         #endif
     65
     66   type = mesh.m_vertexType;
     67   
    7268        vertexStride = mesh.m_vertexStride;
    7369
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2828        BT_DECLARE_ALIGNED_ALLOCATOR();
    2929
    30         int                     m_numTriangles;
    31         const unsigned char *           m_triangleIndexBase;
    32         int                     m_triangleIndexStride;
    33         int                     m_numVertices;
    34         const unsigned char *           m_vertexBase;
    35         int                     m_vertexStride;
    36         // The index type is set when adding an indexed mesh to the
    37         // btTriangleIndexVertexArray, do not set it manually
    38         PHY_ScalarType          m_indexType;
    39         int                     pad;
     30   int                     m_numTriangles;
     31   const unsigned char *   m_triangleIndexBase;
     32   int                     m_triangleIndexStride;
     33   int                     m_numVertices;
     34   const unsigned char *   m_vertexBase;
     35   int                     m_vertexStride;
     36
     37   // The index type is set when adding an indexed mesh to the
     38   // btTriangleIndexVertexArray, do not set it manually
     39   PHY_ScalarType m_indexType;
     40
     41   // The vertex type has a default type similar to Bullet's precision mode (float or double)
     42   // but can be set manually if you for example run Bullet with double precision but have
     43   // mesh data in single precision..
     44   PHY_ScalarType m_vertexType;
     45
     46
     47   btIndexedMesh()
     48           :m_indexType(PHY_INTEGER),
     49#ifdef BT_USE_DOUBLE_PRECISION
     50      m_vertexType(PHY_DOUBLE)
     51#else // BT_USE_DOUBLE_PRECISION
     52      m_vertexType(PHY_FLOAT)
     53#endif // BT_USE_DOUBLE_PRECISION
     54      {
     55      }
    4056}
    4157;
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp

    r5781 r8284  
    1 
    21/*
    32Bullet Continuous Collision Detection and Physics Library
    4 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    54
    65This software is provided 'as-is', without any express or implied warranty.
    76In no event will the authors be held liable for any damages arising from the use of this software.
    8 Permission is granted to anyone to use this software for any purpose,
    9 including commercial applications, and to alter it and redistribute it freely,
     7Permission is granted to anyone to use this software for any purpose, 
     8including commercial applications, and to alter it and redistribute it freely, 
    109subject to the following restrictions:
    1110
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
     15
    1516
    1617#include "btTriangleMesh.h"
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    13133. This notice may not be removed or altered from any source distribution.
    1414*/
    15 
    1615
    1716#ifndef TRIANGLE_MESH_H
     
    4241                btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true);
    4342
    44                 int             findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices);
    45                 void    addIndex(int index);
    46 
    4743                bool    getUse32bitIndices() const
    4844                {
     
    6359                virtual void    preallocateIndices(int numindices){(void) numindices;}
    6460
     61                ///findOrAddVertex is an internal method, use addTriangle instead
     62                int             findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices);
     63                ///addIndex is an internal method, use addTriangle instead
     64                void    addIndex(int index);
    6565               
    6666};
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    9292
    9393        SupportVertexCallback(const btVector3& supportVecWorld,const btTransform& trans)
    94                 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(-1e30))
     94                : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(-BT_LARGE_FLOAT))
    9595               
    9696        {
     
    200200        SupportVertexCallback supportCallback(vec,ident);
    201201
    202         btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     202        btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    203203       
    204204        processAllTriangles(&supportCallback,-aabbMax,aabbMax);
     
    208208        return supportVertex;
    209209}
     210
     211
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    8080        virtual const char*     getName()const {return "TRIANGLEMESH";}
    8181
     82       
    8283
    8384};
    8485
     86
     87
     88
    8589#endif //TRIANGLE_MESH_SHAPE_H
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btTriangleShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2020#include "btBoxShape.h"
    2121
    22 class btTriangleShape : public btPolyhedralConvexShape
     22ATTRIBUTE_ALIGNED16(class) btTriangleShape : public btPolyhedralConvexShape
    2323{
    2424
     
    3131        {
    3232                return 3;
     33        }
     34
     35        btVector3& getVertexPtr(int index)
     36        {
     37                return m_vertices1[index];
    3338        }
    3439
     
    7883        }
    7984
    80 
     85        btTriangleShape() : btPolyhedralConvexShape ()
     86    {
     87                m_shapeType = TRIANGLE_SHAPE_PROXYTYPE;
     88        }
    8189
    8290        btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2) : btPolyhedralConvexShape ()
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2007 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.h

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp

    r5781 r8284  
    9797        {
    9898               
    99                 btGjkPairDetector gjk(m_convexA,m_convexB,m_simplexSolver,m_penetrationDepthSolver);           
     99                btGjkPairDetector gjk(m_convexA,m_convexB,m_convexA->getShapeType(),m_convexB->getShapeType(),m_convexA->getMargin(),m_convexB->getMargin(),m_simplexSolver,m_penetrationDepthSolver);         
    100100                btGjkPairDetector::ClosestPointInput input;
    101101       
     
    122122                while (dist > radius)
    123123                {
     124                        if (result.m_debugDrawer)
     125                        {
     126                                result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1));
     127                        }
    124128                        numIter++;
    125129                        if (numIter > maxIter)
     
    170174                        btTransformUtil::integrateTransform(fromB,linVelB,angVelB,lambda,interpolatedTransB);
    171175                        relativeTrans = interpolatedTransB.inverseTimes(interpolatedTransA);
     176
     177                        if (result.m_debugDrawer)
     178                        {
     179                                result.m_debugDrawer->drawSphere(interpolatedTransA.getOrigin(),0.2f,btVector3(1,0,0));
     180                        }
    172181
    173182                        result.DebugDraw( lambda );
     
    198207                                return false;
    199208                        }
     209                       
    200210
    201211                }
     
    225235
    226236}
    227 
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexCast.h

    r5781 r8284  
    4242
    4343                CastResult()
    44                         :m_fraction(btScalar(1e30)),
     44                        :m_fraction(btScalar(BT_LARGE_FLOAT)),
    4545                        m_debugDrawer(0),
    4646                        m_allowedPenetration(btScalar(0))
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h

    r5781 r8284  
    1515
    1616
    17 #ifndef CONVEX_PENETRATION_DEPTH_H
    18 #define CONVEX_PENETRATION_DEPTH_H
     17#ifndef __CONVEX_PENETRATION_DEPTH_H
     18#define __CONVEX_PENETRATION_DEPTH_H
    1919
    2020class btStackAlloc;
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h

    r5781 r8284  
    3434                virtual ~Result(){}     
    3535
    36                 ///setShapeIdentifiers provides experimental support for per-triangle material / custom material combiner
    37                 virtual void setShapeIdentifiers(int partId0,int index0,        int partId1,int index1)=0;
     36                ///setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material combiner
     37                virtual void setShapeIdentifiersA(int partId0,int index0)=0;
     38                virtual void setShapeIdentifiersB(int partId1,int index1)=0;
    3839                virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)=0;
    3940        };
     
    4243        {
    4344                ClosestPointInput()
    44                         :m_maximumDistanceSquared(btScalar(1e30)),
     45                        :m_maximumDistanceSquared(btScalar(BT_LARGE_FLOAT)),
    4546                        m_stackAlloc(0)
    4647                {
     
    6970                btScalar        m_distance; //negative means penetration !
    7071
    71                 btStorageResult() : m_distance(btScalar(1e30))
     72                btStorageResult() : m_distance(btScalar(BT_LARGE_FLOAT))
    7273                {
    7374
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp

    r5781 r8284  
    6969                btMatrix3x3                             m_toshape1;
    7070                btTransform                             m_toshape0;
     71#ifdef __SPU__
     72                bool                                    m_enableMargin;
     73#else
    7174                btVector3                               (btConvexShape::*Ls)(const btVector3&) const;
     75#endif//__SPU__
     76               
     77
     78                MinkowskiDiff()
     79                {
     80
     81                }
     82#ifdef __SPU__
     83                        void                                    EnableMargin(bool enable)
     84                {
     85                        m_enableMargin = enable;
     86                }       
     87                inline btVector3                Support0(const btVector3& d) const
     88                {
     89                        if (m_enableMargin)
     90                        {
     91                                return m_shapes[0]->localGetSupportVertexNonVirtual(d);
     92                        } else
     93                        {
     94                                return m_shapes[0]->localGetSupportVertexWithoutMarginNonVirtual(d);
     95                        }
     96                }
     97                inline btVector3                Support1(const btVector3& d) const
     98                {
     99                        if (m_enableMargin)
     100                        {
     101                                return m_toshape0*(m_shapes[1]->localGetSupportVertexNonVirtual(m_toshape1*d));
     102                        } else
     103                        {
     104                                return m_toshape0*(m_shapes[1]->localGetSupportVertexWithoutMarginNonVirtual(m_toshape1*d));
     105                        }
     106                }
     107#else
    72108                void                                    EnableMargin(bool enable)
    73109                {
     
    85121                        return(m_toshape0*((m_shapes[1])->*(Ls))(m_toshape1*d));
    86122                }
     123#endif //__SPU__
     124
    87125                inline btVector3                Support(const btVector3& d) const
    88126                {
     
    203241                                        }
    204242                                        /* Check for termination                                */
    205                                         const btScalar  omega=dot(m_ray,w)/rl;
     243                                        const btScalar  omega=btDot(m_ray,w)/rl;
    206244                                        alpha=btMax(omega,alpha);
    207245                                        if(((rl-alpha)-(GJK_ACCURARY*rl))<=0)
     
    260298                                case    eStatus::Valid:         m_distance=m_ray.length();break;
    261299                                case    eStatus::Inside:        m_distance=0;break;
     300                                default:
     301                                        {
     302                                        }
    262303                                }       
    263304                                return(m_status);
     
    289330                                                        btVector3               axis=btVector3(0,0,0);
    290331                                                        axis[i]=1;
    291                                                         const btVector3 p=cross(d,axis);
     332                                                        const btVector3 p=btCross(d,axis);
    292333                                                        if(p.length2()>0)
    293334                                                        {
     
    304345                                case    3:
    305346                                        {
    306                                                 const btVector3 n=cross(m_simplex->c[1]->w-m_simplex->c[0]->w,
     347                                                const btVector3 n=btCross(m_simplex->c[1]->w-m_simplex->c[0]->w,
    307348                                                        m_simplex->c[2]->w-m_simplex->c[0]->w);
    308349                                                if(n.length2()>0)
     
    358399                                if(l>GJK_SIMPLEX2_EPS)
    359400                                {
    360                                         const btScalar  t(l>0?-dot(a,d)/l:0);
     401                                        const btScalar  t(l>0?-btDot(a,d)/l:0);
    361402                                        if(t>=1)                { w[0]=0;w[1]=1;m=2;return(b.length2()); }
    362403                                        else if(t<=0)   { w[0]=1;w[1]=0;m=1;return(a.length2()); }
     
    373414                                const btVector3*        vt[]={&a,&b,&c};
    374415                                const btVector3         dl[]={a-b,b-c,c-a};
    375                                 const btVector3         n=cross(dl[0],dl[1]);
     416                                const btVector3         n=btCross(dl[0],dl[1]);
    376417                                const btScalar          l=n.length2();
    377418                                if(l>GJK_SIMPLEX3_EPS)
    378419                                {
    379420                                        btScalar        mindist=-1;
    380                                         btScalar        subw[2];
    381                                         U                       subm;
     421                                        btScalar        subw[2]={0.f,0.f};
     422                                        U                       subm(0);
    382423                                        for(U i=0;i<3;++i)
    383424                                        {
    384                                                 if(dot(*vt[i],cross(dl[i],n))>0)
     425                                                if(btDot(*vt[i],btCross(dl[i],n))>0)
    385426                                                {
    386427                                                        const U                 j=imd3[i];
     
    398439                                        if(mindist<0)
    399440                                        {
    400                                                 const btScalar  d=dot(a,n);     
     441                                                const btScalar  d=btDot(a,n);   
    401442                                                const btScalar  s=btSqrt(l);
    402443                                                const btVector3 p=n*(d/l);
    403444                                                mindist =       p.length2();
    404445                                                m               =       7;
    405                                                 w[0]    =       (cross(dl[1],b-p)).length()/s;
    406                                                 w[1]    =       (cross(dl[2],c-p)).length()/s;
     446                                                w[0]    =       (btCross(dl[1],b-p)).length()/s;
     447                                                w[1]    =       (btCross(dl[2],c-p)).length()/s;
    407448                                                w[2]    =       1-(w[0]+w[1]);
    408449                                        }
     
    421462                                const btVector3         dl[]={a-d,b-d,c-d};
    422463                                const btScalar          vl=det(dl[0],dl[1],dl[2]);
    423                                 const bool                      ng=(vl*dot(a,cross(b-c,a-b)))<=0;
     464                                const bool                      ng=(vl*btDot(a,btCross(b-c,a-b)))<=0;
    424465                                if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS))
    425466                                {
    426467                                        btScalar        mindist=-1;
    427                                         btScalar        subw[3];
    428                                         U                       subm;
     468                                        btScalar        subw[3]={0.f,0.f,0.f};
     469                                        U                       subm(0);
    429470                                        for(U i=0;i<3;++i)
    430471                                        {
    431472                                                const U                 j=imd3[i];
    432                                                 const btScalar  s=vl*dot(d,cross(dl[i],dl[j]));
     473                                                const btScalar  s=vl*btDot(d,btCross(dl[i],dl[j]));
    433474                                                if(s>0)
    434475                                                {
     
    602643                                                                best->pass      =       (U1)(++pass);
    603644                                                                gjk.getsupport(best->n,*w);
    604                                                                 const btScalar  wdist=dot(best->n,w->w)-best->d;
     645                                                                const btScalar  wdist=btDot(best->n,w->w)-best->d;
    605646                                                                if(wdist>EPA_ACCURACY)
    606647                                                                {
     
    629670                                                m_result.c[1]   =       outer.c[1];
    630671                                                m_result.c[2]   =       outer.c[2];
    631                                                 m_result.p[0]   =       cross(  outer.c[1]->w-projection,
     672                                                m_result.p[0]   =       btCross(        outer.c[1]->w-projection,
    632673                                                        outer.c[2]->w-projection).length();
    633                                                 m_result.p[1]   =       cross(  outer.c[2]->w-projection,
     674                                                m_result.p[1]   =       btCross(        outer.c[2]->w-projection,
    634675                                                        outer.c[0]->w-projection).length();
    635                                                 m_result.p[2]   =       cross(  outer.c[0]->w-projection,
     676                                                m_result.p[2]   =       btCross(        outer.c[0]->w-projection,
    636677                                                        outer.c[1]->w-projection).length();
    637678                                                const btScalar  sum=m_result.p[0]+m_result.p[1]+m_result.p[2];
     
    667708                                        face->c[1]      =       b;
    668709                                        face->c[2]      =       c;
    669                                         face->n         =       cross(b->w-a->w,c->w-a->w);
     710                                        face->n         =       btCross(b->w-a->w,c->w-a->w);
    670711                                        const btScalar  l=face->n.length();
    671712                                        const bool              v=l>EPA_ACCURACY;
    672713                                        face->p         =       btMin(btMin(
    673                                                 dot(a->w,cross(face->n,a->w-b->w)),
    674                                                 dot(b->w,cross(face->n,b->w-c->w))),
    675                                                 dot(c->w,cross(face->n,c->w-a->w)))     /
     714                                                btDot(a->w,btCross(face->n,a->w-b->w)),
     715                                                btDot(b->w,btCross(face->n,b->w-c->w))),
     716                                                btDot(c->w,btCross(face->n,c->w-a->w))) /
    676717                                                (v?l:1);
    677718                                        face->p         =       face->p>=-EPA_INSIDE_EPS?0:face->p;
    678719                                        if(v)
    679720                                        {
    680                                                 face->d         =       dot(a->w,face->n)/l;
     721                                                face->d         =       btDot(a->w,face->n)/l;
    681722                                                face->n         /=      l;
    682723                                                if(forced||(face->d>=-EPA_PLANE_EPS))
     
    716757                                {
    717758                                        const U e1=i1m3[e];
    718                                         if((dot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)
     759                                        if((btDot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)
    719760                                        {
    720761                                                sFace*  nf=newface(f->c[e1],f->c[e],w,false);
     
    855896                results.status=sResults::GJK_Failed;
    856897                break;
     898                default:
     899                                        {
     900                                        }
    857901        }
    858902        return(false);
    859903}
    860904
     905#ifndef __SPU__
    861906//
    862907btScalar        btGjkEpaSolver2::SignedDistance(const btVector3& position,
     
    924969                return(true);
    925970}
     971#endif //__SPU__
    926972
    927973/* Symbols cleanup              */
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h

    r5781 r8284  
    5656                                                        sResults& results,
    5757                                                        bool usemargins=true);
    58 
     58#ifndef __SPU__
    5959static btScalar SignedDistance( const btVector3& position,
    6060                                                                btScalar margin,
     
    6767                                                                const btVector3& guess,
    6868                                                                sResults& results);
     69#endif //__SPU__
     70
    6971};
    7072
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp

    r5781 r8284  
    3333        (void)simplexSolver;
    3434
    35         const btScalar                          radialmargin(btScalar(0.));
     35//      const btScalar                          radialmargin(btScalar(0.));
    3636       
    3737        btVector3       guessVector(transformA.getOrigin()-transformB.getOrigin());
    3838        btGjkEpaSolver2::sResults       results;
     39       
     40
    3941        if(btGjkEpaSolver2::Penetration(pConvexA,transformA,
    4042                                                                pConvexB,transformB,
     
    4648                wWitnessOnA = results.witnesses[0];
    4749                wWitnessOnB = results.witnesses[1];
     50                v = results.normal;
    4851                return true;           
     52                } else
     53        {
     54                if(btGjkEpaSolver2::Distance(pConvexA,transformA,pConvexB,transformB,guessVector,results))
     55                {
     56                        wWitnessOnA = results.witnesses[0];
     57                        wWitnessOnB = results.witnesses[1];
     58                        v = results.normal;
     59                        return false;
    4960                }
     61        }
    5062
    5163        return false;
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h

    r5781 r8284  
    2626        public :
    2727
     28                btGjkEpaPenetrationDepthSolver()
     29                {
     30                }
     31
    2832                bool                    calcPenDepth( btSimplexSolverInterface& simplexSolver,
    2933                                                                          const btConvexShape* pConvexA, const btConvexShape* pConvexB,
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp

    r5781 r8284  
    3939
    4040
    41 
    4241btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver*  penetrationDepthSolver)
    43 :m_cachedSeparatingAxis(btScalar(0.),btScalar(0.),btScalar(1.)),
     42:m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)),
    4443m_penetrationDepthSolver(penetrationDepthSolver),
    4544m_simplexSolver(simplexSolver),
    4645m_minkowskiA(objectA),
    4746m_minkowskiB(objectB),
     47m_shapeTypeA(objectA->getShapeType()),
     48m_shapeTypeB(objectB->getShapeType()),
     49m_marginA(objectA->getMargin()),
     50m_marginB(objectB->getMargin()),
    4851m_ignoreMargin(false),
    4952m_lastUsedMethod(-1),
     
    5154{
    5255}
    53 
    54 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults)
     56btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver*        penetrationDepthSolver)
     57:m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)),
     58m_penetrationDepthSolver(penetrationDepthSolver),
     59m_simplexSolver(simplexSolver),
     60m_minkowskiA(objectA),
     61m_minkowskiB(objectB),
     62m_shapeTypeA(shapeTypeA),
     63m_shapeTypeB(shapeTypeB),
     64m_marginA(marginA),
     65m_marginB(marginB),
     66m_ignoreMargin(false),
     67m_lastUsedMethod(-1),
     68m_catchDegeneracies(1)
     69{
     70}
     71
     72void    btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults)
     73{
     74        (void)swapResults;
     75
     76        getClosestPointsNonVirtual(input,output,debugDraw);
     77}
     78
     79#ifdef __SPU__
     80void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw)
     81#else
     82void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw)
     83#endif
    5584{
    5685        m_cachedSeparatingDistance = 0.f;
     
    6594        localTransB.getOrigin() -= positionOffset;
    6695
    67 #ifdef __SPU__
    68         btScalar marginA = m_minkowskiA->getMarginNonVirtual();
    69         btScalar marginB = m_minkowskiB->getMarginNonVirtual();
    70 #else
    71         btScalar marginA = m_minkowskiA->getMargin();
    72         btScalar marginB = m_minkowskiB->getMargin();
    73 #ifdef TEST_NON_VIRTUAL
    74         btScalar marginAv = m_minkowskiA->getMarginNonVirtual();
    75         btScalar marginBv = m_minkowskiB->getMarginNonVirtual();
    76         btAssert(marginA == marginAv);
    77         btAssert(marginB == marginBv);
    78 #endif //TEST_NON_VIRTUAL
    79 #endif
    80        
    81 
     96        bool check2d = m_minkowskiA->isConvex2d() && m_minkowskiB->isConvex2d();
     97
     98        btScalar marginA = m_marginA;
     99        btScalar marginB = m_marginB;
    82100
    83101        gNumGjkChecks++;
     
    108126
    109127        {
    110                 btScalar squaredDistance = SIMD_INFINITY;
     128                btScalar squaredDistance = BT_LARGE_FLOAT;
    111129                btScalar delta = btScalar(0.);
    112130               
     
    124142                        btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
    125143
     144#if 1
     145
     146                        btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
     147                        btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
     148
     149//                      btVector3 pInA  = localGetSupportingVertexWithoutMargin(m_shapeTypeA, m_minkowskiA, seperatingAxisInA,input.m_convexVertexData[0]);//, &featureIndexA);
     150//                      btVector3 qInB  = localGetSupportingVertexWithoutMargin(m_shapeTypeB, m_minkowskiB, seperatingAxisInB,input.m_convexVertexData[1]);//, &featureIndexB);
     151
     152#else
    126153#ifdef __SPU__
    127154                        btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
     
    137164#endif //
    138165#endif //__SPU__
     166#endif
     167
    139168
    140169                        btVector3  pWorld = localTransA(pInA); 
     
    145174#endif
    146175
     176                        if (check2d)
     177                        {
     178                                pWorld[2] = 0.f;
     179                                qWorld[2] = 0.f;
     180                        }
     181
    147182                        btVector3 w     = pWorld - qWorld;
    148183                        delta = m_cachedSeparatingAxis.dot(w);
     
    151186                        if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * input.m_maximumDistanceSquared))
    152187                        {
     188                                m_degenerateSimplex = 10;
    153189                                checkSimplex=true;
    154190                                //checkPenetration = false;
     
    172208                                {
    173209                                        m_degenerateSimplex = 2;
     210                                } else
     211                                {
     212                                        m_degenerateSimplex = 11;
    174213                                }
    175214                                checkSimplex = true;
     
    185224                spu_printf("addVertex 2\n");
    186225#endif
     226                        btVector3 newCachedSeparatingAxis;
     227
    187228                        //calculate the closest point to the origin (update vector v)
    188                         if (!m_simplexSolver->closest(m_cachedSeparatingAxis))
     229                        if (!m_simplexSolver->closest(newCachedSeparatingAxis))
    189230                        {
    190231                                m_degenerateSimplex = 3;
     
    193234                        }
    194235
    195                         if(m_cachedSeparatingAxis.length2()<REL_ERROR2)
     236                        if(newCachedSeparatingAxis.length2()<REL_ERROR2)
    196237            {
     238                                m_cachedSeparatingAxis = newCachedSeparatingAxis;
    197239                m_degenerateSimplex = 6;
    198240                checkSimplex = true;
     
    201243
    202244                        btScalar previousSquaredDistance = squaredDistance;
    203                         squaredDistance = m_cachedSeparatingAxis.length2();
     245                        squaredDistance = newCachedSeparatingAxis.length2();
     246#if 0
     247///warning: this termination condition leads to some problems in 2d test case see Bullet/Demos/Box2dDemo
     248                        if (squaredDistance>previousSquaredDistance)
     249                        {
     250                                m_degenerateSimplex = 7;
     251                                squaredDistance = previousSquaredDistance;
     252                checkSimplex = false;
     253                break;
     254                        }
     255#endif //
    204256                       
     257                        m_cachedSeparatingAxis = newCachedSeparatingAxis;
     258
    205259                        //redundant m_simplexSolver->compute_points(pointOnA, pointOnB);
    206260
     
    210264                                m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
    211265                                checkSimplex = true;
     266                                m_degenerateSimplex = 12;
     267                               
    212268                                break;
    213269                        }
     
    240296                                //do we need this backup_closest here ?
    241297                                m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
     298                                m_degenerateSimplex = 13;
    242299                                break;
    243300                        }
     
    248305                        m_simplexSolver->compute_points(pointOnA, pointOnB);
    249306                        normalInB = pointOnA-pointOnB;
    250                         btScalar lenSqr = m_cachedSeparatingAxis.length2();
     307                        btScalar lenSqr =m_cachedSeparatingAxis.length2();
     308                       
    251309                        //valid normal
    252310                        if (lenSqr < 0.0001)
     
    280338                {
    281339                        //penetration case
    282                
     340
    283341                        //if there is no way to handle penetrations, bail out
    284342                        if (m_penetrationDepthSolver)
     
    288346                               
    289347                                gNumDeepPenetrationChecks++;
     348                                m_cachedSeparatingAxis.setZero();
    290349
    291350                                bool isValid2 = m_penetrationDepthSolver->calcPenDepth(
     
    297356                                        );
    298357
     358
    299359                                if (isValid2)
    300360                                {
    301361                                        btVector3 tmpNormalInB = tmpPointOnB-tmpPointOnA;
    302362                                        btScalar lenSqr = tmpNormalInB.length2();
     363                                        if (lenSqr <= (SIMD_EPSILON*SIMD_EPSILON))
     364                                        {
     365                                                tmpNormalInB = m_cachedSeparatingAxis;
     366                                                lenSqr = m_cachedSeparatingAxis.length2();
     367                                        }
     368
    303369                                        if (lenSqr > (SIMD_EPSILON*SIMD_EPSILON))
    304370                                        {
     
    316382                                                } else
    317383                                                {
    318                                                        
     384                                                        m_lastUsedMethod = 8;
    319385                                                }
    320386                                        } else
    321387                                        {
    322                                                 //isValid = false;
    323                                                 m_lastUsedMethod = 4;
     388                                                m_lastUsedMethod = 9;
    324389                                        }
    325390                                } else
     391
    326392                                {
    327                                         m_lastUsedMethod = 5;
     393                                        ///this is another degenerate case, where the initial GJK calculation reports a degenerate case
     394                                        ///EPA reports no penetration, and the second GJK (using the supporting vector without margin)
     395                                        ///reports a valid positive distance. Use the results of the second GJK instead of failing.
     396                                        ///thanks to Jacob.Langford for the reproduction case
     397                                        ///http://code.google.com/p/bullet/issues/detail?id=250
     398
     399                               
     400                                        if (m_cachedSeparatingAxis.length2() > btScalar(0.))
     401                                        {
     402                                                btScalar distance2 = (tmpPointOnA-tmpPointOnB).length()-margin;
     403                                                //only replace valid distances when the distance is less
     404                                                if (!isValid || (distance2 < distance))
     405                                                {
     406                                                        distance = distance2;
     407                                                        pointOnA = tmpPointOnA;
     408                                                        pointOnB = tmpPointOnB;
     409                                                        pointOnA -= m_cachedSeparatingAxis * marginA ;
     410                                                        pointOnB += m_cachedSeparatingAxis * marginB ;
     411                                                        normalInB = m_cachedSeparatingAxis;
     412                                                        normalInB.normalize();
     413                                                        isValid = true;
     414                                                        m_lastUsedMethod = 6;
     415                                                } else
     416                                                {
     417                                                        m_lastUsedMethod = 5;
     418                                                }
     419                                        }
    328420                                }
    329421                               
    330422                        }
     423
    331424                }
    332425        }
    333426
    334         if (isValid)
     427       
     428
     429        if (isValid && ((distance < 0) || (distance*distance < input.m_maximumDistanceSquared)))
    335430        {
    336 #ifdef __SPU__
    337                 //spu_printf("distance\n");
    338 #endif //__CELLOS_LV2__
    339 
    340 
    341 #ifdef DEBUG_SPU_COLLISION_DETECTION
    342                 spu_printf("output 1\n");
    343 #endif
     431#if 0
     432///some debugging
     433//              if (check2d)
     434                {
     435                        printf("n = %2.3f,%2.3f,%2.3f. ",normalInB[0],normalInB[1],normalInB[2]);
     436                        printf("distance = %2.3f exit=%d deg=%d\n",distance,m_lastUsedMethod,m_degenerateSimplex);
     437                }
     438#endif
     439
    344440                m_cachedSeparatingAxis = normalInB;
    345441                m_cachedSeparatingDistance = distance;
     
    350446                        distance);
    351447
    352 #ifdef DEBUG_SPU_COLLISION_DETECTION
    353                 spu_printf("output 2\n");
    354 #endif
    355                 //printf("gjk add:%f",distance);
    356448        }
    357449
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h

    r5781 r8284  
    3737        const btConvexShape* m_minkowskiA;
    3838        const btConvexShape* m_minkowskiB;
     39        int     m_shapeTypeA;
     40        int m_shapeTypeB;
     41        btScalar        m_marginA;
     42        btScalar        m_marginB;
     43
    3944        bool            m_ignoreMargin;
    4045        btScalar        m_cachedSeparatingDistance;
     
    5156
    5257        btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver*     penetrationDepthSolver);
     58        btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver*   penetrationDepthSolver);
    5359        virtual ~btGjkPairDetector() {};
    5460
    5561        virtual void    getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults=false);
     62
     63        void    getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw);
     64       
    5665
    5766        void setMinkowskiA(btConvexShape* minkA)
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h

    r5781 r8284  
    2020#include "LinearMath/btTransformUtil.h"
    2121
     22// Don't change following order of parameters
     23ATTRIBUTE_ALIGNED16(struct) PfxConstraintRow {
     24        btScalar mNormal[3];
     25        btScalar mRhs;
     26        btScalar mJacDiagInv;
     27        btScalar mLowerLimit;
     28        btScalar mUpperLimit;
     29        btScalar mAccumImpulse;
     30};
    2231
    2332
     
    3544                                m_appliedImpulseLateral1(0.f),
    3645                                m_appliedImpulseLateral2(0.f),
     46                                m_contactMotion1(0.f),
     47                                m_contactMotion2(0.f),
     48                                m_contactCFM1(0.f),
     49                                m_contactCFM2(0.f),
    3750                                m_lifeTime(0)
    3851                        {
     
    5366                                        m_appliedImpulseLateral1(0.f),
    5467                                        m_appliedImpulseLateral2(0.f),
     68                                        m_contactMotion1(0.f),
     69                                        m_contactMotion2(0.f),
     70                                        m_contactCFM1(0.f),
     71                                        m_contactCFM2(0.f),
    5572                                        m_lifeTime(0)
    5673                        {
    57                                
    58                                        
     74                                mConstraintRow[0].mAccumImpulse = 0.f;
     75                                mConstraintRow[1].mAccumImpulse = 0.f;
     76                                mConstraintRow[2].mAccumImpulse = 0.f;
    5977                        }
    6078
     
    84102                        btScalar                m_appliedImpulseLateral1;
    85103                        btScalar                m_appliedImpulseLateral2;
     104                        btScalar                m_contactMotion1;
     105                        btScalar                m_contactMotion2;
     106                        btScalar                m_contactCFM1;
     107                        btScalar                m_contactCFM2;
     108
    86109                        int                             m_lifeTime;//lifetime of the contactpoint in frames
    87110                       
    88111                        btVector3               m_lateralFrictionDir1;
    89112                        btVector3               m_lateralFrictionDir2;
     113
     114
     115
     116                        PfxConstraintRow mConstraintRow[3];
     117
    90118
    91119                        btScalar getDistance() const
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp

    r5781 r8284  
    2121
    2222#define NUM_UNITSPHERE_POINTS 42
    23 static btVector3        sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
    24 {
    25 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
    26 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
    27 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
    28 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
    29 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
    30 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
    31 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
    32 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
    33 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
    34 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
    35 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
    36 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
    37 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
    38 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
    39 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
    40 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
    41 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
    42 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
    43 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
    44 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
    45 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
    46 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
    47 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
    48 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
    49 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
    50 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
    51 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
    52 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
    53 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
    54 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
    55 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
    56 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
    57 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
    58 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
    59 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
    60 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
    61 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
    62 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
    63 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
    64 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
    65 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
    66 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
    67 };
    6823
    6924
     
    7934        (void)v;
    8035       
     36        bool check2d= convexA->isConvex2d() && convexB->isConvex2d();
    8137
    8238        struct btIntermediateResult : public btDiscreteCollisionDetectorInterface::Result
     
    9248                bool    m_hasResult;
    9349
    94                 virtual void setShapeIdentifiers(int partId0,int index0,        int partId1,int index1)
     50                virtual void setShapeIdentifiersA(int partId0,int index0)
    9551                {
    9652                        (void)partId0;
    9753                        (void)index0;
     54                }
     55                virtual void setShapeIdentifiersB(int partId1,int index1)
     56                {
    9857                        (void)partId1;
    9958                        (void)index1;
     
    10968
    11069        //just take fixed number of orientation, and sample the penetration depth in that direction
    111         btScalar minProj = btScalar(1e30);
     70        btScalar minProj = btScalar(BT_LARGE_FLOAT);
    11271        btVector3 minNorm(btScalar(0.), btScalar(0.), btScalar(0.));
    11372        btVector3 minA,minB;
     
    13089        for (i=0;i<numSampleDirections;i++)
    13190        {
    132                 const btVector3& norm = sPenetrationDirections[i];
     91                btVector3 norm = getPenetrationDirections()[i];
    13392                seperatingAxisInABatch[i] =  (-norm) * transA.getBasis() ;
    13493                seperatingAxisInBBatch[i] =  norm   * transB.getBasis() ;
     
    144103                                convexA->getPreferredPenetrationDirection(i,norm);
    145104                                norm  = transA.getBasis() * norm;
    146                                 sPenetrationDirections[numSampleDirections] = norm;
     105                                getPenetrationDirections()[numSampleDirections] = norm;
    147106                                seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis();
    148107                                seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis();
     
    161120                                convexB->getPreferredPenetrationDirection(i,norm);
    162121                                norm  = transB.getBasis() * norm;
    163                                 sPenetrationDirections[numSampleDirections] = norm;
     122                                getPenetrationDirections()[numSampleDirections] = norm;
    164123                                seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis();
    165124                                seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis();
     
    171130
    172131
     132
    173133        convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,numSampleDirections);
    174134        convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,numSampleDirections);
     
    176136        for (i=0;i<numSampleDirections;i++)
    177137        {
    178                 const btVector3& norm = sPenetrationDirections[i];
    179                 seperatingAxisInA = seperatingAxisInABatch[i];
    180                 seperatingAxisInB = seperatingAxisInBBatch[i];
    181 
    182                 pInA = supportVerticesABatch[i];
    183                 qInB = supportVerticesBBatch[i];
    184 
    185                 pWorld = transA(pInA); 
    186                 qWorld = transB(qInB);
    187                 w       = qWorld - pWorld;
    188                 btScalar delta = norm.dot(w);
    189                 //find smallest delta
    190                 if (delta < minProj)
    191                 {
    192                         minProj = delta;
    193                         minNorm = norm;
    194                         minA = pWorld;
    195                         minB = qWorld;
     138                btVector3 norm = getPenetrationDirections()[i];
     139                if (check2d)
     140                {
     141                        norm[2] = 0.f;
     142                }
     143                if (norm.length2()>0.01)
     144                {
     145
     146                        seperatingAxisInA = seperatingAxisInABatch[i];
     147                        seperatingAxisInB = seperatingAxisInBBatch[i];
     148
     149                        pInA = supportVerticesABatch[i];
     150                        qInB = supportVerticesBBatch[i];
     151
     152                        pWorld = transA(pInA); 
     153                        qWorld = transB(qInB);
     154                        if (check2d)
     155                        {
     156                                pWorld[2] = 0.f;
     157                                qWorld[2] = 0.f;
     158                        }
     159
     160                        w       = qWorld - pWorld;
     161                        btScalar delta = norm.dot(w);
     162                        //find smallest delta
     163                        if (delta < minProj)
     164                        {
     165                                minProj = delta;
     166                                minNorm = norm;
     167                                minA = pWorld;
     168                                minB = qWorld;
     169                        }
    196170                }
    197171        }       
     
    210184                                convexA->getPreferredPenetrationDirection(i,norm);
    211185                                norm  = transA.getBasis() * norm;
    212                                 sPenetrationDirections[numSampleDirections] = norm;
     186                                getPenetrationDirections()[numSampleDirections] = norm;
    213187                                numSampleDirections++;
    214188                        }
     
    225199                                convexB->getPreferredPenetrationDirection(i,norm);
    226200                                norm  = transB.getBasis() * norm;
    227                                 sPenetrationDirections[numSampleDirections] = norm;
     201                                getPenetrationDirections()[numSampleDirections] = norm;
    228202                                numSampleDirections++;
    229203                        }
     
    234208        for (int i=0;i<numSampleDirections;i++)
    235209        {
    236                 const btVector3& norm = sPenetrationDirections[i];
     210                const btVector3& norm = getPenetrationDirections()[i];
    237211                seperatingAxisInA = (-norm)* transA.getBasis();
    238212                seperatingAxisInB = norm* transB.getBasis();
     
    262236                return false;
    263237
    264         minProj += (convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual());
     238        btScalar extraSeparation = 0.5f;///scale dependent
     239        minProj += extraSeparation+(convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual());
    265240
    266241
     
    300275        input.m_transformA = displacedTrans;
    301276        input.m_transformB = transB;
    302         input.m_maximumDistanceSquared = btScalar(1e30);//minProj;
     277        input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);//minProj;
    303278       
    304279        btIntermediateResult res;
     280        gjkdet.setCachedSeperatingAxis(-minNorm);
    305281        gjkdet.getClosestPoints(input,res,debugDraw);
    306282
     
    311287        btScalar penetration_relaxation= btScalar(1.);
    312288        minNorm*=penetration_relaxation;
     289       
    313290
    314291        if (res.m_hasResult)
     
    317294                pa = res.m_pointInWorld - minNorm * correctedMinNorm;
    318295                pb = res.m_pointInWorld;
     296                v = minNorm;
    319297               
    320298#ifdef DEBUG_DRAW
     
    331309}
    332310
    333 
    334 
     311btVector3*      btMinkowskiPenetrationDepthSolver::getPenetrationDirections()
     312{
     313        static btVector3        sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =
     314        {
     315        btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),
     316        btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),
     317        btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),
     318        btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),
     319        btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),
     320        btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),
     321        btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),
     322        btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),
     323        btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),
     324        btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),
     325        btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),
     326        btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),
     327        btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),
     328        btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),
     329        btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),
     330        btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),
     331        btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),
     332        btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),
     333        btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),
     334        btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),
     335        btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),
     336        btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),
     337        btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),
     338        btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),
     339        btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),
     340        btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),
     341        btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),
     342        btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),
     343        btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),
     344        btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),
     345        btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),
     346        btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),
     347        btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),
     348        btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),
     349        btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),
     350        btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),
     351        btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),
     352        btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),
     353        btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),
     354        btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),
     355        btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),
     356        btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))
     357        };
     358
     359        return sPenetrationDirections;
     360}
     361
     362
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h

    r5781 r8284  
    2323class btMinkowskiPenetrationDepthSolver : public btConvexPenetrationDepthSolver
    2424{
     25protected:
     26
     27        static btVector3*       getPenetrationDirections();
     28
    2529public:
    2630
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp

    r5781 r8284  
    2626
    2727btPersistentManifold::btPersistentManifold()
    28 :m_body0(0),
     28:btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE),
     29m_body0(0),
    2930m_body1(0),
    3031m_cachedPoints (0),
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h

    r5781 r8284  
    3131typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1);
    3232extern ContactDestroyedCallback gContactDestroyedCallback;
    33 
    34 
    35 
     33extern ContactProcessedCallback gContactProcessedCallback;
     34
     35
     36enum btContactManifoldTypes
     37{
     38        BT_PERSISTENT_MANIFOLD_TYPE = 1,
     39        MAX_CONTACT_MANIFOLD_TYPE
     40};
    3641
    3742#define MANIFOLD_CACHE_SIZE 4
     
    4449///the contact point with deepest penetration is always kept, and it tries to maximuze the area covered by the points
    4550///note that some pairs of objects might have more then one contact manifold.
    46 ATTRIBUTE_ALIGNED16( class) btPersistentManifold
     51
     52
     53ATTRIBUTE_ALIGNED128( class) btPersistentManifold : public btTypedObject
     54//ATTRIBUTE_ALIGNED16( class) btPersistentManifold : public btTypedObject
    4755{
    4856
     
    5361        void* m_body0;
    5462        void* m_body1;
     63
    5564        int     m_cachedPoints;
    5665
     
    6877        BT_DECLARE_ALIGNED_ALLOCATOR();
    6978
     79        int     m_companionIdA;
     80        int     m_companionIdB;
     81
    7082        int m_index1a;
    7183
     
    7385
    7486        btPersistentManifold(void* body0,void* body1,int , btScalar contactBreakingThreshold,btScalar contactProcessingThreshold)
    75                 : m_body0(body0),m_body1(body1),m_cachedPoints(0),
     87                : btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE),
     88        m_body0(body0),m_body1(body1),m_cachedPoints(0),
    7689                m_contactBreakingThreshold(contactBreakingThreshold),
    7790                m_contactProcessingThreshold(contactProcessingThreshold)
    7891        {
    79                
    8092        }
    8193
     
    135147                        //get rid of duplicated userPersistentData pointer
    136148                        m_pointCache[lastUsedIndex].m_userPersistentData = 0;
     149                        m_pointCache[lastUsedIndex].mConstraintRow[0].mAccumImpulse = 0.f;
     150                        m_pointCache[lastUsedIndex].mConstraintRow[1].mAccumImpulse = 0.f;
     151                        m_pointCache[lastUsedIndex].mConstraintRow[2].mAccumImpulse = 0.f;
     152
    137153                        m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f;
    138154                        m_pointCache[lastUsedIndex].m_lateralFrictionInitialized = false;
     
    152168#ifdef MAINTAIN_PERSISTENCY
    153169                int     lifeTime = m_pointCache[insertIndex].getLifeTime();
    154                 btScalar        appliedImpulse = m_pointCache[insertIndex].m_appliedImpulse;
    155                 btScalar        appliedLateralImpulse1 = m_pointCache[insertIndex].m_appliedImpulseLateral1;
    156                 btScalar        appliedLateralImpulse2 = m_pointCache[insertIndex].m_appliedImpulseLateral2;
    157                                
     170                btScalar        appliedImpulse = m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse;
     171                btScalar        appliedLateralImpulse1 = m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse;
     172                btScalar        appliedLateralImpulse2 = m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse;
     173//              bool isLateralFrictionInitialized = m_pointCache[insertIndex].m_lateralFrictionInitialized;
     174               
     175               
     176                       
    158177                btAssert(lifeTime>=0);
    159178                void* cache = m_pointCache[insertIndex].m_userPersistentData;
     
    166185                m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2;
    167186               
     187                m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse =  appliedImpulse;
     188                m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse = appliedLateralImpulse1;
     189                m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse = appliedLateralImpulse2;
     190
     191
    168192                m_pointCache[insertIndex].m_lifeTime = lifeTime;
    169193#else
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPointCollector.h

    r5781 r8284  
    3232
    3333        btPointCollector ()
    34                 : m_distance(btScalar(1e30)),m_hasResult(false)
     34                : m_distance(btScalar(BT_LARGE_FLOAT)),m_hasResult(false)
    3535        {
    3636        }
    3737
    38         virtual void setShapeIdentifiers(int partId0,int index0,        int partId1,int index1)
     38        virtual void setShapeIdentifiersA(int partId0,int index0)
    3939        {
    4040                (void)partId0;
    4141                (void)index0;
     42                       
     43        }
     44        virtual void setShapeIdentifiersB(int partId1,int index1)
     45        {
    4246                (void)partId1;
    4347                (void)index1;
    44                 //??
    4548        }
    4649
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp

    r5781 r8284  
    115115                        }
    116116                }
    117                 m_simplexSolver->addVertex( w, supVertexA , supVertexB);
     117                ///Just like regular GJK only add the vertex if it isn't already (close) to current vertex, it would lead to divisions by zero and NaN etc.
     118                if (!m_simplexSolver->inSimplex(w))
     119                        m_simplexSolver->addVertex( w, supVertexA , supVertexB);
     120
    118121                if (m_simplexSolver->closest(v))
    119122                {
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp

    r5781 r8284  
    6969        m_numVertices = 0;
    7070        m_needsUpdate = true;
    71         m_lastW = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
     71        m_lastW = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
    7272        m_cachedBC.reset();
    7373}
     
    290290        for (i=0;i<numverts;i++)
    291291        {
     292#ifdef BT_USE_EQUAL_VERTEX_THRESHOLD
     293                if ( m_simplexVectorW[i].distance2(w) <= m_equalVertexThreshold)
     294#else
    292295                if (m_simplexVectorW[i] == w)
     296#endif
    293297                        found = true;
    294298        }
  • code/branches/kicklib2/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h

    r5781 r8284  
    2424
    2525#define VORONOI_SIMPLEX_MAX_VERTS 5
     26
     27///disable next define, or use defaultCollisionConfiguration->getSimplexSolver()->setEqualVertexThreshold(0.f) to disable/configure
     28#define BT_USE_EQUAL_VERTEX_THRESHOLD
     29#define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 0.0001f
     30
    2631
    2732struct btUsageBitfield{
     
    107112        btVector3       m_cachedV;
    108113        btVector3       m_lastW;
     114       
     115        btScalar        m_equalVertexThreshold;
    109116        bool            m_cachedValidClosest;
     117
    110118
    111119        btSubSimplexClosestResult m_cachedBC;
     
    123131public:
    124132
     133        btVoronoiSimplexSolver()
     134                :  m_equalVertexThreshold(VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD)
     135        {
     136        }
    125137         void reset();
    126138
    127139         void addVertex(const btVector3& w, const btVector3& p, const btVector3& q);
    128140
     141         void   setEqualVertexThreshold(btScalar threshold)
     142         {
     143                 m_equalVertexThreshold = threshold;
     144         }
     145
     146         btScalar       getEqualVertexThreshold() const
     147         {
     148                 return m_equalVertexThreshold;
     149         }
    129150
    130151         bool closest(btVector3& v);
Note: See TracChangeset for help on using the changeset viewer.