00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
00017 #define SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
00018
00019 #include "btConstraintSolver.h"
00020 class btIDebugDraw;
00021 #include "btContactConstraint.h"
00022 #include "btSolverBody.h"
00023 #include "btSolverConstraint.h"
00024 #include "btTypedConstraint.h"
00025 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
00026
00028 class btSequentialImpulseConstraintSolver : public btConstraintSolver
00029 {
00030 protected:
00031
00032 btConstraintArray m_tmpSolverContactConstraintPool;
00033 btConstraintArray m_tmpSolverNonContactConstraintPool;
00034 btConstraintArray m_tmpSolverContactFrictionConstraintPool;
00035 btAlignedObjectArray<int> m_orderTmpConstraintPool;
00036 btAlignedObjectArray<int> m_orderFrictionConstraintPool;
00037 btAlignedObjectArray<btTypedConstraint::btConstraintInfo1> m_tmpConstraintSizesPool;
00038
00039 void setupFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyIdB,
00040 btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,
00041 btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation,
00042 btScalar desiredVelocity=0., btScalar cfmSlip=0.);
00043
00044 btSolverConstraint& addFrictionConstraint(const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity=0., btScalar cfmSlip=0.);
00045
00046 void setupContactConstraint(btSolverConstraint& solverConstraint, btCollisionObject* colObj0, btCollisionObject* colObj1, btManifoldPoint& cp,
00047 const btContactSolverInfo& infoGlobal, btVector3& vel, btScalar& rel_vel, btScalar& relaxation,
00048 btVector3& rel_pos1, btVector3& rel_pos2);
00049
00050 void setFrictionConstraintImpulse( btSolverConstraint& solverConstraint, btRigidBody* rb0, btRigidBody* rb1,
00051 btManifoldPoint& cp, const btContactSolverInfo& infoGlobal);
00052
00054 unsigned long m_btSeed2;
00055
00056
00057 btScalar restitutionCurve(btScalar rel_vel, btScalar restitution);
00058
00059 void convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal);
00060
00061
00062 void resolveSplitPenetrationSIMD(
00063 btRigidBody& body1,
00064 btRigidBody& body2,
00065 const btSolverConstraint& contactConstraint);
00066
00067 void resolveSplitPenetrationImpulseCacheFriendly(
00068 btRigidBody& body1,
00069 btRigidBody& body2,
00070 const btSolverConstraint& contactConstraint);
00071
00072
00073 int getOrInitSolverBody(btCollisionObject& body);
00074
00075 void resolveSingleConstraintRowGeneric(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint);
00076
00077 void resolveSingleConstraintRowGenericSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint);
00078
00079 void resolveSingleConstraintRowLowerLimit(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint);
00080
00081 void resolveSingleConstraintRowLowerLimitSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint);
00082
00083 protected:
00084 static btRigidBody& getFixedBody()
00085 {
00086 static btRigidBody s_fixed(0, 0,0);
00087 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));
00088 return s_fixed;
00089 }
00090 virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);
00091 virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);
00092 btScalar solveSingleIteration(int iteration, btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);
00093
00094 virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);
00095 virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);
00096
00097
00098 public:
00099
00100
00101 btSequentialImpulseConstraintSolver();
00102 virtual ~btSequentialImpulseConstraintSolver();
00103
00104 virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer, btStackAlloc* stackAlloc,btDispatcher* dispatcher);
00105
00106
00107
00109 virtual void reset();
00110
00111 unsigned long btRand2();
00112
00113 int btRandInt2 (int n);
00114
00115 void setRandSeed(unsigned long seed)
00116 {
00117 m_btSeed2 = seed;
00118 }
00119 unsigned long getRandSeed() const
00120 {
00121 return m_btSeed2;
00122 }
00123
00124 };
00125
00126 #ifndef BT_PREFER_SIMD
00127 typedef btSequentialImpulseConstraintSolver btSequentialImpulseConstraintSolverPrefered;
00128 #endif
00129
00130
00131 #endif //SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H
00132