Box2D Convex Polygons / Triangulation

2 posts / 0 new
Last post
bensmiley
Box2D Convex Polygons / Triangulation

Box2D only accepts convex shapes with 8 points or fewer. Most 2D levels contain shapes with more complex geometries. To solve this problem it's necessary to decompose the complex shape into a number of sub shapes each with it's own fixture. These fixtures are then added to the Box2D body.

bensmiley

creating polygon works perfect but i think it does not work because it is a concave shape.
i need to create that shape with multiple convex shapes.
I think that will fix it.

look at this:
http://www.emanueleferonato.com/2008/12/19/understanding-custom-polygons...

You have to break up the shape into convex polygons with no more than 8 points. You could do this manually or you could use a triangulation or polygonization algorithm (there are a number that can be adapted from the internet). After you've polygonized the shape, you need to make a composite Box2D body. To do this, create a number of fixture each associated with one of the polygons. Then add all of these fixtures to the body. There's an example of this in the Shape Workshop bundle.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.