Fix issues with btCompoundShape when adding/removing child shapes after construction of a btRigidBody.

Thanks tp for the report:
http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2925&p=11700#p11700
This commit is contained in:
erwin.coumans
2008-12-07 20:57:38 +00:00
parent 06167a0b31
commit f3a70b65eb
4 changed files with 63 additions and 6 deletions

View File

@@ -22,7 +22,8 @@ btCompoundShape::btCompoundShape(bool enableDynamicAabbTree)
m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
m_collisionMargin(btScalar(0.)),
m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
m_dynamicAabbTree(0)
m_dynamicAabbTree(0),
m_updateRevision(1)
{
m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
@@ -46,6 +47,7 @@ btCompoundShape::~btCompoundShape()
void btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
{
m_updateRevision++;
//m_childTransforms.push_back(localTransform);
//m_childShapes.push_back(shape);
btCompoundShapeChild child;
@@ -99,6 +101,7 @@ void btCompoundShape::updateChildTransform(int childIndex, const btTransform& ne
void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
{
m_updateRevision++;
btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
if (m_dynamicAabbTree)
{
@@ -113,6 +116,7 @@ void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
void btCompoundShape::removeChildShape(btCollisionShape* shape)
{
m_updateRevision++;
// Find the children containing the shape specified, and remove those children.
//note: there might be multiple children using the same shape!
for(int i = m_children.size()-1; i >= 0 ; i--)
@@ -139,6 +143,7 @@ void btCompoundShape::recalculateLocalAabb()
{
// Recalculate the local aabb
// Brute force, it iterates over all the shapes left.
m_localAabbMin = btVector3(btScalar(1e30),btScalar(1e30),btScalar(1e30));
m_localAabbMax = btVector3(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));
@@ -161,8 +166,16 @@ void btCompoundShape::recalculateLocalAabb()
void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
{
btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
//avoid an illegal AABB when there are no children
if (!m_children.size())
{
localHalfExtents.setValue(0,0,0);
localCenter.setValue(0,0,0);
}
localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
btMatrix3x3 abs_b = trans.getBasis().absolute();
@@ -173,7 +186,7 @@ void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVect
abs_b[2].dot(localHalfExtents));
aabbMin = center-extent;
aabbMax = center+extent;
}
void btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const