I have a vector of rigid bodies r_body with a certain number of constraints r_constraints that I would like to delete in order to reinitialise the scene. But it seems like it's not working...
Here is the code where I delete everything in my scene:
Code: Select all
for (unsigned int i(r_constraints.size() - 1) ; i > 0 ; i--)
{
world->removeConstraint(r_constraints.at(i));
delete r_constraints.at(i);
}
//remove the rigidbodies from the dynamics world and delete them
for (int i(world->getNumCollisionObjects() - 1) ; i >= 0 ; i--)
{
btCollisionObject* obj = world->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
delete body->getMotionState();
}
world->removeCollisionObject( obj );
delete obj;
}
//delete collision shapes
for (unsigned int j(0) ; j < r_shapes.size() ; j++)
{
btCollisionShape* shape = r_shapes[j];
r_shapes[j] = 0;
delete shape;
}
r_body.clear();
r_shapes.clear();
r_motionStates.clear();
r_constraints.clear();
world->clearForces();
I would be very happy if you could help !
Martin