Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2008, 11:45:51 PM (15 years ago)
Author:
rgrieder
Message:

Updated to Bullet 2.73 (first part).

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  
    2121#define CONETWISTCONSTRAINT_H
    2222
    23 #include "../../LinearMath/btVector3.h"
     23#include "LinearMath/btVector3.h"
    2424#include "btJacobianEntry.h"
    2525#include "btTypedConstraint.h"
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.cpp

    r2192 r2430  
    426426
    427427        return btScalar(0.);
    428 };
    429 
     428}
     429
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.h

    r2192 r2430  
    1717#define CONTACT_CONSTRAINT_H
    1818
    19 //todo: make into a proper class working with the iterative constraint solver
     19///@todo: make into a proper class working with the iterative constraint solver
    2020
    2121class btRigidBody;
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h

    r2192 r2430  
    2222        SOLVER_FRICTION_SEPARATE = 2,
    2323        SOLVER_USE_WARMSTARTING = 4,
    24         SOLVER_CACHE_FRIENDLY = 8
     24        SOLVER_USE_FRICTION_WARMSTARTING = 8,
     25        SOLVER_CACHE_FRIENDLY = 16
    2526};
    2627
     
    4546
    4647        int                     m_solverMode;
     48        int     m_restingContactRestitutionThreshold;
    4749
    4850
     
    6971                m_linearSlop = btScalar(0.0);
    7072                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
    7275        }
    7376};
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp

    r2192 r2430  
    2727
    2828
    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 };
    3229#define GENERIC_D6_DISABLE_WARMSTARTING 1
    3330
     
    157154    btScalar clippedMotorImpulse;
    158155
    159     //todo: should clip against accumulated impulse
     156    ///@todo: should clip against accumulated impulse
    160157    if (unclippedMotorImpulse>0.0f)
    161158    {
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp

    r2192 r2430  
    324324                                        getRigidBodyB().computeAngularImpulseDenominator(normal);
    325325                                // scale for mass and relaxation
    326                                 //todo:  expose this 0.9 factor to developer
    327326                                velrelOrthog *= (btScalar(1.)/denom) * m_relaxationFactor;
    328327                        }
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp

    r2192 r2430  
    438438
    439439
    440 void    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)
     440btSolverConstraint&     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)
    441441{
    442442
     
    492492        solverConstraint.m_jacDiagABInv = denom;
    493493
    494 
     494        return solverConstraint;
    495495}
    496496
     
    719719
    720720                                                        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)
    723724                                                        {
    724725                                                                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                                                        }
    726734
    727735                                                       
     
    761769                                                                        cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel);
    762770                                                                        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                                                                        }
    766778                                                                } else
    767779                                                                {
    768780                                                                        //re-calculate friction direction every frame, todo: check if this is really needed
    769                                                                        
    770781                                                                        btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2);
    771782                                                                        addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation);
    772783                                                                        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                                                                        }
    773788                                                                }
    774                                                                 cp.m_lateralFrictionInitialized = true;
    775789                                                               
    776790                                                        } else
    777791                                                        {
    778792                                                                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);
    780795                                                        }
    781796
     797                                                        if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING)
    782798                                                        {
    783                                                                 btSolverConstraint& frictionConstraint1 = m_tmpSolverFrictionConstraintPool[solverConstraint.m_frictionIndex];
    784                                                                 if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
    785799                                                                {
    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                                                                }
    792813                                                                {
    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                                                                        }
    808826                                                                }
    809827                                                        }
     
    833851        int numFrictionPool = m_tmpSolverFrictionConstraintPool.size();
    834852
    835         ///todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
     853        ///@todo: use stack allocator for such temporarily memory, same for solver bodies/constraints
    836854        m_orderTmpConstraintPool.resize(numConstraintPool);
    837855        m_orderFrictionConstraintPool.resize(numFrictionPool);
     
    9851003                btAssert(pt);
    9861004                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                }
    9891010
    9901011                //do a callback here?
     
    12211242                                cpd->m_penetration = cp.getDistance();///btScalar(info.m_numIterations);
    12221243                                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                                }
    12291255                               
    12301256                                //restitution and penetration work in same direction so
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h

    r2192 r2430  
    2424
    2525
    26 /// 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
     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
    3030class btSequentialImpulseConstraintSolver : public btConstraintSolver
    3131{
     
    4242        btScalar solveFriction(btRigidBody* body0,btRigidBody* body1, btManifoldPoint& cp, const btContactSolverInfo& info,int iter,btIDebugDraw* debugDrawer);
    4343        void  prepareConstraints(btPersistentManifold* manifoldPtr, const btContactSolverInfo& info,btIDebugDraw* debugDrawer);
    44         void    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);
     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);
    4545
    4646        ContactSolverFunc m_contactDispatch[MAX_CONTACT_SOLVER_TYPES][MAX_CONTACT_SOLVER_TYPES];
  • code/branches/physics/src/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h

    r2192 r2430  
    2525
    2626
    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.
    2828ATTRIBUTE_ALIGNED16 (struct)    btSolverBody
    2929{
    3030        BT_DECLARE_ALIGNED_ALLOCATOR();
    3131       
     32        btMatrix3x3             m_worldInvInertiaTensor;
     33
    3234        btVector3               m_angularVelocity;
     35        btVector3               m_linearVelocity;
     36        btVector3               m_centerOfMassPosition;
     37        btVector3               m_pushVelocity;
     38        btVector3               m_turnVelocity;
     39
    3340        float                   m_angularFactor;
    3441        float                   m_invMass;
    3542        float                   m_friction;
    3643        btRigidBody*    m_originalBody;
    37         btVector3               m_linearVelocity;
    38         btVector3               m_centerOfMassPosition;
    39        
    40         btVector3               m_pushVelocity;
    41         btVector3               m_turnVelocity;
    4244       
    4345       
Note: See TracChangeset for help on using the changeset viewer.