btCGProjection.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Written by Xuchen Han <xuchenhan2015@u.northwestern.edu>
  3. Bullet Continuous Collision Detection and Physics Library
  4. Copyright (c) 2019 Google Inc. http://bulletphysics.org
  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. 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.
  11. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  12. 3. This notice may not be removed or altered from any source distribution.
  13. */
  14. #ifndef BT_CG_PROJECTION_H
  15. #define BT_CG_PROJECTION_H
  16. #include "btSoftBody.h"
  17. #include "BulletDynamics/Featherstone/btMultiBodyLinkCollider.h"
  18. #include "BulletDynamics/Featherstone/btMultiBodyConstraint.h"
  19. struct DeformableContactConstraint
  20. {
  21. const btSoftBody::Node* m_node;
  22. btAlignedObjectArray<const btSoftBody::RContact*> m_contact;
  23. btAlignedObjectArray<btVector3> m_total_normal_dv;
  24. btAlignedObjectArray<btVector3> m_total_tangent_dv;
  25. btAlignedObjectArray<bool> m_static;
  26. btAlignedObjectArray<bool> m_can_be_dynamic;
  27. DeformableContactConstraint(const btSoftBody::RContact& rcontact) : m_node(rcontact.m_node)
  28. {
  29. append(rcontact);
  30. }
  31. DeformableContactConstraint() : m_node(NULL)
  32. {
  33. m_contact.push_back(NULL);
  34. }
  35. void append(const btSoftBody::RContact& rcontact)
  36. {
  37. m_contact.push_back(&rcontact);
  38. m_total_normal_dv.push_back(btVector3(0, 0, 0));
  39. m_total_tangent_dv.push_back(btVector3(0, 0, 0));
  40. m_static.push_back(false);
  41. m_can_be_dynamic.push_back(true);
  42. }
  43. void replace(const btSoftBody::RContact& rcontact)
  44. {
  45. m_contact.clear();
  46. m_total_normal_dv.clear();
  47. m_total_tangent_dv.clear();
  48. m_static.clear();
  49. m_can_be_dynamic.clear();
  50. append(rcontact);
  51. }
  52. ~DeformableContactConstraint()
  53. {
  54. }
  55. };
  56. class btCGProjection
  57. {
  58. public:
  59. typedef btAlignedObjectArray<btVector3> TVStack;
  60. typedef btAlignedObjectArray<btAlignedObjectArray<btVector3> > TVArrayStack;
  61. typedef btAlignedObjectArray<btAlignedObjectArray<btScalar> > TArrayStack;
  62. btAlignedObjectArray<btSoftBody*>& m_softBodies;
  63. const btScalar& m_dt;
  64. // map from node indices to node pointers
  65. const btAlignedObjectArray<btSoftBody::Node*>* m_nodes;
  66. btCGProjection(btAlignedObjectArray<btSoftBody*>& softBodies, const btScalar& dt)
  67. : m_softBodies(softBodies), m_dt(dt)
  68. {
  69. }
  70. virtual ~btCGProjection()
  71. {
  72. }
  73. // apply the constraints
  74. virtual void project(TVStack& x) = 0;
  75. virtual void setConstraints() = 0;
  76. // update the constraints
  77. virtual btScalar update() = 0;
  78. virtual void reinitialize(bool nodeUpdated)
  79. {
  80. }
  81. virtual void setIndices(const btAlignedObjectArray<btSoftBody::Node*>* nodes)
  82. {
  83. m_nodes = nodes;
  84. }
  85. };
  86. #endif /* btCGProjection_h */