17 #ifndef BT_SPARSE_SDF_H
18 #define BT_SPARSE_SDF_H
25 #if !defined (get16bits)
26 #define get16bits(d) ((((unsigned int)(((const unsigned char *)(d))[1])) << 8)\
27 +(unsigned int)(((const unsigned char *)(d))[0]) )
32 inline unsigned int HsiehHash (
const char * data,
int len) {
33 unsigned int hash = len, tmp;
37 for (;len > 0; len--) {
40 hash = (hash << 16) ^ tmp;
41 data += 2*
sizeof (
unsigned short);
57 template <const
int CELLSIZE>
71 btScalar d[CELLSIZE + 1][CELLSIZE + 1][CELLSIZE + 1];
100 void Initialize(
int hashsize = 2383,
int clampCells = 256 * 1024)
105 cells.resize(hashsize, 0);
118 for (
int i = 0, ni =
cells.size(); i < ni; ++i)
138 const int life =
puid - lifetime;
139 for (
int i = 0; i <
cells.size(); ++i)
141 Cell*& root =
cells[i];
171 for (
int i = 0; i <
cells.size(); ++i)
173 Cell*& root =
cells[i];
179 if (pc->pclient == pcs)
206 const unsigned h =
Hash(ix.b, iy.b, iz.b, shape);
207 Cell*& root =
cells[static_cast<int>(h %
cells.size())];
213 if ((c->hash == h) &&
217 (c->pclient == shape))
236 static int numResets = 0;
254 const int o[] = {ix.i, iy.i, iz.i};
255 const btScalar d[] = {c->d[o[0] + 0][o[1] + 0][o[2] + 0],
256 c->d[o[0] + 1][o[1] + 0][o[2] + 0],
257 c->d[o[0] + 1][o[1] + 1][o[2] + 0],
258 c->d[o[0] + 0][o[1] + 1][o[2] + 0],
259 c->d[o[0] + 0][o[1] + 0][o[2] + 1],
260 c->d[o[0] + 1][o[1] + 0][o[2] + 1],
261 c->d[o[0] + 1][o[1] + 1][o[2] + 1],
262 c->d[o[0] + 0][o[1] + 1][o[2] + 1]};
265 const btScalar gx[] = {d[1] - d[0], d[2] - d[3],
266 d[5] - d[4], d[6] - d[7]};
267 const btScalar gy[] = {d[3] - d[0], d[2] - d[1],
268 d[7] - d[4], d[6] - d[5]};
269 const btScalar gz[] = {d[4] - d[0], d[5] - d[1],
270 d[7] - d[3], d[6] - d[2]};
272 Lerp(gx[2], gx[3], iy.f), iz.f));
274 Lerp(gy[2], gy[3], ix.f), iz.f));
276 Lerp(gz[2], gz[3], ix.f), iy.f));
283 Lerp(d[3], d[2], ix.f), iy.f);
285 Lerp(d[7], d[6], ix.f), iy.f);
286 return (
Lerp(d0, d1, iz.f) - margin);
295 for (
int k = 0; k <= CELLSIZE; ++k)
298 for (
int j = 0; j <= CELLSIZE; ++j)
301 for (
int i = 0; i <= CELLSIZE; ++i)
319 const btConvexShape* csh = static_cast<const btConvexShape*>(shape);
331 const int o = x < 0 ? (int)(-x + 1) : 0;
334 const btScalar k = (x - r.b) * CELLSIZE;
343 return (a + (b - a) * t);
363 myset.p = (
void*)shape;
364 const char* ptr = (
const char*)&myset;
366 unsigned int result =
HsiehHash(ptr,
sizeof(btS) );
372 #endif //BT_SPARSE_SDF_H