Removing objects which leave the allowable coordinate space

Official forum for the Chipmunk2D Physics Library.
Post Reply
Erithil
Posts: 7
Joined: Fri Jan 14, 2011 4:19 pm
Contact:

Removing objects which leave the allowable coordinate space

Post by Erithil »

Hi,

I'm currently developing an iPhone game, and I'm running into an occasional problem where objects sometimes pass through the bounding shapes I'm using for the edge of the world. This happens when the forces involved in the simulation cause an object to accelerate to a high velocity.

I understand that Chipmunk doesn't directly offer tunneling prevention, and that the normal ways to address this are to decrease the timestep and/or increase the size of the shapes. I have made such changes once or twice, and it takes care of the immediate problem.

That said, this seems like it is a little inefficient, since all I really want to do is de-spawn objects whose coordinates leave some allowable bounds. Furthermore, this solution isn't acceptably foolproof, since the consequences of an object escaping the imposed bounds are that it will continue to be accelerated by gravity until it falls to an enormously negative y-coordinate where the floating point precision breaks down and the program stalls in an infinite loop in handleQueryRehashHelper().

The approach I'm currently considering is to simply use my user code to test whether a body has left the allowed coordinate bounds. However, this is messy since I have many different types of objects, each of which can be associated with various numbers of cpBodys. Basically, I want to know if there is a cleaner solution whereby I can perform this test inside chipmunk instead of in the user code. What would you suggest?

Thanks in advance,

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

Re: Removing objects which leave the allowable coordinate space

Post by slembcke »

Making a thick border or using a small time step and setting the v_limit property of a body to a reasonable finite amount would make it nearly impossible for an object to escape.

If you really want to be extra sure, iterate your game objects or the bodies in the space and check their coordinates.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Erithil
Posts: 7
Joined: Fri Jan 14, 2011 4:19 pm
Contact:

Re: Removing objects which leave the allowable coordinate space

Post by Erithil »

I think that we want the extra security of coordinate checking. I'd like to iterate over all cpBodies in our cpSpace, however, I couldn't find any documentation about doing this. I also noticed in the code the note saying that cpArrays will probably go away in the future. Is there a semi-abstraction-safe way that I can iterate over the cpBodies?

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

Re: Removing objects which leave the allowable coordinate space

Post by slembcke »

Apparently I missed the function in the documentation, cpSpaceEachBody():
http://code.google.com/p/chipmunk-physi ... pace.h#196

That said, I'd still highly recommend iterating over your own list of objects in the world instead as you cannot remove things during iteration. Iterating your own list of game objects makes it easy to work around the iteration/mutation problem in whatever way you want.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Erithil
Posts: 7
Joined: Fri Jan 14, 2011 4:19 pm
Contact:

Re: Removing objects which leave the allowable coordinate space

Post by Erithil »

That's alright. I already have a queue system in place for the purpose of later deleting or modifying objects which have been identified during callbacks.

Thanks a bunch.
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests