Page 1 of 1

is there a limit to the size of a cpSpace / ChipmunkSpace ?

Posted: Wed Jan 26, 2011 4:04 pm
by horseshoe7
I think the subject says it all.

I want to make a game where an object is tracked to be at the centre of the screen, but can 'fall' indefinitely.

Should I make a 'wrap around' and some boundaries to my space? I suppose it has to have some limit - the limit of the float type...

Re: is there a limit to the size of a cpSpace / ChipmunkSpace ?

Posted: Wed Jan 26, 2011 5:48 pm
by slembcke
It's only limited by the precision of the floating point type used. If you let an object accelerate constantly for a few minutes, you just might end up running into problems with 32bit floats though. Try it first, you might find that there really aren't any problems. Chipmunk is normally configured to use 64 bit doubles, but uses 32 bit floats on the iPhone. If you are on the iPhone, try changing the type in chipmunk_types.h before trying what I describe below. While 64 bit math is (usually) slightly faster on desktop machines, it's quite a bit slower on the iPhone.

I threw together a simple car racing game over infinite terrain a couple years ago called Byte Racer (http://howlingmoonsoftware.com/extras.php). What I did for that to avoid precision issues was to create a somewhat wraparound world like you suggested earlier. Basically when the car would get further than a certain distance away from the origin, I would subtract it's position from every rigid body (the chassis, the wheels, and the static bodies the ground segments were attached to). The ground was created using perlin noise generated in screen sized chunks. The segments for each chunk shared a rigid body that I would move when the car's position was reset back to the origin. I of course would have to rehash the static hash each time this happened.

For any reasonable human attention span it probably would have worked fine without the wrapping, but it seemed like a fun experiment to try out.