0
\$\begingroup\$

For example, in the code below, will the assert ever fail?

for (const b2ContactEdge *contactEdge = playerPhysicsBody->GetContactList(); contactEdge; contactEdge = contactEdge->next) {
    assert(contactEdge->contact->GetFixtureA()->GetBody() == playerPhysicsBody);
}

I wasn't able to determine this from the source code. From some brief debugging, it seems to be the case, but I want to avoid any subtle bugs if this assumption is wrong.

The reason that I want to do this is to find the particular fixture that belongs to the player that was involved in the contact.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Shortly after posting I tested this out a bit more and found that the assert will fail. GetFixtureA() may or may not return a fixture belonging to playerPhysicsBody.

I'm now using this convenience function to safely find the fixture that I want:

inline const b2Fixture *contactFixtureFor(const b2Body *body, const b2ContactEdge *contactEdge) {
    return contactEdge->contact->GetFixtureA()->GetBody() == body
            ? contactEdge->contact->GetFixtureA()
            : contactEdge->contact->GetFixtureB();
}
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .