bullet3的碰撞检测例子在examples/collision,CollisionTutorialBullet2类中,先是plCreateCollisionWorld,然后plCreateSphereShape,创建一些几何shape,然后调plCollide执行两个shape之间的碰撞检测,返回contact 点个数及坐标,调plWorldCollide执行world中所有shape的碰撞检测。
plXXX(...)这些函数是在CollisionSdkC_Api.h包装中的,都是间接调CollisionSdkInterface接口中的方法,sdk具体实现在internal目录中,实现了bullet2版本和bullet3版本,例如collide方法,bullet2中是,类和api前缀一般都是bt
int Bullet2CollisionSdk::collide(plCollisionWorldHandle worldHandle, plCollisionObjectHandle colA, plCollisionObjectHandle colB,
lwContactPoint* pointsOut, int pointCapacity)
{
btCollisionWorld* world = (btCollisionWorld*)worldHandle;
btCollisionObject* colObjA = (btCollisionObject*)colA;
btCollisionObject* colObjB = (btCollisionObject*)colB;
btAssert(world && colObjA && colObjB);
if (world == m_internalData->m_collisionWorld && colObjA && colObjB)
{
Bullet2ContactResultCallback cb(pointsOut, pointCapacity);
world->contactPairTest(colObjA, colObjB, cb);
return cb.m_numContacts;
}
return 0;
}
bullet3中的实现,类前缀为b3
int RealTimeBullet3CollisionSdk::collide(plCollisionWorldHandle worldHandle, plCollisionObjectHandle colAHandle, plCollisionObjectHandle colBHandle,
lwContactPoint* pointsOutOrg, int pointCapacity)
{
RTB3CollisionWorld* world = (RTB3CollisionWorld*)worldHandle;
RTB3_ColliderOpaque2Int caster;
caster.m_ptrValue = colAHandle;
int colAIndex = caster.m_intValue;
caster.m_ptrValue = colBHandle;
int colBIndex = caster.m_intValue;
const b3Collidable& colA = world->m_collidables[colAIndex];
const b3Collidable& colB = world->m_collidables[colBIndex];
plContactCache contactCache;
contactCache.pointCapacity = pointCapacity;
contactCache.pointsOut = pointsOutOrg;
contactCache.numAddedPoints = 0;
for (int i = 0; i < colA.m_numChildShapes; i++)
{
for (int j = 0; j < colB.m_numChildShapes; j++)
{
if (contactCache.numAddedPoints < pointCapacity)
{
//funcTbl_detectCollision[world->m_childShapes[colA.m_shapeIndex+i].m_shapeType]
// [world->m_childShapes[colB.m_shapeIndex+j].m_shapeType](world,colAIndex,colA.m_shapeIndex+i,colBIndex,colB.m_shapeIndex+j,&contactCache);
}
}
return contactCache.numAddedPoints;
}
return 0;
}
标签:pointCapacity,int,contactCache,collision,例子,bullet3,world,colB,colA
From: https://www.cnblogs.com/abcstar/p/18049577