Update to btDbvt and btDbvtBroadphase, thanks to Nathanael Presson
This commit is contained in:
@@ -772,16 +772,17 @@ return(sizeof(GJK)+sizeof(EPA));
|
||||
}
|
||||
|
||||
//
|
||||
btScalar btGjkEpaSolver2::Distance( const btConvexShape* shape0,
|
||||
bool btGjkEpaSolver2::Distance( const btConvexShape* shape0,
|
||||
const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,
|
||||
const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results)
|
||||
{
|
||||
tShape shape;
|
||||
Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,false);
|
||||
GJK gjk;
|
||||
GJK::eStatus::_ gjk_status=gjk.Evaluate(shape,btVector3(1,1,1));
|
||||
GJK gjk;
|
||||
GJK::eStatus::_ gjk_status=gjk.Evaluate(shape,guess);
|
||||
if(gjk_status==GJK::eStatus::Valid)
|
||||
{
|
||||
btVector3 w0=btVector3(0,0,0);
|
||||
@@ -794,17 +795,62 @@ if(gjk_status==GJK::eStatus::Valid)
|
||||
}
|
||||
results.witnesses[0] = wtrs0*w0;
|
||||
results.witnesses[1] = wtrs0*w1;
|
||||
return((w0-w1).length());
|
||||
results.normal = w0-w1;
|
||||
results.distance = results.normal.length();
|
||||
results.normal /= results.distance>GJK_MIN_DISTANCE?results.distance:1;
|
||||
return(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
results.status = gjk_status==GJK::eStatus::Inside?
|
||||
sResults::Penetrating :
|
||||
sResults::GJK_Failed ;
|
||||
return(-1);
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool btGjkEpaSolver2::Penetration( const btConvexShape* shape0,
|
||||
const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,
|
||||
const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results,
|
||||
bool usemargins)
|
||||
{
|
||||
tShape shape;
|
||||
Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,usemargins);
|
||||
GJK gjk;
|
||||
GJK::eStatus::_ gjk_status=gjk.Evaluate(shape,-guess);
|
||||
switch(gjk_status)
|
||||
{
|
||||
case GJK::eStatus::Inside:
|
||||
{
|
||||
EPA epa;
|
||||
EPA::eStatus::_ epa_status=epa.Evaluate(gjk,-guess);
|
||||
if(epa_status!=EPA::eStatus::Failed)
|
||||
{
|
||||
btVector3 w0=btVector3(0,0,0);
|
||||
for(U i=0;i<epa.m_result.rank;++i)
|
||||
{
|
||||
w0+=shape.Support(epa.m_result.c[i]->d,0)*epa.m_result.p[i];
|
||||
}
|
||||
results.status = sResults::Penetrating;
|
||||
results.witnesses[0] = wtrs0*w0;
|
||||
results.witnesses[1] = wtrs0*(w0-epa.m_normal*epa.m_depth);
|
||||
results.normal = -epa.m_normal;
|
||||
results.distance = -epa.m_depth;
|
||||
return(true);
|
||||
} else results.status=sResults::EPA_Failed;
|
||||
}
|
||||
break;
|
||||
case GJK::eStatus::Failed:
|
||||
results.status=sResults::GJK_Failed;
|
||||
break;
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
//
|
||||
btScalar btGjkEpaSolver2::SignedDistance(const btVector3& position,
|
||||
btScalar margin,
|
||||
@@ -857,42 +903,17 @@ return(SIMD_INFINITY);
|
||||
}
|
||||
|
||||
//
|
||||
bool btGjkEpaSolver2::Penetration( const btConvexShape* shape0,
|
||||
bool btGjkEpaSolver2::SignedDistance(const btConvexShape* shape0,
|
||||
const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,
|
||||
const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results)
|
||||
{
|
||||
tShape shape;
|
||||
Initialize(shape0,wtrs0,shape1,wtrs1,results,shape,true);
|
||||
GJK gjk;
|
||||
GJK::eStatus::_ gjk_status=gjk.Evaluate(shape,-guess);
|
||||
switch(gjk_status)
|
||||
{
|
||||
case GJK::eStatus::Inside:
|
||||
{
|
||||
EPA epa;
|
||||
EPA::eStatus::_ epa_status=epa.Evaluate(gjk,-guess);
|
||||
if(epa_status!=EPA::eStatus::Failed)
|
||||
{
|
||||
btVector3 w0=btVector3(0,0,0);
|
||||
for(U i=0;i<epa.m_result.rank;++i)
|
||||
{
|
||||
w0+=shape.Support(epa.m_result.c[i]->d,0)*epa.m_result.p[i];
|
||||
}
|
||||
results.status = sResults::Penetrating;
|
||||
results.witnesses[0] = wtrs0*w0;
|
||||
results.witnesses[1] = wtrs0*(w0-epa.m_normal*epa.m_depth);
|
||||
return(true);
|
||||
} else results.status=sResults::EPA_Failed;
|
||||
}
|
||||
break;
|
||||
case GJK::eStatus::Failed:
|
||||
results.status=sResults::GJK_Failed;
|
||||
break;
|
||||
}
|
||||
return(false);
|
||||
if(!Distance(shape0,wtrs0,shape1,wtrs1,guess,results))
|
||||
return(Penetration(shape0,wtrs0,shape1,wtrs1,guess,results,false));
|
||||
else
|
||||
return(true);
|
||||
}
|
||||
|
||||
/* Symbols cleanup */
|
||||
|
||||
@@ -40,24 +40,32 @@ struct sResults
|
||||
} status;
|
||||
btVector3 witnesses[2];
|
||||
btVector3 normal;
|
||||
btScalar distance;
|
||||
};
|
||||
|
||||
static int StackSizeRequirement();
|
||||
|
||||
static btScalar Distance( const btConvexShape* shape0,const btTransform& wtrs0,
|
||||
static bool Distance( const btConvexShape* shape0,const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,const btTransform& wtrs1,
|
||||
sResults& results);
|
||||
|
||||
const btVector3& guess,
|
||||
sResults& results);
|
||||
|
||||
static bool Penetration(const btConvexShape* shape0,const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results,
|
||||
bool usemargins=true);
|
||||
|
||||
static btScalar SignedDistance( const btVector3& position,
|
||||
btScalar margin,
|
||||
const btConvexShape* shape,
|
||||
const btTransform& wtrs,
|
||||
sResults& results);
|
||||
|
||||
static bool Penetration(const btConvexShape* shape0,const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results);
|
||||
|
||||
static bool SignedDistance( const btConvexShape* shape0,const btTransform& wtrs0,
|
||||
const btConvexShape* shape1,const btTransform& wtrs1,
|
||||
const btVector3& guess,
|
||||
sResults& results);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user