btMLCPSolver.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 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.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. ///original version written by Erwin Coumans, October 2013
  14. #ifndef BT_MLCP_SOLVER_H
  15. #define BT_MLCP_SOLVER_H
  16. #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h"
  17. #include "LinearMath/btMatrixX.h"
  18. #include "BulletDynamics/MLCPSolvers/btMLCPSolverInterface.h"
  19. class btMLCPSolver : public btSequentialImpulseConstraintSolver
  20. {
  21. protected:
  22. btMatrixXu m_A;
  23. btVectorXu m_b;
  24. btVectorXu m_x;
  25. btVectorXu m_lo;
  26. btVectorXu m_hi;
  27. ///when using 'split impulse' we solve two separate (M)LCPs
  28. btVectorXu m_bSplit;
  29. btVectorXu m_xSplit;
  30. btVectorXu m_bSplit1;
  31. btVectorXu m_xSplit2;
  32. btAlignedObjectArray<int> m_limitDependencies;
  33. btAlignedObjectArray<btSolverConstraint*> m_allConstraintPtrArray;
  34. btMLCPSolverInterface* m_solver;
  35. int m_fallback;
  36. /// The following scratch variables are not stateful -- contents are cleared prior to each use.
  37. /// They are only cached here to avoid extra memory allocations and deallocations and to ensure
  38. /// that multiple instances of the solver can be run in parallel.
  39. btMatrixXu m_scratchJ3;
  40. btMatrixXu m_scratchJInvM3;
  41. btAlignedObjectArray<int> m_scratchOfs;
  42. btMatrixXu m_scratchMInv;
  43. btMatrixXu m_scratchJ;
  44. btMatrixXu m_scratchJTranspose;
  45. btMatrixXu m_scratchTmp;
  46. virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);
  47. virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds, btTypedConstraint** constraints, int numConstraints, const btContactSolverInfo& infoGlobal, btIDebugDraw* debugDrawer);
  48. virtual void createMLCP(const btContactSolverInfo& infoGlobal);
  49. virtual void createMLCPFast(const btContactSolverInfo& infoGlobal);
  50. //return true is it solves the problem successfully
  51. virtual bool solveMLCP(const btContactSolverInfo& infoGlobal);
  52. public:
  53. btMLCPSolver(btMLCPSolverInterface* solver);
  54. virtual ~btMLCPSolver();
  55. void setMLCPSolver(btMLCPSolverInterface* solver)
  56. {
  57. m_solver = solver;
  58. }
  59. int getNumFallbacks() const
  60. {
  61. return m_fallback;
  62. }
  63. void setNumFallbacks(int num)
  64. {
  65. m_fallback = num;
  66. }
  67. virtual btConstraintSolverType getSolverType() const
  68. {
  69. return BT_MLCP_SOLVER;
  70. }
  71. };
  72. #endif //BT_MLCP_SOLVER_H