2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5
This software is provided 'as-is', without any express or implied warranty.
6
In no event will the authors be held liable for any damages arising from the use of this software.
7
Permission is granted to anyone to use this software for any purpose,
8
including commercial applications, and to alter it and redistribute it freely,
9
subject to the following restrictions:
11
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
3. This notice may not be removed or altered from any source distribution.
15
///btSoftBody implementation by Nathanael Presson
17
#ifndef _BT_SOFT_BODY_H
18
#define _BT_SOFT_BODY_H
20
#include "LinearMath/btAlignedObjectArray.h"
21
#include "LinearMath/btTransform.h"
22
#include "LinearMath/btIDebugDraw.h"
23
#include "BulletDynamics/Dynamics/btRigidBody.h"
25
#include "BulletCollision/CollisionShapes/btConcaveShape.h"
26
#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
27
#include "btSparseSDF.h"
28
#include "BulletCollision/BroadphaseCollision/btDbvt.h"
30
//#ifdef BT_USE_DOUBLE_PRECISION
31
//#define btRigidBodyData btRigidBodyDoubleData
32
//#define btRigidBodyDataName "btRigidBodyDoubleData"
34
#define btSoftBodyData btSoftBodyFloatData
35
#define btSoftBodyDataName "btSoftBodyFloatData"
36
//#endif //BT_USE_DOUBLE_PRECISION
38
class btBroadphaseInterface;
40
class btSoftBodySolver;
42
/* btSoftBodyWorldInfo */
43
struct btSoftBodyWorldInfo
46
btScalar water_density;
47
btScalar water_offset;
48
btVector3 water_normal;
49
btBroadphaseInterface* m_broadphase;
50
btDispatcher* m_dispatcher;
52
btSparseSdf<3> m_sparsesdf;
55
:air_density((btScalar)1.2),
67
///The btSoftBody is an class to simulate cloth and volumetric soft bodies.
68
///There is two-way interaction between btSoftBody and btRigidBody/btCollisionObject.
69
class btSoftBody : public btCollisionObject
72
btAlignedObjectArray<class btCollisionObject*> m_collisionDisabledObjects;
74
// The solver object that handles this soft body
75
btSoftBodySolver *m_softBodySolver;
82
struct eAeroModel { enum _ {
83
V_Point, ///Vertex normals are oriented toward velocity
84
V_TwoSided, ///Vertex normals are fliped to match velocity
85
V_OneSided, ///Vertex normals are taken as it is
86
F_TwoSided, ///Face normals are fliped to match velocity
87
F_OneSided, ///Face normals are taken as it is
91
///eVSolver : velocities solvers
92
struct eVSolver { enum _ {
93
Linear, ///Linear solver
97
///ePSolver : positions solvers
98
struct ePSolver { enum _ {
99
Linear, ///Linear solver
100
Anchors, ///Anchor solver
101
RContacts, ///Rigid contacts solver
102
SContacts, ///Soft contacts solver
107
struct eSolverPresets { enum _ {
115
struct eFeature { enum _ {
123
typedef btAlignedObjectArray<eVSolver::_> tVSolverArray;
124
typedef btAlignedObjectArray<ePSolver::_> tPSolverArray;
131
struct fCollision { enum _ {
132
RVSmask = 0x000f, ///Rigid versus soft mask
133
SDF_RS = 0x0001, ///SDF based rigid vs soft
134
CL_RS = 0x0002, ///Cluster vs convex rigid vs soft
136
SVSmask = 0x0030, ///Rigid versus soft mask
137
VF_SS = 0x0010, ///Vertex vs face soft vs soft handling
138
CL_SS = 0x0020, ///Cluster vs cluster soft vs soft handling
139
CL_SELF = 0x0040, ///Cluster soft body self collision
146
struct fMaterial { enum _ {
147
DebugDraw = 0x0001, /// Enable debug draw
160
btSoftBody* body; /// soft body
161
eFeature::_ feature; /// feature type
162
int index; /// feature index
163
btScalar fraction; /// time of impact fraction (rayorg+(rayto-rayfrom)*fraction)
169
virtual btScalar Eval(const btVector3& x)=0;
176
typedef btAlignedObjectArray<btScalar> tScalarArray;
177
typedef btAlignedObjectArray<btVector3> tVector3Array;
179
/* sCti is Softbody contact info */
182
btCollisionObject* m_colObj; /* Rigid body */
183
btVector3 m_normal; /* Outward normal */
184
btScalar m_offset; /* Offset from origin */
190
btVector3 m_velocity; /* Velocity */
191
btScalar m_pressure; /* Pressure */
192
btScalar m_density; /* Density */
198
void* m_tag; // User data
199
Element() : m_tag(0) {}
202
struct Material : Element
204
btScalar m_kLST; // Linear stiffness coefficient [0,1]
205
btScalar m_kAST; // Area/Angular stiffness coefficient [0,1]
206
btScalar m_kVST; // Volume stiffness coefficient [0,1]
207
int m_flags; // Flags
211
struct Feature : Element
213
Material* m_material; // Material
216
struct Node : Feature
218
btVector3 m_x; // Position
219
btVector3 m_q; // Previous step position
220
btVector3 m_v; // Velocity
221
btVector3 m_f; // Force accumulator
222
btVector3 m_n; // Normal
223
btScalar m_im; // 1/mass
224
btScalar m_area; // Area
225
btDbvtNode* m_leaf; // Leaf data
226
int m_battach:1; // Attached
229
struct Link : Feature
231
Node* m_n[2]; // Node pointers
232
btScalar m_rl; // Rest length
233
int m_bbending:1; // Bending link
234
btScalar m_c0; // (ima+imb)*kLST
235
btScalar m_c1; // rl^2
236
btScalar m_c2; // |gradient|^2/c0
237
btVector3 m_c3; // gradient
240
struct Face : Feature
242
Node* m_n[3]; // Node pointers
243
btVector3 m_normal; // Normal
244
btScalar m_ra; // Rest area
245
btDbvtNode* m_leaf; // Leaf data
248
struct Tetra : Feature
250
Node* m_n[4]; // Node pointers
251
btScalar m_rv; // Rest volume
252
btDbvtNode* m_leaf; // Leaf data
253
btVector3 m_c0[4]; // gradients
254
btScalar m_c1; // (4*kVST)/(im0+im1+im2+im3)
255
btScalar m_c2; // m_c1/sum(|g0..3|^2)
260
sCti m_cti; // Contact infos
261
Node* m_node; // Owner node
262
btMatrix3x3 m_c0; // Impulse matrix
263
btVector3 m_c1; // Relative anchor
264
btScalar m_c2; // ima*dt
265
btScalar m_c3; // Friction
266
btScalar m_c4; // Hardness
271
Node* m_node; // Node
272
Face* m_face; // Face
273
btVector3 m_weights; // Weigths
274
btVector3 m_normal; // Normal
275
btScalar m_margin; // Margin
276
btScalar m_friction; // Friction
277
btScalar m_cfm[2]; // Constraint force mixing
282
Node* m_node; // Node pointer
283
btVector3 m_local; // Anchor position in body space
284
btRigidBody* m_body; // Body
285
btScalar m_influence;
286
btMatrix3x3 m_c0; // Impulse matrix
287
btVector3 m_c1; // Relative anchor
288
btScalar m_c2; // ima*dt
291
struct Note : Element
293
const char* m_text; // Text
294
btVector3 m_offset; // Offset
296
Node* m_nodes[4]; // Nodes
297
btScalar m_coords[4]; // Coordinates
302
bool m_bvolume; // Is valid
303
bool m_bframe; // Is frame
304
btScalar m_volume; // Rest volume
305
tVector3Array m_pos; // Reference positions
306
tScalarArray m_wgh; // Weights
307
btVector3 m_com; // COM
308
btMatrix3x3 m_rot; // Rotation
309
btMatrix3x3 m_scl; // Scale
310
btMatrix3x3 m_aqq; // Base scaling
315
tScalarArray m_masses;
316
btAlignedObjectArray<Node*> m_nodes;
317
tVector3Array m_framerefs;
318
btTransform m_framexform;
324
btVector3 m_vimpulses[2];
325
btVector3 m_dimpulses[2];
331
btScalar m_ndamping; /* Node damping */
332
btScalar m_ldamping; /* Linear damping */
333
btScalar m_adamping; /* Angular damping */
335
btScalar m_maxSelfCollisionImpulse;
336
btScalar m_selfCollisionImpulseFactor;
337
bool m_containsAnchor;
340
Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0)
341
,m_maxSelfCollisionImpulse(100.f),
342
m_selfCollisionImpulseFactor(0.01f),
343
m_containsAnchor(false)
349
btVector3 m_velocity;
353
Impulse() : m_velocity(0,0,0),m_drift(0,0,0),m_asVelocity(0),m_asDrift(0) {}
354
Impulse operator -() const
357
i.m_velocity=-i.m_velocity;
358
i.m_drift=-i.m_drift;
361
Impulse operator*(btScalar x) const
373
btRigidBody* m_rigid;
374
btCollisionObject* m_collisionObject;
376
Body() : m_soft(0),m_rigid(0),m_collisionObject(0) {}
377
Body(Cluster* p) : m_soft(p),m_rigid(0),m_collisionObject(0) {}
378
Body(btCollisionObject* colObj) : m_soft(0),m_collisionObject(colObj)
380
m_rigid = btRigidBody::upcast(m_collisionObject);
383
void activate() const
387
if (m_collisionObject)
388
m_collisionObject->activate();
391
const btMatrix3x3& invWorldInertia() const
393
static const btMatrix3x3 iwi(0,0,0,0,0,0,0,0,0);
394
if(m_rigid) return(m_rigid->getInvInertiaTensorWorld());
395
if(m_soft) return(m_soft->m_invwi);
398
btScalar invMass() const
400
if(m_rigid) return(m_rigid->getInvMass());
401
if(m_soft) return(m_soft->m_imass);
404
const btTransform& xform() const
406
static const btTransform identity=btTransform::getIdentity();
407
if(m_collisionObject) return(m_collisionObject->getWorldTransform());
408
if(m_soft) return(m_soft->m_framexform);
411
btVector3 linearVelocity() const
413
if(m_rigid) return(m_rigid->getLinearVelocity());
414
if(m_soft) return(m_soft->m_lv);
415
return(btVector3(0,0,0));
417
btVector3 angularVelocity(const btVector3& rpos) const
419
if(m_rigid) return(btCross(m_rigid->getAngularVelocity(),rpos));
420
if(m_soft) return(btCross(m_soft->m_av,rpos));
421
return(btVector3(0,0,0));
423
btVector3 angularVelocity() const
425
if(m_rigid) return(m_rigid->getAngularVelocity());
426
if(m_soft) return(m_soft->m_av);
427
return(btVector3(0,0,0));
429
btVector3 velocity(const btVector3& rpos) const
431
return(linearVelocity()+angularVelocity(rpos));
433
void applyVImpulse(const btVector3& impulse,const btVector3& rpos) const
435
if(m_rigid) m_rigid->applyImpulse(impulse,rpos);
436
if(m_soft) btSoftBody::clusterVImpulse(m_soft,rpos,impulse);
438
void applyDImpulse(const btVector3& impulse,const btVector3& rpos) const
440
if(m_rigid) m_rigid->applyImpulse(impulse,rpos);
441
if(m_soft) btSoftBody::clusterDImpulse(m_soft,rpos,impulse);
443
void applyImpulse(const Impulse& impulse,const btVector3& rpos) const
445
if(impulse.m_asVelocity)
447
// printf("impulse.m_velocity = %f,%f,%f\n",impulse.m_velocity.getX(),impulse.m_velocity.getY(),impulse.m_velocity.getZ());
448
applyVImpulse(impulse.m_velocity,rpos);
450
if(impulse.m_asDrift)
452
// printf("impulse.m_drift = %f,%f,%f\n",impulse.m_drift.getX(),impulse.m_drift.getY(),impulse.m_drift.getZ());
453
applyDImpulse(impulse.m_drift,rpos);
456
void applyVAImpulse(const btVector3& impulse) const
458
if(m_rigid) m_rigid->applyTorqueImpulse(impulse);
459
if(m_soft) btSoftBody::clusterVAImpulse(m_soft,impulse);
461
void applyDAImpulse(const btVector3& impulse) const
463
if(m_rigid) m_rigid->applyTorqueImpulse(impulse);
464
if(m_soft) btSoftBody::clusterDAImpulse(m_soft,impulse);
466
void applyAImpulse(const Impulse& impulse) const
468
if(impulse.m_asVelocity) applyVAImpulse(impulse.m_velocity);
469
if(impulse.m_asDrift) applyDAImpulse(impulse.m_drift);
471
void applyDCImpulse(const btVector3& impulse) const
473
if(m_rigid) m_rigid->applyCentralImpulse(impulse);
474
if(m_soft) btSoftBody::clusterDCImpulse(m_soft,impulse);
480
struct eType { enum _ {
487
Specs() : erp(1),cfm(1),split(1) {}
499
btMatrix3x3 m_massmatrix;
502
Joint() : m_delete(false) {}
503
virtual void Prepare(btScalar dt,int iterations);
504
virtual void Solve(btScalar dt,btScalar sor)=0;
505
virtual void Terminate(btScalar dt)=0;
506
virtual eType::_ Type() const=0;
509
struct LJoint : Joint
511
struct Specs : Joint::Specs
516
void Prepare(btScalar dt,int iterations);
517
void Solve(btScalar dt,btScalar sor);
518
void Terminate(btScalar dt);
519
eType::_ Type() const { return(eType::Linear); }
522
struct AJoint : Joint
526
virtual void Prepare(AJoint*) {}
527
virtual btScalar Speed(AJoint*,btScalar current) { return(current); }
528
static IControl* Default() { static IControl def;return(&def); }
530
struct Specs : Joint::Specs
532
Specs() : icontrol(IControl::Default()) {}
537
IControl* m_icontrol;
538
void Prepare(btScalar dt,int iterations);
539
void Solve(btScalar dt,btScalar sor);
540
void Terminate(btScalar dt);
541
eType::_ Type() const { return(eType::Angular); }
544
struct CJoint : Joint
551
void Prepare(btScalar dt,int iterations);
552
void Solve(btScalar dt,btScalar sor);
553
void Terminate(btScalar dt);
554
eType::_ Type() const { return(eType::Contact); }
559
eAeroModel::_ aeromodel; // Aerodynamic model (default: V_Point)
560
btScalar kVCF; // Velocities correction factor (Baumgarte)
561
btScalar kDP; // Damping coefficient [0,1]
562
btScalar kDG; // Drag coefficient [0,+inf]
563
btScalar kLF; // Lift coefficient [0,+inf]
564
btScalar kPR; // Pressure coefficient [-inf,+inf]
565
btScalar kVC; // Volume conversation coefficient [0,+inf]
566
btScalar kDF; // Dynamic friction coefficient [0,1]
567
btScalar kMT; // Pose matching coefficient [0,1]
568
btScalar kCHR; // Rigid contacts hardness [0,1]
569
btScalar kKHR; // Kinetic contacts hardness [0,1]
570
btScalar kSHR; // Soft contacts hardness [0,1]
571
btScalar kAHR; // Anchors hardness [0,1]
572
btScalar kSRHR_CL; // Soft vs rigid hardness [0,1] (cluster only)
573
btScalar kSKHR_CL; // Soft vs kinetic hardness [0,1] (cluster only)
574
btScalar kSSHR_CL; // Soft vs soft hardness [0,1] (cluster only)
575
btScalar kSR_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
576
btScalar kSK_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
577
btScalar kSS_SPLT_CL; // Soft vs rigid impulse split [0,1] (cluster only)
578
btScalar maxvolume; // Maximum volume ratio for pose
579
btScalar timescale; // Time scale
580
int viterations; // Velocities solver iterations
581
int piterations; // Positions solver iterations
582
int diterations; // Drift solver iterations
583
int citerations; // Cluster solver iterations
584
int collisions; // Collisions flags
585
tVSolverArray m_vsequence; // Velocity solvers sequence
586
tPSolverArray m_psequence; // Position solvers sequence
587
tPSolverArray m_dsequence; // Drift solvers sequence
592
btScalar sdt; // dt*timescale
593
btScalar isdt; // 1/sdt
594
btScalar velmrg; // velocity margin
595
btScalar radmrg; // radial margin
596
btScalar updmrg; // Update margin
598
/// RayFromToCaster takes a ray from, ray to (instead of direction!)
599
struct RayFromToCaster : btDbvt::ICollide
603
btVector3 m_rayNormalizedDirection;
607
RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt);
608
void Process(const btDbvtNode* leaf);
610
static inline btScalar rayFromToTriangle(const btVector3& rayFrom,
611
const btVector3& rayTo,
612
const btVector3& rayNormalizedDirection,
616
btScalar maxt=SIMD_INFINITY);
623
typedef void (*psolver_t)(btSoftBody*,btScalar,btScalar);
624
typedef void (*vsolver_t)(btSoftBody*,btScalar);
625
typedef btAlignedObjectArray<Cluster*> tClusterArray;
626
typedef btAlignedObjectArray<Note> tNoteArray;
627
typedef btAlignedObjectArray<Node> tNodeArray;
628
typedef btAlignedObjectArray<btDbvtNode*> tLeafArray;
629
typedef btAlignedObjectArray<Link> tLinkArray;
630
typedef btAlignedObjectArray<Face> tFaceArray;
631
typedef btAlignedObjectArray<Tetra> tTetraArray;
632
typedef btAlignedObjectArray<Anchor> tAnchorArray;
633
typedef btAlignedObjectArray<RContact> tRContactArray;
634
typedef btAlignedObjectArray<SContact> tSContactArray;
635
typedef btAlignedObjectArray<Material*> tMaterialArray;
636
typedef btAlignedObjectArray<Joint*> tJointArray;
637
typedef btAlignedObjectArray<btSoftBody*> tSoftBodyArray;
643
Config m_cfg; // Configuration
644
SolverState m_sst; // Solver state
646
void* m_tag; // User data
647
btSoftBodyWorldInfo* m_worldInfo; // World info
648
tNoteArray m_notes; // Notes
649
tNodeArray m_nodes; // Nodes
650
tLinkArray m_links; // Links
651
tFaceArray m_faces; // Faces
652
tTetraArray m_tetras; // Tetras
653
tAnchorArray m_anchors; // Anchors
654
tRContactArray m_rcontacts; // Rigid contacts
655
tSContactArray m_scontacts; // Soft contacts
656
tJointArray m_joints; // Joints
657
tMaterialArray m_materials; // Materials
658
btScalar m_timeacc; // Time accumulator
659
btVector3 m_bounds[2]; // Spatial bounds
660
bool m_bUpdateRtCst; // Update runtime constants
661
btDbvt m_ndbvt; // Nodes tree
662
btDbvt m_fdbvt; // Faces tree
663
btDbvt m_cdbvt; // Clusters tree
664
tClusterArray m_clusters; // Clusters
666
btAlignedObjectArray<bool>m_clusterConnectivity;//cluster connectivity, for self-collision
668
btTransform m_initialWorldTransform;
670
btVector3 m_windVelocity;
676
btSoftBody( btSoftBodyWorldInfo* worldInfo,int node_count, const btVector3* x, const btScalar* m);
679
btSoftBody( btSoftBodyWorldInfo* worldInfo);
684
virtual ~btSoftBody();
685
/* Check for existing link */
687
btAlignedObjectArray<int> m_userIndexMapping;
689
btSoftBodyWorldInfo* getWorldInfo()
694
///@todo: avoid internal softbody shape hack and move collision code to collision library
695
virtual void setCollisionShape(btCollisionShape* collisionShape)
700
bool checkLink( int node0,
702
bool checkLink( const Node* node0,
703
const Node* node1) const;
704
/* Check for existring face */
705
bool checkFace( int node0,
708
/* Append material */
709
Material* appendMaterial();
711
void appendNote( const char* text,
713
const btVector4& c=btVector4(1,0,0,0),
718
void appendNote( const char* text,
721
void appendNote( const char* text,
724
void appendNote( const char* text,
728
void appendNode( const btVector3& x,btScalar m);
730
void appendLink(int model=-1,Material* mat=0);
731
void appendLink( int node0,
734
bool bcheckexist=false);
735
void appendLink( Node* node0,
738
bool bcheckexist=false);
740
void appendFace(int model=-1,Material* mat=0);
741
void appendFace( int node0,
745
void appendTetra(int model,Material* mat);
747
void appendTetra(int node0,
755
void appendAnchor( int node,
756
btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
757
void appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
758
/* Append linear joint */
759
void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
760
void appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
761
void appendLinearJoint(const LJoint::Specs& specs,btSoftBody* body);
762
/* Append linear joint */
763
void appendAngularJoint(const AJoint::Specs& specs,Cluster* body0,Body body1);
764
void appendAngularJoint(const AJoint::Specs& specs,Body body=Body());
765
void appendAngularJoint(const AJoint::Specs& specs,btSoftBody* body);
766
/* Add force (or gravity) to the entire body */
767
void addForce( const btVector3& force);
768
/* Add force (or gravity) to a node of the body */
769
void addForce( const btVector3& force,
771
/* Add velocity to the entire body */
772
void addVelocity( const btVector3& velocity);
774
/* Set velocity for the entire body */
775
void setVelocity( const btVector3& velocity);
777
/* Add velocity to a node of the body */
778
void addVelocity( const btVector3& velocity,
781
void setMass( int node,
784
btScalar getMass( int node) const;
786
btScalar getTotalMass() const;
787
/* Set total mass (weighted by previous masses) */
788
void setTotalMass( btScalar mass,
789
bool fromfaces=false);
790
/* Set total density */
791
void setTotalDensity(btScalar density);
792
/* Set volume mass (using tetrahedrons) */
793
void setVolumeMass( btScalar mass);
794
/* Set volume density (using tetrahedrons) */
795
void setVolumeDensity( btScalar density);
797
void transform( const btTransform& trs);
799
void translate( const btVector3& trs);
801
void rotate( const btQuaternion& rot);
803
void scale( const btVector3& scl);
804
/* Set current state as pose */
805
void setPose( bool bvolume,
807
/* Return the volume */
808
btScalar getVolume() const;
810
int clusterCount() const;
811
/* Cluster center of mass */
812
static btVector3 clusterCom(const Cluster* cluster);
813
btVector3 clusterCom(int cluster) const;
814
/* Cluster velocity at rpos */
815
static btVector3 clusterVelocity(const Cluster* cluster,const btVector3& rpos);
816
/* Cluster impulse */
817
static void clusterVImpulse(Cluster* cluster,const btVector3& rpos,const btVector3& impulse);
818
static void clusterDImpulse(Cluster* cluster,const btVector3& rpos,const btVector3& impulse);
819
static void clusterImpulse(Cluster* cluster,const btVector3& rpos,const Impulse& impulse);
820
static void clusterVAImpulse(Cluster* cluster,const btVector3& impulse);
821
static void clusterDAImpulse(Cluster* cluster,const btVector3& impulse);
822
static void clusterAImpulse(Cluster* cluster,const Impulse& impulse);
823
static void clusterDCImpulse(Cluster* cluster,const btVector3& impulse);
824
/* Generate bending constraints based on distance in the adjency graph */
825
int generateBendingConstraints( int distance,
827
/* Randomize constraints to reduce solver bias */
828
void randomizeConstraints();
829
/* Release clusters */
830
void releaseCluster(int index);
831
void releaseClusters();
832
/* Generate clusters (K-mean) */
833
///generateClusters with k=0 will create a convex cluster for each tetrahedron or triangle
834
///otherwise an approximation will be used (better performance)
835
int generateClusters(int k,int maxiterations=8192);
837
void refine(ImplicitFn* ifn,btScalar accurary,bool cut);
839
bool cutLink(int node0,int node1,btScalar position);
840
bool cutLink(const Node* node0,const Node* node1,btScalar position);
842
///Ray casting using rayFrom and rayTo in worldspace, (not direction!)
843
bool rayTest(const btVector3& rayFrom,
844
const btVector3& rayTo,
847
void setSolver(eSolverPresets::_ preset);
849
void predictMotion(btScalar dt);
850
/* solveConstraints */
851
void solveConstraints();
853
void staticSolve(int iterations);
854
/* solveCommonConstraints */
855
static void solveCommonConstraints(btSoftBody** bodies,int count,int iterations);
857
static void solveClusters(const btAlignedObjectArray<btSoftBody*>& bodies);
858
/* integrateMotion */
859
void integrateMotion();
860
/* defaultCollisionHandlers */
861
void defaultCollisionHandler(btCollisionObject* pco);
862
void defaultCollisionHandler(btSoftBody* psb);
867
// Functionality to deal with new accelerated solvers.
871
* Set a wind velocity for interaction with the air.
873
void setWindVelocity( const btVector3 &velocity );
877
* Return the wind velocity for interaction with the air.
879
const btVector3& getWindVelocity();
882
// Set the solver that handles this soft body
883
// Should not be allowed to get out of sync with reality
884
// Currently called internally on addition to the world
885
void setSoftBodySolver( btSoftBodySolver *softBodySolver )
887
m_softBodySolver = softBodySolver;
891
// Return the solver that handles this soft body
893
btSoftBodySolver *getSoftBodySolver()
895
return m_softBodySolver;
899
// Return the solver that handles this soft body
901
btSoftBodySolver *getSoftBodySolver() const
903
return m_softBodySolver;
911
static const btSoftBody* upcast(const btCollisionObject* colObj)
913
if (colObj->getInternalType()==CO_SOFT_BODY)
914
return (const btSoftBody*)colObj;
917
static btSoftBody* upcast(btCollisionObject* colObj)
919
if (colObj->getInternalType()==CO_SOFT_BODY)
920
return (btSoftBody*)colObj;
925
// ::btCollisionObject
928
virtual void getAabb(btVector3& aabbMin,btVector3& aabbMax) const
930
aabbMin = m_bounds[0];
931
aabbMax = m_bounds[1];
936
void pointersToIndices();
937
void indicesToPointers(const int* map=0);
939
int rayTest(const btVector3& rayFrom,const btVector3& rayTo,
940
btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const;
941
void initializeFaceTree();
942
btVector3 evaluateCom() const;
943
bool checkContact(btCollisionObject* colObj,const btVector3& x,btScalar margin,btSoftBody::sCti& cti) const;
944
void updateNormals();
947
void updateConstants();
948
void initializeClusters();
949
void updateClusters();
950
void cleanupClusters();
951
void prepareClusters(int iterations);
952
void solveClusters(btScalar sor);
953
void applyClusters(bool drift);
956
static void PSolve_Anchors(btSoftBody* psb,btScalar kst,btScalar ti);
957
static void PSolve_RContacts(btSoftBody* psb,btScalar kst,btScalar ti);
958
static void PSolve_SContacts(btSoftBody* psb,btScalar,btScalar ti);
959
static void PSolve_Links(btSoftBody* psb,btScalar kst,btScalar ti);
960
static void VSolve_Links(btSoftBody* psb,btScalar kst);
961
static psolver_t getSolver(ePSolver::_ solver);
962
static vsolver_t getSolver(eVSolver::_ solver);
965
virtual int calculateSerializeBufferSize() const;
967
///fills the dataBuffer and returns the struct name (and 0 on failure)
968
virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
970
//virtual void serializeSingleObject(class btSerializer* serializer) const;
978
#endif //_BT_SOFT_BODY_H