Drawing concave shapes with Box2D in flash

After being stuck at using box2d, drawing clockwise polygons and concave shapes came a small break through when I bumped into an article and code by Paul Bourke, which was quickly ported over to ActionScript to solve two of my problems, which was to find if the vertices were ordered clockwise or counter-clockwise; and also if my polygon was convex or concave.
Original C source and explanation here: http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/clockwise.htm

My second problem was actually drawing those concave shapes. The concave shapes are actually triangular fixtures grouped together in a body. The code for triangulation actually came from Zevan Rosser
actionsnippet.com – http://actionsnippet.com/?p=1462. Armed with all these and some more digging, through changes in the new box2d and it was done ‘~_~ *phew*

Its still not perfect, there are bugs and you still can’t draw very complex shapes which overlap and possibly look like a meaning less scribble :B But as far as I wanted, it can draw closed shapes :)

Click and drag to draw, D to toggle Debugdraw

The current version has a lot of Flixel code in it, I’ll post the code as soon as I clean it up and make it more generic. More soon ^_^
Ok, so done with the clean up, plain flash and as3, box2d included as well, and removed all the Flixel dependencies, hope it helps :)

Download code here: https://github.com/yadurajiv/concaveShapes

  • Print
  • email
  • PDF
  • Twitter
  • Identi.ca
  • Google Bookmarks
  • Digg
  • del.icio.us
  • StumbleUpon
  • Ping.fm
  • Facebook
  • DZone
  • FriendFeed
  • Reddit
  • Technorati

7 comments to Drawing concave shapes with Box2D in flash

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">