This project has moved. For the latest updates, please go here.

Help with Placement of shapes

Topics: Developer Forum
Jan 28, 2011 at 10:07 PM

I am trying to get ideas/algorithms to address the following.  Any help is highly apprehended.

I have a simulation with 0 to many shapes and in the middle I need to add a new shapes.

The hard part is where can I place it.  It must not overlap with other shapes in the simulation.

So, this results in two questions.  Does anyone have any experience/thoughts on a efficient algorithm for this.  I know I could do some sort of random or brute force but I don't like either of those.

The second questions, is there any support in Farseer 3.2 for checking if two shapes overlap?  I believe that any algorithm will require this test.


Thanks again.


Jim K.

Jan 29, 2011 at 9:38 PM

When placing the shape, calculate its AABB.

Transform _transform = new Transform(_position, new Mat22(_angle));
AABB aabb;
_shape.ComputeAABB(out aabb, ref _transform, 0);

Then query the simulator for any bodies that intersect that AABB:

List<Fixture> affectedFixtures = new List<Fixture>();
World.QueryAABB(fixture =>
    return true;
}, ref aabb);

Then loop through each body in that list, then through each fixture in that body.FixtureList, and check for a collision with the fixture's shape:

Manifold manifold = new Manifold();
Collision.Collision.CollidePolygons(ref manifold, _polygonA, ref _transformA, _polygonB, ref _transformB);
Look at PolyCollisionTest.cs in the testbed for an example on colliding shapes.