Posted in Projects on September 23rd, 2008 by sHTiF
I got back recently to one of my older research AS project that i did a while ago based on Box2D flash port Box2DAS3 lib 1.4 but since there is already version 2.1 of that library out i decided to discard it and create it from scratch using Flex. Its simple application with some potential, it automatically assigns physics attributes to any object you draw and binds it to the simulation world. Thats why the simple title, PhysIT!
The main problem in this application was to create the polygons from the drawn line, you cant simply store the mouse positions into an array and create polygon accordingly. Doing it this way may encounter 2 major problems.
First the array will be large and the polygon precision unnecessary complex. I resolved this using an algorithm that goes over all points and merge 2 adjancent points that are too close to each other. This algorithm is recursive since going over all again once is sometimes not enough ;)
Second and greater problem is that you can draw non-convex (concave) object which the physics engine simply cant process. I solved it first time by figuring out a fast triangulation algorithm (those that already made tristrips in OGL will know), but this time i decided on a different algorithm that simply takes non-convex object and breaks it into two or more convex objects as we know from geometry this is possible after all in worst scenario you can end up with triangles.
Ok, if you are interested in anything i mentioned just ask in forums, its way too complex to post algorithms here. Thank you.
Latest version: DEMO TEMPORARILY REMOVED
Forum Link: PhysIT forum topic
Be aware that you need to draw the objects CW becouse doing it CCW will result in possible bugs.
This is alpha version just for fun there may and will be errors ;)