17 #ifndef BT_SPARSE_SDF_H 
   18 #define BT_SPARSE_SDF_H 
   24 template <const 
int DWORDLEN>
 
   27         const unsigned short* data = (
const unsigned short*)pdata;
 
   28         unsigned hash = DWORDLEN << 2, tmp;
 
   29         for (
int i = 0; i < DWORDLEN; ++i)
 
   32                 tmp = (data[1] << 11) ^ hash;
 
   33                 hash = (hash << 16) ^ tmp;
 
   46 template <const 
int CELLSIZE>
 
   60                 btScalar d[CELLSIZE + 1][CELLSIZE + 1][CELLSIZE + 1];
 
   84         void Initialize(
int hashsize = 2383, 
int clampCells = 256 * 1024)
 
   89                 cells.resize(hashsize, 0);
 
   95                 for (
int i = 0, ni = 
cells.size(); i < ni; ++i)
 
  115                 const int life = 
puid - lifetime;
 
  116                 for (
int i = 0; i < 
cells.size(); ++i)
 
  118                         Cell*& root = 
cells[i];
 
  148                 for (
int i = 0; i < 
cells.size(); ++i)
 
  150                         Cell*& root = 
cells[i];
 
  156                                 if (pc->pclient == pcs)
 
  183                 const unsigned h = 
Hash(ix.b, iy.b, iz.b, shape);
 
  184                 Cell*& root = 
cells[static_cast<int>(h % 
cells.size())];
 
  190                         if ((c->hash == h) &&
 
  194                                 (c->pclient == shape))
 
  210                                 static int numResets = 0;
 
  228                 const int o[] = {ix.i, iy.i, iz.i};
 
  229                 const btScalar d[] = {c->d[o[0] + 0][o[1] + 0][o[2] + 0],
 
  230                                                           c->d[o[0] + 1][o[1] + 0][o[2] + 0],
 
  231                                                           c->d[o[0] + 1][o[1] + 1][o[2] + 0],
 
  232                                                           c->d[o[0] + 0][o[1] + 1][o[2] + 0],
 
  233                                                           c->d[o[0] + 0][o[1] + 0][o[2] + 1],
 
  234                                                           c->d[o[0] + 1][o[1] + 0][o[2] + 1],
 
  235                                                           c->d[o[0] + 1][o[1] + 1][o[2] + 1],
 
  236                                                           c->d[o[0] + 0][o[1] + 1][o[2] + 1]};
 
  239                 const btScalar gx[] = {d[1] - d[0], d[2] - d[3],
 
  240                                                            d[5] - d[4], d[6] - d[7]};
 
  241                 const btScalar gy[] = {d[3] - d[0], d[2] - d[1],
 
  242                                                            d[7] - d[4], d[6] - d[5]};
 
  243                 const btScalar gz[] = {d[4] - d[0], d[5] - d[1],
 
  244                                                            d[7] - d[3], d[6] - d[2]};
 
  246                                                  Lerp(gx[2], gx[3], iy.f), iz.f));
 
  248                                                  Lerp(gy[2], gy[3], ix.f), iz.f));
 
  250                                                  Lerp(gz[2], gz[3], ix.f), iy.f));
 
  257                                                                  Lerp(d[3], d[2], ix.f), iy.f);
 
  259                                                                  Lerp(d[7], d[6], ix.f), iy.f);
 
  260                 return (
Lerp(d0, d1, iz.f) - margin);
 
  269                 for (
int k = 0; k <= CELLSIZE; ++k)
 
  272                         for (
int j = 0; j <= CELLSIZE; ++j)
 
  275                                 for (
int i = 0; i <= CELLSIZE; ++i)
 
  293                         const btConvexShape* csh = static_cast<const btConvexShape*>(shape);
 
  305                 const int o = x < 0 ? (int)(-x + 1) : 0;
 
  308                 const btScalar k = (x - r.b) * CELLSIZE;
 
  317                 return (a + (b - a) * t);
 
  334                 myset.p = (
void*)shape;
 
  335                 const void* ptr = &myset;
 
  337                 unsigned int result = 
HsiehHash<
sizeof(btS) / 4>(ptr);
 
  343 #endif  //BT_SPARSE_SDF_H