EndContact, b2WorldManifold.normal vs b2Manifold.localNormal

Hey All,

I've got two quick questions...

When setting up my contact listener I've been using the values from the b2WorldManifold, which I get by doing:
Code:
    void PhysicsContactListener::BeginContact(b2Contact* aContact) {
        b2WorldManifold worldManifold;
        aContact->GetWorldManifold(&worldManifold);


...but I've noticed that when I do this in my EndContact function, it sometimes has 0 for both x and y values of the normal.

I was poking around and noticed that there's a b2Manifold returned by b2Contact::GetManifold(), which has a normal called "localNormal". I ran a few quick tests and it looked like this had correct values of the normal, even when the worldManifold had values of 0. Can someone explain to me what the difference is between these two normals, and why the world doesn't have correct values sometimes?

My second question is: After I get a BeginContact call, for the corresponding EndContact call are the fixtures going to be in the same order? As in, the fixtureA from BeginContact is going to be fixtureA in EndContact, and the fixtureB from BeginContact is going to be fixtureB in EndContact.

Thanks,
-Dave
On coordinate systems: http://en.wikipedia.org/wiki/Local_coordinates

Once a contact is created I do not change the order of the fixtures. However, I do not promise never to do so.
Hm... I understand the difference between a local vs world coordinate system. I guess my question was more like, will the local normal's components be rotated based on the rotations of the colliding bodies? Or, to say it in a different way, is the local coordinate system rotated based on the rotation of the body?

Is there some way to identify which EndContact call corresponds to BeginContact call? Something along the lines of a unique id for the contact possibly?

-Dave
Quote:
Is there some way to identify which EndContact call corresponds to BeginContact call? Something along the lines of a unique id for the contact possibly?
Since the same two fixtures are involved, you could make a kind of id from that. ie. in C I guess you could have a 64bit value which stores both fixture pointers. But I'm not sure how useful that would be. Typically your game is not interested in the contacts themselves, but rather when contacts begin/end, you usually want to tell two of your game objects that they are now touching/not touching each other. I think the best way to do this is by storing in your game object a list of other objects it is currently touching. In BeginContact you get your game objects (which you set in the user data) from the relevant fixtures/bodies, and just tell them each to add the other game object to their list. In EndContact, you just tell them to remove the other from their list. Then you can use this list in a game object to efficiently check whether it is touching something, how many things it's touching, and what those things are.
That's almost exactly what I'm actually trying to do, with one additional thing. I'd like to only keep track of the contacts which have a y normal > 0.5.

When I add to the list of objects in BeginContact I check if worldManifold.normal.y > 0.5. When I get a EndContact, I'd like to check here if the worldManifold.normal.y > 0.5 so I can remove it from the list (if I don't check it, my list becomes incorrect if I collide with the same fixture twice).

My issue comes in here when the corresponding EndContact's worldManifold's normal has both an x and y magnitude of 0, so I can't check the direction of the contact. This was way I was exploring the localNormal, becuase it looked like it still had valid non-zero values when the worldManifold did not.

This leads me to my possible work around, which is that I don't REALLY need to know what the normal is in EndContact as long as I could tell that it corresponded to the BeginContact with the normal I was looking for.

Is this possibly a bug, or is the 0 normals intentional?
The normal will be invalid if the point count is zero.
Is there a way to match EndContact calls with their corresponding BeginContact calls?
...define 'corresponding'
😀

I can't help thinking that maybe you are approaching your problem the wrong way. Can you tell us why you want to track only contacts/end contacts with normal > 0.5? That sounds like you are trying to see how vertically something bounced... ?
I'm using it to determine how many objects are currently touching my object in that direction.
Is it not possible to go through all the objects touching, and check which ones are in that direction (based on the position of them) ?

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