Add support for childshape index for btCompoundShape during ContactAddedCallback,
see example in Bullet/Demos/ConvexDecompositionDemo Removed some warnings
This commit is contained in:
@@ -267,7 +267,7 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
|
||||
int maxc, dContactGeom * /*contact*/, int /*skip*/,btDiscreteCollisionDetectorInterface::Result& output)
|
||||
{
|
||||
const btScalar fudge_factor = btScalar(1.05);
|
||||
btVector3 p,pp,normalC;
|
||||
btVector3 p,pp,normalC(0.f,0.f,0.f);
|
||||
const btScalar *normalR = 0;
|
||||
btScalar A[3],B[3],R11,R12,R13,R21,R22,R23,R31,R32,R33,
|
||||
Q11,Q12,Q13,Q21,Q22,Q23,Q31,Q32,Q33,s,s2,l;
|
||||
|
||||
@@ -142,6 +142,15 @@ public:
|
||||
if (!m_childCollisionAlgorithms[index])
|
||||
m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold);
|
||||
|
||||
///detect swapping case
|
||||
if (m_resultOut->getBody0Internal() == m_compoundColObj)
|
||||
{
|
||||
m_resultOut->setShapeIdentifiersA(-1,index);
|
||||
} else
|
||||
{
|
||||
m_resultOut->setShapeIdentifiersB(-1,index);
|
||||
}
|
||||
|
||||
m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut);
|
||||
if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
|
||||
{
|
||||
|
||||
@@ -124,8 +124,8 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, i
|
||||
///this should use the btDispatcher, so the actual registered algorithm is used
|
||||
// btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
|
||||
|
||||
m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex);
|
||||
// cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex);
|
||||
m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
|
||||
|
||||
// cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
|
||||
colAlgo->~btCollisionAlgorithm();
|
||||
|
||||
@@ -47,6 +47,12 @@ btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* b
|
||||
:m_manifoldPtr(0),
|
||||
m_body0(body0),
|
||||
m_body1(body1)
|
||||
#ifdef DEBUG_PART_INDEX
|
||||
,m_partId0(-1),
|
||||
m_partId1(-1),
|
||||
m_index0(-1),
|
||||
m_index1(-1)
|
||||
#endif //DEBUG_PART_INDEX
|
||||
{
|
||||
m_rootTransA = body0->getWorldTransform();
|
||||
m_rootTransB = body1->getWorldTransform();
|
||||
@@ -88,10 +94,19 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
|
||||
newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
|
||||
|
||||
//BP mod, store contact triangles.
|
||||
newPt.m_partId0 = m_partId0;
|
||||
newPt.m_partId1 = m_partId1;
|
||||
newPt.m_index0 = m_index0;
|
||||
newPt.m_index1 = m_index1;
|
||||
if (isSwapped)
|
||||
{
|
||||
newPt.m_partId0 = m_partId1;
|
||||
newPt.m_partId1 = m_partId0;
|
||||
newPt.m_index0 = m_index1;
|
||||
newPt.m_index1 = m_index0;
|
||||
} else
|
||||
{
|
||||
newPt.m_partId0 = m_partId0;
|
||||
newPt.m_partId1 = m_partId1;
|
||||
newPt.m_index0 = m_index0;
|
||||
newPt.m_index1 = m_index1;
|
||||
}
|
||||
//printf("depth=%f\n",depth);
|
||||
///@todo, check this for any side effects
|
||||
if (insertIndex >= 0)
|
||||
@@ -112,7 +127,7 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
|
||||
//experimental feature info, for per-triangle material etc.
|
||||
btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
|
||||
btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
|
||||
(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,m_partId0,m_index0,obj1,m_partId1,m_index1);
|
||||
(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ class btManifoldPoint;
|
||||
typedef bool (*ContactAddedCallback)(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);
|
||||
extern ContactAddedCallback gContactAddedCallback;
|
||||
|
||||
//#define DEBUG_PART_INDEX 1
|
||||
|
||||
|
||||
///btManifoldResult is a helper class to manage contact results.
|
||||
@@ -50,6 +51,13 @@ class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
|
||||
public:
|
||||
|
||||
btManifoldResult()
|
||||
#ifdef DEBUG_PART_INDEX
|
||||
:
|
||||
m_partId0(-1),
|
||||
m_partId1(-1),
|
||||
m_index0(-1),
|
||||
m_index1(-1)
|
||||
#endif //DEBUG_PART_INDEX
|
||||
{
|
||||
}
|
||||
|
||||
@@ -71,12 +79,16 @@ public:
|
||||
return m_manifoldPtr;
|
||||
}
|
||||
|
||||
virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
virtual void setShapeIdentifiersA(int partId0,int index0)
|
||||
{
|
||||
m_partId0=partId0;
|
||||
m_partId1=partId1;
|
||||
m_index0=index0;
|
||||
m_index1=index1;
|
||||
m_partId0=partId0;
|
||||
m_index0=index0;
|
||||
}
|
||||
|
||||
virtual void setShapeIdentifiersB( int partId1,int index1)
|
||||
{
|
||||
m_partId1=partId1;
|
||||
m_index1=index1;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +111,16 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
const btCollisionObject* getBody0Internal() const
|
||||
{
|
||||
return m_body0;
|
||||
}
|
||||
|
||||
const btCollisionObject* getBody1Internal() const
|
||||
{
|
||||
return m_body1;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //MANIFOLD_RESULT_H
|
||||
|
||||
@@ -340,7 +340,7 @@ btScalar btConvexShape::getMarginNonVirtual () const
|
||||
btAssert (0);
|
||||
return btScalar(0.0f);
|
||||
}
|
||||
|
||||
#ifndef __SPU__
|
||||
void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
|
||||
{
|
||||
switch (m_shapeType)
|
||||
@@ -425,3 +425,5 @@ void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin,
|
||||
// should never reach here
|
||||
btAssert (0);
|
||||
}
|
||||
|
||||
#endif //__SPU__
|
||||
|
||||
@@ -24,9 +24,10 @@ btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape()
|
||||
btVector3 btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
|
||||
{
|
||||
|
||||
int i;
|
||||
|
||||
btVector3 supVec(0,0,0);
|
||||
#ifndef __SPU__
|
||||
int i;
|
||||
btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
|
||||
|
||||
btVector3 vec = vec0;
|
||||
@@ -54,8 +55,9 @@ btVector3 btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(const b
|
||||
}
|
||||
}
|
||||
|
||||
return supVec;
|
||||
|
||||
#endif //__SPU__
|
||||
return supVec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,12 +45,13 @@ ATTRIBUTE_ALIGNED16( struct) btIndexedMesh
|
||||
|
||||
|
||||
btIndexedMesh()
|
||||
{
|
||||
:m_indexType(PHY_INTEGER),
|
||||
#ifdef BT_USE_DOUBLE_PRECISION
|
||||
m_vertexType = PHY_DOUBLE;
|
||||
m_vertexType(PHY_DOUBLE)
|
||||
#else // BT_USE_DOUBLE_PRECISION
|
||||
m_vertexType = PHY_FLOAT;
|
||||
m_vertexType(PHY_FLOAT)
|
||||
#endif // BT_USE_DOUBLE_PRECISION
|
||||
{
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
@@ -231,6 +231,8 @@ class btPrimitiveManagerBase
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~btPrimitiveManagerBase() {}
|
||||
|
||||
//! determines if this manager consist on only triangles, which special case will be optimized
|
||||
virtual bool is_trimesh() const = 0;
|
||||
virtual int get_primitive_count() const = 0;
|
||||
|
||||
@@ -102,6 +102,7 @@ public:
|
||||
{
|
||||
return m_parent->m_gim_shape->getChildShape(index);
|
||||
}
|
||||
virtual ~ChildShapeRetriever() {}
|
||||
};
|
||||
|
||||
class TriangleShapeRetriever:public ChildShapeRetriever
|
||||
@@ -113,6 +114,7 @@ public:
|
||||
m_parent->m_gim_shape->getBulletTriangle(index,m_parent->m_trishape);
|
||||
return &m_parent->m_trishape;
|
||||
}
|
||||
virtual ~TriangleShapeRetriever() {}
|
||||
};
|
||||
|
||||
class TetraShapeRetriever:public ChildShapeRetriever
|
||||
@@ -213,7 +215,8 @@ void btGImpactCollisionAlgorithm::addContactPoint(btCollisionObject * body0,
|
||||
const btVector3 & normal,
|
||||
btScalar distance)
|
||||
{
|
||||
m_resultOut->setShapeIdentifiers(m_part0,m_triface0,m_part1,m_triface1);
|
||||
m_resultOut->setShapeIdentifiersA(m_part0,m_triface0);
|
||||
m_resultOut->setShapeIdentifiersB(m_part1,m_triface1);
|
||||
checkManifold(body0,body1);
|
||||
m_resultOut->addContactPoint(normal,point,distance);
|
||||
}
|
||||
@@ -236,7 +239,8 @@ void btGImpactCollisionAlgorithm::shape_vs_shape_collision(
|
||||
btCollisionAlgorithm* algor = newAlgorithm(body0,body1);
|
||||
// post : checkManifold is called
|
||||
|
||||
m_resultOut->setShapeIdentifiers(m_part0,m_triface0,m_part1,m_triface1);
|
||||
m_resultOut->setShapeIdentifiersA(m_part0,m_triface0);
|
||||
m_resultOut->setShapeIdentifiersB(m_part1,m_triface1);
|
||||
|
||||
algor->processCollision(body0,body1,*m_dispatchInfo,m_resultOut);
|
||||
|
||||
@@ -262,7 +266,8 @@ void btGImpactCollisionAlgorithm::convex_vs_convex_collision(
|
||||
body1->internalSetTemporaryCollisionShape(shape1);
|
||||
|
||||
|
||||
m_resultOut->setShapeIdentifiers(m_part0,m_triface0,m_part1,m_triface1);
|
||||
m_resultOut->setShapeIdentifiersA(m_part0,m_triface0);
|
||||
m_resultOut->setShapeIdentifiersB(m_part1,m_triface1);
|
||||
|
||||
checkConvexAlgorithm(body0,body1);
|
||||
m_convex_algorithm->processCollision(body0,body1,*m_dispatchInfo,m_resultOut);
|
||||
|
||||
@@ -302,6 +302,7 @@ public:
|
||||
class CompoundPrimitiveManager:public btPrimitiveManagerBase
|
||||
{
|
||||
public:
|
||||
virtual ~CompoundPrimitiveManager() {}
|
||||
btGImpactCompoundShape * m_compoundShape;
|
||||
|
||||
|
||||
@@ -582,6 +583,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual ~TrimeshPrimitiveManager() {}
|
||||
|
||||
void lock()
|
||||
{
|
||||
|
||||
@@ -33,8 +33,9 @@ struct btDiscreteCollisionDetectorInterface
|
||||
|
||||
virtual ~Result(){}
|
||||
|
||||
///setShapeIdentifiers provides experimental support for per-triangle material / custom material combiner
|
||||
virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1)=0;
|
||||
///setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material combiner
|
||||
virtual void setShapeIdentifiersA(int partId0,int index0)=0;
|
||||
virtual void setShapeIdentifiersB(int partId1,int index1)=0;
|
||||
virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)=0;
|
||||
};
|
||||
|
||||
|
||||
@@ -297,6 +297,9 @@ namespace gjkepa2_impl
|
||||
{
|
||||
case eStatus::Valid: m_distance=m_ray.length();break;
|
||||
case eStatus::Inside: m_distance=0;break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
return(m_status);
|
||||
}
|
||||
@@ -415,8 +418,8 @@ namespace gjkepa2_impl
|
||||
if(l>GJK_SIMPLEX3_EPS)
|
||||
{
|
||||
btScalar mindist=-1;
|
||||
btScalar subw[2];
|
||||
U subm;
|
||||
btScalar subw[2]={0.f,0.f};
|
||||
U subm(0);
|
||||
for(U i=0;i<3;++i)
|
||||
{
|
||||
if(btDot(*vt[i],btCross(dl[i],n))>0)
|
||||
@@ -462,8 +465,8 @@ namespace gjkepa2_impl
|
||||
if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS))
|
||||
{
|
||||
btScalar mindist=-1;
|
||||
btScalar subw[3];
|
||||
U subm;
|
||||
btScalar subw[3]={0.f,0.f,0.f};
|
||||
U subm(0);
|
||||
for(U i=0;i<3;++i)
|
||||
{
|
||||
const U j=imd3[i];
|
||||
@@ -892,6 +895,9 @@ bool btGjkEpaSolver2::Penetration( const btConvexShape* shape0,
|
||||
case GJK::eStatus::Failed:
|
||||
results.status=sResults::GJK_Failed;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ static bool Penetration(const btConvexShape* shape0,const btTransform& wtrs0,
|
||||
const btVector3& guess,
|
||||
sResults& results,
|
||||
bool usemargins=true);
|
||||
|
||||
#ifndef __SPU__
|
||||
static btScalar SignedDistance( const btVector3& position,
|
||||
btScalar margin,
|
||||
const btConvexShape* shape,
|
||||
@@ -66,6 +66,8 @@ static bool SignedDistance( const btConvexShape* shape0,const btTransform& wtrs
|
||||
const btConvexShape* shape1,const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results);
|
||||
#endif //__SPU__
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,7 @@ bool btGjkEpaPenetrationDepthSolver::calcPenDepth( btSimplexSolverInterface& sim
|
||||
(void)v;
|
||||
(void)simplexSolver;
|
||||
|
||||
const btScalar radialmargin(btScalar(0.));
|
||||
// const btScalar radialmargin(btScalar(0.));
|
||||
|
||||
btVector3 guessVector(transformA.getOrigin()-transformB.getOrigin());
|
||||
btGjkEpaSolver2::sResults results;
|
||||
|
||||
@@ -91,10 +91,13 @@ bool btMinkowskiPenetrationDepthSolver::calcPenDepth(btSimplexSolverInterface& s
|
||||
btScalar m_depth;
|
||||
bool m_hasResult;
|
||||
|
||||
virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
virtual void setShapeIdentifiersA(int partId0,int index0)
|
||||
{
|
||||
(void)partId0;
|
||||
(void)index0;
|
||||
}
|
||||
virtual void setShapeIdentifiersB(int partId1,int index1)
|
||||
{
|
||||
(void)partId1;
|
||||
(void)index1;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,16 @@ struct btPointCollector : public btDiscreteCollisionDetectorInterface::Result
|
||||
{
|
||||
}
|
||||
|
||||
virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1)
|
||||
virtual void setShapeIdentifiersA(int partId0,int index0)
|
||||
{
|
||||
(void)partId0;
|
||||
(void)index0;
|
||||
|
||||
}
|
||||
virtual void setShapeIdentifiersB(int partId1,int index1)
|
||||
{
|
||||
(void)partId1;
|
||||
(void)index1;
|
||||
//??
|
||||
}
|
||||
|
||||
virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
|
||||
|
||||
Reference in New Issue
Block a user