PDA

View Full Version : Chipmunk physics released.


Skorche
2007.01.12, 12:02 AM
Chipmunk is the 2D rigid body game physics library that I've been working on for quite a while now. It's still not nearly feature complete, but I think it's to a point where it should be very usable.

Links:
ChipmunkDemo (http://aerosol.googlecode.com/files/ChipmunkDemo.tar.gz)
Static Library (http://aerosol.googlecode.com/files/ChipmunkStaticLib1.tar.gz)
Docs (http://epoxy.morris.umn.edu/~lembckesd/chipmunk-docs.html) (rough draft)
Source code (http://aerosol.googlecode.com/files/ChipmunkRelease1.tar.gz)

Edit: Brain fart! I seem to have forgotten to point out that the source download has the demo code, which would be highly useful to look at. I also didn't point out in the documentation that you only need to include chipmunk.h. (Though I expect people could figure that out pretty easily)

Also, I should point out more prominently that only collision is working (and quite well I might add :) ). I have not started implementing joints yet.

maximile
2007.01.12, 07:19 AM
Fantastic! This is almost as exciting as the Macworld Expo keynote!

I'm gonna have so much fun trying to get this to work for me. And the new demos are so cool! We get our own little version of the pile of dominoes!

Anyway, I'm very excited about this. It might be just what I needed to give me the impetus to finish off this 2D thing I've been working on.

Joseph Duchesne
2007.01.12, 07:22 AM
I would like to say nice work :D This engine has just about the same abilities as the one I coded for MadTak, the one difference being that you know how to code a physics library and at the time I had no idea what inertia was...

I think I might just pop my code out and your library in :D ... I was experimenting with using Newton, but it's really wasteful to use a 3D engine for 2D stuff.

One question though: does this library use some sort of quadtree initial collision check or is it bounding boxes or another method I've never heard of?

MacGoober
2007.01.12, 12:32 PM
Just a few days ago literally I was thinking about trying to work on this exact concept- a physics framework that would provide the math backbone for developers. Then I found this thread today randomly. Demo's look great, awesome work! :)

Frank C.
2007.01.12, 03:21 PM
Nice :D

The simulation looks very stable, and the speed is fantastic.

ThemsAllTook
2007.01.12, 03:39 PM
Awesome! Demos look really solid. I also really like the look of the API. I may try to put together something using this framework over the weekend...

Skorche
2007.01.12, 03:58 PM
Glad everyone is liking it so far. I hope it holds up to the hype.

One question though: does this library use some sort of quadtree initial collision check or is it bounding boxes or another method I've never heard of?

It uses spatial hashing actually. It's supposed to be more efficient than trees in the best case (O(n) instead of O(n log n)). The idea is that you have an infinite grid that you map onto a hashtable. Then you only check collisions with objects that overlap the same cells.

The code is in cpSpaceHash.c if you want to check it out. (No comments though, sorry. :blush: )

Duane
2007.01.12, 05:04 PM
great code should be self explainable anyway :D

Joseph Duchesne
2007.01.12, 06:28 PM
great code should be self explainable anyway :D

But this product nears completion... does great code ever near completion? ;)

Not in my experience :P

I hadn't heard of the spatial hashing method. I'm glad one of us it on the ball ;) Someone should be :P

AnotherJake
2007.01.12, 09:00 PM
Looks pretty neato, good job Skorche! :D

AndyKorth
2007.01.13, 05:34 AM
Skorche is a very clever guy.

Nick
2007.01.20, 08:39 PM
So I built the library from the source but when I try to actually use it I get this error:

/usr/bin/ld: Undefined symbols:
cpInitChipmunk()
/Users/nickgravelyn/Desktop/Spyscroller/build/Spyscroller.build/Debug/Spyscroller.build/Objects-normal/ppc/main.o reference to undefined cpInitChipmunk()
collect2: ld returned 1 exit status

I did link with the library and #included "chipmunk.h" so I'm not sure what the problem is unless somehow using Xcode I added the library to the file without actually linking it with the project. But it's in the Link With Libraries and Frameworks build phase, so I doubt that's it.

Skorche
2007.01.20, 09:26 PM
The static library shouldn't have any problems. It's used the build the demo application.

You might have to add the directory that the library is in under the library search paths build setting.

Nick
2007.01.20, 10:28 PM
I made sure to add the directory to both the library search path and framework search path. I've tried rebuilding the library as well as my project, but I keep getting the error. It's odd, because the demo does compile and run in the other project.

Skorche
2007.01.21, 12:38 AM
Turns out that Nick was using Chipmunk from C++ and forgot to put an extern "C" declaration around the Chipmunk header. I'll add this to the header for future versions.

Fenris
2007.01.21, 04:05 AM
An oddity: I've tried to download it numerous times over the past two weeks, but aerosol.googlecode.com has been unavailable every time?

Skorche
2007.01.21, 02:51 PM
Really? That's strange. Can you get to Google Hosting (http://code.google.com/hosting/) and search for "aerosol"?

Anyway, I put a temporary copy of the files here. (http://epoxy.morris.umn.edu/~lembckesd/ChipmunkTemp/)

Fenris
2007.01.21, 07:57 PM
I get to the http://code.google.com/p/aerosol/downloads/list page but skipping onwards to aerosol.google breaks... anyway, thanks! :)

Skorche
2007.01.30, 04:19 AM
Pin and pivot joints are working now. I also came up with another handy joint that I call a chain joint. It's like a pin joint, but it only constrains the bodies when they get too far apart. Expect an update soonish.

Also, has anyone actually tried Chipmunk yet in a project? Any comments/complaints?

Joseph Duchesne
2007.01.30, 07:23 AM
I'm planning on giving it a shot when I have some free time. Possibly as soon as thursday, definitely by saturday (presuming that life doesn't get in the way as it so likes to do).

I've looked at the library and poked through the source and I'm quite impressed with the end result :)

Fenris
2007.01.30, 08:20 AM
I will use Chipmunk for my coming project, but that won't be until summer... :/

Frank C.
2007.01.30, 03:57 PM
Also, has anyone actually tried Chipmunk yet in a project? Any comments/complaints?
Any chance you'll have a framework (preferred) or dylib target in the furture? A precompiled binary-only distribution would be cool too ;) That'd make it easier to interface with languages other than C - though I see you've included Ruby bindings as well.

Now I know I could get in there and set this up myself, but I'm lazy :sneaky:

Skorche
2007.01.30, 04:16 PM
Any chance you'll have a framework (preferred) or dylib target in the furture? A precompiled binary-only distribution would be cool too ;) That'd make it easier to interface with languages other than C - though I see you've included Ruby bindings as well.

I do have a precompiled static library in the download links.

I'm certainly not against offering a framework. I remember trying to build a framework a couple of years ago and not having a lot of luck. Though I really had no idea what I was doing at the time.

OneSadCookie
2007.01.30, 04:30 PM
Why on earth would you want a framework as opposed to a static library? o_O

Frank C.
2007.01.30, 06:09 PM
Why on earth would you want a framework as opposed to a static library? o_O
To access the library from REALbasic <ducks>.

I could alternately wrap up the static lib in an RB plugin but declaring out to a framework is easier to maintain/update and just less of a hassle all-round.

Skorche
2007.01.30, 07:39 PM
I think I'm more or less happy with the way that I have joints working so far. I'll probably write up some documentation later this week. Until then, I've updated the demo with to show off the new joints.

Link: Chipmunk Demo (http://epoxy.morris.umn.edu/~lembckesd/ChipmunkDemo.tar.gz)

The bridges are just different kinds of joints (pin, pivot, and chain), not very interesting. The vehicle uses pin joints and damped springs to get that nice soft suspension. (Dirt Bike anyone?)

Frank: You can use C libraries from REALBasic? How can it handle C data types?

Frank C.
2007.01.30, 08:43 PM
Frank: You can use C libraries from REALBasic?
Yup. I routinely declare out to FMOD Ex, OpenGL, and loads of system frameworks from RB - wouldn't be using it if I couldn't!

How can it handle C data types?
Newer versions of RB have C-compatible structs and most if not all the datatypes you'll need; signed/unsigned ints, shorts, 64 bit numbers etc., as well as direct conversion for all manners of strings. These were all possible to deal with previously using the memoryblock class but it was a bit of a headache at times. You can also implement callbacks from external libraries, so there's not much you can't do so long as the library supplies a flat C interface. Basically you re-write the C header declarations in terms RB can understand and call the library as usual - the only time this gets hairy is when API calls are actually macros, but those can be dealt with as well.

The new joints look sweet BTW :D

OneSadCookie
2007.01.30, 09:06 PM
If you have a static library libfoo.a, turning it into a loadable bundle is as simple as

gcc -all_load -lfoo -bundle -o foo.bundle

Frank C.
2007.01.31, 12:27 AM
gcc -all_load -lfoo -bundle -o foo.bundle
I new that Terminal.app was good for something... Turns out -dynamiclib works out better for RB though. Bundles can work too, but you have to use "soft" declares, and package the bundle in a framework (which isn't a big deal either way I guess).

Thanks for the heads up!

Skorche
2007.02.01, 02:05 AM
It's been a long time since I made a good interactive physics demo, so I couldn't resist posting this: MoonBuggy.tar.gz (http://epoxy.morris.umn.edu/~lembckesd/MoonBuggy.tar.gz)

Arrow keys drive, space bar flips the suspension if you get stuck. The terrain is randomly generated, so close and reopen it if it gives you a bad track.

It's programmed in Ruby so you can poke around at the source in Resources/main.rb. Oh, and ignore the strange textures, they were just the first things I had laying around.

maximile
2007.02.07, 10:41 AM
Also, has anyone actually tried Chipmunk yet in a project? Any comments/complaints?

Well, I'd complain that the documentation is insufficient for my noobish skillz. I'm slowly getting to grips with it by working through the demo code. The documentation seems to throw you in at the deep end a little. I'd like to see a tutorial, or at least a bit about what you actually need to do to get something working. What a "space" is, that sort of thing. Unless this is fairly common terminology, which, having not used a physics library like this before, I don't know about.

That said, I know that the documentation is actually very lavish when compared with most projects like this. And by doing lots of "command-double-clicking", I'm starting to understand it fairly well, I think. The way you've written it makes it really easy to see what does what, for which I am very grateful. Hopefully there might be some user-submitted tutorials coming as people start to work with it.

Anyway, I'm going to try to make a few demos of my own when I get a chance; that'll test to see if I really understand it.

And BTW, MoonBuggy is great fun. :) It's probably just a side-effect of how Chipmunk works, but I like how the wheel digs into the ground when it spins... like if you try to reverse up a hill that's too steep.

Skorche
2007.02.07, 02:57 PM
The documentation should be significantly improved for the next release, and I'm just about ready to do another release. I want to make sure that I'm happy with the API and that the docs are fully up to date. There are some slight API changes, and I want to make sure that they are for the better. I'm also adding documentation for the Ruby extension.

Making some well commented tutorials is an item on the to do list, but I haven't gotten around to it yet.

P.S. Actually, the wheel digging into the ground isn't supposed to happen. It only happens when the trailing wheel slips. I think it's caused by a combination of the pin joint and the spring. I suspect the damping in the spring force is to blame, but I'm not really sure.

Joseph Duchesne
2007.02.07, 04:01 PM
I went ahead and implanted it in a sub-screen in my game. I now have a block falling and hitting a slope. Fairly straight forward I suppose :). I was expecting an addForce function but that's only because I'm now used to APIs being uselessly complicated. I'm planning on replacing my own excuse for physics with this. Remarkably my "library" works a lot like yours, as far as functions are concerned. Of course on a technical level mine is slow, unoptomized, and ridiculously buggy. The biggest trick will be working everything in to the 40 or so C files that make up the game itself.

It wasn't "easy" to implement a little demo of my own, but it wasn't really hard either. Just a bit of poking around the docs and the demo. It could use a short tutorial to get people started with something that they can see. I can write one if you think that the API is "stable" enough to merit me taking the time to do so.

Another question: is this library written with cross platform in mind? Being a physics library I can't really imagine there being much to tie into the OS, but all the same I thought I might ask.

Duane
2007.02.07, 04:17 PM
it worked on linux for me!

Skorche
2007.02.07, 05:50 PM
There is no platform dependence to speak of. There's even a build script for the demos under linux. However, floating point math is performed differently on different architectures/compilers. Use Chipmunk to affect the gameplay, not run complicated animations and you'll be fine.