Anyone want to work with me on chipmunk physics?

BlitzMax Forums/BlitzMax Module Tweaks/Anyone want to work with me on chipmunk physics?

altitudems(Posted 2007) [#1]
Some of you may know that I have been working on 2d physics mods for a while now. I also had a go ad porting a few c++ libraries including Erin Catto's Box2d. It just isn't very easy for me to interpret c++ code and all the maths involved.

However, because I am unsatisfied with current available solutions and my own systems, I would like to try this again.

I propose a community project to port (or wrap) the Chipmunk physics library:
http://wiki.slembcke.net/main/published/Chipmunk

Are there interested people here, who could give some time to this project? Should we try? Could this be a successful community project?

Your thoughts please. :)


Gabriel(Posted 2007) [#2]
Why port it? It's got a pure C API, according to the docs, so you should have no trouble calling a compiled version from BlitzMax. You might have to wrap the C-structs as BlitzMax types, and you could perhaps write a nice BMax style OO interface to it for those of us prefer that, and that's about it. If you're familiar enough with C++ to even attempt porting them ( I couldn't! ) then you should be plenty capable of wrapping it up.


altitudems(Posted 2007) [#3]
Well, I did consider just wraping it in a BMAX module, but I think we could end-up with more flexibility if we just ported it. Also its not straight C, its actualy C99, so I wonder if there would be any issues. Anyway it shouldn't be hard to port, there are really only ~9files if you merge the .h and .c files. I've actualy already started porting things, its pretty easy. My plan for now is to port everything verbadim, and then when that is working, make a nice OOP implimentation.


Gabriel(Posted 2007) [#4]
Yeah, I realize it's not pure C, but the API it exports is pure C, so you don't have any name-mangling issues and it wouldn't have to be recompiled in order for BlitzMax to be able to use it. But yeah, I'm sure you're right that it's more flexible if ported, but porting is probably beyond my rudimentary C++ skills ( I always forget that C trig functions use radians! ) so I'm afraid I won't be any help.


Brucey(Posted 2007) [#5]
Also its not straight C, its actualy C99, so I wonder if there would be any issues.

Other than compiling it with the appropriate compiler flag set, it should just work.

It's probably better to wrap rather than port, imo. It should be faster that way - at least when it comes to the core engine - rather than having to deal with Max's GC.


altitudems(Posted 2007) [#6]
hrmmm... ok I may look into just wrapping it then. Your advice is has a lot of experience behind it. Also there is supposed to be a 4th release soon so it would be easier to keep things updated with a simple wrapper. Thanks!

Ok so first step would be to compile it to a static library, and the next start externing functions in blitz right?

Can you tell I haven't tried this before?
I'll take a look at some code done by you and others.


Brucey(Posted 2007) [#7]
Hallo again,

I've had a quick go at wrapping it, and so far I have demo1 running (a box falling down some stairs).
Compiling the source directly into the module - can't be doing with static libs really.

And it magically appears to work on all three platforms...


LarsG(Posted 2007) [#8]
@Brucey:

I have to say... either you neglect sleep, or you've found some way of getting more hours out of a day!! ;)


Brucey(Posted 2007) [#9]
Nah.. what with Eskom's idea of power management (rolling power-cuts, or as they call it "load shedding"), I've had to resort to the Powerbook over the last few days, so I thought it would be fun to do some proper Mac development for a change... and with chipmunk beginning with "C" it means re-compiling the module is quicker than waiting for "W" (wxMax).

Demo2 is running also, now. A ball and some more boxes.

Rather than have Blitz draw the boxes/circles using DrawLine etc (which is slow), I decided to draw images instead for the demos... which is more likely the end-use for the module anyways.

Next stop, Demo 3...


altitudems(Posted 2007) [#10]
Brucey, I didn't expect that, wow thanks!

Can't wait to start using this.


Oddball(Posted 2007) [#11]
Wow this looks good. What's the license like for this? Can it be used commercially? Any chance you could zip it up and send me preview of what you've got so far Brucey? I'm always interested in seeing new physics code.


altitudems(Posted 2007) [#12]
Yes, it can be used commercially. And i think you could even add new features, change a few things and sell it under a new name if you wanted to. Its got a pretty liberal license.

The only gotcha right now is that, there is still no swept collision. So for fast moving objects you will need to use workarounds.


Steffenk(Posted 2007) [#13]
Any news on this subject would be appreciated. I hope Brucey releases something like a first preview soon. We should split up the work somewhat, maybe using some kind of repository (Sf.net/GoogleCode) or so.


altitudems(Posted 2007) [#14]
Sounds good to me, I'm looking forward to working on this too. I was working on porting the code, but since the king of modules decided to help wrap the engine, I decided to wait.

Brucey, can you give us some code? I would like to help with documentation or whatever else. I would also like to work on some OOP implementation.


Brucey(Posted 2007) [#15]
Sorry for the 5 day delay... :-)

I've put the code up here : http://maxmods.googlecode.com/
(available via svn for now, until we get to a point for release)

Demos 1-6 are working, and I'm currently implementing joints etc to get demo 7 up and running.

Notes:
Rather than compile up a separate static library, I'm compiling the source with the module directly.
This means that the module requires compiling with the gnu99 flag set, which in turn means that you'll need to compile it with my "tweaked" bmk. Details are on the site.

I've also hacked Chipmunk in places to tie BlitzMax objects and their Chipmunk counterparts paired. But that's just under-the-hood stuff that you don't need to know about to use it :-)

It has been tested on Linux, Mac and Windows. It appears to function the same on all three platforms.

Have a look and see what you think...


fredborg(Posted 2007) [#16]
Demos work like a charm! Another great wrap from Brucey :)


Brucey(Posted 2007) [#17]
Thanks ;-)

Just committed joints support and a working Demo7.


The Chipmunk demos assume the origin is in the bottom-left corner, so I've had to (try my best) to invert y coords and reverse shape vert orders, to get it working with the origin at the top-left.


fredborg(Posted 2007) [#18]
It seems to work correctly as well. The joints are not drawn, but I guess they shouldn't be :)

Very well done.


altitudems(Posted 2007) [#19]
Very good job Brucey, I didn't think it would take that much glue. There are a few missing commands still, but its getting really close. I might post some more examples soon.

Thanks!


Brucey(Posted 2007) [#20]
Yep. It's just about there, me thinks.

Some docs still to fill in also, and I image, some more work once the next version comes out.


Brucey(Posted 2007) [#21]
Updated repository.

Implemented the paired collision functions, and amended Demo1 to show it in use.
Also filled in some of the other gaps and added more of the documentation.

:o)


xlsior(Posted 2007) [#22]
Looks interesting...


MGE(Posted 2007) [#23]
"Notes: Rather than compile up a separate static library, I'm compiling the source with the module directly.
This means that the module requires compiling with the gnu99 flag set, which in turn means that you'll need to compile it with my "tweaked" bmk. Details are on the site."

If a noob decided to have a look, is there detailed directions, procedures, for them? (me?) Thanks!


Brucey(Posted 2007) [#24]
It may seem a large amount of effort to go through to get at the code for now, and if you don't really want to go to all that effort, you may prefer to wait a little longer...

However.. ;-)

To get the source (until it's feature-complete enough to earn a proper release), you'll need a subversion client.

This page : http://code.google.com/p/maxmods/source
Has links regarding getting and using a subversion client, as well as the URL you would use to download the code.

This page : http://code.google.com/p/wxmax/wiki/WhatToDoWithBmk
Is a short guide to downloading and building the custom BMK exe. Remember to backup your current one before you copy over it with the new one (just in case).

The module (chimpunk.mod) should be placed so that it fits into the following directory structure :
  BlitzMax/mod/bah.mod/chipmunk.mod

Then you just need to build modules, and try running the provided demos.


altitudems(Posted 2007) [#25]
Looking good, thanks for your efforts. There are still a few missing commands though, I have them added here locally.

Most notably in the body class:
cpBodyApplyImpulse
cpBodySetTorque
cpBodySetMass
cpBodySetMoment
cpBodySlew

I'm having a go of porting the buggy demo, and some of these are necessary to do so.

I think I will also start working on making this easier to plug into existing blitz games. So possibly some conversion to the blitzmax coordinate system, more complete object drawing, and image drawing, shape creation etc.

I have several other unreleased mods that have been waiting for a better physics system, and this might be what they need. I would just need to integrate them.


Brucey(Posted 2007) [#26]
So possibly some conversion to the blitzmax coordinate system

The demos already use a top-left coordinate system, although origin is centered on the screen.
The original used a bottom-left origin, I just inverted Y on everything.

I'll try and sort out all the missing functions.


altitudems(Posted 2007) [#27]
Just in case anyone missed it version 4.02 was released by the author of Chipmunk Physics.


Brucey(Posted 2007) [#28]
we have bindings for version 3, with 4 coming soon.

Actually, I've been keeping the source reasonably in sync with the svn repository. Most of the recent changes have been to makefiles and whatnot...


altitudems(Posted 2007) [#29]
Well I guess your on top of it then :)

Why am I not surprised.

Awesome, thanks!


Chroma(Posted 2007) [#30]
Ok nm. Chipmunk is the bomb. Looked on your goodlecode thing Brucey but couldn't find any source etc.


verfum(Posted 2008) [#31]
Did the missing functions get added? I'm trying to use body.applyImpulse and I'm getting no resluts? :( Or is there a special way of doing this? And examples perhaps.