extracting world state

kees
Posts: 3
Joined: Wed Mar 19, 2008 7:46 pm

extracting world state

Post by kees »

Hi all,

I want to dump information about the world state to stdout.
In my application (adapted from BasicDemo) I have a world with boxes only.

The code below works fine if I stop the time stepping and call it by pressing the
';' key. However if I then restart the simulation it immediately crashes when I add another
box to the dynamics world. Can someone tell me what I am doing wrong?

Added keyboard handler in DemoAplication.cpp:

Code: Select all

case ';':
      {
	printf("bl=[\n");
      {
	  btCollisionObjectArray objectArray = m_dynamicsWorld->getCollisionObjectArray();
	  int nObjects = objectArray.size();
	  for(int i=0;i<nObjects;i++) {
	    btCollisionObject *cObj = objectArray[i];
	    btCollisionShape* collisionShape = cObj->getCollisionShape();
	    btTransform transf = cObj->getWorldTransform();
	    btBoxShape *boxShape = (btBoxShape *) collisionShape;
	    btVector3 v,vWorld;
	    int nVertices = boxShape->getNumVertices();
	    for(int k=0;k<nVertices;k++) {
	      boxShape->getVertex(k,v);
	      vWorld = transf(v);
	      double x = vWorld.getX();
	      double y = vWorld.getY();
	      double z = vWorld.getZ();
	      printf("%14e %14e %14e\n",x,y,z);
	    }
	  }
	  printf("];\n");
	  fflush(stdout);
	}
	break;
Many thanks,
Kees
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: extracting world state

Post by Erwin Coumans »

You probably want to use references, not duplicates of the collision objects array. That causes troubles.
So use:

Code: Select all

btCollisionObjectArray& objectArray = m_dynamicsWorld->getCollisionObjectArray();
instead of

Code: Select all

btCollisionObjectArray objectArray = m_dynamicsWorld->getCollisionObjectArray();
Hope this helps,
Erwin