PDA

View Full Version : Pascal Chipmunk Physics port



NoshBar
28-03-2008, 10:15 AM
Hey everyone.

I wanted to try using C OBJ files directly in Delphi, as described here:
http://rvelthuis.de/articles/articles-cobjs.html

I decided to use the Chipmunk Physics engine, as it's plain C (otherwise Box2D would've been it):
http://wiki.slembcke.net/main/published/Chipmunk

I got the files building with the free Borland C++ commandline tools, linked the objects in, converted the headers... but things went... a little weird thereafter. I kept getting random crashes.

So I took a look, and with all the headers already converted, I figured I'd just go ahead and port the rest of the code.

So that's what I've done, it's "working", it's got some glaring bugs (demo's 4 and 7), but it's alright to start working with already, I'd think.
It _is_ just a direct port of the C code, and so isn't very Object Pascal-like, but as with the bugs, I'll be improving that situation over time if people are interested too.

So, get it here:
http://www.tisfat.pwp.blueyonder.co.uk/programmy/index.html

Huehnerschaender
28-03-2008, 01:44 PM
If it is Chipmunk that you are after and not the problem to use the C module in Delphi, then I'd like to point you to a thread at DanJetX forums, where a user named "Light" compiled the Chipmunk physics library into a small DLL and currently writes a Delphi wrapper to easily use it.

He also posted a demo which shows some of the very nice Chipmunk features.

I guess he will update this soon and finally posts source code (currently only demo exe and dll)

You might also want to directly contact him at the forums.

Here is the link:
http://www.ericbehme.de/phpBB2DAN/viewtopic.php?t=506

Robert Kosek
28-03-2008, 02:09 PM
Chipmunk is astounding. :shock: I certainly hope one, or both, of you succeed in making your headers for Chipmunk!

Edit: WAIT, FPC can compile inline C can't it? I think it can... :think:

NoshBar
28-03-2008, 02:28 PM
Huehnerschaender: thanks, I didn't know anyone else was doing something Chipmunk related, handy to know!
Chipmunk _was_ kind of just the victim of me having fun with C OBJ's in Delphi though :)

Robert Kosek: I had no idea FPC could do that... *sigh*, I really should read before I go off on insane one night coding sessions... I'll go read up on it now.
(P.S: not sure if I explained it properly, but I've actually converted all the code from C to Pascal, so there wouldn't be a need for the DLL at all, and effectively, I do have all the headers converted right now, sorry if I'm misunderstand you now)

Meh, I stand by my first reason for doing this: fun. It might seem wrong, but I had fun converting it, it helped me learn a lot about the engine itself, and now using it is super easy.

Regardless, thanks for the comments!

Robert Kosek
28-03-2008, 02:50 PM
I don't see what you've done as being wrong; native language ports are always welcome, especially if you keep them maintained. Under the MIT license I think that you are permitted to port the code, if you retain the original copyright. The MIT license is very liberal in what you can do with it.

I thought you meant that you were compiling objects into the application like folks do with Zlib and BZip2. There is a Pascal port of Zlib, but not BZip2 unfortunately.

I would be very interested in trying this out in the next 2d game I write. Must there be gravity, or could you run Chipmunk in space?

NoshBar
28-03-2008, 03:01 PM
Right, I have a tendancy of abusing the English language beyond comprehension, sorry.

I _was_ trying to link in the OBJ files to prevent me from porting it, but then saw how little code there was, and ditched the OBJ idea.

Chipmunk lets you set gravity, and when initialised, is 0, so basically space from the word go.

Robert Kosek
28-03-2008, 03:16 PM
Right, I have a tendancy of abusing the English language beyond comprehension, sorry.Uh, I was actually skimming real quick and missed the fact that you said you ditched the OBJ data. My error, not yours. Your English is excellent.

Thank you for your work in making a native port for Chipmunk. I will be trying this out sometime soon. ;)

Brainer
28-03-2008, 06:48 PM
I think you might like it:
http://www.sendspace.com/file/8ewkb7

NoshBar
28-03-2008, 08:46 PM
Awesome! Thanks Brainer, I always trust other people's code over my own :D

FreePascal doesn't seem to like some things in it, but that's easily fixed.
It also includes chipmunk.inc, but I'm not sure if that's even necessary, it looks pretty complete without it...

Anyway, I am truly grateful, ta!

Brainer
28-03-2008, 08:46 PM
No probs, man! :D I'm glad it can be of any help to you. :)

Robert Kosek
28-03-2008, 09:06 PM
This is good news. Now to learn how to use Chipmunk and make something with it. :)

Brainer
28-03-2008, 09:09 PM
I think you'll like it, Robert. :)
http://www.sendspace.com/file/x151lj

Robert Kosek
28-03-2008, 09:24 PM
Goodie! This'll be easier than I feared. In fact, this'll be downright easy and fun to learn.

Edit: Awesome resource. I had to dig around on my HD for DOT again, but this is going to be fun to learn.

savage
29-03-2008, 09:48 AM
Very cool stuff. Brainer, could you please post something in the "Your Projects" forum about this, so I can promote it to a news item. Thanks.

Brainer
29-03-2008, 10:01 AM
Savage, it's not my project. :) Anyway, I'll post something. :)

NoshBar
29-03-2008, 04:35 PM
*sigh*, where did I go wrong in this post? From converting the entire engine and all demos myself in the first post, to having someone else's version making news?

I'm feeling quite bummed now, I really wanted to help and make a difference.

Oh well, suck it up and move on I suppose.
Anyone needing anything done that I could possibly do? :P

savage
29-03-2008, 04:44 PM
Don't be too hard on yourself. Might be an idea to post something on these forums first before starting on such a beast. That way you can be fairly sure no-one has already worked on it.

If you are seriously looking for something to fix, there is a slight bug in my and Marteen's translation of Cal3D to Pascal. I've looked through the code several times but could never spot what we did wrong. Considering it was about 95% working it seems a shame to leave it that way. Maybe a fresh pair of eye,s like yourself, could make the difference. And if you are feeling really energetic, you could always update it to the latest version.

You definitely made a difference as it's now front page news, so more people are aware of both yours and the other translation.