hi, i just review the engine code especially the file btCompoundCollisionAlgorithm.cpp and also did some test, i think the engine can't support your special case currently. from the code below it only can record the shape index at some compound shape but don't konw which compound shape it belongs to, so i don't think it can cover the recursive case.
Code: Select all
if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
{
tmpWrap = m_resultOut->getBody0Wrap();
m_resultOut->setBody0Wrap(&compoundWrap);
m_resultOut->setShapeIdentifiersA(-1, index);
}
else
{
tmpWrap = m_resultOut->getBody1Wrap();
m_resultOut->setBody1Wrap(&compoundWrap);
m_resultOut->setShapeIdentifiersB(-1, index);
}
algo->processCollision(&compoundWrap, m_otherObjWrap, m_dispatchInfo, m_resultOut)
i make some change in the btCompoundCollisionAlgorithm.cpp and also create a test demo which should can meet your requirement. but be noted i don't sure if it will cause other issues because of this change. just for a reference in order to involve more guy's discussion.
i use ths m_partId0 to indicate the compound shape level and m_index0 to indicate the shape index in the compund shape.
the following is the code snippet that will be easy for other guy's review, more details are attached.
SimpleBox.cpp:
Code: Select all
bool testContactProcessedCallback(btManifoldPoint& cp, void* bod0, void* bod1)
{
btCollisionObject* o1 = static_cast<btCollisionObject*>(bod0);
btCollisionObject* o2 = static_cast<btCollisionObject*>(bod1);
if (o1 == bodyGround || o2 == bodyGround) return true;
printf("O1=%p, o2=%p ############\n", o1, o2);
printf("m_partId0=%d, m_partId1=%d m_index0=%d m_index1=%d", cp.m_partId0, cp.m_partId1, cp.m_index0, cp.m_index1);
const btCollisionShape* childShape = NULL;
if (cp.m_index0 != -1)
childShape = compoundLevel[cp.m_partId0]->getChildShape(cp.m_index0);
else if (cp.m_index1 != -1)
childShape = compoundLevel[cp.m_partId1]->getChildShape(cp.m_index1);
if (childShape == NULL)
printf("no compound shape #############");
else
printf("childshape = %p id=%p\n", childShape, childShape->getUserPointer())
btCompoundCollisionAlgorithm.cpp
Code: Select all
@@ -159,22 +159,39 @@ public:
algo = m_childCollisionAlgorithms[index];
}
const btCollisionObjectWrapper* tmpWrap = 0;
+ int currentCompoundLevel = 0;
+ const btCollisionObjectWrapper* parentCompoundObj = 0;
+ parentCompoundObj = this->m_compoundColObjWrap->m_parent;
+ while (parentCompoundObj)
+ {
+ if (parentCompoundObj->getCollisionShape()->isCompound())
+ {
+ currentCompoundLevel++;
+ parentCompoundObj = parentCompoundObj->m_parent;
+ }
+ else
+ {
+ break;
+ }
+ }
///detect swapping case
if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
{
tmpWrap = m_resultOut->getBody0Wrap();
m_resultOut->setBody0Wrap(&compoundWrap);
- m_resultOut->setShapeIdentifiersA(-1, index);
+ m_resultOut->setShapeIdentifiersA(currentCompoundLevel, index);
+ m_resultOut->setShapeIdentifiersB(-1, -1);
}
else
{
tmpWrap = m_resultOut->getBody1Wrap();
m_resultOut->setBody1Wrap(&compoundWrap);
- m_resultOut->setShapeIdentifiersB(-1, index);
+ m_resultOut->setShapeIdentifiersB(currentCompoundLevel, index);
+ m_resultOut->setShapeIdentifiersA(-1, -1);
}
algo->processCollision(&compoundWrap, m_otherObjWrap, m_dispatchInfo, m_resultOut);
#if 0
You do not have the required permissions to view the files attached to this post.