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 ...)
Bookmarks