1. ## Simple Chipmunk Physics

Hi,

I feel a bit stupid, but is there anyone who could explain me how to implement the chipmunk physics in a Pascal program? I know there is cpInit etc. But let's assume I just want to have a ball which "bounces" and it is drawn with a simple circle function. Could anyone post some (pseudo)code which explains when I have to do the drawing? And how to "init" the physics system?

2. Hmmm, demo11 from ZenGL maybe can help you with initialization of Chipmunk, and drawing... anyway it will be easy to translate into other engine/API As soon as I resolve a problem with translated Chipmunk demos into Pascal for Linux(using pure OpenGL and glut), I will add them to my Chipmunk Pascal binding - chipmunk-pascal.

3. 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?

4. 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

' Crate a new circle shape
circleShape = cpCircleShapeNew( circleBody, radius, cpvzero )

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()

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

5. 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?

6. Originally Posted by Andru
Hmmm, demo11 from ZenGL maybe can help you with initialization of Chipmunk, and drawing... anyway it will be easy to translate into other engine/API As soon as I resolve a problem with translated Chipmunk demos into Pascal for Linux(using pure OpenGL and glut), I will add them to my Chipmunk Pascal binding - chipmunk-pascal.
A bit incomplete though, with libraries for Windows and Linux but not Mac. Also, a simple demo would be helpful.

(And I am saying that just because FPC interfaces to Chipmunk Physics sounds really, really useful so I really want to try it!)

7. A bit incomplete though, with libraries for Windows and Linux but not Mac. Also, a simple demo would be helpful.
Mmm? And what is libchipmunk.5.3.2.dylib in bin directory do you think? This library, and simple demo, you can find with ZenGL(demo11). Unfortunately I have no time to finish that chipmunk demos, about which I said before.

8. Maybe so but I was referring to what I found at the chipmunk-pascal link.

9. Maybe so but I was referring to what I found at the chipmunk-pascal link.
In chipmunk-pascal svn you can find libchipmunk.dylib too.

10. Two days ago I took another look at the Chipmunk physics. Well, I made some progress, as you can see here (using my SDL based egslengine):

However, I have a problem on Windows 32bit with the static linking (FPC 2.6.0) using the latest headers by Andru. Issue is
Code:
```Target OS: Win32 for i386
Compiling physictest.pas
physictest.pas(124,1) Error: Undefined symbol: _cpInitChipmunk
physictest.pas(124,1) Error: Undefined symbol: _cpMomentForCircle
physictest.pas(124,1) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted```
Any idea?

Page 1 of 2 12 Last

#### Posting Permissions

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