Box2DX find collision points

Hi. I am making a game using Box2DX.

Basically I have a player and some gameObjects. All gameObjects (and the player) have a Body.

Collision works fine. Now I want to get the points of contact. I have found no documentation about how to do it.

So I used Box2DX.Dynamics.PolygonContact.

Here's my code:

Code: Select all

// find GameObjects that collide with the Player
            foreach (GameObject o in gameObjects)
            {
                Box2DX.Dynamics.PolygonContact contact = null;

                Box2DX.Collision.Shape s1 = player.obj.body.GetShapeList();
                Box2DX.Collision.Shape s2 = o.body.GetShapeList();

                while( s1 != null )
                {
                    s2 = o.body.GetShapeList();
                   
                    while (s2 != null)
                    {
                        contact = new Box2DX.Dynamics.PolygonContact(s1, s2);

                        if (contact.GetManifoldCount() > 0)
                        {
                            Console.WriteLine("Contact {0}", contact.GetManifoldCount());
                        }

                        s2 = s2.GetNext();
                    }
                    s1 = s1.GetNext();
                }
            }


Nothing is printed though (because contact.GetManifoldCount() is always zero). What is wrong here?
The recommended way to detect and handle contacts is with a 'contact listener' <- search the manual for that phrase. It gives you a notification when two fixtures begin and end contact, and allows you to manipulate the characteristics of the contact while the fixtures are touching. Check out this page, it's C++ but might help you with finding the contact points: http://www.iforce2d.net/b2dtut/collision-anatomy

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