Question: custom btMotionState and serializing objects

Physics APIs, Physics file formats, Maya, Max, XSI, Cinema 4D, Lightwave, Blender, thinkingParticles™ and other simulation tools, exporters and importers
Post Reply
dan
Posts: 2
Joined: Tue Aug 23, 2011 8:56 pm

Question: custom btMotionState and serializing objects

Post by dan » Tue Aug 23, 2011 9:07 pm

I am currently using a custom btMotionState to get the location and rotation data of an object when it has moved. I was wondering if there is any way to utilize btMotionState to also retrieve other properties such as velocities so I can ultimately serialize the objects to a database once they have been updated. If this is not possible, should I iterate through all of the btDiscreteDynamicsWorld objects and see which active objects have moved?

I am hoping that I can use the btMotionState because it was so easy to setup, but I don't think that is a possiblility....

Thanks so much for your time,
Dan

dan
Posts: 2
Joined: Tue Aug 23, 2011 8:56 pm

Re: Question: custom btMotionState and serializing objects

Post by dan » Wed Aug 24, 2011 12:03 pm

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: Select all

					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

Post Reply