100 for (
int i = 1,
ni =
items.size(); i <
ni; ++i)
109template <
typename T,
typename Q>
112 for (
int i = 0,
ni =
items.size(); i <
ni; ++i)
119template <
typename T,
typename Q>
122 for (
int i = 0,
ni =
items.size(); i <
ni; ++i)
200#define USE_NEW_CONVEX_HULL_COMPUTER
201#ifdef USE_NEW_CONVEX_HULL_COMPUTER
204 int count = vertices.
size();
208 for (
int i = 0; i <
computer.faces.size(); i++)
219 int v2 =
edge->getTargetVertex();
231 hdsc.mMaxVertices = vertices.
size();
234 add(
hres.m_OutputVertices, -center);
236 add(
hres.m_OutputVertices, center);
239 const int idx[] = {
hres.m_Indices[
j * 3 + 0],
hres.m_Indices[
j * 3 + 1],
hres.m_Indices[
j * 3 + 2]};
330 const btVector3 c = (x[0] + x[1] + x[2]) / 3;
331 idraw->drawTriangle((x[0] - c) *
scl + c,
332 (x[1] - c) *
scl + c,
333 (x[2] - c) *
scl + c,
347 const btVector3 x[] = {
t.m_n[0]->m_x,
t.m_n[1]->m_x,
t.m_n[2]->m_x,
t.m_n[3]->m_x};
348 const btVector3 c = (x[0] + x[1] + x[2] + x[3]) / 4;
349 idraw->drawTriangle((x[0] - c) *
scl + c, (x[1] - c) *
scl + c, (x[2] - c) *
scl + c,
col,
alp);
350 idraw->drawTriangle((x[0] - c) *
scl + c, (x[1] - c) *
scl + c, (x[3] - c) *
scl + c,
col,
alp);
351 idraw->drawTriangle((x[1] - c) *
scl + c, (x[2] - c) *
scl + c, (x[3] - c) *
scl + c,
col,
alp);
352 idraw->drawTriangle((x[2] - c) *
scl + c, (x[0] - c) *
scl + c, (x[3] - c) *
scl + c,
col,
alp);
422 const btVector3 a0 =
pj->m_bodies[0].xform().getBasis() *
pj->m_refs[0];
423 const btVector3 a1 =
pj->m_bodies[1].xform().getBasis() *
pj->m_refs[1];
448 char text[2048] = {0};
470 drawTree(
idraw, psb->
m_ndbvt.
m_root, 0,
btVector3(1, 0, 1),
btVector3(1, 1, 1),
mindepth, maxdepth);
479 drawTree(
idraw, psb->
m_fdbvt.
m_root, 0,
btVector3(0, 1, 0),
btVector3(1, 0, 0),
mindepth, maxdepth);
488 drawTree(
idraw, psb->
m_cdbvt.
m_root, 0,
btVector3(0, 1, 1),
btVector3(1, 0, 0),
mindepth, maxdepth);
539#define REOP_NOT_DEPENDENT -1
540#define REOP_NODE_COMPLETE -2
565 for (i = 0; i <
nNodes + 1; i++)
569 for (i = 0; i <
nLinks; i++)
576 for (i = 0; i <
nLinks; i++)
696 const int r =
res + 2;
701 for (i = 0; i < r; ++i)
713 for (i = 1; i < r; ++i)
732#define IDX(_x_, _y_) ((_y_)*rx + (_x_))
734 if ((
resx < 2) || (
resy < 2))
return (0);
773 const bool mdx = (
ix + 1) <
rx;
774 const bool mdy = (
iy + 1) <
ry;
884#define IDX(_x_, _y_) ((_y_)*rx + (_x_))
886 if ((
resx < 2) || (
resy < 2))
return (0);
926 const bool mdx = (
ix + 1) <
rx;
927 const bool mdy = (
iy + 1) <
ry;
1010 tc = (1.0f / ((
resx - 1)) * (
ix + 1));
1023 for (
int i = 0; i < n; i++)
1026 for (
int j = i;
j; p *= 0.5,
j >>= 1)
1037 Hammersley::Generate(&
vtx[0],
vtx.size());
1038 for (
int i = 0; i <
vtx.size(); ++i)
1062 for (i = 0,
j = 0,
ni =
maxidx * 3; i <
ni; ++
j, i += 3)
1064 vtx[
j] =
btVector3(vertices[i], vertices[i + 1], vertices[i + 2]);
1070#define IDX(_x_, _y_) ((_y_)*maxidx + (_x_))
1071 for (
int j = 2,
k = 0;
k < 3;
j =
k++)
1084 if (randomizeConstraints)
1094 int nvertices,
bool randomizeConstraints)
1102 &
hres.m_OutputVertices[0], 0);
1103 for (
int i = 0; i < (
int)
hres.mNumFaces; ++i)
1105 const int idx[] = {
static_cast<int>(
hres.m_Indices[i * 3 + 0]),
1106 static_cast<int>(
hres.m_Indices[i * 3 + 1]),
1107 static_cast<int>(
hres.m_Indices[i * 3 + 2])};
1114 if (randomizeConstraints)
1158 for (
int i = 0; i <
pos.size(); ++i)
1163 sscanf(node,
"%d %f %f %f", &index, &x, &y, &z);
1185 for(
int i=0;i<
nface;++i)
1213 for (
int i = 0; i <
ntetra; ++i)
1263 while (std::getline(
fs,
line))
1265 std::stringstream
ss(
line);
1266 if (
line.size() == (
size_t)(0))
1269 else if (
line.substr(0, 6) ==
"POINTS")
1273 ss.ignore(128,
' ');
1277 else if (
line.substr(0, 5) ==
"CELLS")
1281 ss.ignore(128,
' ');
1285 else if (
line.substr(0, 10) ==
"CELL_TYPES")
1308 printf(
"Load deformable failed: Only Tetrahedra are supported in VTK file.\n");
1312 ss.ignore(128,
' ');
1315 for (
size_t i = 0; i < 4; i++)
1326 for (
int i = 0; i <
n_tets; ++i)
1363 for (
int i = 0; i <
indices.size(); ++i)
1366 index.push_back(psb->
m_tetras[i].m_n[0]->index);
1367 index.push_back(psb->
m_tetras[i].m_n[1]->index);
1368 index.push_back(psb->
m_tetras[i].m_n[2]->index);
1369 index.push_back(psb->
m_tetras[i].m_n[3]->index);
1373 std::map<std::vector<int>, std::vector<int> >
dict;
1374 for (
int i = 0; i <
indices.size(); ++i)
1376 for (
int j = 0;
j < 4; ++
j)
1418 std::vector<int> f =
it->second;
1434 std::map<int, int>
dict;
1437 for (
int d = 0; d < 3; d++)
1439 int index = psb->
m_faces[i].m_n[d]->index;
1440 if (
dict.find(index) ==
dict.end())
1445 for (
int k = 0;
k < 3;
k++)
1457 for (
int n = 0; n < 3; n++)
1470 for (
int d = 0; d < 3; d++)
1480 for (
int n = 0; n < 3; n++)
1482 fs <<
" " << psb->
m_faces[i].m_n[n]->index + 1;
1499 std::stringstream
ss(
line);
1503 else if (
line[0] ==
'f')
1524 for (
int n = 0; n < 3; n++)
1556 btVector3 v0 = b - a, v1 = c - a, v2 = p - a;
1588 for (
int k = 1;
k < 4; ++
k)
1637 for (
int k = 1;
k < 3; ++
k)
const T & btMax(const T &a, const T &b)
const T & btMin(const T &a, const T &b)
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btSqrt(btScalar y)
btScalar btSin(btScalar x)
btScalar btFabs(btScalar x)
btScalar btCos(btScalar x)
static T average(const btAlignedObjectArray< T > &items)
#define REOP_NODE_COMPLETE
static void drawTree(btIDebugDraw *idraw, const btDbvtNode *node, int depth, const btVector3 &ncolor, const btVector3 &lcolor, int mindepth, int maxdepth)
static void mul(btAlignedObjectArray< T > &items, const Q &value)
static int nextLine(const char *buffer)
static void add(btAlignedObjectArray< T > &items, const Q &value)
static T sum(const btAlignedObjectArray< T > &items)
static void drawBox(btIDebugDraw *idraw, const btVector3 &mins, const btVector3 &maxs, const btVector3 &color)
#define REOP_NOT_DEPENDENT
static void drawVertex(btIDebugDraw *idraw, const btVector3 &x, btScalar s, const btVector3 &c)
btSoftBodyHelpers.cpp by Nathanael Presson
LinkDeps_t * LinkDepsPtr_t
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors.
btVector3 lerp(const btVector3 &v1, const btVector3 &v2, const btScalar &t)
Return the linear interpolation between two vectors.
The HullLibrary class can create a convex hull from a collection of vertices, using the ComputeHull m...
HullError CreateConvexHull(const HullDesc &desc, HullResult &result)
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
int size() const
return the number of elements in the array
void resize(int newsize, const T &fillData=T())
void push_back(const T &_Val)
btTransform & getWorldTransform()
const Edge * getNextEdgeOfFace() const
int getSourceVertex() const
Convex hull implementation based on Preparata and Hong See http://code.google.com/p/bullet/issues/det...
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
void appendFace(int model=-1, Material *mat=0)
void setMass(int node, btScalar mass)
btAlignedObjectArray< TetraScratch > m_tetraScratchesTn
void appendTetra(int model, Material *mat)
btAlignedObjectArray< TetraScratch > m_tetraScratches
btAlignedObjectArray< btVector4 > m_renderNodesInterpolationWeights
btAlignedObjectArray< btScalar > m_z
tRContactArray m_rcontacts
btAlignedObjectArray< btAlignedObjectArray< const btSoftBody::Node * > > m_renderNodesParents
tRenderNodeArray m_renderNodes
void randomizeConstraints()
void appendLink(int model=-1, Material *mat=0)
void initializeDmInverse()
btVector3 can be used to represent 3D points and vectors.
void setZ(btScalar _z)
Set the z value.
int minAxis() const
Return the axis with the smallest value Note return values are 0,1,2 for x, y, or z.
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.
DBVT_INLINE btVector3 Extents() const
DBVT_INLINE btVector3 Center() const
DBVT_INLINE bool isinternal() const
DBVT_INLINE bool isleaf() const
static btSoftBody * CreatePatchUV(btSoftBodyWorldInfo &worldInfo, const btVector3 &corner00, const btVector3 &corner10, const btVector3 &corner01, const btVector3 &corner11, int resx, int resy, int fixeds, bool gendiags, float *tex_coords=0)
static void writeObj(const char *file, const btSoftBody *psb)
static btSoftBody * CreateFromTriMesh(btSoftBodyWorldInfo &worldInfo, const btScalar *vertices, const int *triangles, int ntriangles, bool randomizeConstraints=true)
static void extrapolateBarycentricWeights(btSoftBody *psb)
static void DrawNodeTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static void getBarycentricWeights(const btVector3 &a, const btVector3 &b, const btVector3 &c, const btVector3 &d, const btVector3 &p, btVector4 &bary)
static btSoftBody * CreateFromTetGenData(btSoftBodyWorldInfo &worldInfo, const char *ele, const char *face, const char *node, bool bfacelinks, bool btetralinks, bool bfacesfromtetras)
static btSoftBody * CreateFromConvexHull(btSoftBodyWorldInfo &worldInfo, const btVector3 *vertices, int nvertices, bool randomizeConstraints=true)
static btSoftBody * CreateFromVtkFile(btSoftBodyWorldInfo &worldInfo, const char *vtk_file)
static void ReoptimizeLinkOrder(btSoftBody *psb)
Sort the list of links to move link calculations that are dependent upon earlier ones as far as possi...
static void DrawFaceTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static void DrawInfos(btSoftBody *psb, btIDebugDraw *idraw, bool masses, bool areas, bool stress)
static btSoftBody * CreateEllipsoid(btSoftBodyWorldInfo &worldInfo, const btVector3 ¢er, const btVector3 &radius, int res)
static void DrawClusterTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static float CalculateUV(int resx, int resy, int ix, int iy, int id)
static btSoftBody * CreatePatch(btSoftBodyWorldInfo &worldInfo, const btVector3 &corner00, const btVector3 &corner10, const btVector3 &corner01, const btVector3 &corner11, int resx, int resy, int fixeds, bool gendiags, btScalar perturbation=0.)
static void generateBoundaryFaces(btSoftBody *psb)
static void Draw(btSoftBody *psb, btIDebugDraw *idraw, int drawflags=fDrawFlags::Std)
static void duplicateFaces(const char *filename, const btSoftBody *psb)
static void DrawFrame(btSoftBody *psb, btIDebugDraw *idraw)
static btSoftBody * CreateRope(btSoftBodyWorldInfo &worldInfo, const btVector3 &from, const btVector3 &to, int res, int fixeds)
static void interpolateBarycentricWeights(btSoftBody *psb)
btAlignedObjectArray< Node * > m_nodes