btFractureBody.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef BT_FRACTURE_BODY
  2. #define BT_FRACTURE_BODY
  3. class btCollisionShape;
  4. class btDynamicsWorld;
  5. class btCollisionWorld;
  6. class btCompoundShape;
  7. class btManifoldPoint;
  8. #include "LinearMath/btAlignedObjectArray.h"
  9. #include "BulletDynamics/Dynamics/btRigidBody.h"
  10. #define CUSTOM_FRACTURE_TYPE (btRigidBody::CO_USER_TYPE+1)
  11. struct btConnection
  12. {
  13. btCollisionShape* m_childShape0;
  14. btCollisionShape* m_childShape1;
  15. int m_childIndex0;
  16. int m_childIndex1;
  17. btScalar m_strength;
  18. };
  19. class btFractureBody : public btRigidBody
  20. {
  21. //connections
  22. public:
  23. btDynamicsWorld* m_world;
  24. btAlignedObjectArray<btScalar> m_masses;
  25. btAlignedObjectArray<btConnection> m_connections;
  26. btFractureBody( const btRigidBodyConstructionInfo& constructionInfo, btDynamicsWorld* world)
  27. :btRigidBody(constructionInfo),
  28. m_world(world)
  29. {
  30. m_masses.push_back(constructionInfo.m_mass);
  31. m_internalType=CUSTOM_FRACTURE_TYPE+CO_RIGID_BODY;
  32. }
  33. ///btRigidBody constructor for backwards compatibility.
  34. ///To specify friction (etc) during rigid body construction, please use the other constructor (using btRigidBodyConstructionInfo)
  35. btFractureBody( btScalar mass, btMotionState* motionState, btCollisionShape* collisionShape, const btVector3& localInertia, btScalar* masses, int numMasses, btDynamicsWorld* world)
  36. :btRigidBody(mass,motionState,collisionShape,localInertia),
  37. m_world(world)
  38. {
  39. for (int i=0;i<numMasses;i++)
  40. m_masses.push_back(masses[i]);
  41. m_internalType=CUSTOM_FRACTURE_TYPE+CO_RIGID_BODY;
  42. }
  43. void recomputeConnectivity(btCollisionWorld* world);
  44. static btCompoundShape* shiftTransform(btCompoundShape* boxCompound,btScalar* masses,btTransform& shift, btVector3& principalInertia);
  45. static btCompoundShape* shiftTransformDistributeMass(btCompoundShape* boxCompound,btScalar mass,btTransform& shift);
  46. static bool collisionCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);
  47. };
  48. void fractureCallback(btDynamicsWorld* world, btScalar timeStep);
  49. void glueCallback(btDynamicsWorld* world, btScalar timeStep);
  50. #endif //BT_FRACTURE_BODY