Back to index

supertuxkart  0.5+dfsg1
Classes | Defines | Functions | Variables
btSequentialImpulseConstraintSolver.cpp File Reference
#include "btSequentialImpulseConstraintSolver.h"
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
#include "btContactConstraint.h"
#include "btSolve2LinearConstraint.h"
#include "btContactSolverInfo.h"
#include "LinearMath/btIDebugDraw.h"
#include "btJacobianEntry.h"
#include "LinearMath/btMinMax.h"
#include "BulletDynamics/ConstraintSolver/btTypedConstraint.h"
#include <new>
#include "LinearMath/btStackAlloc.h"
#include "LinearMath/btQuickprof.h"
#include "btSolverBody.h"
#include "btSolverConstraint.h"
#include "LinearMath/btAlignedObjectArray.h"

Go to the source code of this file.

Classes

struct  btOrderIndex

Defines

#define SEQUENTIAL_IMPULSE_MAX_SOLVER_POINTS   16384
#define CLAMP_ACCUMULATED_FRICTION_IMPULSE   1
#define NO_FRICTION_WARMSTART   1

Functions

bool MyContactDestroyedCallback (void *userPersistentData)
void initSolverBody (btSolverBody *solverBody, btCollisionObject *collisionObject)
btScalar restitutionCurve (btScalar rel_vel, btScalar restitution)
btScalar resolveSingleCollisionCombinedCacheFriendly (btSolverBody &body1, btSolverBody &body2, const btSolverConstraint &contactConstraint, const btContactSolverInfo &solverInfo)
btScalar resolveSingleFrictionCacheFriendly (btSolverBody &body1, btSolverBody &body2, const btSolverConstraint &contactConstraint, const btContactSolverInfo &solverInfo, btScalar appliedNormalImpulse)

Variables

int totalCpd = 0
int gTotalContactPoints = 0
static btOrderIndex gOrder [SEQUENTIAL_IMPULSE_MAX_SOLVER_POINTS]
btScalar penetrationResolveFactor = btScalar(0.9)

Class Documentation

struct btOrderIndex

Definition at line 44 of file btSequentialImpulseConstraintSolver.cpp.

Class Members
int m_manifoldIndex
int m_pointIndex

Define Documentation

#define NO_FRICTION_WARMSTART   1

Definition at line 52 of file btSequentialImpulseConstraintSolver.cpp.


Function Documentation

void initSolverBody ( btSolverBody *  solverBody,
btCollisionObject *  collisionObject 
)

Definition at line 130 of file btSequentialImpulseConstraintSolver.cpp.

{
       btRigidBody* rb = btRigidBody::upcast(collisionObject);
       if (rb)
       {
              solverBody->m_angularVelocity = rb->getAngularVelocity() ;
              solverBody->m_centerOfMassPosition = collisionObject->getWorldTransform().getOrigin();
              solverBody->m_friction = collisionObject->getFriction();
              solverBody->m_invMass = rb->getInvMass();
              solverBody->m_linearVelocity = rb->getLinearVelocity();
              solverBody->m_originalBody = rb;
              solverBody->m_angularFactor = rb->getAngularFactor();
       } else
       {
              solverBody->m_angularVelocity.setValue(0,0,0);
              solverBody->m_centerOfMassPosition = collisionObject->getWorldTransform().getOrigin();
              solverBody->m_friction = collisionObject->getFriction();
              solverBody->m_invMass = 0.f;
              solverBody->m_linearVelocity.setValue(0,0,0);
              solverBody->m_originalBody = 0;
              solverBody->m_angularFactor = 1.f;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool MyContactDestroyedCallback ( void *  userPersistentData)

Definition at line 96 of file btSequentialImpulseConstraintSolver.cpp.

{
       assert (userPersistentData);
       btConstraintPersistentData* cpd = (btConstraintPersistentData*)userPersistentData;
       btAlignedFree(cpd);
       totalCpd--;
       //printf("totalCpd = %i. DELETED Ptr %x\n",totalCpd,userPersistentData);
       return true;
}

Here is the caller graph for this function:

btScalar resolveSingleCollisionCombinedCacheFriendly ( btSolverBody &  body1,
btSolverBody &  body2,
const btSolverConstraint &  contactConstraint,
const btContactSolverInfo solverInfo 
)

Definition at line 169 of file btSequentialImpulseConstraintSolver.cpp.

{
       (void)solverInfo;

       btScalar normalImpulse;
       
       //  Optimized version of projected relative velocity, use precomputed cross products with normal
       //     body1.getVelocityInLocalPoint(contactConstraint.m_rel_posA,vel1);
       //     body2.getVelocityInLocalPoint(contactConstraint.m_rel_posB,vel2);
       //     btVector3 vel = vel1 - vel2;
       //     btScalar  rel_vel = contactConstraint.m_contactNormal.dot(vel);

       btScalar rel_vel;
       btScalar vel1Dotn = contactConstraint.m_contactNormal.dot(body1.m_linearVelocity) 
                            + contactConstraint.m_relpos1CrossNormal.dot(body1.m_angularVelocity);
       btScalar vel2Dotn = contactConstraint.m_contactNormal.dot(body2.m_linearVelocity) 
                            + contactConstraint.m_relpos2CrossNormal.dot(body2.m_angularVelocity);

       rel_vel = vel1Dotn-vel2Dotn;


       btScalar positionalError = contactConstraint.m_penetration;
       btScalar velocityError = contactConstraint.m_restitution - rel_vel;// * damping;

       btScalar penetrationImpulse = positionalError * contactConstraint.m_jacDiagABInv;
       btScalar      velocityImpulse = velocityError * contactConstraint.m_jacDiagABInv;
       normalImpulse = penetrationImpulse+velocityImpulse;
       
       // See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse
       btScalar oldNormalImpulse = contactConstraint.m_appliedImpulse;
       btScalar sum = oldNormalImpulse + normalImpulse;
       contactConstraint.m_appliedImpulse = btScalar(0.) > sum ? btScalar(0.): sum;

       btScalar oldVelocityImpulse = contactConstraint.m_appliedVelocityImpulse;
       btScalar velocitySum = oldVelocityImpulse + velocityImpulse;
       contactConstraint.m_appliedVelocityImpulse = btScalar(0.) > velocitySum ? btScalar(0.): velocitySum;

       normalImpulse = contactConstraint.m_appliedImpulse - oldNormalImpulse;

       if (body1.m_invMass)
       {
              body1.internalApplyImpulse(contactConstraint.m_contactNormal*body1.m_invMass,
                     contactConstraint.m_angularComponentA,normalImpulse);
       }
       if (body2.m_invMass)
       {
              body2.internalApplyImpulse(contactConstraint.m_contactNormal*body2.m_invMass,
                     contactConstraint.m_angularComponentB,-normalImpulse);
       }



       

       return normalImpulse;
}

Here is the caller graph for this function:

btScalar resolveSingleFrictionCacheFriendly ( btSolverBody &  body1,
btSolverBody &  body2,
const btSolverConstraint &  contactConstraint,
const btContactSolverInfo solverInfo,
btScalar  appliedNormalImpulse 
)

Definition at line 234 of file btSequentialImpulseConstraintSolver.cpp.

{
       (void)solverInfo;

       
       const btScalar combinedFriction = contactConstraint.m_friction;
       
       const btScalar limit = appliedNormalImpulse * combinedFriction;
       
       if (appliedNormalImpulse>btScalar(0.))
       //friction
       {
              
              btScalar j1;
              {

                     btScalar rel_vel;
                     const btScalar vel1Dotn = contactConstraint.m_contactNormal.dot(body1.m_linearVelocity) 
                                          + contactConstraint.m_relpos1CrossNormal.dot(body1.m_angularVelocity);
                     const btScalar vel2Dotn = contactConstraint.m_contactNormal.dot(body2.m_linearVelocity) 
                            + contactConstraint.m_relpos2CrossNormal.dot(body2.m_angularVelocity);
                     rel_vel = vel1Dotn-vel2Dotn;

                     // calculate j that moves us to zero relative velocity
                     j1 = -rel_vel * contactConstraint.m_jacDiagABInv;
#define CLAMP_ACCUMULATED_FRICTION_IMPULSE 1
#ifdef CLAMP_ACCUMULATED_FRICTION_IMPULSE
                     btScalar oldTangentImpulse = contactConstraint.m_appliedImpulse;
                     contactConstraint.m_appliedImpulse = oldTangentImpulse + j1;
                     
                     if (limit < contactConstraint.m_appliedImpulse)
                     {
                            contactConstraint.m_appliedImpulse = limit;
                     } else
                     {
                            if (contactConstraint.m_appliedImpulse < -limit)
                                   contactConstraint.m_appliedImpulse = -limit;
                     }
                     j1 = contactConstraint.m_appliedImpulse - oldTangentImpulse;
#else
                     if (limit < j1)
                     {
                            j1 = limit;
                     } else
                     {
                            if (j1 < -limit)
                                   j1 = -limit;
                     }

#endif //CLAMP_ACCUMULATED_FRICTION_IMPULSE

                     //GEN_set_min(contactConstraint.m_appliedImpulse, limit);
                     //GEN_set_max(contactConstraint.m_appliedImpulse, -limit);

                     

              }
       
              if (body1.m_invMass)
              {
                     body1.internalApplyImpulse(contactConstraint.m_contactNormal*body1.m_invMass,contactConstraint.m_angularComponentA,j1);
              }
              if (body2.m_invMass)
              {
                     body2.internalApplyImpulse(contactConstraint.m_contactNormal*body2.m_invMass,contactConstraint.m_angularComponentB,-j1);
              }

       } 
       return 0.f;
}

Here is the caller graph for this function:

btScalar restitutionCurve ( btScalar  rel_vel,
btScalar  restitution 
)

Definition at line 155 of file btSequentialImpulseConstraintSolver.cpp.

{
       btScalar rest = restitution * -rel_vel;
       return rest;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 53 of file btSequentialImpulseConstraintSolver.cpp.

Definition at line 42 of file btSequentialImpulseConstraintSolver.cpp.

Definition at line 154 of file btSequentialImpulseConstraintSolver.cpp.

int totalCpd = 0

Definition at line 40 of file btSequentialImpulseConstraintSolver.cpp.