dcsimg
A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 57

Thread: [WIP] 2d rigid body physics engine

  1. #21
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    thanks for the catch, jasonpeinko

    http://lab.generalrelativity.org/foam/circle/

    here's a new demo with circles- it was cool to have circles behave like wheels just by tossing them into the engine... left and right arrow keys to spin the wheels.

    still no optimizations- it'll still eat your computer alive!

  2. #22
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    yeah nice one, now release that source

    please
    lather yourself up with soap - soap arcade

  3. #23
    Member
    Join Date
    Aug 2007
    Posts
    61
    Quote Originally Posted by newblack
    still no optimizations- it'll still eat your computer alive!
    omfg theres smoke coming out the back of my computer...

    But seriously - very nice. Why RK4 instead of Verlet? I wish there was a good profiler out there - I'd love to know where the AVM2 spends its time and where best to make improvements. Have you tried running the simulation with no graphics?

  4. #24
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    *sniffle* I flung my car out of bounds to it's death. Then I reloaded and it was back. *happy*

    Too bad my 'in my head' physics game is probably too weird to work with any existing engines. I am probably not smart enough to make my own either, but who knows, maybe one day.

    Gotta to hit my physics books and read up again on angular momentum, vector transformations, and sliding/rolling friction, collision response...

  5. #25
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,928
    Another great bit of work. It seems nothing very cool gets posted here for ages, and then we get a few in one big sweet go.

    As to the profiler rje, I've heard lots of good things about the one with Flex3, but I've not tried it yet as Flex3 projects aren't backwards compatible with Flex2, it's still in beta ( Which times out ) and life's too busy atm to make even more work for myself.

    Squize.

  6. #26
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Still not detecting my player...
    http://www.birchlabs.co.uk/
    You know you want to.

  7. #27
    Senior Member
    Join Date
    May 2006
    Posts
    145
    hummm.. nice one

    I agree looks very stable and it runs smooth and fast in my laptop.

    If you can make this sophisticated engine, and if you want to make rope and spring, I think a 2D liquid and rag doll (interconnected objects) is not far ahead. do you ever think of improving your engine to an extent where it can handle even an arbitrary collision like
    and could you make a level designer for you engine, it would give us LOTS of fun.

    nonetheless, very good job!

  8. #28
    Senior Member ozmic66's Avatar
    Join Date
    Oct 2005
    Posts
    472
    These are very impressive demos, very cool to see this in actionscript.
    As you might know, I also love physics, and I've been working on a rigid body solver myself... (see blog in my sig)

    If you don't mind, I have some technical questions

    I've seen you use an rk4 integrator, but how do you solve collisions? constraint/impulse/penalty based?

    What's your friction model like?

    Thanks for the great post
    Always nice to see some new and innovative things here once in a while

    - Oz
    Pixelwave Flash-based iPhone framework
    iPhone Games: Flyloop | Freedom Run

    Twitter: Oztune

  9. #29
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    Geez, you make a few sponsored games, get some favourable reviews, and start to think you're actually not a bad programmer, then something like this comes along and you realise "Nope. Still crap"

  10. #30
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    thanks again everyone- here's a high-level roadmap for those interested:

    1. adding a few more geometrical features first: cubic and quadratic bezier curves, capsules and lozenges.

    2. implementing a coarse and fine collision detection scheme (instead of blind, brute force)- spatially with quadtrees/simple grids and geometrically with bounding areas.

    3. component objects- this will lead to contextual coarse collision detection via bounding volume hierarchies.

    4. attempting to implement a global contact solution...

    5. contingent on 4, improve friction

    6. release a quiet beta

    @ozmic66/rje --> integration:
    ok, first the easy answer to why rk4 instead of verlet/euler- it's sturdier and more accurate. but a huge goal of mine was to make solvers completely swappable. it allows you to use different solvers where you deem fit. for instance, in the case of constraints, a much more accurate result is obtained from RK4- but something less "volatile" might only deserve Euler....

    ok, the harder question- forces/collisions etc.: the difficult part (from an implementation standpoint) of using a great numerical integrator like rk4 is that to be worthwhile, all forces have to be accumulated from within the step. it's unrealistic/painstaking to even imagine finding/resolving collisions also- it would run even worse than it does!

    so i allow collisions (which are handled via impulses) to get integrated a few times each step- semi-pseudo code of it looks like this:

    Code:
    var i:int = Engine.SOLVER_ITERATIONS;
    while( --i )
    {
    
       for each( var solver:ISolver in solvers )
       {
          solver.step( dt / Engine.SOLVER_ITERATIONS );
       }
    
       resolveCollisions();
    
    }
    contact friction also gets applied via impulse in the collision solver. there's a TON i want to do to improve friction but for now it's just applying an impulse that's opposite the relative tangential (to the collision normal) velocity at the contact point scaled by the colliding objects' coefficient of friction.

    @ArielGenesis-->
    i think that there's no decent way of generalizing a collision scenario like the one in your image. objects that complex would just need to get abstracted anyway.

    @VENGEANCE MX-->
    what browser/player no. are you using?

    @EvilKris-->
    lol. i guarantee it's nothing spectacular compared to a successful, well-written game!

  11. #31
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    Quote Originally Posted by newblack
    2. implementing a coarse and fine collision detection scheme (instead of blind, brute force)- spatially with quadtrees/simple grids and geometrically with bounding areas.
    yes, thats something which lacks in every engine I've seen.
    lather yourself up with soap - soap arcade

  12. #32
    Senior Member
    Join Date
    May 2006
    Posts
    145
    I dont really understand what you are doing but that is the best physics engine i ever saw so far... Not only accurate, but also realistic in the terms of mass and gravity and acceleration.

  13. #33
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    916
    fun fun fun


    I thought trees are only good for static scenes, otherwise re-building it would kill the benefits.
    Last edited by realMakc; 09-03-2007 at 07:57 AM.
    who is this? a word of friendly advice: FFS stop using AS2

  14. #34
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    here're cubic bezier curves implemented- this will be the last update before spatial partitioning gets thrown in (left and right arrow keys to spin the ball):
    http://lab.generalrelativity.org/foam/bezier/

    i've done a lot of structural reworking and am getting happier with the syntax, so i thought i'd share the implementation for the demo above:

    Code:
    //creates a new instance of the engine
    var foam:Foam = addChild( new Foam() ) as Foam;
    			
    //static elements
    //walls -- RigidBody( x, y, mass, geometry )
    var ceiling:RigidBody = new RigidBody( 400, 0, Number.MAX_VALUE, ShapeUtil.createRectangle( 800, 20 ) );
    var floor:RigidBody = new RigidBody( 400, 500, Number.MAX_VALUE, ShapeUtil.createRectangle( 800, 20 ) );
    var leftWall:RigidBody = new RigidBody( 0, 250, Number.MAX_VALUE, ShapeUtil.createRectangle( 20, 500 ) );
    var rightWall:RigidBody = new RigidBody( 800, 250, Number.MAX_VALUE, ShapeUtil.createRectangle( 20, 500 ) );
    			
    //curve -- CubicBezierCurve( x, y, control 1, anchor 1, control2, anchor 2, geometrical resolution );
    var curve:CubicBezierCurve = new CubicBezierCurve( 110, 400, new Vector( -100, -200 ), new Vector( -100, 90 ), new Vector( 100, 90 ), new Vector(), 9 );
    //incline 
    var incline:RigidBody = new RigidBody( 670, 470, Number.MAX_VALUE, [ new Vector( -320, 20 ), new Vector( 120, 0 ) ] );
    			
    //adds elements to the engine for simulation
    foam.addElements( ceiling, floor, leftWall, rightWall, curve, incline );
    			
    //dynamic elements
    //ball -- Circle( x, y, radius, mass )
    var ball:Circle = new Circle( 60, 100, 50, 70 );
    //adds a force generator for key-driven angular acceleration of ball
    ball.addForceGenerator( new KeyDrivenTorqueGenerator( stage ) );
    			
    //adds the ball to the engine for simulation
    foam.addElement( ball );
    			
    var i:int = -1;
    while( ++i < 3 )
    {
    	//add a triangle, square and pentagon to the engine for simulation
    	foam.addElement( new RigidBody( 600 + 20 * i, 120, 60 + 10 * i, ShapeUtil.createSymmetricPolygon( 3 + i, 35 + 10 * i ) ) );
    }
    			
    //run the simulation
    foam.run();
    as you might imagine there's a lot more that can be set/specified but the bare bones stuff does a better job of presenting the syntax i think. a lot of helper classes will be included when i release it to make some of the mundane stuff a bit more bearable...

    curious to hear your thoughts- thanks!
    Last edited by newblack; 09-08-2007 at 03:31 PM.

  15. #35
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    916
    Quote Originally Posted by newblack
    left and right arrow keys to spin the ball
    this looks like wheel, not ball. make a car demo?
    who is this? a word of friendly advice: FFS stop using AS2

  16. #36
    Senior Member
    Join Date
    Dec 2005
    Posts
    426
    I am very impressed by your engine, and how fast you come out with updates, and how well it runs. Keep up the good work man.

  17. #37
    Senior Member Alluvian's Avatar
    Join Date
    Jun 2006
    Posts
    967
    In about 1-2 years, when you get kidnapped by some guy with a DarthVader mask, we can save a lot of explanation if you just start explaining how to implement the engine to that person in the DarthVader mask. Carry the engine around in a flash drive actually, it will save everyone involved some cab faire, and you would not BELIEVE how hard it is for someone in a DarthVader mask and with a hostage to hail a cab! Not that I would know.

    This DarthVader masked person will let you go once they figure out how to use the engine, so no worries.

  18. #38
    Senior Member
    Join Date
    May 2006
    Location
    Manhattan
    Posts
    246
    @realMakc
    balls spin too! i'll have a new demo before too long

    @jasonpeinko
    thanks!

    @Alluvian
    i'm afraid i have no idea what you're talking about!!! must i be kidnapped?

  19. #39
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    916
    balls spin in 2 planes. wheels - in 1
    who is this? a word of friendly advice: FFS stop using AS2

  20. #40
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    916
    check out this quad tree thingy; author says he'll be testing grid version soon.
    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