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) + (unsigned int)(((const unsigned char*)(d))[0]))
31inline unsigned int HsiehHash(
const char* data,
int len)
33 unsigned int hash = len,
tmp;
37 for (; len > 0; len--)
41 hash = (hash << 16) ^
tmp;
42 data += 2 *
sizeof(
unsigned short);
57template <const
int CELLSIZE>
118 for (
int i = 0,
ni =
cells.size(); i <
ni; ++i)
139 for (
int i = 0; i <
cells.size(); ++i)
171 for (
int i = 0; i <
cells.size(); ++i)
179 if (
pc->pclient ==
pcs)
213 if ((c->hash ==
h) &&
217 (c->pclient == shape))
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]};
331 const int o = x < 0 ? (
int)(-x + 1) : 0;
343 return (a + (b - a) *
t);
363 myset.p = (
void*)shape;
364 const char* ptr = (
const char*)&
myset;
const T & btMax(const T &a, const T &b)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
unsigned int HsiehHash(const char *data, int len)
#define get16bits(d)
btSparseSdf implementation by Nathanael Presson
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
btVector3 can be used to represent 3D points and vectors.
void setZ(btScalar _z)
Set the z value.
const btScalar & z() const
Return the z value.
btVector3 & safeNormalize()
btVector3 normalized() const
Return a normalized version of this vector.
void setY(btScalar _y)
Set the y value.
void setX(btScalar _x)
Set the x value.
static btScalar SignedDistance(const btVector3 &position, btScalar margin, const btConvexShape *shape, const btTransform &wtrs, sResults &results)
const btCollisionShape * pclient
btScalar d[CELLSIZE+1][CELLSIZE+1][CELLSIZE+1]
void GarbageCollect(int lifetime=256)
static IntFrac Decompose(btScalar x)
static btScalar DistanceToShape(const btVector3 &x, const btCollisionShape *shape)
int RemoveReferences(btCollisionShape *pcs)
btScalar m_defaultVoxelsz
btAlignedObjectArray< Cell * > cells
btScalar Evaluate(const btVector3 &x, const btCollisionShape *shape, btVector3 &normal, btScalar margin)
static btScalar Lerp(btScalar a, btScalar b, btScalar t)
static unsigned int Hash(int x, int y, int z, const btCollisionShape *shape)
void setDefaultVoxelsz(btScalar sz)
void Initialize(int hashsize=2383, int clampCells=256 *1024)