i'm looking into simulating glass now and have yet to find any good examples. if anybody has any ideas. . . i'd love to hear them!
right now i do have a destructible object system using compound objects. when a compound object is hit, we compare the force to 2 contact thresholds, subObject and fullObject. if the force is > subObject i find what subObjects are hit and remove those from the compound and release the respective sub objects into the world. if the force is > fullObject (rocket, grenade, car crash). we release all the sub objects. this is working pretty well and i could use this to simulate glass, however i'm interested in dynamically creating triangles for glass after impact.
heres the code i added to btCompoundShape to remove a child, any suggestions here would be great as well.
Code: Select all
void btCompoundShape::removeChildShape(btCollisionShape* shape)
{
int findIndex = m_childShapes.findLinearSearch(shape);
int size = getNumChildShapes();
// if findIndex>=size, this object isn't in the list
if (findIndex<size)
{
// this preserves child shape ordering, although it sucks for speed
for (int i=findIndex; i<size-1; i++)
{
m_childShapes.swap(i, i+1);
m_childTransforms.swap(i, i+1);
}
m_childShapes.pop_back();
m_childTransforms.pop_back();
// TODO: recalculate compound aabb faster (maybe not at all in some cases)
btTransform childTransform;
btVector3 localAabbMin,localAabbMax;
m_localAabbMax.setValue(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
m_localAabbMin.setValue(btScalar(1e30),btScalar(1e30),btScalar(1e30));
for(int i=0; i<size-1; i++)
{
btCollisionShape* shape = m_childShapes[i];
childTransform = getChildTransform(i);
shape->getAabb(childTransform,localAabbMin,localAabbMax);
for (int i=0;i<3;i++)
{
if (m_localAabbMin[i] > localAabbMin[i])
{
m_localAabbMin[i] = localAabbMin[i];
}
if (m_localAabbMax[i] < localAabbMax[i])
{
m_localAabbMax[i] = localAabbMax[i];
}
}
}
}
}