Box2D Forums

It is currently Wed May 22, 2013 1:34 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Contact's Positions
PostPosted: Sun Dec 27, 2009 9:26 pm 
Offline

Joined: Mon Nov 09, 2009 5:40 pm
Posts: 2
Hey everybody,

I've been trying to figure out how exactly to get a list of the positions of contacts between two objects. It's so that I can find whether the player / character can jump or not, depending on either the difference in Y or the angle. I've tried using the Manifold and the contact's themselves, but the local point is not correct. So how do I find the actual position (Vector2) of the contact, or at least with respect to my character?

Thanks in advance,
El-Presidente


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Wed Dec 30, 2009 4:48 pm 
Offline

Joined: Thu Dec 17, 2009 5:02 pm
Posts: 5
You should be able to get the local point (relative to the body's position) by using the contact's manifold's point list.

So something like this (pseudo-code):

Manifold m = myContact.GetManifold();

Vector2 localPoint = m._points[0].LocalPoint; // Assuming you just take the first point on the contact's manifold

You can convert that to world coordinates by doing something like this:

Vector2 worldPoint = myBody.GetWorldPoint(localPoint).


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Fri Jan 15, 2010 3:52 pm 
Offline

Joined: Sun Jul 06, 2008 1:59 pm
Posts: 14
I have the same problem as El-Presidente.
It seems the LocalPoints variable in the ManifoldPoint struct does not contain the local point of the contact.
I only tested in a circle/box collision but if you read the comment above the declaration of struct ManifoldPoint, it says:
/// The local point usage depends on the manifold type:
/// -ShapeType.Circles: the local center of circleB
/// -SeparationFunction.FaceA: the local center of cirlceB or the clip point of polygonB
/// -SeparationFunction.FaceB: the clip point of polygonA

And unfortunately, the comment is right. For instance, in my case, I get the local center of CircleB in my localpoint, that is pretty useless.

Anyone as more information on this? I don't think the contact point is available or even computable only with a class Contact. There probably needs some code in the collides functions in order to get it.
That's strange, especially since this information is available in the C++ version.

Dave.


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Sat Jan 16, 2010 5:17 pm 
Offline

Joined: Thu Jul 24, 2008 8:43 am
Posts: 15
Are you guys using Box2DX or Box2D.XNA?

Box2D.XNA is in sync with the latest version of the C++ code, so it shouldn't be different. If you find that it is, please file a bug on codeplex: http://box2dxna.codeplex.com/WorkItem/List.aspx


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Sun Jan 17, 2010 2:39 am 
Offline

Joined: Sun Jul 06, 2008 1:59 pm
Posts: 14
Thanks for the reply Brandon,
I do think it's not in sync here. I filed a bug.


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Sun Jan 17, 2010 9:26 am 
Offline

Joined: Sun Jul 06, 2008 1:59 pm
Posts: 14
I took some time to debug the problem and the bug is in the following method:
public void GetWorldManifold(out WorldManifold worldManifold)

Here:
Transform xfA, xfB;
bodyA.GetTransform(out xfA);
bodyA.GetTransform(out xfB);

Of course, the last line should be bodyB.GetTransform(out xfB);


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Sun Jan 17, 2010 1:35 pm 
Offline

Joined: Thu Jul 24, 2008 8:43 am
Posts: 15
Great find forzax.

Fix with codeplex change 37320.


Top
 Profile  
 
 Post subject: Re: Contact's Positions
PostPosted: Sat May 21, 2011 11:26 pm 
Offline

Joined: Sat May 21, 2011 11:19 pm
Posts: 1
Yep forzax is great!
astigmatism


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 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