Add early rejection tests during CCD against compound objects

This commit is contained in:
Ryan Huffman
2015-11-16 14:38:14 -08:00
committed by Andrew Meadows
parent 6c67426b6d
commit af442778a6

View File

@@ -793,50 +793,108 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape,
///@todo : use AABB tree or other BVH acceleration structure! ///@todo : use AABB tree or other BVH acceleration structure!
if (collisionShape->isCompound()) if (collisionShape->isCompound())
{ {
BT_PROFILE("convexSweepCompound"); struct btCompoundLeafCallback : btDbvt::ICollide
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape); {
int i=0; btCompoundLeafCallback(
for (i=0;i<compoundShape->getNumChildShapes();i++) const btConvexShape* castShape,
{ const btTransform& convexFromTrans,
btTransform childTrans = compoundShape->getChildTransform(i); const btTransform& convexToTrans,
const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i); btScalar allowedPenetration,
btTransform childWorldTrans = colObjWorldTransform * childTrans; const btCompoundShape* compoundShape,
const btTransform& colObjWorldTransform,
ConvexResultCallback& resultCallback)
:
m_castShape(castShape),
m_convexFromTrans(convexFromTrans),
m_convexToTrans(convexToTrans),
m_allowedPenetration(allowedPenetration),
m_compoundShape(compoundShape),
m_colObjWorldTransform(colObjWorldTransform),
m_resultCallback(resultCallback) {
}
struct LocalInfoAdder : public ConvexResultCallback { const btConvexShape* m_castShape;
const btTransform& m_convexFromTrans;
const btTransform& m_convexToTrans;
btScalar m_allowedPenetration;
const btCompoundShape* m_compoundShape;
const btTransform& m_colObjWorldTransform;
ConvexResultCallback& m_resultCallback;
const btCollisionObjectWrapper* m_colObjWrap;
public:
void Process(const btDbvtNode* leaf)
{
// Processing leaf node
int index = leaf->dataAsInt;
//const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
btTransform childTrans = m_compoundShape->getChildTransform(index);
const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index);
btTransform childWorldTrans = m_colObjWorldTransform * childTrans;
struct LocalInfoAdder : public ConvexResultCallback {
ConvexResultCallback* m_userCallback; ConvexResultCallback* m_userCallback;
int m_i; int m_i;
LocalInfoAdder (int i, ConvexResultCallback *user) LocalInfoAdder(int i, ConvexResultCallback *user)
: m_userCallback(user), m_i(i) : m_userCallback(user), m_i(i)
{
m_closestHitFraction = m_userCallback->m_closestHitFraction;
}
virtual bool needsCollision(btBroadphaseProxy* p) const
{
return m_userCallback->needsCollision(p);
}
virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult& r, bool b)
{ {
btCollisionWorld::LocalShapeInfo shapeInfo; m_closestHitFraction = m_userCallback->m_closestHitFraction;
shapeInfo.m_shapePart = -1; }
shapeInfo.m_triangleIndex = m_i; virtual bool needsCollision(btBroadphaseProxy* p) const
if (r.m_localShapeInfo == NULL) {
r.m_localShapeInfo = &shapeInfo; return m_userCallback->needsCollision(p);
const btScalar result = m_userCallback->addSingleResult(r, b); }
m_closestHitFraction = m_userCallback->m_closestHitFraction; virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& r, bool b)
return result; {
btCollisionWorld::LocalShapeInfo shapeInfo;
shapeInfo.m_shapePart = -1;
shapeInfo.m_triangleIndex = m_i;
if (r.m_localShapeInfo == NULL)
r.m_localShapeInfo = &shapeInfo;
const btScalar result = m_userCallback->addSingleResult(r, b);
m_closestHitFraction = m_userCallback->m_closestHitFraction;
return result;
} }
}; };
LocalInfoAdder my_cb(i, &resultCallback); LocalInfoAdder my_cb(index, &m_resultCallback);
btCollisionObjectWrapper tmpObj(colObjWrap,childCollisionShape,colObjWrap->getCollisionObject(),childWorldTrans,-1,i); btCollisionObjectWrapper tmpObj(m_colObjWrap, childCollisionShape, m_colObjWrap->getCollisionObject(), childWorldTrans, -1, index);
objectQuerySingleInternal(castShape, convexFromTrans,convexToTrans, objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans,
&tmpObj,my_cb, allowedPenetration); &tmpObj, my_cb, m_allowedPenetration);
}
};
} BT_PROFILE("convexSweepCompound");
const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
btVector3 fromLocalAabbMin, fromLocalAabbMax;
btVector3 toLocalAabbMin, toLocalAabbMax;
castShape->getAabb(convexFromTrans, fromLocalAabbMin, fromLocalAabbMax);
castShape->getAabb(convexToTrans, toLocalAabbMin, toLocalAabbMax);
fromLocalAabbMin.setMin(toLocalAabbMin);
fromLocalAabbMax.setMax(toLocalAabbMax);
const btDbvt* tree = compoundShape->getDynamicAabbTree();
if (tree) {
btCompoundLeafCallback callback { castShape, convexFromTrans, convexToTrans,
allowedPenetration, compoundShape, colObjWorldTransform, resultCallback };
const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax);
tree->collideTV(tree->m_root, bounds, callback);
} else {
int i;
for (i=0;i<compoundShape->getNumChildShapes();i++)
{
}
}
} }
} }
} }