Results 1 to 10 of 12

Thread: Simple Chipmunk Physics

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Okay, I guess I can initialize chipmunk, but again... In demo11 the drawing is done by
    Code:
      cpDrawSpace( space, TRUE );
    which means I have to "break down" the source of ZenGL. What if I would add a "ball" with your procedure
    Code:
    procedure cpAddBall( x, y, r, mass, e, u : cpFloat );
    how do I know where to draw the circle when physics were calculated. Assuming my procedure looks like
    Code:
    circle (x,y,radius)
    and my engine is purely procedural driven which means I have to establish a game loop like
    Code:
    repeat
      key=getkey();
      //do all the stuff
    until key=27;
    How can I get the x and y value of my ball?
    Best regards,
    Cybermonkey

  2. #2
    Ok, since no one can answer me, I'll post here an example from Freebasic
    Code:
     ''
     ''  My first chipmunk simulation
     ''
     #include "chipmunk/chipmunk.bi"
     #inclib "chipmunk"
     
    const as cpFloat mass = 5.0, radius = 10 ' Mass and radius values for our circle - you can play around with these
     const as cpFloat dt = 60.0 / 1.0 ' The delta time for physics calculations
     
    dim shared space as cpSpace ptr ' The space where the simulation takes place
     
    screenres 800, 600, 16 ' Setup the screen
     
    cpInitChipmunk() ' Initialize chipmunk
     
    space = cpSpaceNew() ' Create a new space
     space->iterations = 10 ' 10 Iterations per step
     space->gravity = cpv(0, 50) ' Gravity x = 0, y = 50 
     
    dim shared circleBody as cpBody ptr ' Circle body
     dim shared circleShape as cpShape ptr ' Circle shape
     
    ' Create a new circle body
     circleBody = cpBodyNew( mass, cpMomentForCircle( mass, 0.0, radius, cpvzero ) )
     circleBody->p = cpv( 400, 0 ) ' set the circle at the top-middle of the screen
     cpSpaceAddBody( space, circleBody ) ' add the body to the simulation
     
    ' Crate a new circle shape
     circleShape = cpCircleShapeNew( circleBody, radius, cpvzero )
     cpSpaceAddShape( space, circleShape ) ' add the shape to the simulation
     
    do
       screenlock()
         cls
         locate 1, 1: print "The ball should fall down into a bottomless pit"
     
        circle( circleBody->p.x, circleBody->p.y ), radius, rgb( 255, 0, 0 )
       screenunlock()
     
      ' Advance the simulation
       cpSpaceStep( space, dt )
     
      sleep 1, 1
     loop until multikey(&H01) ' Loop until Escape is pressed
     
    ' Cleans up everything associated with this space
     cpSpaceFreeChildren( space )
     cpSpaceFree( space )
     
    end 0
    So I will try to port this to FreePascal. (Of course there's still a timer missing but one step after the other ...)
    Best regards,
    Cybermonkey

  3. #3
    and my engine is purely procedural driven which means I have to establish a game loop like
    ZenGL is also fully procedural.

    How can I get the x and y value of my ball?
    Is it so hard to open zglChipmunk.pas and look to cpDrawSpace(and cpDrawShape), which is used in Draw function of demo11?

    // sorry for late answer...

Bookmarks

Posting Permissions

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