A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [SHOW]SLRBS/GLib update

  1. #1
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246

    [SHOW]SLRBS/GLib update

    As part of releasing GLib, the 2D geometry library I'm working on (http://board.flashkit.com/board/show....php?t=782032), I'll be releasing 2 libraries that use GLib.

    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.

    http://lab.generalrelativity.org/gli...toGen/car.html


    The image shows the Flash file, just a bunch of MovieClips arranged on stage. Here's the only code in the FLA:
    Code:
    import org.generalrelativity.slrbs.SLRBSimulator;
    
    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:

    http://lab.generalrelativity.org/gli...n/ragdoll.html


    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.
    Code:
    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.

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    so your main idea is to let the IDE work again as design tool- and reducing code as much as possible. Very nice idea and execution- cant wait to play with it once you release something.

  3. #3
    Senior Member Sietjp's Avatar
    Join Date
    Jan 2005
    Location
    Paris, France
    Posts
    711
    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.

  4. #4
    Senior Member chriserrorplain's Avatar
    Join Date
    Aug 2002
    Location
    london village
    Posts
    623
    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.


    ChrisError x

  5. #5
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    Excellent work. This is pretty much how the 3D game world has been dealing with physics engines, for almost a decade now. Designers can "physicalize" an object and assign parameters. Keep us posted!

  6. #6
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    yeah, really awesome stuff.

    I believe that every physics engine should have an editor, I guess using CS3 itself is a good way to go
    lather yourself up with soap - soap arcade

  7. #7
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    Thanks, I'll keep everyone up to date on it.

    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.

  8. #8
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    bump!

    so what happened to this? maybe upload to github or something?
    who is this? a word of friendly advice: FFS stop using AS2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center