The first library will be SLRBS (Super Lightweight Rigid Body Simulator lol). I know, I know, the last thing anyone needs in the Flash world is another physics engine, but it has its charms. When I wrote my first engine, FOAM (http://blog.generalrelativity.org/?cat=12), the overwhelming response was from people who wanted to know how to "make my movieclips physics" (i swear to god that's a direct quote). I also noticed that a huge percentage of a physics engine is purely geometrical... So GLib offers means to turn DisplayObjects into a geometrical model.
SLRBS uses GLib to create the geometry for rigid bodies. So what it boils down to is creating a rigid body physics simulation with one line of code. Of course the user will have a lot of control over physical properties etc, but there's a generic simulation startup that should be stupidly easy to use. I even downloaded a trial version of Flash to try it out (where the hell did this wonky panel setup come from? ick).
Here are 2 demos, sorry no interactivity until i clean up the physics quite a bit:
The first is a car rolling off a ramp and through tires and footballs.
The image shows the Flash file, just a bunch of MovieClips arranged on stage. Here's the only code in the FLA:
var simulator:SLRBSimulator = SLRBSimulator.createSLRBSimulatorFromContainer( this );
addEventListener( Event.ENTER_FRAME, onEnterFrame );
function onEnterFrame( event:Event ) : void
simulator.step( 1 / 60 );
And that's it! You pass in the DisplayObjectContainer to build the simulation from and it handles all the creation for you. It uses some defaulting arguments. Most notably is how it builds the car. There are intersection types for how the simulation setup deals with MovieClips that intersect. The default, and what's used here is to pin the top MovieClip to the bottom at its determined center of mass. So each of the wheels get pinned by their centers to the car.
Next is a ragdoll, hanging on and getting beaned by tires and footballs too:
Again, you can see the MovieClip setup as it exists on the Stage in the IDE. The only difference in the code between the 2 is the ragdoll passes an overlap type that builds pin joints at the center of the intersection, which works well for building a quick ragdoll.
var simulator:SLRBSimulator = SLRBSimulator.createSLRBSimulatorFromContainer( this, SLRBSimulator.ACO_PIN_AT_OVERLAP_MEDIAN );
There are 2 other overlap types, complex, which just builds rigid bodies with a combination of intersecting shapes and ignore which will let them start the simulation there.
I still have a lot of work before I'll be happy releasing it, but it was a ton of fun to drag a bunch of MovieClips onto stage and watch them come to life with barely any code. But I totally think the most interesting aspect is that it uses the geometry library well enough that the whole of SLRBS is probably only 200 lines of code if you strip out all the OOP.
Awsome job, and the concept of bringing movieclips to life is strong enough to make this physcis engien very popular.
Maybe that would have been also a good option to make a BOX2D plugin because many devs already knows how it works.
I agree, it looks great and would be excited about getting to play with such a thing. Fellow FK'er _Ric, wrote a kind of half way house to this for a game we worked on before, where by movieclips where placed on stage (and rotated, scaled etc) then on run, they were deleted and replaced with same size rigid bodies, if that makes sense.
I'll release it when I get it a little more robust and able to handle peculiar situations, etc. It's kinda buggy in the specific shape recognition part, ie. successfully determining that it's a circle requires some arbitrary constants, reducing a convex set so that it's a neat and tidy triangle, or just a line segment, risks ending with a poor hull or loss of convexity (when n > 3).
I thought about doing this for Box2D also, but the whole point at first was to use my geometry library; so it does... which means I'd have to rewrite the geometry aspect also or something that ports my geometrical model to Box2D's.