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);
522 x[i]=
lerp(from,to,t);
526 if(fixeds&1) psb->
setMass(0,0);
527 if(fixeds&2) psb->
setMass(r-1,0);
549 #define IDX(_x_,_y_) ((_y_)*rx+(_x_))
551 if((resx<2)||(resy<2))
return(0);
564 for(
int ix=0;ix<rx;++ix)
567 x[
IDX(ix,iy)]=
lerp(py0,py1,tx);
581 for(
int ix=0;ix<rx;++ix)
583 const int idx=
IDX(ix,iy);
584 const bool mdx=(ix+1)<rx;
585 const bool mdy=(iy+1)<ry;
696 #define IDX(_x_,_y_) ((_y_)*rx+(_x_))
698 if((resx<2)||(resy<2))
return(0);
712 for(
int ix=0;ix<rx;++ix)
715 x[
IDX(ix,iy)]=
lerp(py0,py1,tx);
724 if(fixeds&16) psb->
setMass(
IDX((rx-1)/2,0),0);
725 if(fixeds&32) psb->
setMass(
IDX(0,(ry-1)/2),0);
726 if(fixeds&64) psb->
setMass(
IDX(rx-1,(ry-1)/2),0);
727 if(fixeds&128) psb->
setMass(
IDX((rx-1)/2,ry-1),0);
728 if(fixeds&256) psb->
setMass(
IDX((rx-1)/2,(ry-1)/2),0);
737 for(
int ix=0;ix<rx;++ix)
739 const bool mdx=(ix+1)<rx;
740 const bool mdy=(iy+1)<ry;
742 int node00=
IDX(ix,iy);
743 int node01=
IDX(ix+1,iy);
744 int node10=
IDX(ix,iy+1);
745 int node11=
IDX(ix+1,iy+1);
809 tc = (1.0f/((resx-1))*ix);
812 tc = (1.0f/((resy-1))*(resy-1-iy));
815 tc = (1.0f/((resy-1))*(resy-1-iy-1));
818 tc = (1.0f/((resx-1))*(ix+1));
834 for(
int j=i;j;p*=0.5,j>>=1)
if(j&1) t+=p;
844 Hammersley::Generate(&vtx[0],vtx.
size());
845 for(
int i=0;i<vtx.
size();++i)
847 vtx[i]=vtx[i]*radius+center;
856 const int* triangles,
857 int ntriangles,
bool randomizeConstraints)
862 for(i=0,ni=ntriangles*3;i<ni;++i)
864 maxidx=
btMax(triangles[i],maxidx);
869 chks.
resize(maxidx*maxidx,
false);
871 for(i=0,j=0,ni=maxidx*3;i<ni;++j,i+=3)
873 vtx[j]=
btVector3(vertices[i],vertices[i+1],vertices[i+2]);
876 for( i=0,ni=ntriangles*3;i<ni;i+=3)
878 const int idx[]={triangles[i],triangles[i+1],triangles[i+2]};
879 #define IDX(_x_,_y_) ((_y_)*maxidx+(_x_))
880 for(
int j=2,k=0;k<3;j=k++)
882 if(!chks[
IDX(idx[j],idx[k])])
884 chks[
IDX(idx[j],idx[k])]=
true;
885 chks[
IDX(idx[k],idx[j])]=
true;
893 if (randomizeConstraints)
903 int nvertices,
bool randomizeConstraints)
914 const int idx[]={
static_cast<int>(hres.
m_Indices[i*3+0]),
916 static_cast<int>(hres.
m_Indices[i*3+2])};
917 if(idx[0]<idx[1]) psb->
appendLink( idx[0],idx[1]);
918 if(idx[1]<idx[2]) psb->
appendLink( idx[1],idx[2]);
919 if(idx[2]<idx[0]) psb->
appendLink( idx[2],idx[0]);
923 if (randomizeConstraints)
937 while (*buffer !=
'\n')
959 bool bfacesfromtetras)
966 int result = sscanf(node,
"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
967 result = sscanf(node,
"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
971 for(
int i=0;i<pos.
size();++i)
976 sscanf(node,
"%d %f %f %f",&index,&x,&y,&z);
997 sf>>nface;sf>>hasbounds;
998 for(
int i=0;i<nface;++i)
1004 sf>>ni[0];sf>>ni[1];sf>>ni[2];
1022 sscanf(ele,
"%d %d %d",&ntetra,&ncorner,&neattrb);
1026 for(
int i=0;i<ntetra;++i)
1033 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
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)
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
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)
const btScalar & z() const
Return the z value.
static btScalar tetravolume(const btVector3 &x0, const btVector3 &x1, const btVector3 &x2, const btVector3 &x3)