bullet: Update to current svn, r2636
[blender.git] / extern / bullet2 / src / BulletSoftBody / btSoftBody.h
index 7a6bfd53205cdbb33bd826d4e2d59c9203a60f80..2116c34f06d22130a70b946593f1b855fedd6777 100644 (file)
@@ -18,7 +18,6 @@ subject to the following restrictions:
 #define _BT_SOFT_BODY_H
 
 #include "LinearMath/btAlignedObjectArray.h"
-#include "LinearMath/btPoint3.h"
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "BulletDynamics/Dynamics/btRigidBody.h"
@@ -28,8 +27,17 @@ subject to the following restrictions:
 #include "btSparseSDF.h"
 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
 
+//#ifdef BT_USE_DOUBLE_PRECISION
+//#define btRigidBodyData      btRigidBodyDoubleData
+//#define btRigidBodyDataName  "btRigidBodyDoubleData"
+//#else
+#define btSoftBodyData btSoftBodyFloatData
+#define btSoftBodyDataName     "btSoftBodyFloatData"
+//#endif //BT_USE_DOUBLE_PRECISION
+
 class btBroadphaseInterface;
 class btDispatcher;
+class btSoftBodySolver;
 
 /* btSoftBodyWorldInfo */ 
 struct btSoftBodyWorldInfo
@@ -42,33 +50,52 @@ struct      btSoftBodyWorldInfo
        btDispatcher*   m_dispatcher;
        btVector3                               m_gravity;
        btSparseSdf<3>                  m_sparsesdf;
+
+       btSoftBodyWorldInfo()
+               :air_density((btScalar)1.2),
+               water_density(0),
+               water_offset(0),
+               water_normal(0,0,0),
+               m_broadphase(0),
+               m_dispatcher(0),
+               m_gravity(0,-10,0)
+       {
+       }
 };     
 
 
-/// btSoftBody is work-in-progress
+///The btSoftBody is an class to simulate cloth and volumetric soft bodies. 
+///There is two-way interaction between btSoftBody and btRigidBody/btCollisionObject.
 class  btSoftBody : public btCollisionObject
 {
 public:
+       btAlignedObjectArray<const class btCollisionObject*> m_collisionDisabledObjects;
+
+       // The solver object that handles this soft body
+       btSoftBodySolver *m_softBodySolver;
+
        //
        // Enumerations
        //
 
        ///eAeroModel 
        struct eAeroModel { enum _ {
-               V_Point,        ///Vertex normals are oriented toward velocity
-               V_TwoSided,     ///Vertex normals are fliped to match velocity  
-               V_OneSided,     ///Vertex normals are taken as it is    
-               F_TwoSided,     ///Face normals are fliped to match velocity
-               F_OneSided,     ///Face normals are taken as it is
+               V_Point,                        ///Vertex normals are oriented toward velocity
+               V_TwoSided,                     ///Vertex normals are flipped to match velocity 
+               V_TwoSidedLiftDrag, ///Vertex normals are flipped to match velocity and lift and drag forces are applied
+               V_OneSided,                     ///Vertex normals are taken as it is    
+               F_TwoSided,                     ///Face normals are flipped to match velocity
+               F_TwoSidedLiftDrag,     ///Face normals are flipped to match velocity and lift and drag forces are applied 
+               F_OneSided,                     ///Face normals are taken as it is              
                END
        };};
-       
+
        ///eVSolver : velocities solvers
        struct  eVSolver { enum _ {
                Linear,         ///Linear solver
                END
        };};
-       
+
        ///ePSolver : positions solvers
        struct  ePSolver { enum _ {
                Linear,         ///Linear solver
@@ -77,7 +104,7 @@ public:
                SContacts,      ///Soft contacts solver
                END
        };};
-       
+
        ///eSolverPresets
        struct  eSolverPresets { enum _ {
                Positions,
@@ -85,37 +112,39 @@ public:
                Default =       Positions,
                END
        };};
-       
+
        ///eFeature
        struct  eFeature { enum _ {
                None,
                Node,
                Link,
                Face,
+               Tetra,
                END
        };};
-       
+
        typedef btAlignedObjectArray<eVSolver::_>       tVSolverArray;
        typedef btAlignedObjectArray<ePSolver::_>       tPSolverArray;
-       
+
        //
        // Flags
        //
-       
+
        ///fCollision
        struct fCollision { enum _ {
                RVSmask =       0x000f, ///Rigid versus soft mask
                SDF_RS  =       0x0001, ///SDF based rigid vs soft
                CL_RS   =       0x0002, ///Cluster vs convex rigid vs soft
-               
-               SVSmask =       0x00f0, ///Rigid versus soft mask               
+
+               SVSmask =       0x0030, ///Rigid versus soft mask               
                VF_SS   =       0x0010, ///Vertex vs face soft vs soft handling
                CL_SS   =       0x0020, ///Cluster vs cluster soft vs soft handling
+               CL_SELF =       0x0040, ///Cluster soft body self collision
                /* presets      */ 
                Default =       SDF_RS,
                END
        };};
-       
+
        ///fMaterial
        struct fMaterial { enum _ {
                DebugDraw       =       0x0001, /// Enable debug draw
@@ -123,26 +152,26 @@ public:
                Default         =       DebugDraw,
                END
        };};
-               
+
        //
        // API Types
        //
-       
+
        /* sRayCast             */ 
        struct sRayCast
        {
                btSoftBody*     body;           /// soft body
                eFeature::_     feature;        /// feature type
                int                     index;          /// feature index
-               btScalar        time;           /// time of impact (rayorg+raydir*time)
+               btScalar        fraction;               /// time of impact fraction (rayorg+(rayto-rayfrom)*fraction)
        };
-       
+
        /* ImplicitFn   */ 
        struct  ImplicitFn
        {
                virtual btScalar        Eval(const btVector3& x)=0;
        };
-       
+
        //
        // Internal types
        //
@@ -153,7 +182,7 @@ public:
        /* sCti is Softbody contact info        */ 
        struct  sCti
        {
-               btRigidBody*    m_body;         /* Rigid body                   */ 
+               const btCollisionObject*        m_colObj;               /* Rigid body                   */ 
                btVector3               m_normal;       /* Outward normal               */ 
                btScalar                m_offset;       /* Offset from origin   */ 
        };      
@@ -180,7 +209,7 @@ public:
                btScalar                                m_kVST;                 // Volume stiffness coefficient [0,1]
                int                                             m_flags;                // Flags
        };
-               
+
        /* Feature              */ 
        struct  Feature : Element
        {
@@ -218,6 +247,16 @@ public:
                btScalar                                m_ra;                   // Rest area
                btDbvtNode*                             m_leaf;                 // Leaf data
        };
+       /* Tetra                */ 
+       struct  Tetra : Feature
+       {
+               Node*                                   m_n[4];                 // Node pointers                
+               btScalar                                m_rv;                   // Rest volume
+               btDbvtNode*                             m_leaf;                 // Leaf data
+               btVector3                               m_c0[4];                // gradients
+               btScalar                                m_c1;                   // (4*kVST)/(im0+im1+im2+im3)
+               btScalar                                m_c2;                   // m_c1/sum(|g0..3|^2)
+       };
        /* RContact             */ 
        struct  RContact
        {
@@ -246,6 +285,7 @@ public:
                Node*                                   m_node;                 // Node pointer
                btVector3                               m_local;                // Anchor position in body space
                btRigidBody*                    m_body;                 // Body
+               btScalar                                m_influence;
                btMatrix3x3                             m_c0;                   // Impulse matrix
                btVector3                               m_c1;                   // Relative anchor
                btScalar                                m_c2;                   // ima*dt
@@ -274,9 +314,9 @@ public:
        };
        /* Cluster              */ 
        struct  Cluster
-       {               
-               btAlignedObjectArray<Node*>     m_nodes;                
+       {
                tScalarArray                            m_masses;
+               btAlignedObjectArray<Node*>     m_nodes;                
                tVector3Array                           m_framerefs;
                btTransform                                     m_framexform;
                btScalar                                        m_idmass;
@@ -291,12 +331,20 @@ public:
                btVector3                                       m_lv;
                btVector3                                       m_av;
                btDbvtNode*                                     m_leaf;
-               btScalar                                        m_ndamping;
-               btScalar                                        m_ldamping;
-               btScalar                                        m_adamping;
+               btScalar                                        m_ndamping;     /* Node damping         */ 
+               btScalar                                        m_ldamping;     /* Linear damping       */ 
+               btScalar                                        m_adamping;     /* Angular damping      */ 
                btScalar                                        m_matching;
+               btScalar                                        m_maxSelfCollisionImpulse;
+               btScalar                                        m_selfCollisionImpulseFactor;
+               bool                                            m_containsAnchor;
                bool                                            m_collide;
-                                                                       Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}
+               int                                                     m_clusterIndex;
+               Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) 
+               ,m_maxSelfCollisionImpulse(100.f),
+               m_selfCollisionImpulseFactor(0.01f),
+               m_containsAnchor(false)
+               {}
        };
        /* Impulse              */ 
        struct  Impulse
@@ -307,125 +355,143 @@ public:
                int                                                     m_asDrift:1;
                Impulse() : m_velocity(0,0,0),m_drift(0,0,0),m_asVelocity(0),m_asDrift(0)       {}
                Impulse                                         operator -() const
-                       {
+               {
                        Impulse i=*this;
                        i.m_velocity=-i.m_velocity;
                        i.m_drift=-i.m_drift;
                        return(i);
-                       }
+               }
                Impulse                                         operator*(btScalar x) const
-                       {
+               {
                        Impulse i=*this;
                        i.m_velocity*=x;
                        i.m_drift*=x;
                        return(i);
-                       }
+               }
        };
        /* Body                 */ 
        struct  Body
        {
-               Cluster*                m_soft;
-               btRigidBody*                            m_rigid;
-                                                                       Body() : m_soft(0),m_rigid(0)                           {}
-                                                                       Body(Cluster* p) : m_soft(p),m_rigid(0) {}
-                                                                       Body(btRigidBody* p) : m_soft(0),m_rigid(p)     {}
+               Cluster*                        m_soft;
+               btRigidBody*            m_rigid;
+               const btCollisionObject*        m_collisionObject;
+
+               Body() : m_soft(0),m_rigid(0),m_collisionObject(0)                              {}
+               Body(Cluster* p) : m_soft(p),m_rigid(0),m_collisionObject(0)    {}
+               Body(const btCollisionObject* colObj) : m_soft(0),m_collisionObject(colObj)
+               {
+                       m_rigid = (btRigidBody*)btRigidBody::upcast(m_collisionObject);
+               }
+
                void                                            activate() const
-                       {
-                       if(m_rigid) m_rigid->activate();
-                       }
+               {
+                       if(m_rigid) 
+                               m_rigid->activate();
+                       if (m_collisionObject)
+                               m_collisionObject->activate();
+
+               }
                const btMatrix3x3&                      invWorldInertia() const
-                       {
+               {
                        static const btMatrix3x3        iwi(0,0,0,0,0,0,0,0,0);
                        if(m_rigid) return(m_rigid->getInvInertiaTensorWorld());
                        if(m_soft)      return(m_soft->m_invwi);
                        return(iwi);
-                       }
+               }
                btScalar                                        invMass() const
-                       {
+               {
                        if(m_rigid) return(m_rigid->getInvMass());
                        if(m_soft)      return(m_soft->m_imass);
                        return(0);
-                       }
+               }
                const btTransform&                      xform() const
-                       {
+               {
                        static const btTransform        identity=btTransform::getIdentity();            
-                       if(m_rigid) return(m_rigid->getInterpolationWorldTransform());
+                       if(m_collisionObject) return(m_collisionObject->getWorldTransform());
                        if(m_soft)      return(m_soft->m_framexform);
                        return(identity);
-                       }
+               }
                btVector3                                       linearVelocity() const
-                       {
+               {
                        if(m_rigid) return(m_rigid->getLinearVelocity());
                        if(m_soft)      return(m_soft->m_lv);
                        return(btVector3(0,0,0));
-                       }
+               }
                btVector3                                       angularVelocity(const btVector3& rpos) const
-                       {                       
-                       if(m_rigid) return(cross(m_rigid->getAngularVelocity(),rpos));
-                       if(m_soft)      return(cross(m_soft->m_av,rpos));
+               {                       
+                       if(m_rigid) return(btCross(m_rigid->getAngularVelocity(),rpos));
+                       if(m_soft)      return(btCross(m_soft->m_av,rpos));
                        return(btVector3(0,0,0));
-                       }
+               }
                btVector3                                       angularVelocity() const
-                       {                       
+               {                       
                        if(m_rigid) return(m_rigid->getAngularVelocity());
                        if(m_soft)      return(m_soft->m_av);
                        return(btVector3(0,0,0));
-                       }
+               }
                btVector3                                       velocity(const btVector3& rpos) const
-                       {
+               {
                        return(linearVelocity()+angularVelocity(rpos));
-                       }
+               }
                void                                            applyVImpulse(const btVector3& impulse,const btVector3& rpos) const
-                       {
+               {
                        if(m_rigid)     m_rigid->applyImpulse(impulse,rpos);
                        if(m_soft)      btSoftBody::clusterVImpulse(m_soft,rpos,impulse);
-                       }
+               }
                void                                            applyDImpulse(const btVector3& impulse,const btVector3& rpos) const
-                       {
+               {
                        if(m_rigid)     m_rigid->applyImpulse(impulse,rpos);
                        if(m_soft)      btSoftBody::clusterDImpulse(m_soft,rpos,impulse);
-                       }               
+               }               
                void                                            applyImpulse(const Impulse& impulse,const btVector3& rpos) const
+               {
+                       if(impulse.m_asVelocity)        
                        {
-                       if(impulse.m_asVelocity)        applyVImpulse(impulse.m_velocity,rpos);
-                       if(impulse.m_asDrift)           applyDImpulse(impulse.m_drift,rpos);
+//                             printf("impulse.m_velocity = %f,%f,%f\n",impulse.m_velocity.getX(),impulse.m_velocity.getY(),impulse.m_velocity.getZ());
+                               applyVImpulse(impulse.m_velocity,rpos);
                        }
-               void                                            applyVAImpulse(const btVector3& impulse) const
+                       if(impulse.m_asDrift)           
                        {
+//                             printf("impulse.m_drift = %f,%f,%f\n",impulse.m_drift.getX(),impulse.m_drift.getY(),impulse.m_drift.getZ());
+                               applyDImpulse(impulse.m_drift,rpos);
+                       }
+               }
+               void                                            applyVAImpulse(const btVector3& impulse) const
+               {
                        if(m_rigid)     m_rigid->applyTorqueImpulse(impulse);
                        if(m_soft)      btSoftBody::clusterVAImpulse(m_soft,impulse);
-                       }
+               }
                void                                            applyDAImpulse(const btVector3& impulse) const
-                       {
+               {
                        if(m_rigid)     m_rigid->applyTorqueImpulse(impulse);
                        if(m_soft)      btSoftBody::clusterDAImpulse(m_soft,impulse);
-                       }
+               }
                void                                            applyAImpulse(const Impulse& impulse) const
-                       {
+               {
                        if(impulse.m_asVelocity)        applyVAImpulse(impulse.m_velocity);
                        if(impulse.m_asDrift)           applyDAImpulse(impulse.m_drift);
-                       }
+               }
                void                                            applyDCImpulse(const btVector3& impulse) const
-                       {
+               {
                        if(m_rigid)     m_rigid->applyCentralImpulse(impulse);
                        if(m_soft)      btSoftBody::clusterDCImpulse(m_soft,impulse);
-                       }
+               }
        };
        /* Joint                */ 
        struct  Joint
        {
                struct eType { enum _ {
-                       Linear,
+                       Linear=0,
                        Angular,
-                       Contact,
+                       Contact
                };};
                struct Specs
-                       {
-                                               Specs() : erp(1),cfm(1),split(1) {}
+               {
+                       Specs() : erp(1),cfm(1),split(1) {}
                        btScalar        erp;
                        btScalar        cfm;
                        btScalar        split;
-                       };
+               };
                Body                                            m_bodies[2];
                btVector3                                       m_refs[2];
                btScalar                                        m_cfm;
@@ -436,7 +502,7 @@ public:
                btMatrix3x3                                     m_massmatrix;
                bool                                            m_delete;
                virtual                                         ~Joint() {}
-                                                                       Joint() : m_delete(false) {}
+               Joint() : m_delete(false) {}
                virtual void                            Prepare(btScalar dt,int iterations);
                virtual void                            Solve(btScalar dt,btScalar sor)=0;
                virtual void                            Terminate(btScalar dt)=0;
@@ -446,9 +512,9 @@ public:
        struct  LJoint : Joint
        {
                struct Specs : Joint::Specs
-                       {
+               {
                        btVector3       position;
-                       };              
+               };              
                btVector3                                       m_rpos[2];
                void                                            Prepare(btScalar dt,int iterations);
                void                                            Solve(btScalar dt,btScalar sor);
@@ -459,17 +525,17 @@ public:
        struct  AJoint : Joint
        {
                struct IControl
-                       {
+               {
                        virtual void                    Prepare(AJoint*)                                {}
                        virtual btScalar                Speed(AJoint*,btScalar current) { return(current); }
                        static IControl*                Default()                                               { static IControl def;return(&def); }
-                       };
+               };
                struct Specs : Joint::Specs
-                       {
-                                               Specs() : icontrol(IControl::Default()) {}
+               {
+                       Specs() : icontrol(IControl::Default()) {}
                        btVector3       axis;
                        IControl*       icontrol;
-                       };              
+               };              
                btVector3                                       m_axis[2];
                IControl*                                       m_icontrol;
                void                                            Prepare(btScalar dt,int iterations);
@@ -532,26 +598,29 @@ public:
                btScalar                                radmrg;                 // radial margin
                btScalar                                updmrg;                 // Update margin
        };      
-       /* RayCaster    */ 
-       struct  RayCaster : btDbvt::ICollide
-               {
-               btVector3                       o;
-               btVector3                       d;
-               btScalar                        mint;
-               Face*   face;
-               int                                     tests;
-                                                               RayCaster(const btVector3& org,const btVector3& dir,btScalar mxt);
+       /// RayFromToCaster takes a ray from, ray to (instead of direction!)
+       struct  RayFromToCaster : btDbvt::ICollide
+       {
+               btVector3                       m_rayFrom;
+               btVector3                       m_rayTo;
+               btVector3                       m_rayNormalizedDirection;
+               btScalar                        m_mint;
+               Face*                           m_face;
+               int                                     m_tests;
+               RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt);
                void                                    Process(const btDbvtNode* leaf);
-               static inline btScalar  rayTriangle(const btVector3& org,
-                                                                                       const btVector3& dir,
-                                                                                       const btVector3& a,
-                                                                                       const btVector3& b,
-                                                                                       const btVector3& c,
-                                                                                       btScalar maxt=SIMD_INFINITY);
-               };
+
+               static inline btScalar  rayFromToTriangle(const btVector3& rayFrom,
+                       const btVector3& rayTo,
+                       const btVector3& rayNormalizedDirection,
+                       const btVector3& a,
+                       const btVector3& b,
+                       const btVector3& c,
+                       btScalar maxt=SIMD_INFINITY);
+       };
 
        //
-       // Typedef's
+       // Typedefs
        //
 
        typedef void                                                            (*psolver_t)(btSoftBody*,btScalar,btScalar);
@@ -562,6 +631,7 @@ public:
        typedef btAlignedObjectArray<btDbvtNode*>       tLeafArray;
        typedef btAlignedObjectArray<Link>                      tLinkArray;
        typedef btAlignedObjectArray<Face>                      tFaceArray;
+       typedef btAlignedObjectArray<Tetra>                     tTetraArray;
        typedef btAlignedObjectArray<Anchor>            tAnchorArray;
        typedef btAlignedObjectArray<RContact>          tRContactArray;
        typedef btAlignedObjectArray<SContact>          tSContactArray;
@@ -582,6 +652,7 @@ public:
        tNodeArray                              m_nodes;                // Nodes
        tLinkArray                              m_links;                // Links
        tFaceArray                              m_faces;                // Faces
+       tTetraArray                             m_tetras;               // Tetras
        tAnchorArray                    m_anchors;              // Anchors
        tRContactArray                  m_rcontacts;    // Rigid contacts
        tSContactArray                  m_scontacts;    // Soft contacts
@@ -594,74 +665,102 @@ public:
        btDbvt                                  m_fdbvt;                // Faces tree
        btDbvt                                  m_cdbvt;                // Clusters tree
        tClusterArray                   m_clusters;             // Clusters
-               
+
+       btAlignedObjectArray<bool>m_clusterConnectivity;//cluster connectivity, for self-collision
+
+       btTransform                     m_initialWorldTransform;
+
+       btVector3                       m_windVelocity;
+       
+       btScalar        m_restLengthScale;
+       
        //
        // Api
        //
-       
+
        /* ctor                                                                                                                                 */ 
-       btSoftBody(     btSoftBodyWorldInfo* worldInfo,int node_count,
-                               const btVector3* x,
-                               const btScalar* m);
+       btSoftBody(     btSoftBodyWorldInfo* worldInfo,int node_count,          const btVector3* x,             const btScalar* m);
+
+       /* ctor                                                                                                                                 */ 
+       btSoftBody(     btSoftBodyWorldInfo* worldInfo);
+
+       void    initDefaults();
+
        /* dtor                                                                                                                                 */ 
        virtual ~btSoftBody();
        /* Check for existing link                                                                                              */ 
 
        btAlignedObjectArray<int>       m_userIndexMapping;
 
+       btSoftBodyWorldInfo*    getWorldInfo()
+       {
+               return m_worldInfo;
+       }
+
+       ///@todo: avoid internal softbody shape hack and move collision code to collision library
        virtual void    setCollisionShape(btCollisionShape* collisionShape)
        {
-               //don't do anything, due to the internal shape hack: todo: fix this
+               
        }
 
        bool                            checkLink(      int node0,
                int node1) const;
        bool                            checkLink(      const Node* node0,
-                                                                       const Node* node1) const;
+               const Node* node1) const;
        /* Check for existring face                                                                                             */ 
        bool                            checkFace(      int node0,
-                                                                       int node1,
-                                                                       int node2) const;
+               int node1,
+               int node2) const;
        /* Append material                                                                                                              */ 
        Material*                       appendMaterial();
        /* Append note                                                                                                                  */ 
        void                            appendNote(     const char* text,
-                                                                       const btVector3& o,
-                                                                       const btVector4& c=btVector4(1,0,0,0),
-                                                                       Node* n0=0,
-                                                                       Node* n1=0,
-                                                                       Node* n2=0,
-                                                                       Node* n3=0);
+               const btVector3& o,
+               const btVector4& c=btVector4(1,0,0,0),
+               Node* n0=0,
+               Node* n1=0,
+               Node* n2=0,
+               Node* n3=0);
        void                            appendNote(     const char* text,
-                                                                       const btVector3& o,
-                                                                       Node* feature);
+               const btVector3& o,
+               Node* feature);
        void                            appendNote(     const char* text,
-                                                                       const btVector3& o,
-                                                                       Link* feature);
+               const btVector3& o,
+               Link* feature);
        void                            appendNote(     const char* text,
-                                                                       const btVector3& o,
-                                                                       Face* feature);
+               const btVector3& o,
+               Face* feature);
        /* Append node                                                                                                                  */ 
        void                            appendNode(     const btVector3& x,btScalar m);
        /* Append link                                                                                                                  */ 
        void                            appendLink(int model=-1,Material* mat=0);
        void                            appendLink(     int node0,
-                                                                       int node1,
-                                                                       Material* mat=0,
-                                                                       bool bcheckexist=false);
+               int node1,
+               Material* mat=0,
+               bool bcheckexist=false);
        void                            appendLink(     Node* node0,
-                                                                       Node* node1,
-                                                                       Material* mat=0,
-                                                                       bool bcheckexist=false);
+               Node* node1,
+               Material* mat=0,
+               bool bcheckexist=false);
        /* Append face                                                                                                                  */ 
        void                            appendFace(int model=-1,Material* mat=0);
        void                            appendFace(     int node0,
-                                                                       int node1,
-                                                                       int node2,
-                                                                       Material* mat=0);
+               int node1,
+               int node2,
+               Material* mat=0);
+       void                    appendTetra(int model,Material* mat);
+       //
+       void                    appendTetra(int node0,
+                                                                               int node1,
+                                                                               int node2,
+                                                                               int node3,
+                                                                               Material* mat=0);
+
+
        /* Append anchor                                                                                                                */ 
        void                            appendAnchor(   int node,
-                                                                               btRigidBody* body);
+               btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
+       void                    appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
        /* Append linear joint                                                                                                  */ 
        void                            appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
        void                            appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
@@ -674,7 +773,13 @@ public:
        void                            addForce(               const btVector3& force);
        /* Add force (or gravity) to a node of the body                                                 */ 
        void                            addForce(               const btVector3& force,
-                                                                               int node);
+               int node);
+       /* Add aero force to a node of the body */
+       void                        addAeroForceToNode(const btVector3& windVelocity,int nodeIndex);
+
+       /* Add aero force to a face of the body */
+       void                        addAeroForceToFace(const btVector3& windVelocity,int faceIndex);
+
        /* Add velocity to the entire body                                                                              */ 
        void                            addVelocity(    const btVector3& velocity);
 
@@ -683,19 +788,23 @@ public:
 
        /* Add velocity to a node of the body                                                                   */ 
        void                            addVelocity(    const btVector3& velocity,
-                                                                               int node);
+               int node);
        /* Set mass                                                                                                                             */ 
        void                            setMass(                int node,
-                                                                               btScalar mass);
+               btScalar mass);
        /* Get mass                                                                                                                             */ 
        btScalar                        getMass(                int node) const;
        /* Get total mass                                                                                                               */ 
        btScalar                        getTotalMass() const;
        /* Set total mass (weighted by previous masses)                                                 */ 
        void                            setTotalMass(   btScalar mass,
-                                                                               bool fromfaces=false);
+               bool fromfaces=false);
        /* Set total density                                                                                                    */ 
        void                            setTotalDensity(btScalar density);
+       /* Set volume mass (using tetrahedrons)                                                                 */
+       void                            setVolumeMass(          btScalar mass);
+       /* Set volume density (using tetrahedrons)                                                              */
+       void                            setVolumeDensity(       btScalar density);
        /* Transform                                                                                                                    */ 
        void                            transform(              const btTransform& trs);
        /* Translate                                                                                                                    */ 
@@ -704,9 +813,15 @@ public:
        void                            rotate( const btQuaternion& rot);
        /* Scale                                                                                                                                */ 
        void                            scale(  const btVector3& scl);
+       /* Get link resting lengths scale                                                                               */
+       btScalar                        getRestLengthScale();
+       /* Scale resting length of all springs                                                                  */
+       void                            setRestLengthScale(btScalar restLength);
        /* Set current state as pose                                                                                    */ 
        void                            setPose(                bool bvolume,
-                                                                               bool bframe);
+               bool bframe);
+       /* Set current link lengths as resting lengths                                                  */ 
+       void                            resetLinkRestLengths();
        /* Return the volume                                                                                                    */ 
        btScalar                        getVolume() const;
        /* Cluster count                                                                                                                */ 
@@ -726,24 +841,26 @@ public:
        static void                     clusterDCImpulse(Cluster* cluster,const btVector3& impulse);
        /* Generate bending constraints based on distance in the adjency graph  */ 
        int                                     generateBendingConstraints(     int distance,
-                                                                                                       Material* mat=0);
+               Material* mat=0);
        /* Randomize constraints to reduce solver bias                                                  */ 
        void                            randomizeConstraints();
        /* Release clusters                                                                                                             */ 
        void                            releaseCluster(int index);
        void                            releaseClusters();
        /* Generate clusters (K-mean)                                                                                   */ 
+       ///generateClusters with k=0 will create a convex cluster for each tetrahedron or triangle
+       ///otherwise an approximation will be used (better performance)
        int                                     generateClusters(int k,int maxiterations=8192);
        /* Refine                                                                                                                               */ 
        void                            refine(ImplicitFn* ifn,btScalar accurary,bool cut);
        /* CutLink                                                                                                                              */ 
        bool                            cutLink(int node0,int node1,btScalar position);
        bool                            cutLink(const Node* node0,const Node* node1,btScalar position);
-       /* Ray casting                                                                                                                  */ 
-       bool                            rayCast(const btVector3& org,
-                                                               const btVector3& dir,
-                                                               sRayCast& results,
-                                                               btScalar maxtime=SIMD_INFINITY);
+
+       ///Ray casting using rayFrom and rayTo in worldspace, (not direction!)
+       bool                            rayTest(const btVector3& rayFrom,
+               const btVector3& rayTo,
+               sRayCast& results);
        /* Solver presets                                                                                                               */ 
        void                            setSolver(eSolverPresets::_ preset);
        /* predictMotion                                                                                                                */ 
@@ -759,13 +876,56 @@ public:
        /* integrateMotion                                                                                                              */ 
        void                            integrateMotion();
        /* defaultCollisionHandlers                                                                                             */ 
-       void                            defaultCollisionHandler(btCollisionObject* pco);
+       void                            defaultCollisionHandler(const btCollisionObjectWrapper* pcoWrap);
        void                            defaultCollisionHandler(btSoftBody* psb);
-               
+
+
+
+       //
+       // Functionality to deal with new accelerated solvers.
+       //
+
+       /**
+        * Set a wind velocity for interaction with the air.
+        */
+       void setWindVelocity( const btVector3 &velocity );
+
+
+       /**
+        * Return the wind velocity for interaction with the air.
+        */
+       const btVector3& getWindVelocity();
+
+       //
+       // Set the solver that handles this soft body
+       // Should not be allowed to get out of sync with reality
+       // Currently called internally on addition to the world
+       void setSoftBodySolver( btSoftBodySolver *softBodySolver )
+       {
+               m_softBodySolver = softBodySolver;
+       }
+
+       //
+       // Return the solver that handles this soft body
+       // 
+       btSoftBodySolver *getSoftBodySolver()
+       {
+               return m_softBodySolver;
+       }
+
+       //
+       // Return the solver that handles this soft body
+       // 
+       btSoftBodySolver *getSoftBodySolver() const
+       {
+               return m_softBodySolver;
+       }
+
+
        //
        // Cast
        //
-               
+
        static const btSoftBody*        upcast(const btCollisionObject* colObj)
        {
                if (colObj->getInternalType()==CO_SOFT_BODY)
@@ -793,15 +953,18 @@ public:
        //
        void                            pointersToIndices();
        void                            indicesToPointers(const int* map=0);
-       int                                     rayCast(const btVector3& org,const btVector3& dir,
-                                                               btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
+
+       int                                     rayTest(const btVector3& rayFrom,const btVector3& rayTo,
+               btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
        void                            initializeFaceTree();
        btVector3                       evaluateCom() const;
-       bool                            checkContact(btRigidBody* prb,const btVector3& x,btScalar margin,btSoftBody::sCti& cti) const;
+       bool                            checkContact(const btCollisionObjectWrapper* colObjWrap,const btVector3& x,btScalar margin,btSoftBody::sCti& cti) const;
        void                            updateNormals();
        void                            updateBounds();
        void                            updatePose();
        void                            updateConstants();
+       void                            updateLinkConstants();
+       void                            updateArea(bool averageArea = true);
        void                            initializeClusters();
        void                            updateClusters();
        void                            cleanupClusters();
@@ -817,9 +980,19 @@ public:
        static void                     VSolve_Links(btSoftBody* psb,btScalar kst);
        static psolver_t        getSolver(ePSolver::_ solver);
        static vsolver_t        getSolver(eVSolver::_ solver);
-       
+
+
+       virtual int     calculateSerializeBufferSize()  const;
+
+       ///fills the dataBuffer and returns the struct name (and 0 on failure)
+       virtual const char*     serialize(void* dataBuffer,  class btSerializer* serializer) const;
+
+       //virtual void serializeSingleObject(class btSerializer* serializer) const;
+
+
 };
 
 
 
+
 #endif //_BT_SOFT_BODY_H