Computation of Minimal Distance and Penetration Depth

tobias
Posts: 1
Joined: Mon Jan 13, 2014 8:56 pm

Computation of Minimal Distance and Penetration Depth

Post by tobias »

Hi!

I am currently working on a project where I need to compute the minimal distance between objects. If the objects are penetrating each other, I need their penetration depth. Bullet seems to be a good library for this task, but I just started diving in and have some starting problems. It would be nice, if someone could help me.

I looked into the CollisionInterfaceDemo and found a code snipped, which should push me into the right direction:

Code: Select all

//another way is to directly query the dispatcher for both objects. The objects don't need to be inserted into the world

	btCollisionAlgorithm* algo = collisionWorld->getDispatcher()->findAlgorithm(&objects[0],&objects[1]);
	btManifoldResult contactPointResult(&objects[0],&objects[1]);
	algo->processCollision(&objects[0],&objects[1],collisionWorld->getDispatchInfo(),&contactPointResult);
	
	btManifoldArray manifoldArray;
	algo->getAllContactManifolds(manifoldArray);
This code is disabled in the demo.
As far as I understand, this code finds me the right algorithm for my kind of objects (mostly convex objects) and computes the contact manifold. My Problem is that it seems, that the bullet interface changed over time. The findAlgorithm method takes now two btCollisionObjectWrapper objects instead of btCollisionObject objects. How can I get the wrapper of an collision object? Do I have to create it on my own?

Regardless of this problem, I am not quite sure if I am doing the right thing. Are the contact points of the contact manifold containing the penetration depth if objects are penetrating each other and otherwise containing the minimal distance? Or do I have to use multiple algorithms?

Thanks in advance!
Tobias
bwelch
Posts: 48
Joined: Thu Dec 12, 2013 4:04 pm

Re: Computation of Minimal Distance and Penetration Depth

Post by bwelch »

I don't know about your specific case, but if it's anything like the collision callback function, you can just cast the btCollisionObjectWrapper as you need to. For example, in my project I have:

Code: Select all

bool btCallback(btManifoldPoint& cp,const btCollisionObjectWrapper* obj1,int id1,int index1,const btCollisionObjectWrapper* obj2,int id2,int index2)
{
                else if(((bulletObject*)obj1->getCollisionObject()->getUserPointer())->btid == 1){	//if obj1 is a booster, speed up obj2
		btVector3 boostdir;
		boostdir.setX(((bulletObject*)obj2->getCollisionObject()->getUserPointer())->body->getLinearVelocity().getX());
		boostdir.setY(((bulletObject*)obj2->getCollisionObject()->getUserPointer())->body->getLinearVelocity().getY());
		boostdir.setZ(((bulletObject*)obj2->getCollisionObject()->getUserPointer())->body->getLinearVelocity().getZ());
		((bulletObject*)obj2->getCollisionObject()->getUserPointer())->body->applyCentralForce(btVector3(boostdir.x()*20,boostdir.y()*20,boostdir.z()*20));
		//((bulletObject*)obj2->getCollisionObject()->getUserPointer())->body->applyCentralForce(btVector3(100,0,0));
		WriteLine(((bulletObject*)obj2->getCollisionObject()->getUserPointer())->body->getCenterOfMassTransform().getOrigin().getX());
		WriteLine("BOOST!");
}
}
So where I cast obj1 and obj2 into my custom struct bulletObject, you could cast into btCollisionObject if that's what you need. Again, I'm not sure if this applies to your specific use-case, but maybe it'll point you in the right direction.