|
Bullet Collision Detection & Physics Library
|
Go to the documentation of this file.
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);
151 static const int ncolors=
sizeof(spectrum)/
sizeof(spectrum[0])-1;
153 stress=btMax<btScalar>(0,btMin<btScalar>(1,stress))*ncolors;
154 const int sel=(int)stress;
156 return(spectrum[sel]+(spectrum[sel+1]-spectrum[sel])*frc);
186 for(j=0,nj=vertices.
size();j<nj;++j)
188 vertices[j]=psb->
m_clusters[i]->m_nodes[j]->m_x;
190 #define USE_NEW_CONVEX_HULL_COMPUTER
191 #ifdef USE_NEW_CONVEX_HULL_COMPUTER
194 int count = vertices.
size();
197 computer.
compute(&vertices[0].getX(),stride,count,shrink,shrinkClamp);
198 for (
int i=0;i<computer.
faces.
size();i++)
201 int face = computer.
faces[i];
208 while (edge!=firstEdge)
306 idraw->
drawLine(o-x*nscl,o+x*nscl,ccolor);
307 idraw->
drawLine(o-y*nscl,o+y*nscl,ccolor);
340 const btVector3 c=(x[0]+x[1]+x[2]+x[3])/4;
341 idraw->
drawTriangle((x[0]-c)*scl+c,(x[1]-c)*scl+c,(x[2]-c)*scl+c,col,alp);
342 idraw->
drawTriangle((x[0]-c)*scl+c,(x[1]-c)*scl+c,(x[3]-c)*scl+c,col,alp);
343 idraw->
drawTriangle((x[1]-c)*scl+c,(x[2]-c)*scl+c,(x[3]-c)*scl+c,col,alp);
344 idraw->
drawTriangle((x[2]-c)*scl+c,(x[0]-c)*scl+c,(x[3]-c)*scl+c,col,alp);
378 for(
int j=0;j<n.
m_rank;++j)
446 sprintf(buff,
" M(%.2f)",1/n.
m_im);
451 sprintf(buff,
" A(%.2f)",n.
m_area);
464 drawTree(idraw,psb->
m_ndbvt.
m_root,0,
btVector3(1,0,1),
btVector3(1,1,1),mindepth,maxdepth);
473 drawTree(idraw,psb->
m_fdbvt.
m_root,0,
btVector3(0,1,0),
btVector3(1,0,0),mindepth,maxdepth);
482 drawTree(idraw,psb->
m_cdbvt.
m_root,0,
btVector3(0,1,1),
btVector3(1,0,0),mindepth,maxdepth);
534 #define REOP_NOT_DEPENDENT -1
535 #define REOP_NODE_COMPLETE -2 // Must be less than REOP_NOT_DEPENDENT
546 int readyListHead, readyListTail, linkNum, linkDepFrees, depLink;
549 int *nodeWrittenAt =
new int[nNodes+1];
550 int *linkDepA =
new int[nLinks];
551 int *linkDepB =
new int[nLinks];
552 int *readyList =
new int[nLinks];
561 for (i=0; i < nNodes+1; i++) {
564 for (i=0; i < nLinks; i++) {
565 linkDepListStarts[i] = NULL;
567 readyListHead = readyListTail = linkDepFrees = 0;
570 for (i=0; i < nLinks; i++) {
574 ar = (lr->
m_n[0] - node0)/(node1 - node0);
575 br = (lr->
m_n[1] - node0)/(node1 - node0);
577 linkDepA[i] = nodeWrittenAt[ar];
578 linkDep = &linkDepFreeList[linkDepFrees++];
580 linkDep->
next = linkDepListStarts[nodeWrittenAt[ar]];
581 linkDepListStarts[nodeWrittenAt[ar]] = linkDep;
586 linkDepB[i] = nodeWrittenAt[br];
587 linkDep = &linkDepFreeList[linkDepFrees++];
588 linkDep->
value = -(i+1);
589 linkDep->
next = linkDepListStarts[nodeWrittenAt[br]];
590 linkDepListStarts[nodeWrittenAt[br]] = linkDep;
597 readyList[readyListTail++] = i;
602 nodeWrittenAt[ar] = nodeWrittenAt[br] = i;
611 while (readyListHead != readyListTail) {
613 linkNum = readyList[readyListHead++];
615 psb->
m_links[i++] = linkBuffer[linkNum];
618 linkDep = linkDepListStarts[linkNum];
620 depLink = linkDep->
value;
624 depLink = -depLink - 1;
629 readyList[readyListTail++] = depLink;
632 linkDep = linkDep->
next;
637 delete [] nodeWrittenAt;
641 delete [] linkDepFreeList;
642 delete [] linkDepListStarts;
643 delete [] linkBuffer;
686 x[i]=
lerp(from,to,t);
690 if(fixeds&1) psb->
setMass(0,0);
691 if(fixeds&2) psb->
setMass(r-1,0);
713 #define IDX(_x_,_y_) ((_y_)*rx+(_x_))
715 if((resx<2)||(resy<2))
return(0);
728 for(
int ix=0;ix<rx;++ix)
731 x[
IDX(ix,iy)]=
lerp(py0,py1,tx);
745 for(
int ix=0;ix<rx;++ix)
747 const int idx=
IDX(ix,iy);
748 const bool mdx=(ix+1)<rx;
749 const bool mdy=(iy+1)<ry;
860 #define IDX(_x_,_y_) ((_y_)*rx+(_x_))
862 if((resx<2)||(resy<2))
return(0);
876 for(
int ix=0;ix<rx;++ix)
879 x[
IDX(ix,iy)]=
lerp(py0,py1,tx);
888 if(fixeds&16) psb->
setMass(
IDX((rx-1)/2,0),0);
889 if(fixeds&32) psb->
setMass(
IDX(0,(ry-1)/2),0);
890 if(fixeds&64) psb->
setMass(
IDX(rx-1,(ry-1)/2),0);
891 if(fixeds&128) psb->
setMass(
IDX((rx-1)/2,ry-1),0);
892 if(fixeds&256) psb->
setMass(
IDX((rx-1)/2,(ry-1)/2),0);
901 for(
int ix=0;ix<rx;++ix)
903 const bool mdx=(ix+1)<rx;
904 const bool mdy=(iy+1)<ry;
906 int node00=
IDX(ix,iy);
907 int node01=
IDX(ix+1,iy);
908 int node10=
IDX(ix,iy+1);
909 int node11=
IDX(ix+1,iy+1);
973 tc = (1.0f/((resx-1))*ix);
976 tc = (1.0f/((resy-1))*(resy-1-iy));
979 tc = (1.0f/((resy-1))*(resy-1-iy-1));
982 tc = (1.0f/((resx-1))*(ix+1));
998 for(
int j=i;j;p*=0.5,j>>=1)
if(j&1) t+=p;
1008 Hammersley::Generate(&vtx[0],vtx.
size());
1009 for(
int i=0;i<vtx.
size();++i)
1011 vtx[i]=vtx[i]*radius+center;
1020 const int* triangles,
1021 int ntriangles,
bool randomizeConstraints)
1026 for(i=0,ni=ntriangles*3;i<ni;++i)
1028 maxidx=
btMax(triangles[i],maxidx);
1033 chks.
resize(maxidx*maxidx,
false);
1035 for(i=0,j=0,ni=maxidx*3;i<ni;++j,i+=3)
1037 vtx[j]=
btVector3(vertices[i],vertices[i+1],vertices[i+2]);
1040 for( i=0,ni=ntriangles*3;i<ni;i+=3)
1042 const int idx[]={triangles[i],triangles[i+1],triangles[i+2]};
1043 #define IDX(_x_,_y_) ((_y_)*maxidx+(_x_))
1044 for(
int j=2,k=0;k<3;j=k++)
1046 if(!chks[
IDX(idx[j],idx[k])])
1048 chks[
IDX(idx[j],idx[k])]=
true;
1049 chks[
IDX(idx[k],idx[j])]=
true;
1057 if (randomizeConstraints)
1067 int nvertices,
bool randomizeConstraints)
1078 const int idx[]={
static_cast<int>(hres.
m_Indices[i*3+0]),
1079 static_cast<int>(hres.
m_Indices[i*3+1]),
1080 static_cast<int>(hres.
m_Indices[i*3+2])};
1081 if(idx[0]<idx[1]) psb->
appendLink( idx[0],idx[1]);
1082 if(idx[1]<idx[2]) psb->
appendLink( idx[1],idx[2]);
1083 if(idx[2]<idx[0]) psb->
appendLink( idx[2],idx[0]);
1087 if (randomizeConstraints)
1101 while (*buffer !=
'\n')
1108 if (buffer[0]==0x0a)
1113 return numBytesRead;
1123 bool bfacesfromtetras)
1130 int result = sscanf(node,
"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
1131 result = sscanf(node,
"%d %d %d %d",&nnode,&ndims,&nattrb,&hasbounds);
1135 for(
int i=0;i<pos.
size();++i)
1140 sscanf(node,
"%d %f %f %f",&index,&x,&y,&z);
1161 sf>>nface;sf>>hasbounds;
1162 for(
int i=0;i<nface;++i)
1168 sf>>ni[0];sf>>ni[1];sf>>ni[2];
1186 sscanf(ele,
"%d %d %d",&ntetra,&ncorner,&neattrb);
1190 for(
int i=0;i<ntetra;++i)
1197 sscanf(ele,
"%d %d %d %d %d",&index,&ni[0],&ni[1],&ni[2],&ni[3]);
const Edge * getNextEdgeOfFace() const
const btTransform & xform() const
static void DrawClusterTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
#define REOP_NODE_COMPLETE
HullError ReleaseResult(HullResult &result)
unsigned int mMaxVertices
void appendLink(int model=-1, Material *mat=0)
virtual void drawTriangle(const btVector3 &v0, const btVector3 &v1, const btVector3 &v2, const btVector3 &, const btVector3 &, const btVector3 &, const btVector3 &color, btScalar alpha)
btAlignedObjectArray< btVector3 > vertices
void appendFace(int model=-1, Material *mat=0)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
int getTargetVertex() const
int getSourceVertex() const
virtual eType::_ Type() const =0
static btSoftBody * CreateFromTriMesh(btSoftBodyWorldInfo &worldInfo, const btScalar *vertices, const int *triangles, int ntriangles, bool randomizeConstraints=true)
static void DrawNodeTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
btAlignedObjectArray< btVector3 > m_OutputVertices
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)
#define REOP_NOT_DEPENDENT
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
static btSoftBody * CreateRope(btSoftBodyWorldInfo &worldInfo, const btVector3 &from, const btVector3 &to, int res, int fixeds)
btAlignedObjectArray< int > faces
LinkDeps_t * LinkDepsPtr_t
static void DrawFrame(btSoftBody *psb, btIDebugDraw *idraw)
The HullLibrary class can create a convex hull from a collection of vertices, using the ComputeHull m...
static void add(btAlignedObjectArray< T > &items, const Q &value)
void randomizeConstraints()
unsigned int mNumOutputVertices
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)
const T & btMax(const T &a, const T &b)
const btScalar & y() const
Return the y value.
btTransform & getWorldTransform()
btAlignedObjectArray< Node * > m_nodes
btScalar btSin(btScalar x)
HullError CreateConvexHull(const HullDesc &desc, HullResult &result)
static btSoftBody * CreateEllipsoid(btSoftBodyWorldInfo &worldInfo, const btVector3 ¢er, const btVector3 &radius, int res)
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
static void drawBox(btIDebugDraw *idraw, const btVector3 &mins, const btVector3 &maxs, const btVector3 &color)
void resize(int newsize, const T &fillData=T())
static btSoftBody * CreateFromTetGenData(btSoftBodyWorldInfo &worldInfo, const char *ele, const char *face, const char *node, bool bfacelinks, bool btetralinks, bool bfacesfromtetras)
btAlignedObjectArray< Edge > edges
static void mul(btAlignedObjectArray< T > &items, const Q &value)
Convex hull implementation based on Preparata and Hong See http://code.google.com/p/bullet/issues/det...
btScalar btCos(btScalar x)
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
static void drawVertex(btIDebugDraw *idraw, const btVector3 &x, btScalar s, const btVector3 &c)
btSoftBodyHelpers.cpp by Nathanael Presson
btVector3 can be used to represent 3D points and vectors.
DBVT_INLINE btVector3 Extents() const
virtual void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)=0
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
static void DrawInfos(btSoftBody *psb, btIDebugDraw *idraw, bool masses, bool areas, bool stress)
tRContactArray m_rcontacts
static void ReoptimizeLinkOrder(btSoftBody *psb)
Sort the list of links to move link calculations that are dependent upon earlier ones as far as possi...
DBVT_INLINE bool isinternal() const
btScalar btDot(const btVector3 &v1, const btVector3 &v2)
Return the dot product between two vectors.
const btScalar & x() const
Return the x value.
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
void appendTetra(int model, Material *mat)
btVector3 lerp(const btVector3 &v1, const btVector3 &v2, const btScalar &t)
Return the linear interpolation between two vectors.
static void drawTree(btIDebugDraw *idraw, const btDbvtNode *node, int depth, const btVector3 &ncolor, const btVector3 &lcolor, int mindepth, int maxdepth)
DBVT_INLINE bool isleaf() const
static void Draw(btSoftBody *psb, btIDebugDraw *idraw, int drawflags=fDrawFlags::Std)
btAlignedObjectArray< unsigned int > m_Indices
int minAxis() const
Return the axis with the smallest value Note return values are 0,1,2 for x, y, or z.
static float CalculateUV(int resx, int resy, int ix, int iy, int id)
void setMass(int node, btScalar mass)
btScalar compute(const void *coords, bool doubleCoords, int stride, int count, btScalar shrink, btScalar shrinkClamp)
static int nextLine(const char *buffer)
static void DrawFaceTree(btSoftBody *psb, btIDebugDraw *idraw, int mindepth=0, int maxdepth=-1)
btScalar btSqrt(btScalar y)
static T average(const btAlignedObjectArray< T > &items)
DBVT_INLINE btVector3 Center() const
static btSoftBody * CreateFromConvexHull(btSoftBodyWorldInfo &worldInfo, const btVector3 *vertices, int nvertices, bool randomizeConstraints=true)
btVector3 normalized() const
Return a normalized version of this vector.
static T sum(const btAlignedObjectArray< T > &items)
const btScalar & z() const
Return the z value.
int size() const
return the number of elements in the array