Box2D Forums

It is currently Mon Sep 22, 2014 5:16 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Mar 11, 2012 12:36 pm 
Offline

Joined: Wed Aug 11, 2010 5:18 am
Posts: 10
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:
// 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?


Top
 Profile  
 
PostPosted: Mon Mar 12, 2012 5:10 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1943
Location: Tokyo
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group