17#ifndef _BT_SOFT_BODY_INTERNALS_H
18#define _BT_SOFT_BODY_INTERNALS_H
38 void resize(
int n,
const T& init=T()) {
dim=n;
store.resize((n*(n+1))/2,init); }
85 aabbMin=aabbMax=crns[0];
156 virtual const char*
getName()
const {
return "SOFTCLUSTER";}
176 memset(&value,0,
sizeof(T));
189{
return(a+(b-a)*t); }
193{
return((b+a*t-b*t)/(a*b)); }
200 r[0]=
Lerp(a[0],b[0],t);
201 r[1]=
Lerp(a[1],b[1],t);
202 r[2]=
Lerp(a[2],b[2],t);
209 if(sql>(maxlength*maxlength))
210 return((v*maxlength)/
btSqrt(sql));
216static inline T
Clamp(
const T& x,
const T& l,
const T& h)
217{
return(x<l?l:x>h?h:x); }
220static inline T
Sq(
const T& x)
224static inline T
Cube(
const T& x)
228static inline T
Sign(
const T& x)
229{
return((T)(x<0?-1:+1)); }
250 m[0]=
btVector3(1-xx+xx*s,xy*s-xy,zx*s-zx);
251 m[1]=
btVector3(xy*s-xy,1-yy+yy*s,yz*s-yz);
252 m[2]=
btVector3(zx*s-zx,yz*s-yz,1-zz+zz*s);
278 for(
int i=0;i<3;++i) r[i]=a[i]+b[i];
286 for(
int i=0;i<3;++i) r[i]=a[i]-b[i];
294 for(
int i=0;i<3;++i) r[i]=a[i]*b;
339 return(a*
btDot(v,a));
409 return(a*coord.
x()+b*coord.
y()+c*coord.
z());
420 const btScalar isum=1/(w[0]+w[1]+w[2]);
421 return(
btVector3(w[1]*isum,w[2]*isum,w[0]*isum));
429 const int maxiterations=256)
433 if(values[0]>values[1])
436 btSwap(values[0],values[1]);
438 if(values[0]>-accuracy)
return(-1);
439 if(values[1]<+accuracy)
return(-1);
440 for(
int i=0;i<maxiterations;++i)
442 const btScalar t=
Lerp(span[0],span[1],values[0]/(values[0]-values[1]));
444 if((t<=0)||(t>=1))
break;
445 if(
btFabs(v)<accuracy)
return(t);
447 { span[0]=t;values[0]=v; }
449 { span[1]=t;values[1]=v; }
550 if((a==ma)&&(b==mb))
return(0);
551 if((a==mb)&&(b==ma))
return(1);
564 static const int maxiterations=16;
573 if(
btFabs(a[p][q])>accuracy)
575 const btScalar w=(a[q][q]-a[p][p])/(2*a[p][q]);
587 }
while((++iterations)<maxiterations);
590 *values=
btVector3(a[0][0],a[1][1],a[2][2]);
597 const btScalar m[2][3]={ {a[p][0],a[p][1],a[p][2]},
598 {a[q][0],a[q][1],a[q][2]}};
601 for(i=0;i<3;++i) a[p][i]=c*m[0][i]-s*m[1][i];
602 for(i=0;i<3;++i) a[q][i]=c*m[1][i]+s*m[0][i];
606 const btScalar m[2][3]={ {a[0][p],a[1][p],a[2][p]},
607 {a[0][q],a[1][q],a[2][q]}};
610 for(i=0;i<3;++i) a[i][p]=c*m[0][i]-s*m[1][i];
611 for(i=0;i<3;++i) a[i][q]=c*m[1][i]+s*m[0][i];
766 bool connected=
false;
779 cla->
m_com-clb->m_com,res))
833 static const btMatrix3x3 iwiStatic(0,0,0,0,0,0,0,0,0);
884 if( (n[0]->m_im<=0)||
#define btAlignedAlloc(size, alignment)
@ SOFTBODY_SHAPE_PROXYTYPE
const T & btMax(const T &a, const T &b)
const T & btMin(const T &a, const T &b)
btQuaternion inverse(const btQuaternion &q)
Return the inverse of a quaternion.
btScalar length(const btQuaternion &q)
Return the length of a quaternion.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
#define ATTRIBUTE_ALIGNED16(a)
btScalar btSqrt(btScalar y)
btScalar btFabs(btScalar x)
static btVector3 ProjectOnAxis(const btVector3 &v, const btVector3 &a)
static bool CompGreater(const T &a, const T &b)
static btMatrix3x3 Mul(const btMatrix3x3 &a, btScalar b)
static btScalar ImplicitSolve(btSoftBody::ImplicitFn *fn, const btVector3 &a, const btVector3 &b, const btScalar accuracy, const int maxiterations=256)
static void Orthogonalize(btMatrix3x3 &m)
static btMatrix3x3 Cross(const btVector3 &v)
static btMatrix3x3 MassMatrix(btScalar im, const btMatrix3x3 &iwi, const btVector3 &r)
static btDbvtVolume VolumeOf(const btSoftBody::Face &f, btScalar margin)
static T Lerp(const T &a, const T &b, btScalar t)
static btMatrix3x3 AngularImpulseMatrix(const btMatrix3x3 &iia, const btMatrix3x3 &iib)
static btScalar AreaOf(const btVector3 &x0, const btVector3 &x1, const btVector3 &x2)
static btVector3 NormalizeAny(const btVector3 &v)
static int PolarDecompose(const btMatrix3x3 &m, btMatrix3x3 &q, btMatrix3x3 &s)
static int MatchEdge(const btSoftBody::Node *a, const btSoftBody::Node *b, const btSoftBody::Node *ma, const btSoftBody::Node *mb)
static bool CompLess(const T &a, const T &b)
static T BaryEval(const T &a, const T &b, const T &c, const btVector3 &coord)
static btVector3 CenterOf(const btSoftBody::Face &f)
static bool SameSign(const T &x, const T &y)
static void EvaluateMedium(const btSoftBodyWorldInfo *wfi, const btVector3 &x, btSoftBody::sMedium &medium)
static btVector3 BaryCoord(const btVector3 &a, const btVector3 &b, const btVector3 &c, const btVector3 &p)
static btMatrix3x3 ScaleAlongAxis(const btVector3 &a, btScalar s)
static void ZeroInitialize(T &value)
static btMatrix3x3 Add(const btMatrix3x3 &a, const btMatrix3x3 &b)
static T InvLerp(const T &a, const T &b, btScalar t)
static btVector3 ProjectOnPlane(const btVector3 &v, const btVector3 &a)
static btScalar ClusterMetric(const btVector3 &x, const btVector3 &y)
static btMatrix3x3 ImpulseMatrix(btScalar dt, btScalar ima, btScalar imb, const btMatrix3x3 &iwi, const btVector3 &r)
static void ApplyClampedForce(btSoftBody::Node &n, const btVector3 &f, btScalar dt)
static void ProjectOrigin(const btVector3 &a, const btVector3 &b, btVector3 &prj, btScalar &sqd)
static btMatrix3x3 Sub(const btMatrix3x3 &a, const btMatrix3x3 &b)
static T Sign(const T &x)
static btVector3 Clamp(const btVector3 &v, btScalar maxlength)
static btMatrix3x3 Diagonal(btScalar x)
static T Cube(const T &x)
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.
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 push_back(const T &_Val)
bool isStaticOrKinematicObject() const
btTransform & getWorldTransform()
void activate(bool forceActivation=false) const
btScalar getFriction() const
const btCollisionShape * getCollisionShape() const
virtual btScalar getMargin() const =0
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const =0
getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
The btConvexInternalShape is an internal base class, shared by most convex shape implementations.
virtual void setMargin(btScalar margin)
virtual btScalar getMargin() const
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with...
void setIdentity()
Set the matrix to the identity.
This class is used to compute the polar decomposition of a matrix.
unsigned int decompose(const btMatrix3x3 &a, btMatrix3x3 &u, btMatrix3x3 &h) const
Decomposes a matrix into orthogonal and symmetric, positive-definite parts.
The btRigidBody is the main class for rigid body objects.
btVector3 getVelocityInLocalPoint(const btVector3 &rel_pos) const
btScalar getInvMass() const
const btMatrix3x3 & getInvInertiaTensorWorld() const
virtual void calculateLocalInertia(btScalar, btVector3 &) const
void processAllTriangles(btTriangleCallback *, const btVector3 &, const btVector3 &) const
virtual void setLocalScaling(const btVector3 &)
virtual const char * getName() const
virtual const btVector3 & getLocalScaling() const
btSoftBodyCollisionShape(btSoftBody *backptr)
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
virtual ~btSoftBodyCollisionShape()
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
btAlignedObjectArray< bool > m_clusterConnectivity
tRContactArray m_rcontacts
tSContactArray m_scontacts
bool checkContact(const btCollisionObjectWrapper *colObjWrap, const btVector3 &x, btScalar margin, btSoftBody::sCti &cti) const
virtual void setMargin(btScalar margin)
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const
getAabb's default implementation is brute force, expected derived classes to implement a fast dedicat...
btSoftClusterCollisionShape(const btSoftBody::Cluster *cluster)
virtual int getShapeType() const
virtual void calculateLocalInertia(btScalar mass, btVector3 &inertia) const
virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3 &vec) const
virtual btScalar getMargin() const
const btSoftBody::Cluster * m_cluster
virtual btVector3 localGetSupportingVertex(const btVector3 &vec) const
virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const
virtual const char * getName() const
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
btVector3 can be used to represent 3D points and vectors.
void setMax(const btVector3 &other)
Set each element to the max of the current values and the values of another btVector3.
const btScalar & z() const
Return the z value.
btScalar length() const
Return the length of the vector.
btVector3 normalized() const
Return a normalized version of this vector.
btScalar length2() const
Return the length of the vector squared.
const btScalar & x() const
Return the x value.
void setMin(const btVector3 &other)
Set each element to the min of the current values and the values of another btVector3.
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
const btScalar & y() const
Return the y value.
const btCollisionShape * getCollisionShape() const
const btCollisionObject * getCollisionObject() const
const btTransform & getWorldTransform() const
static btDbvtAabbMm FromMM(const btVector3 &mi, const btVector3 &mx)
static btDbvtAabbMm FromPoints(const btVector3 *pts, int n)
DBVT_INLINE void Expand(const btVector3 &e)
DBVT_PREFIX void collideTV(const btDbvtNode *root, const btDbvtVolume &volume, DBVT_IPOLICY) const
DBVT_PREFIX void collideTT(const btDbvtNode *root0, const btDbvtNode *root1, DBVT_IPOLICY)
static void mulPQ(btMatrix3x3 &a, btScalar c, btScalar s, int p, int q)
static int system(btMatrix3x3 &a, btMatrix3x3 *vectors, btVector3 *values=0)
static void mulTPQ(btMatrix3x3 &a, btScalar c, btScalar s, int p, int q)
static btScalar SignedDistance(const btVector3 &position, btScalar margin, const btConvexShape *shape, const btTransform &wtrs, sResults &results)
const btMatrix3x3 & invWorldInertia() const
btVector3 velocity(const btVector3 &rpos) const
const btTransform & xform() const
btAlignedObjectArray< Node * > m_nodes
virtual btScalar Eval(const btVector3 &x)=0
bool SolveContact(const btGjkEpaSolver2::sResults &res, btSoftBody::Body ba, const btSoftBody::Body bb, btSoftBody::CJoint &joint)
void Process(const btDbvtNode *leaf)
void ProcessColObj(btSoftBody *ps, const btCollisionObjectWrapper *colObWrap)
const btCollisionObjectWrapper * m_colObjWrap
void Process(const btDbvtNode *la, const btDbvtNode *lb)
void ProcessSoftSoft(btSoftBody *psa, btSoftBody *psb)
void DoNode(btSoftBody::Node &n) const
void Process(const btDbvtNode *leaf)
btRigidBody * m_rigidBody
const btCollisionObjectWrapper * m_colObj1Wrap
void Process(const btDbvtNode *lnode, const btDbvtNode *lface)
btSoftBody implementation by Nathanael Presson
int index(int c, int r) const
T & operator()(int c, int r)
btAlignedObjectArray< T > store
void resize(int n, const T &init=T())
btSymMatrix(int n, const T &init=T())
const T & operator()(int c, int r) const