moving a btcollisionbody from one physics world to another

sisilmet2000
Posts: 6
Joined: Mon Apr 29, 2013 1:30 am

moving a btcollisionbody from one physics world to another

Post by sisilmet2000 »

hi,
I have two physics worlds set up. I now want to move a body that is being simulated in physics world 1 to physics world 2. I may need to move this body back to physics world 1 at some point. What is the best way of doing that?
Is there some way of disabling the body in one world ? i was thinking of creating similar bodies in world1 and world2. Then disabling it in world1 and copying over the body information from world1 to world 2. Is there any way to do that ? Or is the only way to remove a body completely from one world and adding it to another world ?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: moving a btcollisionbody from one physics world to anoth

Post by xexuxjy »

You should just be able to call world1->removeCollisionObject followed by world2->addCollisionObject (and in reverse)
sisilmet2000
Posts: 6
Joined: Mon Apr 29, 2013 1:30 am

Re: moving a btcollisionbody from one physics world to anoth

Post by sisilmet2000 »

Is there any way to disable it instead of removing ?
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: moving a btcollisionbody from one physics world to anoth

Post by Mako_energy02 »

sisilmet2000 wrote:Is there any way to disable it instead of removing ?
An object can be disabled, yes...however that doesn't really work in this context. CollisionObject's don't have a sense of per-world activation. They don't have a sense of per-world anything. They are given a single broadphase handle which is used as it's connection to the world. If you attempt to make it join another world without removing it from the first, it'll overwrite that broadphase handle and the object will only be aware of the second world. Both worlds will be aware of it and could cause the issues with the simulation (I haven't done this before personally but there was a thread describing issues with this a while back). This is compounded with the issue of cleanup, when you go to remove the object from all worlds it'll work fine on the initial world you remove it from, but when another world tries to remove it you will get a segmentation fault because it'll cause a double delete.

TLDR; No. Gotta remove it.
sisilmet2000
Posts: 6
Joined: Mon Apr 29, 2013 1:30 am

Re: moving a btcollisionbody from one physics world to anoth

Post by sisilmet2000 »

Ok. However the problem you describe would occur if I use the same object in both worlds.
The idea was to create duplicate objects in world1 and world2. If I disable the object in world1, I would copy the state data (I.e current position, transform,velocity etc) to the object in world2 and continue simulation in world2.

Would this work since there won't be issues with deleting the object or sharing the broadphase? If yes, how do I disable the object exactly ? Using DISABLE_SIMULATION ? Or is there another way to do it ?
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: moving a btcollisionbody from one physics world to anoth

Post by Mako_energy02 »

Oh, I see. Yeah that should be possible. You disable it by setting it's activation state with btCollisionObject::setActivationState(int newState), passing in DISABLE_SIMULATION, yes. This is another one of those things I haven't personally done, but that is my current understanding of the system. Should that fail I am far more confident that removing them from the world would work.