dynamicsWorld->stepSimulation(1.f/60.f,10);
//print positions of all objects
for (int j=dynamicsWorld->getNumCollisionObjects()-1; j>=0 ;j--)
{
// -- For each RigidBody
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[j];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
model[j]->X = float(trans.getOrigin().getX());
model[j]->Y = float(trans.getOrigin().getY());
model[j]->Z = float(trans.getOrigin().getZ());
//printf("world pos = %f,%f,%f\n",float(trans.getOrigin().getX()),float(trans.getOrigin().getY()),float(trans.getOrigin().getZ()));
}
I want to be able to change the position (x, y, z), I tried the following but it doesn't work:
float newX = // Any new X value here
float newY = // Any new Y value here
float newZ = // Any new Z value here
int modelId = 1;
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[modelId];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
{
btTransform trans;
// -- Set new transform
trans.setOrigin(btVector3(newX, newY, newZ));
body->getMotionState()->setWorldTransform(trans);
}






