- Timestamp:
- Dec 13, 2008, 11:45:51 PM (16 years ago)
- Location:
- code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h
r2192 r2430 21 21 #define CONETWISTCONSTRAINT_H 22 22 23 #include " ../../LinearMath/btVector3.h"23 #include "LinearMath/btVector3.h" 24 24 #include "btJacobianEntry.h" 25 25 #include "btTypedConstraint.h" -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.cpp
r2192 r2430 426 426 427 427 return btScalar(0.); 428 } ;429 428 } 429 -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.h
r2192 r2430 17 17 #define CONTACT_CONSTRAINT_H 18 18 19 // todo: make into a proper class working with the iterative constraint solver19 ///@todo: make into a proper class working with the iterative constraint solver 20 20 21 21 class btRigidBody; -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h
r2192 r2430 22 22 SOLVER_FRICTION_SEPARATE = 2, 23 23 SOLVER_USE_WARMSTARTING = 4, 24 SOLVER_CACHE_FRIENDLY = 8 24 SOLVER_USE_FRICTION_WARMSTARTING = 8, 25 SOLVER_CACHE_FRIENDLY = 16 25 26 }; 26 27 … … 45 46 46 47 int m_solverMode; 48 int m_restingContactRestitutionThreshold; 47 49 48 50 … … 69 71 m_linearSlop = btScalar(0.0); 70 72 m_warmstartingFactor=btScalar(0.85); 71 m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING; 73 m_solverMode = SOLVER_CACHE_FRIENDLY | SOLVER_RANDMIZE_ORDER | SOLVER_USE_WARMSTARTING; 74 m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution 72 75 } 73 76 }; -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp
r2192 r2430 27 27 28 28 29 static const btScalar kSign[] = { btScalar(1.0), btScalar(-1.0), btScalar(1.0) };30 static const int kAxisA[] = { 1, 0, 0 };31 static const int kAxisB[] = { 2, 2, 1 };32 29 #define GENERIC_D6_DISABLE_WARMSTARTING 1 33 30 … … 157 154 btScalar clippedMotorImpulse; 158 155 159 // todo: should clip against accumulated impulse156 ///@todo: should clip against accumulated impulse 160 157 if (unclippedMotorImpulse>0.0f) 161 158 { -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp
r2192 r2430 324 324 getRigidBodyB().computeAngularImpulseDenominator(normal); 325 325 // scale for mass and relaxation 326 //todo: expose this 0.9 factor to developer327 326 velrelOrthog *= (btScalar(1.)/denom) * m_relaxationFactor; 328 327 } -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp
r2192 r2430 438 438 439 439 440 voidbtSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation)440 btSolverConstraint& btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation) 441 441 { 442 442 … … 492 492 solverConstraint.m_jacDiagABInv = denom; 493 493 494 494 return solverConstraint; 495 495 } 496 496 … … 719 719 720 720 solverConstraint.m_friction = cp.m_combinedFriction; 721 solverConstraint.m_restitution = restitutionCurve(rel_vel, cp.m_combinedRestitution); 722 if (solverConstraint.m_restitution <= btScalar(0.)) 721 722 723 if (cp.m_lifeTime>infoGlobal.m_restingContactRestitutionThreshold) 723 724 { 724 725 solverConstraint.m_restitution = 0.f; 725 }; 726 } else 727 { 728 solverConstraint.m_restitution = restitutionCurve(rel_vel, cp.m_combinedRestitution); 729 if (solverConstraint.m_restitution <= btScalar(0.)) 730 { 731 solverConstraint.m_restitution = 0.f; 732 }; 733 } 726 734 727 735 … … 761 769 cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel); 762 770 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 763 cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB); 764 cp.m_lateralFrictionDir2.normalize();//?? 765 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 771 if(infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) 772 { 773 cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB); 774 cp.m_lateralFrictionDir2.normalize();//?? 775 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 776 cp.m_lateralFrictionInitialized = true; 777 } 766 778 } else 767 779 { 768 780 //re-calculate friction direction every frame, todo: check if this is really needed 769 770 781 btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2); 771 782 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 772 783 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 784 if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) 785 { 786 cp.m_lateralFrictionInitialized = true; 787 } 773 788 } 774 cp.m_lateralFrictionInitialized = true;775 789 776 790 } else 777 791 { 778 792 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 779 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 793 if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) 794 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 780 795 } 781 796 797 if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) 782 798 { 783 btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex];784 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)785 799 { 786 frictionConstraint1.m_appliedImpulse = cp.m_appliedImpulseLateral1 * infoGlobal.m_warmstartingFactor; 787 if (rb0) 788 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb0->getInvMass(),frictionConstraint1.m_angularComponentA,frictionConstraint1.m_appliedImpulse); 789 if (rb1) 790 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb1->getInvMass(),frictionConstraint1.m_angularComponentB,-frictionConstraint1.m_appliedImpulse); 791 } else 800 btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex]; 801 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING) 802 { 803 frictionConstraint1.m_appliedImpulse = cp.m_appliedImpulseLateral1 * infoGlobal.m_warmstartingFactor; 804 if (rb0) 805 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb0->getInvMass(),frictionConstraint1.m_angularComponentA,frictionConstraint1.m_appliedImpulse); 806 if (rb1) 807 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint1.m_contactNormal*rb1->getInvMass(),frictionConstraint1.m_angularComponentB,-frictionConstraint1.m_appliedImpulse); 808 } else 809 { 810 frictionConstraint1.m_appliedImpulse = 0.f; 811 } 812 } 792 813 { 793 frictionConstraint1.m_appliedImpulse = 0.f; 794 } 795 } 796 { 797 btSolverConstraint& frictionConstraint2 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex+1]; 798 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING) 799 { 800 frictionConstraint2.m_appliedImpulse = cp.m_appliedImpulseLateral2 * infoGlobal.m_warmstartingFactor; 801 if (rb0) 802 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb0->getInvMass(),frictionConstraint2.m_angularComponentA,frictionConstraint2.m_appliedImpulse); 803 if (rb1) 804 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb1->getInvMass(),frictionConstraint2.m_angularComponentB,-frictionConstraint2.m_appliedImpulse); 805 } else 806 { 807 frictionConstraint2.m_appliedImpulse = 0.f; 814 btSolverConstraint& frictionConstraint2 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex+1]; 815 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING) 816 { 817 frictionConstraint2.m_appliedImpulse = cp.m_appliedImpulseLateral2 * infoGlobal.m_warmstartingFactor; 818 if (rb0) 819 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb0->getInvMass(),frictionConstraint2.m_angularComponentA,frictionConstraint2.m_appliedImpulse); 820 if (rb1) 821 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].internalApplyImpulse(frictionConstraint2.m_contactNormal*rb1->getInvMass(),frictionConstraint2.m_angularComponentB,-frictionConstraint2.m_appliedImpulse); 822 } else 823 { 824 frictionConstraint2.m_appliedImpulse = 0.f; 825 } 808 826 } 809 827 } … … 833 851 int numFrictionPool = m_tmpSolverFrictionConstraintPool.size(); 834 852 835 /// todo: use stack allocator for such temporarily memory, same for solver bodies/constraints853 ///@todo: use stack allocator for such temporarily memory, same for solver bodies/constraints 836 854 m_orderTmpConstraintPool.resize(numConstraintPool); 837 855 m_orderFrictionConstraintPool.resize(numFrictionPool); … … 985 1003 btAssert(pt); 986 1004 pt->m_appliedImpulse = solveManifold.m_appliedImpulse; 987 pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; 988 pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex+1].m_appliedImpulse; 1005 if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) 1006 { 1007 pt->m_appliedImpulseLateral1 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; 1008 pt->m_appliedImpulseLateral2 = m_tmpSolverFrictionConstraintPool[solveManifold.m_frictionIndex+1].m_appliedImpulse; 1009 } 989 1010 990 1011 //do a callback here? … … 1221 1242 cpd->m_penetration = cp.getDistance();///btScalar(info.m_numIterations); 1222 1243 cpd->m_friction = cp.m_combinedFriction; 1223 cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution); 1224 if (cpd->m_restitution <= btScalar(0.)) 1225 { 1226 cpd->m_restitution = btScalar(0.0); 1227 1228 }; 1244 if (cp.m_lifeTime>info.m_restingContactRestitutionThreshold) 1245 { 1246 cpd->m_restitution = 0.f; 1247 } else 1248 { 1249 cpd->m_restitution = restitutionCurve(rel_vel, combinedRestitution); 1250 if (cpd->m_restitution <= btScalar(0.)) 1251 { 1252 cpd->m_restitution = btScalar(0.0); 1253 }; 1254 } 1229 1255 1230 1256 //restitution and penetration work in same direction so -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h
r2192 r2430 24 24 25 25 26 /// btSequentialImpulseConstraintSolver uses a Propagation Method and Sequentially applies impulses27 /// 28 /// 29 /// 26 ///The btSequentialImpulseConstraintSolver uses a Propagation Method and Sequentially applies impulses 27 ///The approach is the 3D version of Erin Catto's GDC 2006 tutorial. See http://www.gphysics.com 28 ///Although Sequential Impulse is more intuitive, it is mathematically equivalent to Projected Successive Overrelaxation (iterative LCP) 29 ///Applies impulses for combined restitution and penetration recovery and to simulate friction 30 30 class btSequentialImpulseConstraintSolver : public btConstraintSolver 31 31 { … … 42 42 btScalar solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer); 43 43 void prepareConstraints(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,btIDebugDraw* debugDrawer); 44 voidaddFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation);44 btSolverConstraint& addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation); 45 45 46 46 ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES]; -
code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h
r2192 r2430 25 25 26 26 27 /// btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance.27 ///The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance. 28 28 ATTRIBUTE_ALIGNED16 (struct) btSolverBody 29 29 { 30 30 BT_DECLARE_ALIGNED_ALLOCATOR(); 31 31 32 btMatrix3x3 m_worldInvInertiaTensor; 33 32 34 btVector3 m_angularVelocity; 35 btVector3 m_linearVelocity; 36 btVector3 m_centerOfMassPosition; 37 btVector3 m_pushVelocity; 38 btVector3 m_turnVelocity; 39 33 40 float m_angularFactor; 34 41 float m_invMass; 35 42 float m_friction; 36 43 btRigidBody* m_originalBody; 37 btVector3 m_linearVelocity;38 btVector3 m_centerOfMassPosition;39 40 btVector3 m_pushVelocity;41 btVector3 m_turnVelocity;42 44 43 45
Note: See TracChangeset
for help on using the changeset viewer.