Chipmunk 2D Physics Module

BlitzMax Forums/Brucey's Modules/Chipmunk 2D Physics Module

Brucey(Posted 2007) [#1]
Just a short note to say I've finally built a proper release of the chipmunk module.

Chipmunk is a fast, cross-platform 2D Game Dynamics/Physics engine, written in C.

The module comes with 7 small demos that highlight the various features of the library.

You can download the module from here : http://maxmods.googlecode.com

Note : You *will* need to compile the module using my "tweaked" BMK, since the library source requires it to be compiled in a specific way. You can get the BMK source and instructions from HERE.
Hopefully this is only a temporary requirement (fingers crossed for 1.28... ;-)

As usual... please let me know if you have any issues or comments, and perhaps ideas for improvements.

:o)


grable(Posted 2007) [#2]
I did a checkout of your chipmunk module from svn, and there is a folder "chipmunk.mod" with the same content as the parent folder.
A mini commit "bug" perhaps? ;) hehe

Btw, module and examples compiled fine, cant wait to play with this when i have the time =)


nino(Posted 2007) [#3]
Thanks Brucey - this is exactly what Ive been looking for.


I was thinking of wrapping box2d but it's a bit @.@

Looks like Scott took the best parts of it (algos) for Chipmunk and you've done the wrapping.

happy times.


altitudems(Posted 2007) [#4]
Thanks for posting this, maybe people will actually see this now.

A quick look through this release, and I think cpBodySetTorque is still missing.

I have implemented this before, do you want the code?


Brucey(Posted 2007) [#5]
there is a folder "chipmunk.mod" with the same content as the parent folder.

Thanks.. my feeble attempt at tagging the code... guess I should pay more attention to the options :-p


Filax(Posted 2007) [#6]
Hi Brucey :)

Glad to see that ! but the problem is ? how to compile this
module ?

L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/chipmunk.c:22:20: stdlib.h: No such file or directory
Build Error: failed to compile

Note : My BMK is ok, and mingw installed correctly... :)

Any idea ?


Brucey(Posted 2007) [#7]
Hey Filax.. try commenting out that include for now... Is working fine here.
It was added recently to the library source, but as far as I know, it's a pretty standard header file.

Anyone else having trouble on Windows compiling the module?


LarsG(Posted 2007) [#8]
This is a great lib.. and it's blazingly fast!! :)


Chroma(Posted 2007) [#9]
I agree Lars. I think we found our 2d physics lib!


DavidDC(Posted 2007) [#10]
Working fine here on Leopard : ) Great mod Brucey!

- David


Filax(Posted 2007) [#11]
Hi Brucey :)

My mod install :
C:\BlitzMax\mod\bah.mod\chipmunk.mod (im wrong ?)

I have no other explains to say only this message :


Building Modules
Compiling:chipmunk.c
L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/chipmunk.c:22:20: stdlib.h: No such file or directory
Build Error: failed to compile L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/chipmunk.c
Process complete

MY MingW work correctly, and your new bmk was compiled with success and copied under the good directory

Or more simple, anybody can post a link with a PC compiled
version ? :)


Brucey(Posted 2007) [#12]
Hey Filax... try this :

change line 22 of src/chipmunk.c from
#include "stdlib.h"

to
//#include "stdlib.h"

And see if that works.

Are you the only Windows user then? :-p


Brucey(Posted 2007) [#13]
What it kind of needs now is a slightly higher level API to make building complex shapes easier etc.

Demo2 shows it's quite easy to draw an image where the shape is, since a Shape/Body exposes both its location/rotation, as well as the vertices and their rotations.


Brucey(Posted 2007) [#14]
A quick look through this release, and I think cpBodySetTorque is still missing.

Are you sure? I can't find that.

I added applyimpulse, slew, and applyforce recently.

Hmm... of course, you might just mean that I haven't exposed the variable for changing... ;-)


DavidDC(Posted 2007) [#15]
I just compiled and ran the demos in XP. What a fun module!

- David


altitudems(Posted 2007) [#16]
Brucey my apologies, yes there is no method for setting Torque in this release, there might have been before, I don't remember.

I do know that the buggy demo set torque in order to simulate motor functionality though.

So maybe you could just create a SetTorque method for the body class (granted you would need to expose it in glue somewhere).


Filax(Posted 2007) [#17]
Yes Brucey i'm windows only

So, for the problem i have try to remove all stdio.h under the
sources. But other problems are coming :) referring to other
missing include like math.h, string.h etc

Example:

L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c:23:18: math.h: No such file or directory
L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c:24:19: float.h: No such file or directory
L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c: In function `cpBodySetAngle':
L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c:90: `M_PI' undeclared (first use in this function)
L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c:90: (Each undeclared identifier is reported only once
L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c:90: for each function it appears in.)
Build Error: failed to compile L:/BlitzMax/mod/bah.mod/chipmunk.mod/src/cpBody.c


Brucey(Posted 2007) [#18]
maybe you could just create a SetTorque method

Added... will commit shortly :-)

Should we add the buggy demo to the module, do you think?


altitudems(Posted 2007) [#19]
Might be nice, but even nicer would be higher level API, like you mentioned.

I've been working on one in my free time.


Brucey(Posted 2007) [#20]
Filax, your MinGW isn't working properly.

Either your paths are wrong, or it is missing some vital files.
Did you follow Mark's instructions HERE to ensure you got all the packages you need?
It sounds, according to your error messages, like you are missing the headers - rather vital when it comes to building C/C++ :-)


Chroma(Posted 2007) [#21]
I got this working now and it's astounding and blazingly fast. I'm not gonna try to do anymore 2d physics code. I'll just spend my time working on actual games? Yeah that sounds like a plan.

Thanks Brucey. Superb work.

I vote this the Unofficial 2D physics solution for BlitzMax.


Jesse(Posted 2007) [#22]
works great here on WindowsXP no modifications other than replacing the bmk.
Thanks! for a great mod.


Filax(Posted 2007) [#23]
Hi brucey , i'm fighting with vista and mingw.... Bmax now
won't compile any module :(

http://www.blitzbasic.com/Community/posts.php?topic=72892

Anybody can tell me where i'm wrong ?


Chroma(Posted 2007) [#24]
This Chipmunk module is great fun! Now to just figure out how to get the rotation so I can put an image of a crate over the square box in demo1! And proper timing.


Ian Thompson(Posted 2007) [#25]
Filax did your remember this extra bit for Vista...

"An addition to Vista users. You must also create a new Variable called "MinGW" and set it to c:\MinGW.

After I did that I was able to build modules.

[edit] Under User Variables Click New and name it MinGW. Set its variable to wherever you installed MinGW."


Brucey(Posted 2007) [#26]
Now to just figure out how to get the rotation

Have a look at main2.bmx - drawPolyShape(). Shows getting the body position and angle.
Angle is returned in degrees, for your convenience.


Notes :
Objects like Body and Shape are reference counted for you, so you don't have to keep a reference to all of them yourself if you don't want to. Therefore, when you want to remove an object from the space you need to "free()" it. This will remove it properly from the space.
Note too, that you also need to free() all related shapes/joints too... perhaps this is an enhancement we can have later - whereby the module will free the related parts for you. At the moment, it mirrors the functionality of the library...
You also need to be wary *when* you free() something. For example, freeing an object from a collision function is not advised, since the library is still using them at that point. You should rather flag up that something needs freed and deal with it at the end of the DoStep()/update process.


Filax(Posted 2007) [#27]
Ian Thompson : I do ! :)

Anyone can post a compiled module for pc ? :)


popcade(Posted 2007) [#28]
MinGW on Vista need an extra %GCC_EXEC_PREFIX% thing.

http://wiki.codeblocks.org/index.php?title=MinGW_installation

Anyway this is the compiled from Brucey's distro:
http://icworx.org/_spc/chipmunk.mod.zip
(Keep for few days)


Difference(Posted 2007) [#29]
Great work.
Is the SVN checkout as up to date as the download?
I've really come to like SVN update, where I just rightclick the mod folder and update.
(I'm using TortoiseSVN on Windows, and scplugin on the Mac for anyone looking for easy to use SVN clients)


Brucey(Posted 2007) [#30]
Is the SVN checkout as up to date as the download?

SVN will always be the same or better than the latest available full release :-)


Filax(Posted 2007) [#31]
yoko : Many thanks ! Vars added correctly but i'm alway bugged
with vista :(

VARS :
GCC_EXEC_PREFIX => c:\MinGW
MinGW => c:\MinGW

PATH :
C:\MinGW
%GCC_EXEC_PREFIX%\libexec\gcc\mingw32\3.4.5
%GCC_EXEC_PREFIX%\lib\bin

i have try to add too:
%GCC_EXEC_PREFIX%\include

Great wrapper brucey :) very fun :)


Murilo(Posted 2007) [#32]
This is amazing stuff... Cheers Brucey!

BTW: Let's hope Mark uses your revised BMK in the next release.


Zeke(Posted 2007) [#33]
Filax, fix PATH, C:\MinGW\ to C:\MinGW\bin


Filax(Posted 2007) [#34]
Hi Zeke :) The problem continue... But i have find a temporary
alternative with blide :/ Fu.. Vista...


altitudems(Posted 2007) [#35]
Just in case anyone still needs it here is the compiled mod for windows:

http://www.gigasize.com/get.php?d=gj21cvkn55c

Edit: Nvm someone beat me to it.


xlsior(Posted 2007) [#36]
Looks very interesting, I'll definitely file a copy of that one away.

Hey, Brucey: Any chance of a good A* pathfinding mod at some point in the future? :-)


Brucey(Posted 2007) [#37]
Any chance of a good A* pathfinding mod at some point in the future?

Heh... there's actually a very fast algo on the forum somewhere, in Spanish. It uses arrays and whotnot, rather than Types based like the example that comes with BlitzMax.
I hacked it into a big tower-defense type game I made, and it easily handled a few hundred objects navigating a large maze.

But not really my forte though.
If you can find a lightning fast pathfinding library out there, I could always wrap it ;-)


Difference(Posted 2007) [#38]
SVN will always be the same or better than the latest available full release :-)

Great. Works perfectly on my Intel MacBook and Windows XP.


Sokurah(Posted 2007) [#39]
I think I need someone to take me by the hand and tell me what I'm doing wrong.

I've tried the compiled Windows versions posted by yoko and altitudems, but all I'm getting are the error;

Compile Error
Can't find interface for module 'bah.chipmunk'

It's placed in this folder which should be correct...me thinks...
C:\Util\BlitzMax\mod\chipmunk.mod\


Brucey(Posted 2007) [#40]
I should probably make the instructions on the module page better...

The path should be :

C:\Util\BlitzMax\mod\bah.mod\chipmunk.mod\


Sokurah(Posted 2007) [#41]
Thanks Brucey,

That helped...a little. Still doesn't work though.
Now I'm getting half a screen of errors saying 'undefined reference' to different things.

I'm still v1.24 running though. Will it help if I upgrade to v1.26?


nino(Posted 2007) [#42]
get 1.26 then go here
http://www.blitzbasic.com/Community/posts.php?topic=72892


CopperCircle(Posted 2007) [#43]
Hi, I have just brought BlitzMax and have no idea what im doing.
I copied the compiled mod thats posted above and then tried to build & run demo1.bmx but I just get: Build Error: failed to compile in Blide?

What am I doing wrong,or do I need to learn the basics first somewhere?

Thanks.


Sokurah(Posted 2007) [#44]
Thanks Nino,
The upgrade made it work...that'll teach me to update faster. :-) (the link don't work though)

Now the big problem is 'only' coming up with a game that could benefit from this. :-)


TaskMaster(Posted 2007) [#45]
Brucey, I compiled your bmk.exe and put it into my BlitzMax bin folder. Now, when I build all modules with BLIde, I get a bunch of popup console windows. One for each module that is building.

Is this something I can turn off?

Edit: Nevermind, I built it as a GUI app. After fixing that, it is no longer doing it.


Panno(Posted 2007) [#46]
he coppercircle

its not needed to know the bmax language to run the demos
same as in b3d if you know what i mean.
the demos must run without any language knowlege
but
its better to know what you do.......

dontknow about blide, but it must be work with the standard IDE

works here like a charme , runs smooth and looks cool

thx


Robert Cummings(Posted 2007) [#47]
This thing has never worked for me. I have the compiled mod, the compiled bmx. None of the demos work.


Robert Cummings(Posted 2007) [#48]
I have installed new mingw, rebuilt all modules, installed the bmk.exe which I compiled from your site and it still fails to build any example demo code.

Runs normal code fine.


TaskMaster(Posted 2007) [#49]
Did you install Chipmunk from their site?


popcade(Posted 2007) [#50]
That's strange...

the compiled version doesn't need MinGW to work unless you want to re-build

Did you put the module in
<BlitzMax_Dir>\mod\bah.mod\cipmunk.mod ?


nino(Posted 2007) [#51]
Brucey - did the fix to freeing shapes ever get pushed to http://maxmods.googlecode.com ?


(yeah- i know i could just go check but im lazy)


Brucey(Posted 2007) [#52]
Yep. There's a 1.01 release available with the latest fixes.


Russell(Posted 2007) [#53]
Holy cow! This is it, guys!

Mark, when this baby is completely beta-tested....

P L E A S E !!!!!

include it as part of the standard BMax distribution!

Anyone object to this course of action? Didn't think so ;)

Russell


verfum(Posted 2008) [#54]
I don't get it? Where is the actual Bmax module? with the bmx files? All I can download is the c version, or am I being silly?


verfum(Posted 2008) [#55]
Ah, I have it, needed to click on the download part, it doesn't go straight to it, so it's a little confusing :) It sounds silly but it had me running around in circles.


Raz(Posted 2008) [#56]
I don't suppose someone has a compiled example of this module? I'd be interested to see it :D (not on a suitable machine to install bmax)


verfum(Posted 2008) [#57]
It is already compiled in the downloads section, the google bit. Just download the file with win32 written on it.


verfum(Posted 2008) [#58]
This is a great looking physics engine, but it seems geared around sideways physics, what about top down physics, how hard would it be to do this? for example a top down car game. If it can are there any examples?

Thanks.


Raz(Posted 2008) [#59]
cheers verfum, but I mean like a running demo of what it can do (without having to compile from within bmax)


nino(Posted 2008) [#60]
This is a rough video of a new engine/framework I'm working on for future physle games.

http://www.physle.com/images/newengine.avi


verfum(Posted 2008) [#61]
Do all these 2D physics engines only come with side on examples?


Brucey(Posted 2008) [#62]
Certainly looks that way.

Doing top-down physics is a different thing altogether.
According to the author of Chipmunk it's perhaps not yet entirely suited to top-down games, but it's not impossible to do.

This ruby tutorial touches on doing top down with chipmunk : http://code.google.com/p/gosu/wiki/RubyChipmunkIntegration


nino(Posted 2008) [#63]
Chipmunk work pretty well for simple top down - just dial gravity down to zero. This was my first shot at using it for a simple billiards sim. Definitely primitive but maybe worth a look.




Armitage 1982(Posted 2008) [#64]
I'm having fun with Chipmunk !
Thanks a lot Brucey :)

Today i discovered box2D v2.0 (well almost feature complete for 2.0) as Chipmunk is inspired by (or based on) Box2D does this make it a more featured physic engine ?

Does anybody know the big differences between these engine ?

I wish i could try this by myself but there is no BlitzMax port actually.

The only 2 stuff i would like being optimized with Chipmunk is :
- Elastic shapes don’t stack well (known problem)
- No swept volume collisions (known problem)

Box2D is more often updated with big features and a bigger community too.
What do you think about it ?


Brucey(Posted 2008) [#65]
Perhaps it's worth wrapping it also.... to give us more choice? :-)


Armitage 1982(Posted 2008) [#66]
I don't know, since i don't have the talent require to do so...
But i would like to ! :-)
I'm reading the "old" manual right now and it's quite interesting.
By the way Brucey, impressive collection of modules!
If i knew at that time you would add wxWidgets i'll surely donate rather than buying MaxGUI...


Robb(Posted 2008) [#67]
Rather than start a new thread I thought I'd post this here...

I haven't really had a chance to explore the module yet but is it possible to use chipmunk in a scrolling game? would you have to move all physical bodies individually or can you move the physic space with the game world as it scrolls?


nino(Posted 2008) [#68]
you can absolutely use it in a scrolling environment.
The way i do it is through SetOrigin but there are a number of ways you could accomplish this. Chipmunk really stays away from any type of rendering routines so it's really up to you how you want to implement it. This is one of the things I really like about it.


Robb(Posted 2008) [#69]
Thanks for the reply :-)
It's funny because literally 5 minutes ago I also discovered that I could do this by altering the origin with SetOrigin. This looks to be such a versatile system. I'll definitely look into using it for a game project soon!


Armitage 1982(Posted 2008) [#70]
For those who wonder what big points Box2D v2.0 has to offer i can tell you this :

- Continuous Collision Detection (no more object passing through walls !!
- Callback Collision
- Bouncy object stack correctly (known bug of Chipmunk)
- Manual/wiki/Community and a nice roadmap !

I'm so impatient to play with this ^^


Yahfree(Posted 2008) [#71]
Any beginner tutorials with this? (confused at the moment, demo's don't make sense) but it certainly looks good!


Armitage 1982(Posted 2008) [#72]
I made a new entry on my blog about a "sand-box" software using Chipmunk.



http://arm42.free.fr/blog/index.php

Thanks a lot for your wrapper Brucey, i'm having fun ^^


Brucey(Posted 2008) [#73]
Nice demo :-)

I like the chain-links.


DavidDC(Posted 2008) [#74]
Yes, great demo. I could see that "squid" thing as the star of an R-type style shooter. The more powerups you have, the longer the tail. Well done!