EdgeChainShapes won't collide

I am trying to create shapes for 2 objects with edgeChainDef however when I fly them into each other they won't collide, I don't know what I am doing wrong :S.

Code:
   b2BodyDef bodyDef;
   bodyDef.linearDamping = 1.0;
   bodyDef.massData.mass = .1;
   bodyDef.massData.center.SetZero(); //totalCenterOfMass;
   bodyDef.massData.I = 0.01;
   bodyDef.position.Set(10, 7.5);
   bodyDef.angle = 0;
   bodyDef.angularDamping = 4.0f;
   bodyDef.allowSleep = true;

   b2Body* body = world->CreateBody(&bodyDef);
   player->mBody = body;
   body->SetUserData(&player);

   std::vector<b2Vec2> vertices;
   vertices.push_back(b2Vec2(-.5, .5));
   vertices.push_back(b2Vec2(-.5, -.5));
   vertices.push_back(b2Vec2(.5, -.5));
   vertices.push_back(b2Vec2(.5, .5));

   b2EdgeChainDef edgeChainDef;
   edgeChainDef.isALoop = true;
   edgeChainDef.vertexCount = vertices.size();
   edgeChainDef.vertices = &*vertices.begin();
   body->CreateShape(&edgeChainDef);

   bodyDef.position.Set(10, 4.5);
   body = world->CreateBody(&bodyDef);
   body->CreateShape(&edgeChainDef);
Back when I used EdgeChains, you could not use them with dynamic bodies, only static ones, that might be why they don't collide. If that has changed, disregard this post.
Edge shapes cannot collide at the moment, this feature is not implemented.
Indeed, I have no plans to implement edge-edge collision. Use polygons for dynamic objects.
Damn. EdgeChains were ideal because I want to create the shape based on a sprite, since polygons can't be concave then I think I am pretty much fucked. I have no idea how to develope an algorithm to define all the polygons needed to make up the sprite.
Reaper, have a look at the available info on polygon tessalation (forming b2PolygonShapes from an edge list). There's quite of a lot of (semi-)working code around that'll get you going. This is a superior solution to dynamic edges, just more complicated.
Most games are able to approximate dynamic concave shapes with one or more convex shapes on a single body. For example, you can use several boxes to approximate a chair with a back and legs.
Quote:
Reaper, have a look at the available info on polygon tessalation (forming b2PolygonShapes from an edge list). There's quite of a lot of (semi-)working code around that'll get you going. This is a superior solution to dynamic edges, just more complicated.

Interesting, thanks I'll take a look.

Quote:
Most games are able to approximate dynamic concave shapes with one or more convex shapes on a single body. For example, you can use several boxes to approximate a chair with a back and legs.

Well the reason I need an algorithm is that the sprite might change(Destructible) and I need the shape to change according to it.
I took a look at this article

http://www.geom.uiuc.edu/~samuelp/del_project.html

And well I found a couple of problems with it. It seems to make it work I have to first define all the vertices I want in it, say I trace my image to find vertices that outline it but, the algorithm, instead of giving me polygons to fill up the vertex outline it generates polygons to fill up with triangles any space between vertices. Maybe the next image will express what I want to say better.

Image

I also took a look at

http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html

But that can generate silvers as you call them and screw everything up.
Reaper wrote:
I took a look at this article

http://www.geom.uiuc.edu/~samuelp/del_project.html

And well I found a couple of problems with it. It seems to make it work I have to first define all the vertices I want in it, say I trace my image to find vertices that outline it but, the algorithm, instead of giving me polygons to fill up the vertex outline it generates polygons to fill up with triangles any space between vertices. Maybe the next image will express what I want to say better.

Image

I also took a look at

http://www.cs.unc.edu/~dm/CODE/GEM/chapter.html

But that can generate silvers as you call them and screw everything up.


Make your algorithm smarter about it and don't just connect every vertex to each other. If you define a background color it's pretty trivial to trace the exterior of the shape from the sprite. I did this in some python code using PIL. Once you have a list of pixels that define the shapes, fine local extremes. You'll isolate the vertexes from there. It's pretty brute force but highly effective, just do it when you're loading the level/game and store the results so the player doesn't have to see it mid game.

Further optimizations include approximating curves that appear in sprites, and heuristics to increase performance, depending on how far you want to take it. Breaking up the list of vertexes into without creating slivers is easy, check the angles to make sure the polygon is thick enough before you close it off, and if it isn't make it bigger.

Again, as long as you aren't loading 5000000 sprites all at once mid game, you can spend a lot of processing time on accurate rendering.

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