PDA

View Full Version : Chipmunk release 3


Skorche
2007.03.20, 09:07 PM
The long promised Chipmunk release 3 vaporware has appeared!

Chipmunk wiki page (http://wiki.slembcke.net/main/published/Chipmunk)

Download:
http://files.slembcke.net/chipmunk/ChipmunkRelease3.tar.gz

MoonBuggy Tutorial:
http://files.slembcke.net/chipmunk/tutorials/MoonBuggyTutorial.tar.gz

SVN repository: (I should really create a separate project for this.)
http://aerosol.googlecode.com/svn/trunk/Chipmunk/

Improvements include:

Performance improvements. I got between 20-50% speed improvements in my demos. The stacking box demo can now run at over 1000 steps per second on my G5! (no graphics of course)
Collision layers: Shapes now have a layer bitmask. Objects don't collide unless they are in one or more of the same layers. Transitioning between layers is as simple as flipping bits.
Collision exclusion groups: Shapes also now have a group id. Shapes in the same non-zero group don't collide with each other.
Thick segments shapes: Segment shapes now take an additional radius parameter when instantiating them, allowing you to have nice rounded capsules.
Re-definable precision: All floating point numbers now use the cpFloat type. If for some reason you want to use doubles instead of floats, you can simply edit the chipmunk.h header and recompile.
Fixed a major bug that would cause shapes to attract each other when new shapes were added to a space.
Other minor bug fixes.


API changes:

The arguments for cpCircleShapeNew() and cpCircleShapeInit() have been rearranged to be more consistent with similar function calls.
cpSegmentShapeNew() and cpSegmentShapeInit() now take an additional radius parameter.


I didn't really proofread anything very carefully, so yell at me if I've said something dumb in the docs.

Lastly, does anyone have any ideas for a logo? I'd like to have a logo that people can put on their splash screens, but I can't really think of anything good.

Leisure Suit Lurie
2007.03.20, 09:11 PM
Improvements include:

A major bug that would cause shapes to attract each other when new shapes were added to a space.

...
I didn't really proofread anything very carefully, so yell at me if I've said something dumb in the docs.

You improved it by adding a major bug? :p

Careful with the logo you choose, or this man (http://www.nicholson.com/rhn/basic/) may sue.

Skorche
2007.03.20, 10:32 PM
You improved it by adding a major bug? :p

I guess your logic is sound. I'll fix the bug then. I figured people might find it interesting is all. :wacko: Oh the joys of saying stupid things.

AnotherJake
2007.03.21, 02:03 AM
...Lastly, does anyone have any ideas for a logo? I'd like to have a logo that people can put on their splash screens, but I can't really think of anything good.
I don't know, but a simple side profile of a chipmunk, hunched over and munching on something (like a nut) in solid black on a small white square background would probably work. Trying to associate something to do with physics isn't necessary. As an example, the Apple logo doesn't have spit to do with computers! A chipmunk is easy to remember and associate with the product all by itself.

igame3d
2007.03.21, 04:44 AM
do what designers do
Pick your favorite pose (http://images.google.com/images?client=safari&rls=en&q=chipmunk&ie=UTF-8&oe=UTF-8&um=1&sa=N&tab=wi) and process in image editor until you have high contrast logo, or particularly appealing cartoon caricture.

Oooh I know, I really fine model dressed in a Chipmunk suite.
..er...or something. (http://images.google.com/images?svnum=10&hl=en&safe=off&client=safari&rls=en&q=chipmunk+costume&btnG=Search)

kelvin
2007.03.21, 06:25 AM
I got a good idea for a logo. I'll whip something up when it's not odd hours.

Skorche
2007.04.01, 03:14 AM
So I finally got around to getting a web host instead of serving the Chipmunk stuff from the university CSci server. You can check out the new wiki page here (http://wiki.slembcke.net/main/published/Chipmunk).

I'd also like to thank Frank Condello (kelvin?) for the Chipmunk logo.

kelvin
2007.04.01, 03:17 AM
I didn't send you what I came up with, and no, I'm not Frank.

Edit: Which reminds me... I did end up finding time, I should send this to you...

kelvin
2007.04.01, 04:15 AM
http://variableaspect.com/holding/ChipmunkPhys128.png
Fireworks Originals (http://variableaspect.com/holding/Chipmunk Phys.zip)

Frank C.
2007.04.02, 04:38 AM
For the record, I'm the Frank in question - though I thought my user name would be a dead giveaway ;)

Also, there's no need for a logo copyright notice on the wiki - it was a gift!

kelvin
2007.04.02, 04:59 AM
though I thought my user name would be a dead giveaway ;)

No kidding huh. ;)

Edit: BTW, my full name is Kelvin Nishikawa.

igame3d
2007.04.02, 05:07 AM
Its good stuff.
I started looking at the wiki and stopped getting work done, and its 2AM

..rrrr rodents.

Nice logo.

Skorche
2007.04.02, 05:26 AM
Frank: I guess I can see the connection now. :rolleyes: Thanks again.

kelvin: I'm rather satisfied with Frank's logo, but yours nicely fills some of the white space on the wiki page. I tried putting a screenshot there, and it just didn't look right. Thanks to you as well.

Documentation:
I figure at this point that I should work on providing better documentation for Chipmunk. I was thinking about using Doxygen as it provides rather fancy cross-linked output. The downside is that the output seems poorly organized for C programs.

Does anyone know any viable competition for Doxygen? I looked around for a while, but it seems to be king in the C world.

kelvin
2007.04.02, 05:34 AM
no problem, feel free to do whatever you like with the pngs. It was really just a nice diversion for me.

PowerMacX
2007.04.02, 10:50 AM
Doxygen seems more oriented towards C++. I haven't used other doc generators but if you are going to use it to generate graphs too (include and/or call graphs for C-only code), I highly recommend installing Graphviz (http://www.graphviz.org/) instead of the default dot & neato command line tools (produces nice, antialiased graphs using Quartz)

reubert
2007.04.03, 12:43 AM
I'm thinking of using this for my current project. None of the demos seem to show how to move things though. Is it OK to just update something's position or velocity myself every frame? I tend to like to grab the velocities/positions from the physics engine, then change them a bit depending on keys / world constraints then hand them back. Is that sort of scheme OK? Or do I need to do only apply forces?

Looks great though, I have been trying to push the demos to their breaking points and am impressed so far :) much better than my pathetic attempt at 2D physics!

Skorche
2007.04.03, 03:07 AM
Setting the position of an object every frame can lead to dark places, but changing the velocity or force is game.

It's all in the docs (http://files.slembcke.net/chipmunk/chipmunk-docs.html), there are some relevant notes at the end of the cpBody section, as well as in the Mysteries of cpSpaceStep() explained section.

reubert
2007.04.04, 02:54 AM
Thanks Skorche, I missed that notes section sorry, you're right it was all there.

I'll let you know how I get on :)

Skorche
2007.04.04, 03:07 AM
No problem. There's a lot to take in, and poorly organized documentation to take it in from.

I should probably start a FAQ as that's been asked several times.

reubert
2007.04.04, 04:34 AM
A couple of things. I am using this in a C++ project, and the compiler barfed in cpBB.h saying that cpBBNew(..) was declared extern and later static, so with my limited knowledge of integrating C with C++ I commented out the extern declaration and now seems OK.

Also there is no header guard so I ended up with multiple declaration errors, so (again.. don't really know what I'm doing) I added a header guard to the chipmunk.h file.

Looking good though :) Think at this rate I might be able to replace my whole physics engine within a few hours :D

Skorche
2007.04.04, 05:22 AM
Oh, lightbringer pointed the extern/static problem out to me today (yesterday?). That was definitely a whoops on my part. The extern declaration was supposed to disappear, and GCC didn't complain about it.

I haven't used C++ in a while, what is a header guard, and should I be adding it to the Chipmunk header myself?

reubert
2007.04.04, 05:44 AM
A header guard basically just stops headers (and their declarations) from being included multiple times. I guess C might allow multiple declarations and C++ not. I added to the top:

#ifndef CHIPMUNK_H
#define CHIPMUNK_H

and to the bottom:
#endif

Duane
2007.04.07, 11:51 AM
Yea, it's generally common practice in C++. I've adopted it in C as well, but I'm not sure it's needed.

BTW, this is turning out excellently! I'm actually using this in a small(?) project for fun, as well as a larger project (Catapults!).

OneSadCookie
2007.04.07, 11:57 AM
Yes, it's needed in C just as much as in C++.

lightbringer
2007.04.07, 02:22 PM
Is there a good reason to use #ifndef over #pragma once?

I just like condensing that down to one line.

AnotherJake
2007.04.07, 02:38 PM
Well, pragmas are implementation defined, so it wouldn't be guaranteed to work from compiler to compiler. That's the only reason I can come up with anyway.

OneSadCookie
2007.04.07, 07:53 PM
AFAIK, all the major C compilers (GCC, MSVC, XLC, ICC) implement #pragma once compatibly.

That said, I prefer the header guards -- you can play a few tricks with then (like convincing the compiler a header has been included when it hasn't) that you can't with #pragma once.

skyhawk
2007.04.09, 02:43 AM
First time user:

Uhhhh, my objects are being added to the space. They are drawing. But they are not moving. (when I print stamp every frame, it is indeed incrementing.) I am using a dt of 1.0/60.0.
Any other information or whatever that might be needed?

Here is my function that is adding my objects to the space:

void waterBallFactory(double x, double y)
{
cpBody* waterbody = cpBodyNew(1.0,cpMomentForCircle(1.0,watersize,wate rsize,cpvzero));
cpShape* shape = cpCircleShapeNew(waterbody, watersize, cpv(x,y));
shape->e = .25;
shape->u = 0;
cpSpaceAddShape(space, shape);
}

Skorche
2007.04.09, 04:26 AM
I ended up talking to Skyhawk offline. His problem was twofold.

The reason nothing was moving was that he wasn't adding the waterbodies to the space. That was the simple part. The hard part was figuring out why things exploded after that was fixed.

He was also setting offset of the circle collision shapes to the intended positions of the objects instead of the positions of the rigid bodies. It took me over an hour to catch that. :wacko:

The corrected code was:
void waterBallFactory(double x, double y)
{
cpBody* waterbody = cpBodyNew(1.0,cpMomentForCircle(1.0,watersize,wate rsize,cpvzero));
waterbody->p = cpv(x, y);
cpSpaceAddBody(space, waterbody);
cpShape* shape = cpCircleShapeNew(waterbody, watersize, cpvzero);
shape->e = .25;
shape->u = 0;
cpSpaceAddShape(space, shape);
}

reubert
2007.04.21, 07:40 PM
Well it's taken a total of about 2 hours and I have most of my game engine switched over to chipmunk and it's working beautifully. I was pleasantly surprised to find that I could even set both the rotation and the rotational velocity for a body each step.

One thing that I used to do that I can't seem to do now is to scale and flip objects. This is necessary to allow for a rotation around the y axis. I think I might have to make a couple of different objects and cut between them or something. I'll see how it goes.

Anyway, cheers, it looks a lot more natural than it did before.

Skorche
2007.04.21, 11:23 PM
I was pleasantly surprised to find that I could even set both the rotation and the rotational velocity for a body each step.

Yeah, as long as you are careful about it, it should be okay. The rotation isn't going to be quite as picky as the position.

One thing that I used to do that I can't seem to do now is to scale and flip objects. This is necessary to allow for a rotation around the y axis. I think I might have to make a couple of different objects and cut between them or something. I'll see how it goes.

I thinks that's the best you are going to be able to do currently. In order to make things fast, I wanted to be able to pre-compute as much of the collision information as possible. Considering that the collision detection is pretty fast compared to the constraint solver in most cases now, maybe that was a mistake?

Aressera
2007.04.27, 03:46 PM
So i'm in love with the sequential impulses constraint solver. I've read a few books on physics programming and all of them use an LCP solver. I've done a java implementation for fun and to help understand it before I transition to 3D/C++.

Skorche, I think your implementation is better than Erin Catto's (faster, more robust). The only problem i've encountered is that i can't seem to get kinetic friction to work, no matter what I do. It's not my contact point generator and everything seems right except the simulation. I've basically copied CP's algorithms verbatim. any suggestions?

Skorche
2007.04.27, 06:25 PM
Could you expand upon what you mean by that exactly? Friction just doesn't work period, or it causes other problems?

Do you have the source available anywhere? I could take a look at it.

Aressera
2007.04.28, 05:31 AM
everything else works perfectly except for friction. i do notice that there seems to be some sort of static friction that varies with my changes to the coefficient of friction. I'll see if i can post up some code, but its seriously just a java port of your arbiter code and i've gone through it looking for errors 20 times at least.

don't worry about it just yet though. probably just something really stupid on my part...

Aressera
2007.04.28, 10:33 PM
yep, my stupidity is to blame.

The problem was that in my visibility classes when I converted the rotation of a body to a 2 by 2 matrix i converted from "degrees" to radians for the trig functions, when i was really just converting radians to radians^2. Thus because i was using only circle bodies and they weren't rotationg properly I though that there was no friction bla bla bla. so yeah, works now and worked before, just couldn't see.

Skorche
2007.04.30, 03:33 AM
I've certainly never done that. :sneaky:

reubert
2007.05.02, 04:54 AM
Just thought I'd let you know that I have successfully compiled and run Chipmunk on windows using Visual Studio. There were a few hoops to jump through. From memory:
- All variables within a function need to be declared before any function calls are made, or something like that. So I had to move a lot of variables around
- (Struct){foo, bar} doesn't work, so I had to initialize structs the long way.
- 1.0 / 0.0 gives a divide by zero error so I had to fool the compiler into giving a valid infinity
- Warnings were generated wherever something like 4.0 was assigned to a cpFloat. I added f's to the end of all hard coded constants

I think thats about it, but I'm planning on double checking everything and then creating a dll, so I can send it all your way if you like, or I can go a bit further and make sure the same source still compiles on OSX. The only problem is that the declaring variables at the top of the function thing makes the code look horrible. Also, I guess that adding f's was wrong, perhaps type casting to cpFloat would be better.

reubert
2007.05.02, 05:05 AM
Oh, and the ruby bindings for shape are missing the group methods ;)

OneSadCookie
2007.05.02, 06:27 AM
I'd guess that writing the float/double selection as something like

#if defined(CP_DOUBLE_FLOAT)
typedef double cpFloat;
#define CP_FLOAT(c) (c)
#else
typedef float cpFloat;
#define CP_FLOAT(c) (c##f)
#endif

then using the CP_FLOAT macro everywhere for constants would be the right solution. Certainly GCC generates pretty poor code for float x = 3.0 so it's desirable to have the fs.

The two features MSVC doesn't like are GCC extensions to the C89 standard, so it's perfectly justified in freaking when it sees them. My suggestion there really would be to use MinGW for the windows compile instead of MSVC ;)

PowerMacX
2007.05.02, 09:24 AM
About the variable declaration, check this:
http://edndoc.esri.com/arcobjects/8.3/GettingStarted/.%5CVCppEnv.htm#Variable_declaration

Nonetheless, I certainly remember being bitten by this:

for (int i=0;i<x;i++)
{
....
}
...
for (int i=0;i<y;i++) // Error in Visual C++: the first "i" was magically declared at function scope (!?!?!)

OneSadCookie
2007.05.02, 09:59 PM
For-loop variable declaration is a C++ feature, not a C (until C99, which MSVC doesn't support) feature. Just for clarity.

The scope bug in MSVC 6 was annoying and silly, but had a very simple fix:

#define for if (true) for

:)

maximile
2007.05.07, 12:05 AM
What would be the best way to confine a body to a line, but with some springiness?

I'm trying to do a breakout-style game, and I want the paddle to be free to move horizontally but only give a little in the y axis and quickly spring back to rest. Is this something I could use the cpDampedSpring() for? I was planning to do something similar for the mouse control as well - make the paddle "spring" towards the mouse, but only in the x direction.

Skorche
2007.05.20, 10:25 PM
So I've been MIA for the last couple of weeks while graduating and job hunting. Sorry about that.

reubert: Wow, I figured it would be much simpler than that to get Chipmunk to compile. Does MSVC really not support C99? I've actually been moving in that direction :(. Thanks for the effort though. I wouldn't mind putting up an unofficial Windows build on my site.

maxamile: You could try it with springs, but it would be more difficult. You could certainly give the paddle a nice wobble bouncy appearance this way. Attach a pair of springs to the ends of the paddle and anchor the other ends of the springs to a static body that is locked to the mouse motion. (or just update the anchor points accordingly.)

I think what I would do though is to set the position (and the velocity!) of the paddle in the horizontal direction explicitly every frame. In the vertical direction you could just calculate a simple spring force.

OneSadCookie
2007.05.20, 10:39 PM
Does MSVC really not support C99?

Nor does GCC, really, it just supports enough of it to fake it for many uses...

AnotherJake
2007.05.20, 11:56 PM
So I've been MIA for the last couple of weeks while graduating...
Well, congrats on the graduation!:)

Duane
2007.05.27, 08:31 PM
yea, I don't know a compiler that DOES support C99... sadly.

Skorche
2007.06.26, 02:32 AM
Possibly exciting news: I'm talking with someone interested in adding support for his swept collision code to Chipmunk. No more need to be careful with small/fast objects! http://www.gamedev.net/community/forums/topic.asp?topic_id=452779

In return, he wants a build solution for Chipmunk on Windows. (also good to have) There was mention of MinGW being the easiest solution earlier in this thread. If anyone can help out... (puppy dog eyes)

maximile
2007.06.26, 08:30 AM
Sounds like great news!

unknown
2007.06.26, 10:21 AM
swept collision code

YES YES YES YES!!!!!!

Joseph Duchesne
2007.06.27, 10:03 AM
I can help with anything that needs doing. I'm implementing chipmunk in my game, which is crossplatform (Mac+PC). I can't say my physics programming experience is that great, but I'm a decent programmer otherwise. What needs doing?