how can i detect contact in the 'tick' function?

hi, i'm learning cocos2d-x and box2d. I read this article: http://www.raywenderlich.com/zh-hans/19 ... 8%e5%88%86

but think the storing contacts way is not that direct, i wonder is there a way to write my code like this:

void tick(float duration){
if(bodyCollidesBody(b1, b2)){ //the function name is made up
//do something...
}
}

is there any function like 'bodyCollidesBody', just like the static function CCRect::rectIntersectsRect(x, y) in cocos2d-x?
thx for reply~
Code:
bool RopingPlayer::getContactNormal(b2Vec2 &accumulatedNormals)
{
   accumulatedNormals.SetZero();
   bool foundAContact = false;
   
   for(b2ContactEdge* contactEdge = body->GetContactList(); contactEdge; contactEdge = contactEdge->next) {
      b2Contact* contact = contactEdge->contact;
      if (contact != NULL && contact->IsEnabled() && contact->IsTouching() && contact->GetManifold()->pointCount > 0) // && !contact->IsSensor()
      {
         foundAContact = true;
         
         // Get the b2WorldManifold if you want circle-circle contact normal
         b2Vec2 contactNormal = contact->GetManifold()->localNormal;
         
         if (contact->GetFixtureA()->GetBody() == body)
         {
            contactNormal *= -1.0;
         }
         
         accumulatedNormals += contactNormal;
      }
   }
   
   if (!foundAContact)
   {
      return false;
   }
   
   accumulatedNormals.Normalize();
   return true;
}


I call that code from my ordinary game object update (which happens between b2World updates).
pTymN wrote:
Code:
bool RopingPlayer::getContactNormal(b2Vec2 &accumulatedNormals)
{
   accumulatedNormals.SetZero();
   bool foundAContact = false;
   
   for(b2ContactEdge* contactEdge = body->GetContactList(); contactEdge; contactEdge = contactEdge->next) {
      b2Contact* contact = contactEdge->contact;
      if (contact != NULL && contact->IsEnabled() && contact->IsTouching() && contact->GetManifold()->pointCount > 0) // && !contact->IsSensor()
      {
         foundAContact = true;
         
         // Get the b2WorldManifold if you want circle-circle contact normal
         b2Vec2 contactNormal = contact->GetManifold()->localNormal;
         
         if (contact->GetFixtureA()->GetBody() == body)
         {
            contactNormal *= -1.0;
         }
         
         accumulatedNormals += contactNormal;
      }
   }
   
   if (!foundAContact)
   {
      return false;
   }
   
   accumulatedNormals.Normalize();
   return true;
}


I call that code from my ordinary game object update (which happens between b2World updates).


sorry, but i don't quite understand, could you be a bit more specified how the code above could detects two bodies' contact? i mean, given two bodies as parameters, and return a bool value:
bool bodyContactsBody(const b2Body& b1, const b2Body& b2);
That loop in the method I posted iterates over the contacts in a body. You can call contact->GetFixture[A/B]()->GetBody() to get the two bodies associated with a contact. One of them will be the body from whose contact list you were able to get the contact, and the other body will be whatever the first body is touching. If you go through the contact list for one of the bodies, and there is not a contact that points to both bodies, then they are not colliding.

Original thread: https://box2d.org/forum/viewtopic.php?t=8827