How to save and then restore the world's objects?

Post Reply
Rasoul
Posts: 8
Joined: Wed Sep 05, 2012 7:03 pm

How to save and then restore the world's objects?

Post by Rasoul »

In my project with Bullet, I need to save objects in the world and then restore them such that all the properties of the objects (motion, etc.) are preserved and identically restored. Here is what I managed to figure out:

To save

Code: Select all

  
void saveCurrentWorldScenario(btAlignedObjectArray<btCollisionObject>& sc)
{
  int numObjects = world->m_dynamicsWorld->getNumCollisionObjects();
  sc.resize(numObjects);
  for (int obj_idx=0; obj_idx<numObjects ; obj_idx++)
  {
    sc[obj_idx] = *(world->m_dynamicsWorld->getCollisionObjectArray()[obj_idx]);
  }
}
To restore

Code: Select all

void SimPlanner::buildCurrentWorldFromScenario(btAlignedObjectArray<btCollisionObject>& scene)
{
  int numObjects = scene.size();
  for(unsigned int i=0; i<numObjects; i++)
  {
    btCollisionObject* obj = &scene[i];
   //TODO: add obj to the world
  }
}
I don't know how to restore btCollisionObject's back to the world. I would appreciate it if someone can help me with this.

Bullet Version: 2.80
OS: Ubuntu 11.04
Post Reply