So.. I've been trying to reset several rigidbodies to their initial (i.e stored) positions during a physical simulation. As per instructions on the forum, I remove the bodies from the world, make the required changes, then add them back to the world. However, for some reason, this doesn't quite seem to work as, although the objects are reset to their initial positions correctly, they do not seem to recognise the WANTS_DEACTIVATION flag that I set before adding back to the world, as the objects immediately start falling.
Here is the relevant code I'm using. You'll also notice that I've added a few seemingly-unneccessary lines in there (including setting the WANTS_DEACTIVATION again after adding to world, etc), in my desperation to get this to work

Code: Select all
for(int model = 0; model < (6); model++){
testPhysics.dynamicsWorld->removeRigidBody(scene[model].modelRigidBody);
scene[model].modelRigidBody->setWorldTransform(scene[model].initialTransformInv->inverse());
scene[model].modelRigidBody->setInterpolationWorldTransform(scene[model].initialTransformInv->inverse());
testPhysics.dynamicsWorld->getBroadphase()->getOverlappingPairCache()->cleanProxyFromPairs(scene[model].modelRigidBody->getBroadphaseHandle(),testPhysics.dynamicsWorld->getDispatcher());
scene[model].modelRigidBody->getMotionState()->setWorldTransform(scene[model].initialTransformInv->inverse());
scene[model].modelRigidBody->setCenterOfMassTransform(scene[model].initialTransformInv->inverse());
scene[model].modelRigidBody->clearForces();
scene[model].modelRigidBody->setLinearVelocity(btVector3(0,0,0));
scene[model].modelRigidBody->setAngularVelocity(btVector3(0,0,0));
scene[model].modelRigidBody->setActivationState(WANTS_DEACTIVATION);
scene[model].modelRigidBody->wantsSleeping();
*scene[model].transform = scene[model].initialTransformInv->inverse();
}
for(int model = 0; model < (6); model++){
testPhysics.dynamicsWorld->addRigidBody(scene[model].modelRigidBody);
scene[model].modelRigidBody->setActivationState(WANTS_DEACTIVATION);
//scene[model].modelRigidBody->setGravity(btVector3(0,0,0));
}
Anyway, I've been stuck trying to fix this for a while now, so I could really appreciate some help!