Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

2D physics

BortelsBortels Mod
edited November 2011 in Suggestions Posts: 1,557

Was just poking Love2D, and noticed it has a 2D physics engine.

Just sayin.

So, while it would be keen to have one built-in (add it to the ever-growing list), I'm wondering just how nasty a Box2D translation to lua would be (like they did for javascript). Hmmm... I may have something to do after my current project (still working on vector fonts - nutty, I know).

Comments

  • JohnJohn Admin Mod
    Posts: 788

    Hi there, I'm the physics guy at Two Lives Left (see Crabitron). I've started integrating Box2D into Codea and it works pretty well. At the moment I've only got circle's and no contact events. Here's the example I'm working with at the moment.

        body = nil
        ground = nil
        -- Use this function to perform your initial setup
        function setup()
            print("Hello Physics World!")
            body = circleBody(WIDTH * 0.5,WIDTH * 0.5,100)
            body.restitution = 0.9
            body.radius = 50
            ground = circleBody(WIDTH * 0.5 + 5, 100, 100)
            ground.type = STATIC
        end
    
        -- This function gets called once every frame
        function draw()
            -- This sets the background color to black
            background(0, 0, 0)
            noFill()
            strokeWidth(5)
            if body then
                stroke(255, 0, 0, 255)
                pushMatrix()
                translate(body.x, body.y)
                rotate(body.angle)
                line(0, 0, body.radius, 0)
                ellipse(0, 0, body.radius * 2, body.radius * 2)
                popMatrix()
            
                if CurrentTouch.state == BEGAN then
                    body.y = body.y + 100
                end
            
                if body.y < 0 then
                    body = nil
                end
            end
        
            stroke(255, 183, 0, 255)
            ellipse(ground.x, ground.y, ground.radius * 2, ground.radius * 2)
        end
    

    You basically just create a circleBody with a position and radius. You can then set any other property. We are also looking at having polygonBody as well, which will have an inline editor for editing the vertices, as well as automatic convex decomposition. We will also probably have a compositeBody, which can combine several basic shape bodies.

    Let me know what you think.

  • BortelsBortels Mod
    Posts: 1,557

    I think that's totally cool, is what I think. I never messed with Box2D past the circles/rectangles stuff - no links or chains or joints or such - so what you describe would keep me busy for a while. It sounds very much like you're on the right track.

  • Posts: 11

    I hope the b2world object ref will be accessible so that we could set its gravity interactively.

Sign In or Register to comment.