help, btConvexHullShape contact detection

arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

help, btConvexHullShape contact detection

Post by arman2 »

I did two tests for collision detection of 8192 spheres. In the first one I assumed them as spheres (btSphereShape), 2969 contacts where found (this is a valid number, I have compared it to my other algorithms). In the second, I assumed the spheres as btConvexHullShape, with 180 (also 18000) vertices on the surface of each, 5408 contacts were found.
the boundingSpheres of the second case matches to what it should be (center location and radius). also the aabb matches (I found the radius and center of the shape from aabb, they are exactly similar to original spheres) .
I also set the collision margin to 0.f
the number of contact does not approach the actual number of contacts by using finer meshes.

Shouldn't btConvexHullShape result in same number of contacts? What might be the cause of inaccuracy?
arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

Re: help, btConvexHullShape contact detection

Post by arman2 »

for further clarification this is the pseudo code I have used:

btScalar *point = new btScalar[3];
//x_data, y_data, z_data, r_data are the center and radius of spheres
btConvexHullShape *convTemp = new btConvexHullShape(0, 0, sizeof(btVector3));
//-----------------------------------generating the vertices and adding them to the btConvexHullShape
//*******************************
int count = 1;
for (int j = 1; j < steps1; j++) {
for (int k = 0; k < steps2; k++) {
float phi = -.5*PI + float(j)/steps1*PI;
float tet = float(k) / steps2 * 2.0 * PI;
tempPoint = btVector3(btScalar(x_data + r_data * cos(phi) * cos(tet)), btScalar(y_data + r_data * cos(phi) * sin(tet)), btScalar(z_data + r_data * sin(phi)));
convTemp->addPoint(tempPoint);
count++;
}
}
//--------------------------- end of generating the vertices and adding them to the btConvexHullShape

//object= new btCollisionObject[num_Bodies] saves the collision objects
object.setCollisionShape(convTemp);
object.setCompanionId(i);
collisionWorld->addCollisionObject(&object);


if (collisionWorld)
collisionWorld->performDiscreteCollisionDetection();
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: help, btConvexHullShape contact detection

Post by Dirk Gregorius »

I would assume that Bullet creates exactly one contact point between two spheres, while it creates up to four contact points between convex hulls. You have the source and can always step the code.
arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

Re: help, btConvexHullShape contact detection

Post by arman2 »

Interesting! (I will check it asap and post the result)
since increasing the number of vertices did not change the number of contacts a lot, I assumed the number of contacts is independent of the number of included vertices.
Do you know where does that number of vertices (4) come from or do you know any reference for that?
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: help, btConvexHullShape contact detection

Post by Dirk Gregorius »

Here is a presentation from Erwin about contact creation: http://code.google.com/p/bullet/downloa ... f&can=2&q=

Cheers,
-Dirk
arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

Re: help, btConvexHullShape contact detection

Post by arman2 »

Thanks for the reference.
I checked the contacting pairs. In my code, there is at most one contact point between two convexHulls. The redundant contacts are all associated to the bodies that are not in contact.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: help, btConvexHullShape contact detection

Post by Dirk Gregorius »

Pairs are associated with overlapping AABBs and not with touching shapes.
arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

Re: help, btConvexHullShape contact detection

Post by arman2 »

Yes, you are right. I've just checked it.
so how should I retrieve the actual contacts? currently I am using performDiscreteCollisionDetection() (which belongs to btCollisionWorld), but seems it does not work.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: help, btConvexHullShape contact detection

Post by Dirk Gregorius »

I would assume there are no contacts then. The AABBs overlap but the actual shapes are not touching.
arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

Re: help, btConvexHullShape contact detection

Post by arman2 »

I meant performDiscreteCollisionDetection() reports the contacts of AABBs not the contact of btConvexHullShapes (as you said). So it reports 5408 contacts, which are not actual (only 2969 of them are actual contacts of btConvexHullShapes). So is there any way to retrieve 2969 contacts?
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: help, btConvexHullShape contact detection

Post by Dirk Gregorius »

Why not iterate over all pairs and collect those that are actually in touching?
arman2
Posts: 7
Joined: Thu May 20, 2010 7:57 pm

Re: help, btConvexHullShape contact detection

Post by arman2 »

Seems this is the final solution. I needed some timing results from Bullet, therefore I preferred to totally rely on it.
By the way, this was a useful discussion, thanks man.