| 1 | /* | 
|---|
| 2 | Bullet Continuous Collision Detection and Physics Library | 
|---|
| 3 | Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/ | 
|---|
| 4 |  | 
|---|
| 5 | This software is provided 'as-is', without any express or implied warranty. | 
|---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. | 
|---|
| 7 | Permission is granted to anyone to use this software for any purpose, | 
|---|
| 8 | including commercial applications, and to alter it and redistribute it freely, | 
|---|
| 9 | subject to the following restrictions: | 
|---|
| 10 |  | 
|---|
| 11 | 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. | 
|---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. | 
|---|
| 13 | 3. This notice may not be removed or altered from any source distribution. | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | #ifndef SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H | 
|---|
| 17 | #define SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H | 
|---|
| 18 |  | 
|---|
| 19 | #include "btConstraintSolver.h" | 
|---|
| 20 | class btIDebugDraw; | 
|---|
| 21 | #include "btContactConstraint.h" | 
|---|
| 22 | #include "btSolverBody.h" | 
|---|
| 23 | #include "btSolverConstraint.h" | 
|---|
| 24 |  | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | ///The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (iterative LCP) method. | 
|---|
| 28 | class btSequentialImpulseConstraintSolver : public btConstraintSolver | 
|---|
| 29 | { | 
|---|
| 30 | protected: | 
|---|
| 31 |  | 
|---|
| 32 | btAlignedObjectArray<btSolverBody>      m_tmpSolverBodyPool; | 
|---|
| 33 | btConstraintArray                       m_tmpSolverContactConstraintPool; | 
|---|
| 34 | btConstraintArray                       m_tmpSolverNonContactConstraintPool; | 
|---|
| 35 | btConstraintArray                       m_tmpSolverContactFrictionConstraintPool; | 
|---|
| 36 | btAlignedObjectArray<int>       m_orderTmpConstraintPool; | 
|---|
| 37 | btAlignedObjectArray<int>       m_orderFrictionConstraintPool; | 
|---|
| 38 |  | 
|---|
| 39 | 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); | 
|---|
| 40 |  | 
|---|
| 41 | ///m_btSeed2 is used for re-arranging the constraint rows. improves convergence/quality of friction | 
|---|
| 42 | unsigned long   m_btSeed2; | 
|---|
| 43 |  | 
|---|
| 44 | void    initSolverBody(btSolverBody* solverBody, btCollisionObject* collisionObject); | 
|---|
| 45 | btScalar restitutionCurve(btScalar rel_vel, btScalar restitution); | 
|---|
| 46 |  | 
|---|
| 47 | void    convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal); | 
|---|
| 48 |  | 
|---|
| 49 | void    resolveSplitPenetrationImpulseCacheFriendly( | 
|---|
| 50 | btSolverBody& body1, | 
|---|
| 51 | btSolverBody& body2, | 
|---|
| 52 | const btSolverConstraint& contactConstraint, | 
|---|
| 53 | const btContactSolverInfo& solverInfo); | 
|---|
| 54 |  | 
|---|
| 55 | //internal method | 
|---|
| 56 | int     getOrInitSolverBody(btCollisionObject& body); | 
|---|
| 57 |  | 
|---|
| 58 | void    resolveSingleConstraintRowGeneric(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint); | 
|---|
| 59 |  | 
|---|
| 60 | void    resolveSingleConstraintRowGenericSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint); | 
|---|
| 61 |  | 
|---|
| 62 | void    resolveSingleConstraintRowLowerLimit(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint); | 
|---|
| 63 |  | 
|---|
| 64 | void    resolveSingleConstraintRowLowerLimitSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint); | 
|---|
| 65 |  | 
|---|
| 66 | public: | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | btSequentialImpulseConstraintSolver(); | 
|---|
| 70 | virtual ~btSequentialImpulseConstraintSolver(); | 
|---|
| 71 |  | 
|---|
| 72 | virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer, btStackAlloc* stackAlloc,btDispatcher* dispatcher); | 
|---|
| 73 |  | 
|---|
| 74 | btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); | 
|---|
| 75 | btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); | 
|---|
| 76 |  | 
|---|
| 77 | ///clear internal cached data and reset random seed | 
|---|
| 78 | virtual void    reset(); | 
|---|
| 79 |  | 
|---|
| 80 | unsigned long btRand2(); | 
|---|
| 81 |  | 
|---|
| 82 | int btRandInt2 (int n); | 
|---|
| 83 |  | 
|---|
| 84 | void    setRandSeed(unsigned long seed) | 
|---|
| 85 | { | 
|---|
| 86 | m_btSeed2 = seed; | 
|---|
| 87 | } | 
|---|
| 88 | unsigned long   getRandSeed() const | 
|---|
| 89 | { | 
|---|
| 90 | return m_btSeed2; | 
|---|
| 91 | } | 
|---|
| 92 |  | 
|---|
| 93 | }; | 
|---|
| 94 |  | 
|---|
| 95 | #ifndef BT_PREFER_SIMD | 
|---|
| 96 | typedef btSequentialImpulseConstraintSolver btSequentialImpulseConstraintSolverPrefered; | 
|---|
| 97 | #endif | 
|---|
| 98 |  | 
|---|
| 99 |  | 
|---|
| 100 | #endif //SEQUENTIAL_IMPULSE_CONSTRAINT_SOLVER_H | 
|---|
| 101 |  | 
|---|