- Timestamp:
- Oct 20, 2008, 5:40:38 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletSoftBody/btSoftBody.h
r1963 r1972 63 63 END 64 64 };}; 65 65 66 66 ///eVSolver : velocities solvers 67 67 struct eVSolver { enum _ { … … 69 69 END 70 70 };}; 71 71 72 72 ///ePSolver : positions solvers 73 73 struct ePSolver { enum _ { … … 78 78 END 79 79 };}; 80 80 81 81 ///eSolverPresets 82 82 struct eSolverPresets { enum _ { … … 86 86 END 87 87 };}; 88 88 89 89 ///eFeature 90 90 struct eFeature { enum _ { … … 95 95 END 96 96 };}; 97 97 98 98 typedef btAlignedObjectArray<eVSolver::_> tVSolverArray; 99 99 typedef btAlignedObjectArray<ePSolver::_> tPSolverArray; 100 100 101 101 // 102 102 // Flags 103 103 // 104 104 105 105 ///fCollision 106 106 struct fCollision { enum _ { … … 108 108 SDF_RS = 0x0001, ///SDF based rigid vs soft 109 109 CL_RS = 0x0002, ///Cluster vs convex rigid vs soft 110 110 111 111 SVSmask = 0x00f0, ///Rigid versus soft mask 112 112 VF_SS = 0x0010, ///Vertex vs face soft vs soft handling … … 116 116 END 117 117 };}; 118 118 119 119 ///fMaterial 120 120 struct fMaterial { enum _ { … … 124 124 END 125 125 };}; 126 126 127 127 // 128 128 // API Types 129 129 // 130 130 131 131 /* sRayCast */ 132 132 struct sRayCast … … 135 135 eFeature::_ feature; /// feature type 136 136 int index; /// feature index 137 btScalar fraction; /// time of impact fraction (rayorg+(rayto-rayfrom)*fraction)138 }; 139 137 btScalar time; /// time of impact (rayorg+raydir*time) 138 }; 139 140 140 /* ImplicitFn */ 141 141 struct ImplicitFn … … 143 143 virtual btScalar Eval(const btVector3& x)=0; 144 144 }; 145 145 146 146 // 147 147 // Internal types … … 181 181 int m_flags; // Flags 182 182 }; 183 183 184 184 /* Feature */ 185 185 struct Feature : Element … … 297 297 btScalar m_matching; 298 298 bool m_collide; 299 Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {}299 Cluster() : m_leaf(0),m_ndamping(0),m_ldamping(0),m_adamping(0),m_matching(0) {} 300 300 }; 301 301 /* Impulse */ … … 308 308 Impulse() : m_velocity(0,0,0),m_drift(0,0,0),m_asVelocity(0),m_asDrift(0) {} 309 309 Impulse operator -() const 310 {310 { 311 311 Impulse i=*this; 312 312 i.m_velocity=-i.m_velocity; 313 313 i.m_drift=-i.m_drift; 314 314 return(i); 315 }315 } 316 316 Impulse operator*(btScalar x) const 317 {317 { 318 318 Impulse i=*this; 319 319 i.m_velocity*=x; 320 320 i.m_drift*=x; 321 321 return(i); 322 }322 } 323 323 }; 324 324 /* Body */ … … 327 327 Cluster* m_soft; 328 328 btRigidBody* m_rigid; 329 Body() : m_soft(0),m_rigid(0) {}330 Body(Cluster* p) : m_soft(p),m_rigid(0) {}331 Body(btRigidBody* p) : m_soft(0),m_rigid(p) {}329 Body() : m_soft(0),m_rigid(0) {} 330 Body(Cluster* p) : m_soft(p),m_rigid(0) {} 331 Body(btRigidBody* p) : m_soft(0),m_rigid(p) {} 332 332 void activate() const 333 {333 { 334 334 if(m_rigid) m_rigid->activate(); 335 }335 } 336 336 const btMatrix3x3& invWorldInertia() const 337 {337 { 338 338 static const btMatrix3x3 iwi(0,0,0,0,0,0,0,0,0); 339 339 if(m_rigid) return(m_rigid->getInvInertiaTensorWorld()); 340 340 if(m_soft) return(m_soft->m_invwi); 341 341 return(iwi); 342 }342 } 343 343 btScalar invMass() const 344 {344 { 345 345 if(m_rigid) return(m_rigid->getInvMass()); 346 346 if(m_soft) return(m_soft->m_imass); 347 347 return(0); 348 }348 } 349 349 const btTransform& xform() const 350 {350 { 351 351 static const btTransform identity=btTransform::getIdentity(); 352 352 if(m_rigid) return(m_rigid->getInterpolationWorldTransform()); 353 353 if(m_soft) return(m_soft->m_framexform); 354 354 return(identity); 355 }355 } 356 356 btVector3 linearVelocity() const 357 {357 { 358 358 if(m_rigid) return(m_rigid->getLinearVelocity()); 359 359 if(m_soft) return(m_soft->m_lv); 360 360 return(btVector3(0,0,0)); 361 }361 } 362 362 btVector3 angularVelocity(const btVector3& rpos) const 363 {363 { 364 364 if(m_rigid) return(cross(m_rigid->getAngularVelocity(),rpos)); 365 365 if(m_soft) return(cross(m_soft->m_av,rpos)); 366 366 return(btVector3(0,0,0)); 367 }367 } 368 368 btVector3 angularVelocity() const 369 {369 { 370 370 if(m_rigid) return(m_rigid->getAngularVelocity()); 371 371 if(m_soft) return(m_soft->m_av); 372 372 return(btVector3(0,0,0)); 373 }373 } 374 374 btVector3 velocity(const btVector3& rpos) const 375 {375 { 376 376 return(linearVelocity()+angularVelocity(rpos)); 377 }377 } 378 378 void applyVImpulse(const btVector3& impulse,const btVector3& rpos) const 379 {379 { 380 380 if(m_rigid) m_rigid->applyImpulse(impulse,rpos); 381 381 if(m_soft) btSoftBody::clusterVImpulse(m_soft,rpos,impulse); 382 }382 } 383 383 void applyDImpulse(const btVector3& impulse,const btVector3& rpos) const 384 {384 { 385 385 if(m_rigid) m_rigid->applyImpulse(impulse,rpos); 386 386 if(m_soft) btSoftBody::clusterDImpulse(m_soft,rpos,impulse); 387 }387 } 388 388 void applyImpulse(const Impulse& impulse,const btVector3& rpos) const 389 {389 { 390 390 if(impulse.m_asVelocity) applyVImpulse(impulse.m_velocity,rpos); 391 391 if(impulse.m_asDrift) applyDImpulse(impulse.m_drift,rpos); 392 }392 } 393 393 void applyVAImpulse(const btVector3& impulse) const 394 {394 { 395 395 if(m_rigid) m_rigid->applyTorqueImpulse(impulse); 396 396 if(m_soft) btSoftBody::clusterVAImpulse(m_soft,impulse); 397 }397 } 398 398 void applyDAImpulse(const btVector3& impulse) const 399 {399 { 400 400 if(m_rigid) m_rigid->applyTorqueImpulse(impulse); 401 401 if(m_soft) btSoftBody::clusterDAImpulse(m_soft,impulse); 402 }402 } 403 403 void applyAImpulse(const Impulse& impulse) const 404 {404 { 405 405 if(impulse.m_asVelocity) applyVAImpulse(impulse.m_velocity); 406 406 if(impulse.m_asDrift) applyDAImpulse(impulse.m_drift); 407 }407 } 408 408 void applyDCImpulse(const btVector3& impulse) const 409 {409 { 410 410 if(m_rigid) m_rigid->applyCentralImpulse(impulse); 411 411 if(m_soft) btSoftBody::clusterDCImpulse(m_soft,impulse); 412 }412 } 413 413 }; 414 414 /* Joint */ … … 421 421 };}; 422 422 struct Specs 423 {424 Specs() : erp(1),cfm(1),split(1) {}423 { 424 Specs() : erp(1),cfm(1),split(1) {} 425 425 btScalar erp; 426 426 btScalar cfm; 427 427 btScalar split; 428 };428 }; 429 429 Body m_bodies[2]; 430 430 btVector3 m_refs[2]; … … 437 437 bool m_delete; 438 438 virtual ~Joint() {} 439 Joint() : m_delete(false) {}439 Joint() : m_delete(false) {} 440 440 virtual void Prepare(btScalar dt,int iterations); 441 441 virtual void Solve(btScalar dt,btScalar sor)=0; … … 447 447 { 448 448 struct Specs : Joint::Specs 449 {449 { 450 450 btVector3 position; 451 };451 }; 452 452 btVector3 m_rpos[2]; 453 453 void Prepare(btScalar dt,int iterations); … … 460 460 { 461 461 struct IControl 462 {462 { 463 463 virtual void Prepare(AJoint*) {} 464 464 virtual btScalar Speed(AJoint*,btScalar current) { return(current); } 465 465 static IControl* Default() { static IControl def;return(&def); } 466 };466 }; 467 467 struct Specs : Joint::Specs 468 {469 Specs() : icontrol(IControl::Default()) {}468 { 469 Specs() : icontrol(IControl::Default()) {} 470 470 btVector3 axis; 471 471 IControl* icontrol; 472 };472 }; 473 473 btVector3 m_axis[2]; 474 474 IControl* m_icontrol; … … 533 533 btScalar updmrg; // Update margin 534 534 }; 535 /// RayFromToCaster takes a ray from, ray to (instead of direction!) 536 struct RayFromToCaster : btDbvt::ICollide 537 { 538 btVector3 m_rayFrom; 539 btVector3 m_rayTo; 540 btVector3 m_rayNormalizedDirection; 541 btScalar m_mint; 542 Face* m_face; 543 int m_tests; 544 RayFromToCaster(const btVector3& rayFrom,const btVector3& rayTo,btScalar mxt); 535 /* RayCaster */ 536 struct RayCaster : btDbvt::ICollide 537 { 538 btVector3 o; 539 btVector3 d; 540 btScalar mint; 541 Face* face; 542 int tests; 543 RayCaster(const btVector3& org,const btVector3& dir,btScalar mxt); 545 544 void Process(const btDbvtNode* leaf); 546 547 static inline btScalar rayFromToTriangle(const btVector3& rayFrom, 548 const btVector3& rayTo, 549 const btVector3& rayNormalizedDirection, 550 const btVector3& a, 551 const btVector3& b, 552 const btVector3& c, 553 btScalar maxt=SIMD_INFINITY); 554 }; 545 static inline btScalar rayTriangle(const btVector3& org, 546 const btVector3& dir, 547 const btVector3& a, 548 const btVector3& b, 549 const btVector3& c, 550 btScalar maxt=SIMD_INFINITY); 551 }; 555 552 556 553 // … … 598 595 btDbvt m_cdbvt; // Clusters tree 599 596 tClusterArray m_clusters; // Clusters 600 597 601 598 // 602 599 // Api 603 600 // 604 601 605 602 /* ctor */ 606 603 btSoftBody( btSoftBodyWorldInfo* worldInfo,int node_count, 607 const btVector3* x,608 const btScalar* m);604 const btVector3* x, 605 const btScalar* m); 609 606 /* dtor */ 610 607 virtual ~btSoftBody(); … … 626 623 int node1) const; 627 624 bool checkLink( const Node* node0, 628 const Node* node1) const;625 const Node* node1) const; 629 626 /* Check for existring face */ 630 627 bool checkFace( int node0, 631 int node1,632 int node2) const;628 int node1, 629 int node2) const; 633 630 /* Append material */ 634 631 Material* appendMaterial(); 635 632 /* Append note */ 636 633 void appendNote( const char* text, 637 const btVector3& o,638 const btVector4& c=btVector4(1,0,0,0),639 Node* n0=0,640 Node* n1=0,641 Node* n2=0,642 Node* n3=0);634 const btVector3& o, 635 const btVector4& c=btVector4(1,0,0,0), 636 Node* n0=0, 637 Node* n1=0, 638 Node* n2=0, 639 Node* n3=0); 643 640 void appendNote( const char* text, 644 const btVector3& o,645 Node* feature);641 const btVector3& o, 642 Node* feature); 646 643 void appendNote( const char* text, 647 const btVector3& o,648 Link* feature);644 const btVector3& o, 645 Link* feature); 649 646 void appendNote( const char* text, 650 const btVector3& o,651 Face* feature);647 const btVector3& o, 648 Face* feature); 652 649 /* Append node */ 653 650 void appendNode( const btVector3& x,btScalar m); … … 655 652 void appendLink(int model=-1,Material* mat=0); 656 653 void appendLink( int node0, 657 int node1,658 Material* mat=0,659 bool bcheckexist=false);654 int node1, 655 Material* mat=0, 656 bool bcheckexist=false); 660 657 void appendLink( Node* node0, 661 Node* node1,662 Material* mat=0,663 bool bcheckexist=false);658 Node* node1, 659 Material* mat=0, 660 bool bcheckexist=false); 664 661 /* Append face */ 665 662 void appendFace(int model=-1,Material* mat=0); 666 663 void appendFace( int node0, 667 int node1,668 int node2,669 Material* mat=0);664 int node1, 665 int node2, 666 Material* mat=0); 670 667 /* Append anchor */ 671 668 void appendAnchor( int node, 672 btRigidBody* body);669 btRigidBody* body); 673 670 /* Append linear joint */ 674 671 void appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1); … … 683 680 /* Add force (or gravity) to a node of the body */ 684 681 void addForce( const btVector3& force, 685 int node);682 int node); 686 683 /* Add velocity to the entire body */ 687 684 void addVelocity( const btVector3& velocity); … … 692 689 /* Add velocity to a node of the body */ 693 690 void addVelocity( const btVector3& velocity, 694 int node);691 int node); 695 692 /* Set mass */ 696 693 void setMass( int node, 697 btScalar mass);694 btScalar mass); 698 695 /* Get mass */ 699 696 btScalar getMass( int node) const; … … 702 699 /* Set total mass (weighted by previous masses) */ 703 700 void setTotalMass( btScalar mass, 704 bool fromfaces=false);701 bool fromfaces=false); 705 702 /* Set total density */ 706 703 void setTotalDensity(btScalar density); … … 715 712 /* Set current state as pose */ 716 713 void setPose( bool bvolume, 717 bool bframe);714 bool bframe); 718 715 /* Return the volume */ 719 716 btScalar getVolume() const; … … 735 732 /* Generate bending constraints based on distance in the adjency graph */ 736 733 int generateBendingConstraints( int distance, 737 Material* mat=0);734 Material* mat=0); 738 735 /* Randomize constraints to reduce solver bias */ 739 736 void randomizeConstraints(); … … 748 745 bool cutLink(int node0,int node1,btScalar position); 749 746 bool cutLink(const Node* node0,const Node* node1,btScalar position); 750 751 ///Ray casting using rayFrom and rayTo in worldspace, (not direction!)752 bool rayTest(const btVector3& rayFrom,753 const btVector3& rayTo,754 sRayCast& results);747 /* Ray casting */ 748 bool rayCast(const btVector3& org, 749 const btVector3& dir, 750 sRayCast& results, 751 btScalar maxtime=SIMD_INFINITY); 755 752 /* Solver presets */ 756 753 void setSolver(eSolverPresets::_ preset); … … 770 767 void defaultCollisionHandler(btCollisionObject* pco); 771 768 void defaultCollisionHandler(btSoftBody* psb); 772 769 773 770 // 774 771 // Cast 775 772 // 776 773 777 774 static const btSoftBody* upcast(const btCollisionObject* colObj) 778 775 { … … 802 799 void pointersToIndices(); 803 800 void indicesToPointers(const int* map=0); 804 805 int rayTest(const btVector3& rayFrom,const btVector3& rayTo, 806 btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const; 801 int rayCast(const btVector3& org,const btVector3& dir, 802 btScalar& mint,eFeature::_& feature,int& index,bool bcountonly) const; 807 803 void initializeFaceTree(); 808 804 btVector3 evaluateCom() const; … … 827 823 static psolver_t getSolver(ePSolver::_ solver); 828 824 static vsolver_t getSolver(eVSolver::_ solver); 829 825 830 826 }; 831 827
Note: See TracChangeset
for help on using the changeset viewer.