Object with multiple bodies (Wrapping world)

I really stuck at implementing wrapping world.

My idea is to use object wich contains NSMutableArray of its bodies (which can be up to 4 elements). When i create the object i add initial body to the array simultaneously with adding it to the world.

Then when some conditions occur i add one more body with modified position. But this body exists only as element of the array.

I can't understand how to properly create copy of body from an element of the array in the world if i must use safe adding as safe removing (outside of world->Step())?

Any clues?
After few tries i replaced NSMutableArray with usual NSArray with 9 elements for superposition matrix. It covers all situations and has a more clear logic for me.

But the main problem is creating body without adding to the world. For example:

In collision logic (pseudocode)

Code: Select all

[self.bodies addObjectAtIndex:index] = [self masterBody];


where

Code: Select all

masterBody
returns a template (master copy) for object body. But i can't write this method because there is only one

Code: Select all

world->CreateBody(&bodyDef);
method.

I can create separately only definition of the body, but full creation (with fixtures) can't be made without adding it to the world.

Any ideas? Use separate world for storing template bodies of every game object?
Okay, i'm one step from creating wrapping world.

I need the last function: to transfer impulse between all bodies in the system.

How to apply impulse to all other bodies of the object (stored in the array) if one of them get hit?

Don't understand how to calculate the impulse.

Original thread: https://box2d.org/forum/viewtopic.php?t=8106