67                 if(node->
isinternal()&&((depth<maxdepth)||(maxdepth<0)))
    69                         drawTree(idraw,node->
childs[0],depth+1,ncolor,lcolor,mindepth,maxdepth);
    70                         drawTree(idraw,node->
childs[1],depth+1,ncolor,lcolor,mindepth,maxdepth);
    90                 for(
int i=1,ni=items.
size();i<ni;++i)
    99 template <
typename T,
typename Q>
   102         for(
int i=0,ni=items.
size();i<ni;++i)
   109 template <
typename T,
typename Q>
   112         for(
int i=0,ni=items.
size();i<ni;++i)
   119 template <
typename T>
   123         return(
sum(items)/n);
   149         static const int                ncolors=
sizeof(spectrum)/
sizeof(spectrum[0])-1;
   151         stress=btMax<btScalar>(0,btMin<btScalar>(1,stress))*ncolors;
   152         const int                               sel=(int)stress;
   154         return(spectrum[sel]+(spectrum[sel+1]-spectrum[sel])*frc);
   184                                 for(j=0,nj=vertices.
size();j<nj;++j)
   186                                         vertices[j]=psb->
m_clusters[i]->m_nodes[j]->m_x;
   188 #define USE_NEW_CONVEX_HULL_COMPUTER   189 #ifdef USE_NEW_CONVEX_HULL_COMPUTER   192                                 int count = vertices.
size();
   195                                 computer.
compute(&vertices[0].getX(),stride,count,shrink,shrinkClamp);
   196                                 for (
int i=0;i<computer.
faces.
size();i++)
   199                                         int face = computer.
faces[i];
   206                                         while (edge!=firstEdge)
   220                                 hdsc.mMaxVertices=vertices.
size();
   223                                 add(hres.m_OutputVertices,-center);
   225                                 add(hres.m_OutputVertices,center);
   226                                 for(j=0;j<(int)hres.mNumFaces;++j)
   228                                         const int idx[]={hres.m_Indices[j*3+0],hres.m_Indices[j*3+1],hres.m_Indices[j*3+2]};
   230                                                 hres.m_OutputVertices[idx[1]],
   231                                                 hres.m_OutputVertices[idx[2]],
   304                                 idraw->
drawLine(o-x*nscl,o+x*nscl,ccolor);
   305                                 idraw->
drawLine(o-y*nscl,o+y*nscl,ccolor);
   338                         const btVector3                         c=(x[0]+x[1]+x[2]+x[3])/4;
   339                         idraw->
drawTriangle((x[0]-c)*scl+c,(x[1]-c)*scl+c,(x[2]-c)*scl+c,col,alp);
   340                         idraw->
drawTriangle((x[0]-c)*scl+c,(x[1]-c)*scl+c,(x[3]-c)*scl+c,col,alp);
   341                         idraw->
drawTriangle((x[1]-c)*scl+c,(x[2]-c)*scl+c,(x[3]-c)*scl+c,col,alp);
   342                         idraw->
drawTriangle((x[2]-c)*scl+c,(x[0]-c)*scl+c,(x[3]-c)*scl+c,col,alp);
   376                         for(
int j=0;j<n.
m_rank;++j)
   444                         sprintf(buff,
" M(%.2f)",1/n.
m_im);
   449                         sprintf(buff,
" A(%.2f)",n.
m_area);
   462         drawTree(idraw,psb->
m_ndbvt.
m_root,0,
btVector3(1,0,1),
btVector3(1,1,1),mindepth,maxdepth);
   471         drawTree(idraw,psb->
m_fdbvt.
m_root,0,
btVector3(0,1,0),
btVector3(1,0,0),mindepth,maxdepth);
   480         drawTree(idraw,psb->
m_cdbvt.
m_root,0,
btVector3(0,1,1),
btVector3(1,0,0),mindepth,maxdepth);
   532 #define REOP_NOT_DEPENDENT      -1   533 #define REOP_NODE_COMPLETE      -2      // Must be less than REOP_NOT_DEPENDENT   544         int readyListHead, readyListTail, linkNum, linkDepFrees, depLink;
   547         int *nodeWrittenAt = 
new int[nNodes+1]; 
   548         int *linkDepA = 
new int[nLinks];                        
   549         int *linkDepB = 
new int[nLinks];
   550         int *readyList = 
new int[nLinks];               
   559         for (i=0; i < nNodes+1; i++) {
   562         for (i=0; i < nLinks; i++) {
   563                 linkDepListStarts[i] = NULL;
   565         readyListHead = readyListTail = linkDepFrees = 0;
   568         for (i=0; i < nLinks; i++) {
   572                 ar = (lr->
m_n[0] - node0)/(node1 - node0);
   573                 br = (lr->
m_n[1] - node0)/(node1 - node0);
   575                         linkDepA[i] = nodeWrittenAt[ar];
   576                         linkDep = &linkDepFreeList[linkDepFrees++];
   578                         linkDep->
next = linkDepListStarts[nodeWrittenAt[ar]];
   579                         linkDepListStarts[nodeWrittenAt[ar]] = linkDep;
   584                         linkDepB[i] = nodeWrittenAt[br];
   585                         linkDep = &linkDepFreeList[linkDepFrees++];
   586                         linkDep->
value = -(i+1);
   587                         linkDep->
next = linkDepListStarts[nodeWrittenAt[br]];
   588                         linkDepListStarts[nodeWrittenAt[br]] = linkDep;
   595                         readyList[readyListTail++] = i;
   600                 nodeWrittenAt[ar] = nodeWrittenAt[br] = i;
   609         while (readyListHead != readyListTail) {
   611                 linkNum = readyList[readyListHead++];
   613                 psb->
m_links[i++] = linkBuffer[linkNum];
   616                 linkDep = linkDepListStarts[linkNum];
   618                         depLink = linkDep->
value;
   622                                 depLink = -depLink - 1;
   627                                 readyList[readyListTail++] = depLink;
   630                         linkDep = linkDep->
next;
   635         delete [] nodeWrittenAt;
   639         delete [] linkDepFreeList;
   640         delete [] linkDepListStarts;
   641         delete [] linkBuffer;
   684                 x[i]=
lerp(from,to,t);
   688         if(fixeds&1) psb->
setMass(0,0);
   689         if(fixeds&2) psb->
setMass(r-1,0);
   711 #define IDX(_x_,_y_)    ((_y_)*rx+(_x_))   713         if((resx<2)||(resy<2)) 
return(0);
   726                 for(
int ix=0;ix<rx;++ix)
   729                         x[
IDX(ix,iy)]=
lerp(py0,py1,tx);
   743                 for(
int ix=0;ix<rx;++ix)
   745                         const int       idx=
IDX(ix,iy);
   746                         const bool      mdx=(ix+1)<rx;
   747                         const bool      mdy=(iy+1)<ry;
   858 #define IDX(_x_,_y_)    ((_y_)*rx+(_x_))   860         if((resx<2)||(resy<2)) 
return(0);
   874                 for(
int ix=0;ix<rx;++ix)
   877                         x[
IDX(ix,iy)]=
lerp(py0,py1,tx);
   886         if(fixeds&16)           psb->
setMass(
IDX((rx-1)/2,0),0);
   887         if(fixeds&32)           psb->
setMass(
IDX(0,(ry-1)/2),0);
   888         if(fixeds&64)           psb->
setMass(
IDX(rx-1,(ry-1)/2),0);
   889         if(fixeds&128)          psb->
setMass(
IDX((rx-1)/2,ry-1),0);
   890         if(fixeds&256)          psb->
setMass(
IDX((rx-1)/2,(ry-1)/2),0);
   899                 for(
int ix=0;ix<rx;++ix)
   901                         const bool      mdx=(ix+1)<rx;
   902                         const bool      mdy=(iy+1)<ry;
   904                         int node00=
IDX(ix,iy);
   905                         int node01=
IDX(ix+1,iy);
   906                         int node10=
IDX(ix,iy+1);
   907                         int node11=
IDX(ix+1,iy+1);
   971                 tc = (1.0f/((resx-1))*ix);
   974                 tc = (1.0f/((resy-1))*(resy-1-iy));
   977                 tc = (1.0f/((resy-1))*(resy-1-iy-1));
   980                 tc = (1.0f/((resx-1))*(ix+1));
   996                                 for(
int j=i;j;p*=0.5,j>>=1) 
if(j&1) t+=p;
  1006         Hammersley::Generate(&vtx[0],vtx.
size());
  1007         for(
int i=0;i<vtx.
size();++i)
  1009                 vtx[i]=vtx[i]*radius+center;
  1018                                                                                                          const int* triangles,
  1019                                                                                                          int ntriangles, 
bool randomizeConstraints)
  1024         for(i=0,ni=ntriangles*3;i<ni;++i)
  1026                 maxidx=
btMax(triangles[i],maxidx);
  1031         chks.
resize(maxidx*maxidx,
false);
  1033         for(i=0,j=0,ni=maxidx*3;i<ni;++j,i+=3)
  1035                 vtx[j]=
btVector3(vertices[i],vertices[i+1],vertices[i+2]);
  1038         for( i=0,ni=ntriangles*3;i<ni;i+=3)
  1040                 const int idx[]={triangles[i],triangles[i+1],triangles[i+2]};
  1041 #define IDX(_x_,_y_) ((_y_)*maxidx+(_x_))  1042                 for(
int j=2,k=0;k<3;j=k++)
  1044                         if(!chks[
IDX(idx[j],idx[k])])
  1046                                 chks[
IDX(idx[j],idx[k])]=
true;
  1047                                 chks[
IDX(idx[k],idx[j])]=
true;
  1055         if (randomizeConstraints)
  1065                                                                                                                 int nvertices, 
bool randomizeConstraints)
  1076                 const int idx[]={       
static_cast<int>(hres.
m_Indices[i*3+0]),
  1077                                                         static_cast<int>(hres.
m_Indices[i*3+1]),
  1078                                                         static_cast<int>(hres.
m_Indices[i*3+2])};
  1079                 if(idx[0]<idx[1]) psb->
appendLink(      idx[0],idx[1]);
  1080                 if(idx[1]<idx[2]) psb->
appendLink(      idx[1],idx[2]);
  1081                 if(idx[2]<idx[0]) psb->
appendLink(      idx[2],idx[0]);
  1085         if (randomizeConstraints)
  1099         while (*buffer != 
'\n')
  1106         if (buffer[0]==0x0a)
  1111         return numBytesRead;
  1121                                                                                                         bool bfacesfromtetras)
  1128 int result = sscanf(node,
"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
  1129 result = sscanf(node,
"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
  1133 for(
int i=0;i<pos.
size();++i)
  1138         sscanf(node,
"%d %f %f %f",&index,&x,&y,&z);
  1159         sf>>nface;sf>>hasbounds;
  1160         for(
int i=0;i<nface;++i)
  1166                 sf>>ni[0];sf>>ni[1];sf>>ni[2];
  1184         sscanf(ele,
"%d %d %d",&ntetra,&ncorner,&neattrb);
  1188         for(
int i=0;i<ntetra;++i)
  1195                 sscanf(ele,
"%d %d %d %d %d",&index,&ni[0],&ni[1],&ni[2],&ni[3]);
 static T sum(const btAlignedObjectArray< T > &items)
const Edge * getNextEdgeOfFace() const 
DBVT_INLINE bool isleaf() const 
btAlignedObjectArray< Edge > edges
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)
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
btScalar btSin(btScalar x)
int getTargetVertex() const 
virtual void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)=0
static btSoftBody * CreateEllipsoid(btSoftBodyWorldInfo &worldInfo, const btVector3 ¢er, const btVector3 &radius, int res)
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 btSqrt(btScalar y)
btAlignedObjectArray< unsigned int > m_Indices
btAlignedObjectArray< Node * > m_nodes
int getSourceVertex() const 
#define REOP_NOT_DEPENDENT
const btTransform & xform() const 
static btSoftBody * CreateFromTetGenData(btSoftBodyWorldInfo &worldInfo, const char *ele, const char *face, const char *node, bool bfacelinks, bool btetralinks, bool bfacesfromtetras)
static void DrawFaceTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
void appendLink(int model=-1, Material *mat=0)
LinkDeps_t * LinkDepsPtr_t
DBVT_INLINE bool isinternal() const 
Convex hull implementation based on Preparata and Hong See http://code.google.com/p/bullet/issues/det...
const btScalar & x() const 
Return the x value. 
static void Draw(btSoftBody *psb, btIDebugDraw *idraw, int drawflags=fDrawFlags::Std)
static void add(btAlignedObjectArray< T > &items, const Q &value)
void appendFace(int model=-1, Material *mat=0)
static btSoftBody * CreateFromConvexHull(btSoftBodyWorldInfo &worldInfo, const btVector3 *vertices, int nvertices, bool randomizeConstraints=true)
static void drawBox(btIDebugDraw *idraw, const btVector3 &mins, const btVector3 &maxs, const btVector3 &color)
btVector3 btCross(const btVector3 &v1, const btVector3 &v2)
Return the cross product of two vectors. 
virtual void draw3dText(const btVector3 &location, const char *textString)=0
btTransform & getWorldTransform()
static void mul(btAlignedObjectArray< T > &items, const Q &value)
int size() const 
return the number of elements in the array 
HullError CreateConvexHull(const HullDesc &desc, HullResult &result)
virtual eType::_ Type() const =0
void randomizeConstraints()
static btSoftBody * CreateRope(btSoftBodyWorldInfo &worldInfo, const btVector3 &from, const btVector3 &to, int res, int fixeds)
static void DrawInfos(btSoftBody *psb, btIDebugDraw *idraw, bool masses, bool areas, bool stress)
void appendTetra(int model, Material *mat)
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations...
btAlignedObjectArray< btVector3 > m_OutputVertices
DBVT_INLINE btVector3 Center() const 
const btScalar & y() const 
Return the y value. 
DBVT_INLINE btVector3 Extents() const 
static void DrawNodeTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
static void drawVertex(btIDebugDraw *idraw, const btVector3 &x, btScalar s, const btVector3 &c)
btSoftBodyHelpers.cpp by Nathanael Presson 
static void DrawClusterTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
btVector3 can be used to represent 3D points and vectors. 
btAlignedObjectArray< btVector3 > vertices
virtual void drawTriangle(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2, const btVector3 &, const btVector3 &, const btVector3 &, const btVector3 &color, btScalar alpha)
static float CalculateUV(int resx, int resy, int ix, int iy, int id)
btVector3 normalized() const 
Return a normalized version of this vector. 
unsigned int mNumOutputVertices
static void ReoptimizeLinkOrder(btSoftBody *psb)
Sort the list of links to move link calculations that are dependent upon earlier ones as far as possi...
void resize(int newsize, const T &fillData=T())
static void drawTree(btIDebugDraw *idraw, const btDbvtNode *node, int depth, const btVector3 &ncolor, const btVector3 &lcolor, int mindepth, int maxdepth)
static btSoftBody * CreateFromTriMesh(btSoftBodyWorldInfo &worldInfo, const btScalar *vertices, const int *triangles, int ntriangles, bool randomizeConstraints=true)
int minAxis() const 
Return the axis with the smallest value Note return values are 0,1,2 for x, y, or z...
const T & btMax(const T &a, const T &b)
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
btScalar compute(const void *coords, bool doubleCoords, int stride, int count, btScalar shrink, btScalar shrinkClamp)
The HullLibrary class can create a convex hull from a collection of vertices, using the ComputeHull m...
static int nextLine(const char *buffer)
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors. 
static T average(const btAlignedObjectArray< T > &items)
HullError ReleaseResult(HullResult &result)
The btSoftBody is an class to simulate cloth and volumetric soft bodies. 
unsigned int mMaxVertices
void setMass(int node, btScalar mass)
tRContactArray m_rcontacts
btAlignedObjectArray< int > faces
btVector3 lerp(const btVector3 &v1, const btVector3 &v2, const btScalar &t)
Return the linear interpolation between two vectors. 
static void DrawFrame(btSoftBody *psb, btIDebugDraw *idraw)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btCos(btScalar x)
#define REOP_NODE_COMPLETE
const btScalar & z() const 
Return the z value. 
static btScalar tetravolume(const btVector3 &x0, const btVector3 &x1, const btVector3 &x2, const btVector3 &x3)