Preventing collisions (enlarge AABB?)

PORRAS
Posts: 15
Joined: Tue Oct 13, 2009 2:49 pm

Preventing collisions (enlarge AABB?)

Post by PORRAS »

Hi all.

I'm using Bullet on my Final Project degree. I only use the collision detection module, and my objective is to detect collisions when the links of a robot arm hits external objects. More exactly, the aim is to prevent these collisions, so an alert could be generated and any security action would be taken.

I have successfully created the robot arm and detected collisions, but, how could I define a security margin for preventing them? This margin or distance has to be a constant. I've thought about enlarging their AABBs, so, for a given movement in the direction of a collision, the objects would appear earlier in the list of potential colliding pairs, and this would give us the opportunity to work with their contact manifolds. Then, set this distance as the collision margin for all objects, so we could do:

Code: Select all

	int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
	bool contact=false;

	for (int i=0;i<numManifolds;i++)
	   {
		  btPersistentManifold* contactManifold =  collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);

		  btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		  btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
	   
		  int numContacts = contactManifold->getNumContacts();

		  for (int j=0;j<numContacts;j++)
		  {
			 btManifoldPoint& pt = contactManifold->getContactPoint(j);
			 if (pt.getDistance()<SECURITY_MARGIN)
			 {
				contact=true;
			 }	 
		  }
	}

Where "SECURITY_MARGIN" is this constant distance we want to maintain. This is because pt.getDistance() gives us a penetration distance (I guess, but I'm not sure), and if every object had the same margin, the distance between the original objects would be reached when this penetration were equal to this margin.

Is it right? I haven't tested it yet, because I don't know whether is possible to enlarge AABBs (and if it's, how).

Any other suggestion?

Thanks in advance.

Regards,
Francisco