btMultiBodyJointMotor.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library
  3. Copyright (c) 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. ///This file was written by Erwin Coumans
  14. #include "btMultiBodyJointMotor.h"
  15. #include "btMultiBody.h"
  16. #include "btMultiBodyLinkCollider.h"
  17. #include "bullet/BulletCollision//CollisionDispatch/btCollisionObject.h"
  18. btMultiBodyJointMotor::btMultiBodyJointMotor(btMultiBody* body, int link, btScalar desiredVelocity, btScalar maxMotorImpulse)
  19. :btMultiBodyConstraint(body,body,link,link,1,true),
  20. m_desiredVelocity(desiredVelocity)
  21. {
  22. m_maxAppliedImpulse = maxMotorImpulse;
  23. // the data.m_jacobians never change, so may as well
  24. // initialize them here
  25. // note: we rely on the fact that data.m_jacobians are
  26. // always initialized to zero by the Constraint ctor
  27. // row 0: the lower bound
  28. jacobianA(0)[6 + link] = 1;
  29. }
  30. btMultiBodyJointMotor::~btMultiBodyJointMotor()
  31. {
  32. }
  33. int btMultiBodyJointMotor::getIslandIdA() const
  34. {
  35. btMultiBodyLinkCollider* col = m_bodyA->getBaseCollider();
  36. if (col)
  37. return col->getIslandTag();
  38. for (int i=0;i<m_bodyA->getNumLinks();i++)
  39. {
  40. if (m_bodyA->getLink(i).m_collider)
  41. return m_bodyA->getLink(i).m_collider->getIslandTag();
  42. }
  43. return -1;
  44. }
  45. int btMultiBodyJointMotor::getIslandIdB() const
  46. {
  47. btMultiBodyLinkCollider* col = m_bodyB->getBaseCollider();
  48. if (col)
  49. return col->getIslandTag();
  50. for (int i=0;i<m_bodyB->getNumLinks();i++)
  51. {
  52. col = m_bodyB->getLink(i).m_collider;
  53. if (col)
  54. return col->getIslandTag();
  55. }
  56. return -1;
  57. }
  58. void btMultiBodyJointMotor::createConstraintRows(btMultiBodyConstraintArray& constraintRows,
  59. btMultiBodyJacobianData& data,
  60. const btContactSolverInfo& infoGlobal)
  61. {
  62. // only positions need to be updated -- data.m_jacobians and force
  63. // directions were set in the ctor and never change.
  64. for (int row=0;row<getNumRows();row++)
  65. {
  66. btMultiBodySolverConstraint& constraintRow = constraintRows.expandNonInitializing();
  67. btScalar penetration = 0;
  68. fillConstraintRowMultiBodyMultiBody(constraintRow,data,jacobianA(row),jacobianB(row),infoGlobal,m_desiredVelocity,-m_maxAppliedImpulse,m_maxAppliedImpulse);
  69. }
  70. }