I created my own contact listener, implementing usual 4 methods: BeginContact, EndContact, PreSolve, PostSolve.
Where from what parameters of these methods can i current contact points?
I tried something like this, but nothing helped
void CListener::PreSolve(b2Contact* contact, const b2Manifold* oldManifold) {
for(int i = 0 ; i < oldManifold->pointCount; ++i) {
b2ManifoldPoint p = oldManifold->points[i];
}
}
In Box2D version 2.3.2, the "contact" points are obtained from the
contactparameter (the first parameter) of theb2ContactListenermethods. I put contact in parenthesis as these include points obtained in overlapped situations as well (where the shapes have moved beyond touching).The base contact point information is obtained from the contacts'
b2Manifoldstructure returned from theb2Contact::GetManifold()method. These are in coordinates local to the two shapes that are associated with that manifold however.If you want the contact points in world coordinates (which I'd guess is really what you'd want), you can instead call the contacts'
b2Contact::GetWorldManifoldmethod to fill ab2WorldManifoldinstance for you. Under-the-hood, this method is essentially a convenience method that gathers the information needed from the contact including theb2Manifoldand then converts the points to world coordinates.Note that to know how many of the world coordinate contact points are actually valid (which could be 0, 1, or 2) or to know the kind of manifold that's representing the contact, you'll still want access the
b2Manifoldinformation - specifically itspointCountandtypefields.Lastly, the webpage that @iforce2d linked for you, I still find to be helpful and is more verbally and visually comprehensive than what I've stated here.