I have created a simple loop to iterate over all of the objects in the btDiscreteDynamicsWorld after I step the worl and use the btDefaultMotionState. Here is what I do:
Code:
dynamicsWorld->stepSimulation(1/60.f,10);
for (int i=dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
{
btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody* body = btRigidBody::upcast(obj);
if (body && body->isActive() && body->getMotionState())
{
btTransform trans;
body->getMotionState()->getWorldTransform(trans);
btVector3 velocity = body->getLinearVelocity();
std::cout<<"vy: "<< velocity.getY()<<std::endl;
}
}
Is this the best way to iterate over all of the
active objects in the dynamicWorld? Also does this mean that I am ultimately iterating over all of the objects twice to see if they are active because the btMotionState checks for active objects and then I check for them?
Thanks for your time,
Dan