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;
Kees