Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 20, 2008, 5:40:38 PM (16 years ago)
Author:
rgrieder
Message:

Downgraded Bullet to latest tagged version: 2.72
That should give us more stability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/bullet/BulletSoftBody/btSparseSDF.h

    r1963 r1972  
    2424template <const int DWORDLEN>
    2525unsigned int HsiehHash(const void* pdata)
    26 {
     26        {
    2727        const unsigned short*   data=(const unsigned short*)pdata;
    2828        unsigned                                hash=DWORDLEN<<2,tmp;
    2929        for(int i=0;i<DWORDLEN;++i)
    30         {
     30                {
    3131                hash    +=      data[0];
    3232                tmp             =       (data[1]<<11)^hash;
     
    3434                data    +=      2;
    3535                hash    +=      hash>>11;
    36         }
     36                }
    3737        hash^=hash<<3;hash+=hash>>5;
    3838        hash^=hash<<4;hash+=hash>>17;
    3939        hash^=hash<<25;hash+=hash>>6;
    4040        return(hash);
    41 }
     41        }
    4242
    4343template <const int CELLSIZE>
    4444struct  btSparseSdf
    45 {
     45        {
    4646        //
    4747        // Inner types
    4848        //
    4949        struct IntFrac
    50         {
     50                {
    5151                int                                     b;
    5252                int                                     i;
    5353                btScalar                        f;
    54         };
     54                };
    5555        struct  Cell
    56         {
     56                {
    5757                btScalar                        d[CELLSIZE+1][CELLSIZE+1][CELLSIZE+1];
    5858                int                                     c[3];
     
    6161                btCollisionShape*       pclient;
    6262                Cell*                           next;
    63         };
     63                };
    6464        //
    6565        // Fields
    6666        //
    67 
     67       
    6868        btAlignedObjectArray<Cell*>             cells; 
    6969        btScalar                                                voxelsz;
     
    7272        int                                                             nprobes;
    7373        int                                                             nqueries;       
    74 
     74       
    7575        //
    7676        // Methods
    7777        //
    78 
     78       
    7979        //
    8080        void                                    Initialize(int hashsize=2383)
    81         {
     81                {
    8282                cells.resize(hashsize,0);
    8383                Reset();               
    84         }
     84                }
    8585        //
    8686        void                                    Reset()
    87         {
     87                {
    8888                for(int i=0,ni=cells.size();i<ni;++i)
    89                 {
     89                        {
    9090                        Cell*   pc=cells[i];
    9191                        cells[i]=0;
    9292                        while(pc)
    93                         {
     93                                {
    9494                                Cell*   pn=pc->next;
    9595                                delete pc;
    9696                                pc=pn;
    97                         }
    98                 }
     97                                }
     98                        }
    9999                voxelsz         =0.25;
    100100                puid            =0;
     
    102102                nprobes         =1;
    103103                nqueries        =1;
    104         }
     104                }
    105105        //
    106106        void                                    GarbageCollect(int lifetime=256)
    107         {
     107                {
    108108                const int life=puid-lifetime;
    109109                for(int i=0;i<cells.size();++i)
    110                 {
     110                        {
    111111                        Cell*&  root=cells[i];
    112112                        Cell*   pp=0;
    113113                        Cell*   pc=root;
    114114                        while(pc)
    115                         {
     115                                {
    116116                                Cell*   pn=pc->next;
    117117                                if(pc->puid<life)
    118                                 {
     118                                        {
    119119                                        if(pp) pp->next=pn; else root=pn;
    120120                                        delete pc;pc=pp;--ncells;
     121                                        }
     122                                pp=pc;pc=pn;
    121123                                }
    122                                 pp=pc;pc=pn;
    123                         }
    124                 }
     124                        }
    125125                //printf("GC[%d]: %d cells, PpQ: %f\r\n",puid,ncells,nprobes/(btScalar)nqueries);
    126126                nqueries=1;
    127127                nprobes=1;
    128128                ++puid; /* TODO: Reset puid's when int range limit is reached   */
    129                 /* else setup a priority list...                                                */
    130         }
     129                                /* else setup a priority list...                                                */
     130                }
    131131        //
    132132        int                                             RemoveReferences(btCollisionShape* pcs)
    133         {
     133                {
    134134                int     refcount=0;
    135135                for(int i=0;i<cells.size();++i)
    136                 {
     136                        {
    137137                        Cell*&  root=cells[i];
    138138                        Cell*   pp=0;
    139139                        Cell*   pc=root;
    140140                        while(pc)
    141                         {
     141                                {
    142142                                Cell*   pn=pc->next;
    143143                                if(pc->pclient==pcs)
    144                                 {
     144                                        {
    145145                                        if(pp) pp->next=pn; else root=pn;
    146146                                        delete pc;pc=pp;++refcount;
     147                                        }
     148                                pp=pc;pc=pn;
    147149                                }
    148                                 pp=pc;pc=pn;
    149                         }
    150                 }
     150                        }
    151151                return(refcount);
    152         }
     152                }
    153153        //
    154154        btScalar                                Evaluate(       const btVector3& x,
    155                 btCollisionShape* shape,
    156                 btVector3& normal,
    157                 btScalar margin)
    158         {
     155                                                                                btCollisionShape* shape,
     156                                                                                btVector3& normal,
     157                                                                                btScalar margin)
     158                {
    159159                /* Lookup cell                  */
    160160                const btVector3 scx=x/voxelsz;
     
    167167                ++nqueries;
    168168                while(c)
    169                 {
     169                        {
    170170                        ++nprobes;
    171171                        if(     (c->hash==h)    &&
     
    174174                                (c->c[2]==iz.b) &&
    175175                                (c->pclient==shape))
    176                         { break; }
    177                         else
    178                         { c=c->next; }
    179                 }
     176                                { break; }
     177                                else
     178                                { c=c->next; }
     179                        }
    180180                if(!c)
    181                 {
     181                        {
    182182                        ++nprobes;             
    183183                        ++ncells;
     
    188188                        c->c[0]=ix.b;c->c[1]=iy.b;c->c[2]=iz.b;
    189189                        BuildCell(*c);
    190                 }
     190                        }
    191191                c->puid=puid;
    192192                /* Extract infos                */
    193193                const int               o[]={   ix.i,iy.i,iz.i};
    194194                const btScalar  d[]={   c->d[o[0]+0][o[1]+0][o[2]+0],
    195                         c->d[o[0]+1][o[1]+0][o[2]+0],
    196                         c->d[o[0]+1][o[1]+1][o[2]+0],
    197                         c->d[o[0]+0][o[1]+1][o[2]+0],
    198                         c->d[o[0]+0][o[1]+0][o[2]+1],
    199                         c->d[o[0]+1][o[1]+0][o[2]+1],
    200                         c->d[o[0]+1][o[1]+1][o[2]+1],
    201                         c->d[o[0]+0][o[1]+1][o[2]+1]};
     195                                                                c->d[o[0]+1][o[1]+0][o[2]+0],
     196                                                                c->d[o[0]+1][o[1]+1][o[2]+0],
     197                                                                c->d[o[0]+0][o[1]+1][o[2]+0],
     198                                                                c->d[o[0]+0][o[1]+0][o[2]+1],
     199                                                                c->d[o[0]+1][o[1]+0][o[2]+1],
     200                                                                c->d[o[0]+1][o[1]+1][o[2]+1],
     201                                                                c->d[o[0]+0][o[1]+1][o[2]+1]};
    202202                /* Normal       */
    203 #if 1
     203                #if 1
    204204                const btScalar  gx[]={  d[1]-d[0],d[2]-d[3],
    205                         d[5]-d[4],d[6]-d[7]};
     205                                                                d[5]-d[4],d[6]-d[7]};
    206206                const btScalar  gy[]={  d[3]-d[0],d[2]-d[1],
    207                         d[7]-d[4],d[6]-d[5]};
     207                                                                d[7]-d[4],d[6]-d[5]};
    208208                const btScalar  gz[]={  d[4]-d[0],d[5]-d[1],
    209                         d[7]-d[3],d[6]-d[2]};
     209                                                                d[7]-d[3],d[6]-d[2]};
    210210                normal.setX(Lerp(       Lerp(gx[0],gx[1],iy.f),
    211                         Lerp(gx[2],gx[3],iy.f),iz.f));
     211                                                        Lerp(gx[2],gx[3],iy.f),iz.f));
    212212                normal.setY(Lerp(       Lerp(gy[0],gy[1],ix.f),
    213                         Lerp(gy[2],gy[3],ix.f),iz.f));
     213                                                        Lerp(gy[2],gy[3],ix.f),iz.f));
    214214                normal.setZ(Lerp(       Lerp(gz[0],gz[1],ix.f),
    215                         Lerp(gz[2],gz[3],ix.f),iy.f));
     215                                                        Lerp(gz[2],gz[3],ix.f),iy.f));
    216216                normal          =       normal.normalized();
    217 #else
     217                #else
    218218                normal          =       btVector3(d[1]-d[0],d[3]-d[0],d[4]-d[0]).normalized();
    219 #endif
     219                #endif
    220220                /* Distance     */
    221221                const btScalar  d0=Lerp(Lerp(d[0],d[1],ix.f),
    222                         Lerp(d[3],d[2],ix.f),iy.f);
     222                                                                Lerp(d[3],d[2],ix.f),iy.f);
    223223                const btScalar  d1=Lerp(Lerp(d[4],d[5],ix.f),
    224                         Lerp(d[7],d[6],ix.f),iy.f);
     224                                                                Lerp(d[7],d[6],ix.f),iy.f);
    225225                return(Lerp(d0,d1,iz.f)-margin);
    226         }
     226                }
    227227        //
    228228        void                                    BuildCell(Cell& c)
    229         {
     229                {
    230230                const btVector3 org=btVector3(  (btScalar)c.c[0],
    231                         (btScalar)c.c[1],
    232                         (btScalar)c.c[2])       *
    233                         CELLSIZE*voxelsz;
     231                                                                                (btScalar)c.c[1],
     232                                                                                (btScalar)c.c[2])       *
     233                                                                                CELLSIZE*voxelsz;
    234234                for(int k=0;k<=CELLSIZE;++k)
    235                 {
     235                        {
    236236                        const btScalar  z=voxelsz*k+org.z();
    237237                        for(int j=0;j<=CELLSIZE;++j)
    238                         {
     238                                {
    239239                                const btScalar  y=voxelsz*j+org.y();
    240240                                for(int i=0;i<=CELLSIZE;++i)
    241                                 {
     241                                        {
    242242                                        const btScalar  x=voxelsz*i+org.x();
    243243                                        c.d[i][j][k]=DistanceToShape(   btVector3(x,y,z),
    244                                                 c.pclient);
     244                                                                                                        c.pclient);
     245                                        }
    245246                                }
    246247                        }
    247248                }
    248         }
    249249        //
    250250        static inline btScalar  DistanceToShape(const btVector3& x,
    251                 btCollisionShape* shape)
    252         {
     251                                                                                        btCollisionShape* shape)
     252                {
    253253                btTransform     unit;
    254254                unit.setIdentity();
    255255                if(shape->isConvex())
    256                 {
     256                        {
    257257                        btGjkEpaSolver2::sResults       res;
    258258                        btConvexShape*                          csh=static_cast<btConvexShape*>(shape);
    259259                        return(btGjkEpaSolver2::SignedDistance(x,0,csh,unit,res));
    260                 }
     260                        }
    261261                return(0);
    262         }
     262                }
    263263        //
    264264        static inline IntFrac   Decompose(btScalar x)
    265         {
     265                {
    266266                /* That one need a lot of improvements...       */
    267267                /* Remove test, faster floor...                         */
     
    273273                r.i=(int)k;r.f=k-r.i;r.b-=o;
    274274                return(r);
    275         }
     275                }
    276276        //
    277277        static inline btScalar  Lerp(btScalar a,btScalar b,btScalar t)
    278         {
     278                {
    279279                return(a+(b-a)*t);
    280         }
    281 
    282 
     280                }
     281
     282       
    283283
    284284        //
    285285        static inline unsigned int      Hash(int x,int y,int z,btCollisionShape* shape)
    286         {
     286                {
    287287                struct btS
    288288                {
     
    292292
    293293                btS myset;
    294 
     294               
    295295                myset.x=x;myset.y=y;myset.z=z;myset.p=shape;
    296296                const void* ptr = &myset;
    297297
    298298                unsigned int result = HsiehHash<sizeof(btS)/4> (ptr);
    299 
     299               
    300300
    301301                return result;
    302         }
     302                }
    303303};
    304 
     304       
    305305
    306306#endif
Note: See TracChangeset for help on using the changeset viewer.