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
[...] This post was mentioned on Twitter by JuwalBose, yadurajiv. yadurajiv said: Drawing concave shapes with Box2D in flash – http://chronosign.com/rant/yadurajiv/2011/01/694 [...]
[...] Drawing concave shapes with Box2D in flash random sketch-a-thon [...]
Thank you so much! I have a very long time looking for a solution to this problem, and thanks to you now in my game will be easy editor!
p.s. Sorry for my bad English. :)
Glad to hear it helped :) do ping me, if you get time, when your game is out; would love to see it :)
thanks very much.
would you provide me the C++ source code? thanks in advance.
AS3 is pretty close to c++. The box2d stuff is very very similar! I hope you can read through the code and understand as I’m not sure when I can write a c++ version of the same or something similar; it should be trivial though. Will update it if I get to write something soon :) Thanks for reading.