Copying btRigidBody/btCollisionObject? (Physics multiverse?)

User avatar
ejtttje
Posts: 96
Joined: Mon Nov 03, 2008 9:57 pm

Copying btRigidBody/btCollisionObject? (Physics multiverse?)

Post by ejtttje »

Just a quick sanity check if you please: I want to do some planning in a physics world, which will involve a lot of saving/restoring physics state to evaluate various possible actions. It seems this will be a fairly straightforward case of having an array of btRigidObjects, copying this array whenever needed to fork the simulation, adding them to the dynamics world, running a few steps with some controller policy being tested, then removing from the physics world and repeating with some other controller policy and state sample...

Is that going to save all of the relevant internal state of the simulation between each planner increment? In other words, if I do a lot of swapping between btRigidObject arrays to try different actions and eventually find one series of actions which bring me to my goal, and then apply that same series of actions as sequential steps on an extended run of a single set of btRigidObjects, should I get the same deterministic outcome, or are there any known tricks/issues I should be aware of while I'm coding this up?

Edit: One such is trick is I'll need to remove/recreate the constraints between the rigid objects for each state swap, yes? I use btGeneric6DofConstraint, looks like this isn't storing any temporally-based history that I need to store, so that just adds some overhead to the add/remove of the rigid objects from the dynamics world...?

Thanks!
User avatar
ejtttje
Posts: 96
Joined: Mon Nov 03, 2008 9:57 pm

Re: Copying btRigidBody/btCollisionObject? (Physics multiver

Post by ejtttje »

I've gotten a basic version of my program working now. However, there is a small issue:

If I simulate a force pushing on a cube for 150 steps, it slides along the ground and picks up a slight rotation.

If I do the same thing, but call addRigidBody/removeRigidBody on the cube every step, it picks up a slightly different rotation.

The rotation itself is random noise, a bit of jitter between the cube and ground plane. This jitter seems to be from having gravity set too high, which is a separate issue I'll make another thread about. For now, I'm curious if there's something I could tweak to get identical output between the two cases.

EDIT: if I simulate several physics steps between each add/remove pair, then the jitter difference does become negligible, but I'd like to get perfect consistency if possible.