Tag: ios7 box2d

在iOS的box2d中,如何find两个圆形物体之间的距离?

我正在使用下面的代码来获得不同半径的两个圆形主体之间的距离: distance = b2Distance(body1->GetPosition(), body2->GetPosition()); 我已经意识到,可变距离是存储身体的两个中心之间的距离,而不是边界之间的距离。 我想要的是距离= 0当两个身体接触。 我怎样才能做到这一点? 我一直在尝试这个代码,但它失败了: b2DistanceInput *distanceInput; distanceInput->transformA = body1->GetTransform(); distanceInput->transformB = body2->GetTransform(); b2DistanceProxy *proxyA; proxyA->Set(fixtureBody1->GetShape(), 1); b2DistanceProxy *proxyB; proxyB->Set(fixtureBody2->GetShape(), 1); distanceInput->proxyA = *proxyA; distanceInput->proxyB = *proxyB; b2DistanceOutput *theDistance; b2SimplexCache *cache; cache->count = 0; b2Distance(theDistance, cache, distanceInput); getShape方法在b2box代码中给出了错误的访问错误。 有任何想法吗? 谢谢, GA