Multiple shapes to one body

Official forum for the Chipmunk2D Physics Library.
Post Reply
PawApps
Posts: 2
Joined: Sat Oct 01, 2011 12:17 am
Contact:

Multiple shapes to one body

Post by PawApps »

In my research I have come across the following calls:

Code: Select all

- (void)addPostStepRemoval:(id <ChipmunkObject>)obj;

Code: Select all

scheduleToRemoveShape:

Code: Select all

scheduleToRemoveAndFreeShape
I'm looking to remove a body that has multiple shapes. I am currently working with SpaceManager 0.1.1. It doesn't seem like any of these calls are available. Is there an equivalent call in SpaceManager?

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

Re: Multiple shapes to one body

Post by slembcke »

The first method you posted addPostStepRemoval: is an Objective-Chipmunk method. Using that you can remove an entire composite physics object with many bodies, joints and shapes in a single call.

SpaceManager wasn't written by me, so I don't really know that much about it. It's not meant to be a full wrapper like Objective-Chipmunk is and it seems to make the assumption that you will only want 1 shape per body. You'll have to use Chipmunk's C API remove the body, it's shapes and manage the memory.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
PawApps
Posts: 2
Joined: Sat Oct 01, 2011 12:17 am
Contact:

Re: Multiple shapes to one body

Post by PawApps »

slembcke wrote:The first method you posted addPostStepRemoval: is an Objective-Chipmunk method. Using that you can remove an entire composite physics object with many bodies, joints and shapes in a single call.

SpaceManager wasn't written by me, so I don't really know that much about it. It's not meant to be a full wrapper like Objective-Chipmunk is and it seems to make the assumption that you will only want 1 shape per body. You'll have to use Chipmunk's C API remove the body, it's shapes and manage the memory.
For my bodies that only have one shape I have used removeAndFreeShape:(cpShape*);. This takes care of the shape and the associated body, however, when the body has multiple shapes, it doesn't trace back down. My understanding is that a body can have multiple shapes, so the shape knows what body it belongs to, but this call does not check for any other associated shapes.

Is there a way to know from a body object what shapes it is associated with? Is calling the shape a child of body proper?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Multiple shapes to one body

Post by slembcke »

cpBodyGetShapes() allows you to iterate shapes for a body in Chipmunk 6.x
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 22 guests