Connection between Chipmunk and Pymunk

Discuss new features and future development.
pwagner
Posts: 21
Joined: Wed Mar 23, 2011 1:59 am
Contact:

Connection between Chipmunk and Pymunk

Post by pwagner »

Hey there,

I'm in research for a project to calculate some object motion based on a physics engine. My starting point is the game 'Block Builder' which is written in python using pygame which is preferable as I'm a python developer. Therefore I'm trying to figure out if the Pymunk project is still under active development or not? Maybe some of you can answer this.
While I already did a little investigation I found a post about a semi-automatic translation of Chipmunk to Pymunk (Output seems to be the file _chipmunk.py). Maybe this is under active development, but where are the differences in this two and is it still semi-automatic or in the mean time fully-automatic?

Thanks in advance
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Connection between Chipmunk and Pymunk

Post by slembcke »

viblio, the guy that made Pymunk seems to post fairly regularly here so I'm guessing it's not a dead project. I don't know how actively it's maintained though. I never really written games in Python before.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pwagner
Posts: 21
Joined: Wed Mar 23, 2011 1:59 am
Contact:

Re: Connection between Chipmunk and Pymunk

Post by pwagner »

Thank you for the information. That would have been another try to contact the developer of pymunk directly.

Maybe you are able to help once again. As it seems the OLPC project did a comparison of chipmunk and Box2d (respectively their python wrapper) a couple of years ago (Link). They also draw the conclusion that pymunk could benefit of an interface generated with SWIG. So my question is: Is chipmunk SWIG compatible or the other way round does it use non ANSI C style?

Best regards
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Connection between Chipmunk and Pymunk

Post by slembcke »

No idea. I think I used SWIG once like 6 years ago to make a Ruby binding for something. The output was pretty useless, so I made a binding by hand instead. Chipmunk should be SWIG-able, but it uses a number of static inline functions. I'm not sure how SWIG handles those. I think Pymunk uses an FFI library which is probably a bit slower, but makes a more sane API. I'm not really sure.

Oh, also that OLPC page is waaay out of date. Comparing an unspecified version of Chipmunk (presumably with Pymunk?) from ~2007 and the code the used is long gone. Here's a more recent comparison based on the benchmark code I have in trunk:
https://spreadsheets.google.com/ccc?key ... y=COOb4o8N

I like those numbers better, and Chipmunk 6 will improve performance even more. ;)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
pwagner
Posts: 21
Joined: Wed Mar 23, 2011 1:59 am
Contact:

Re: Connection between Chipmunk and Pymunk

Post by pwagner »

Good evening.

Looks pretty interesting. The next step for me is the compilation of the python wrappers and hope the results will be the same. Therefore it would be nice if you could provide the code you used for the benchmark.

Best regards
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Connection between Chipmunk and Pymunk

Post by slembcke »

Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
viblo
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm
Contact:

Re: Connection between Chipmunk and Pymunk

Post by viblo »

Hello! While the development of pymunk is not as fast as it was in the beginning its still not in any way dead. I actually checked in a bugfix last Sunday :) I try to monitor what happens with pymunk at least once a week (google pymunk, last 7 days) and try to be quick to answer any questions, comments or bugreports I find. However, if you really want a quick response to something, then its usually best to either add it as an issue report on the pymunk google code page (as it sends me an email), or email me directly at vb @ viblo.se

That post you found is a bit outdated now. Let me outline how pymunk works today:
I have a script, generate_bindings.py (in the tools folder in svn), that when run on the source of chipmunk creates the _chipmunk.py low level binding file. This file is ready to use, however it is not very convenient as it is just a straight low level binding from the C-code. Therefor pymunk has another layer on top of that, which transforms the C style API into something that feels more pythonic to use. (My goal with pymunk is to make it feel like it was all coded in python, and that it should not be visible that a C library is in the bottom, except for the speed gains)

To actually interface with the C code _chipmunk uses ctypes, the FFI standard library that is part of the python distribution which can interface with dynamic c libraries directly. This has some advantages that I like
  • It is part of the standard library
  • you don't need to compile anything special for python, as long as you have the C library you want to call in a dll (or .so or .dylib on linux/osx)
  • It is quite cross-platform between python versions. (both different versions of the standard runtime 2.6,2.7 3.0 and so on, but also for example pypy)
  • You only write python code to interface with the C library, no special markup, no extra c code and so on.
  • Because of it being only python code that any python programmer can understand, everyone that is using pymunk should be able to read its code if necessary.
  • It is easy to understand, not so much magic happening
  • It is easy to compile everything, as the only thing you need to worry about is the c library (Chipmunk in the case of pymunk, which is very easy to compile)
  • No extra dependencies, python + a compiled library is all you need
The main disadvantages I can see is that the speed is probably a bit slower than other binding methods. However, I don't see it as a really big problem as I think that most time spent in an physics application will be in the actual physics simulation, or outside in the rest of the application in for example drawing and logic. I have not done any real speed comparisons between ctypes and other binding methods, but I have done tests in the python code that indicates that the limit is almost always in other parts of the application even for worst-case type of applications.

Except for the speed another disadvantage is the autogeneration, it is quite basic in ctypes. On the other hand you don't get a perfect python style library from any binding system without a fair amount of work, and with ctypes it's at least easy to understand what's happening and how to work with it.

Before I created pymunk I tried using SWIG a bit (worked a bit on a plugin to pyogre, the python Ogre binding), and I have also looked at other ways to do FFI, but I like ctypes best so far :).
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
pwagner
Posts: 21
Joined: Wed Mar 23, 2011 1:59 am
Contact:

Re: Connection between Chipmunk and Pymunk

Post by pwagner »

Another question I wanted to find out but could nowhere find an explicit answer: What solvers are you using in your code. I read something about semi-implicit Euler solver for speed an stability, so is this the "one" you are using? If so what is the magnitude speed gain and of error compared to a fully implicit Euler solver?

Best regards

BTW: Hope you can understand everything because I'm still not used to write in english. Till now everything worked fine without english :D
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Connection between Chipmunk and Pymunk

Post by slembcke »

It's just regular Euler. 90% of the time when people have problems with Euler it's with springs. I deal with that by providing a damped spring constraint that solves the spring as if it were semi-implicit Euler while retaining the benefits of regular Euler (objects at rest don't move from having gravity integrated into their position).

The choice of vanilla Euler has to do more with stability of the physics than speed or reducing error. The amount of time spent integrating positions is trivially small compared to the contact/constraint solver.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
aisman
Posts: 145
Joined: Tue Mar 04, 2008 2:21 am
Contact:

Re: Connection between Chipmunk and Pymunk

Post by aisman »

slembcke wrote:I like those numbers better, and Chipmunk 6 will improve performance even more. ;)
Is the Chipmunk-6.x branch ready for using?
Is this 6.x early version faster as the 5.3.4 branch?
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests