This project has moved and is read-only. For the latest updates, please go here.

Getting fixtures like with QueryAABB when I have a triangle defined by vertices?

Topics: User Forum
Feb 3, 2011 at 4:42 AM


I'm clearly still new to Farseer, so I don't know exactly how to find out which fixtures are in an arbitrary triangle that I have. I guess this question goes for pretty much any shape defined by vertices - what steps should I take to query Farseer for the fixtures that are within my vertices?

So far, I've tried to create a shape and then compute the AABB based on the vertices I have, but it didn't work on the first try, and also I don't know if that's the right way to be going about doing things. So for reference, what should I do? To sum up the question, I have a list of Vector2s that define a polygon (triangle in this case) and want to query Farseer for the fixtures within it.

Feb 3, 2011 at 1:52 PM

If you want Farseer to do that for you, you can create a fixture from your shape and set fixture.IsSensor to true. Sensors do collision detection but no collision response. That is you can get notified about collisions without your bodies reacting to them.

If you want to know if something is completely contained in your shape you can do it by hand. Convert your list of Vector2s to a Vertices object. Vertices.PointInPoly() can test points against the polygon. You then have to test all the points of a fixture's shape against the vertices object. Alternatively you can convert your Vectors to a shape and use shape.TestPoint().

I'd recommend setting up the sensor method. If you want to check further for complete containment do so by hand within the sensors OnCollision delegate for example.

Feb 4, 2011 at 3:07 AM

Sensors seem to be working perfectly for me. Thank you!