Hi,
I created world with few static objects and one moving object that collides with the static ones. I want to show the contact points between the objects. How to do that?
Thanks
How to get contact points
-
- Posts: 14
- Joined: Fri Oct 24, 2008 3:32 pm
Re: How to get contact points
Hi,
There are 2 ways that I can think of, off the top of my head.
One would be to loop through all contact points or my preferred option, to use the Callbacks (ContactAddedCallback, ContactProcessedCallback, ContactDestroyedCallback).
There is an example of exactly what you want to do. Look at the Collision Interface demo.
I think that does exactly what you want to do, by looping though all contact points, if you combine this with the callbacks, you should get what you want.
The reason I say I prefer the callbacks, is because I feel they can be more efficient and helpful, plus give you an easy way to filter out the ones you don't want to know about.
Hope that helped!
There are 2 ways that I can think of, off the top of my head.
One would be to loop through all contact points or my preferred option, to use the Callbacks (ContactAddedCallback, ContactProcessedCallback, ContactDestroyedCallback).
There is an example of exactly what you want to do. Look at the Collision Interface demo.
I think that does exactly what you want to do, by looping though all contact points, if you combine this with the callbacks, you should get what you want.
The reason I say I prefer the callbacks, is because I feel they can be more efficient and helpful, plus give you an easy way to filter out the ones you don't want to know about.
Hope that helped!
-
- Posts: 6
- Joined: Wed Nov 12, 2008 8:58 pm
Re: How to get contact points
Hi,
Yeah I saw the Collision Interface demo. But that demo shows how to use the collision detection without dynamics. Actually I have dynamic world. Is there any method of the RigidBody that gives the contact points or I have to use callbacks? I searched the documentation but I am a little bit confused.
Thanks
Yeah I saw the Collision Interface demo. But that demo shows how to use the collision detection without dynamics. Actually I have dynamic world. Is there any method of the RigidBody that gives the contact points or I have to use callbacks? I searched the documentation but I am a little bit confused.
Thanks
-
- Posts: 107
- Joined: Fri Sep 19, 2008 6:08 pm
Re: How to get contact points
Hi
Would you try this tutorial here:
http://www.bulletphysics.com/mediawiki- ... d_Triggers
You can set up 3 types of callbacks to let Bullet notify your apps whenever a collision occurs. The callbacks you are most likely interested in is the gContactAddedCallback which pass in both the collided and the collider.
You can use the passed btManifoldPoint object to obtain more collision information about the collided objects (eg, contact points in world and local space, distance, impulse etc)
Hope that helps.
Would you try this tutorial here:
http://www.bulletphysics.com/mediawiki- ... d_Triggers
You can set up 3 types of callbacks to let Bullet notify your apps whenever a collision occurs. The callbacks you are most likely interested in is the gContactAddedCallback which pass in both the collided and the collider.
You can use the passed btManifoldPoint object to obtain more collision information about the collided objects (eg, contact points in world and local space, distance, impulse etc)
Hope that helps.
-
- Posts: 6
- Joined: Wed Nov 12, 2008 8:58 pm
Re: How to get contact points
Yes. That helps a lot.
Btw I have one more question related with the contact points. Since I am using meshes with random topology I am using convex decomposition. The problem is that since it uses convex hulls some contact points are not on the mesh but on the hull. And so visually some contact points are redundant and seems not in place because they are far from the mesh itself. Any idea how to fix that? I want to show only the contact points which are really on the mesh, not on its hull. I tried to check the distance between each contact point and each mesh vertex but it slows down the performance.
Thanks
Btw I have one more question related with the contact points. Since I am using meshes with random topology I am using convex decomposition. The problem is that since it uses convex hulls some contact points are not on the mesh but on the hull. And so visually some contact points are redundant and seems not in place because they are far from the mesh itself. Any idea how to fix that? I want to show only the contact points which are really on the mesh, not on its hull. I tried to check the distance between each contact point and each mesh vertex but it slows down the performance.
Thanks
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: How to get contact points
You should try to use the method used in Collision Interface demo: a dynamics world is also a collision world (btDiscreteDynamicsworld is derived from btCollisionWorld). It is better to iterate over contact points after stepSimulation, instead of using callbacks during stepSimulation. There are other ways, but they are more complicated (using btGhostShape).Yeah I saw the Collision Interface demo. But that demo shows how to use the collision detection without dynamics. Actually I have dynamic world
For static concave meshes you can use btBvhTriangleMeshShape. So the moving objects are btCompoundShape with convex hulls generated by convex decomposition? If you don't want the approximation, you could try to use btGimpactShape for moving concave objects. It will be slower but generates more accurate contact points.The problem is that since it uses convex hulls some contact points are not on the mesh but on the hull.
Hope this helps,
Erwin
-
- Posts: 6
- Joined: Wed Nov 12, 2008 8:58 pm
Re: How to get contact points
Yeah that helps.
But I have one more question. As far as I understand the contact points are points in manifolds between the colliding bodies. When I have the contact manifold I retrieve its contact points. And in the class btManifoldPoint there are 2 objects of type point - point A and point B. I suppose that the first point is on one of the bodies and the second point is on the another one. So is there any way to know which point on which body is? In my application I have one dynamic world. In that world only one object is moving. The rest of the objects are not moving. And I want to show the contact points when the moving object collides with some of the non-moving objects. I prefer to show the contact points on the moving object (also I prefer to reduce the number of the contact points). Here is my code right now.
I suppose it is not the right way to display the contact points.
Thanks
But I have one more question. As far as I understand the contact points are points in manifolds between the colliding bodies. When I have the contact manifold I retrieve its contact points. And in the class btManifoldPoint there are 2 objects of type point - point A and point B. I suppose that the first point is on one of the bodies and the second point is on the another one. So is there any way to know which point on which body is? In my application I have one dynamic world. In that world only one object is moving. The rest of the objects are not moving. And I want to show the contact points when the moving object collides with some of the non-moving objects. I prefer to show the contact points on the moving object (also I prefer to reduce the number of the contact points). Here is my code right now.
Code: Select all
int numManifolds = physics().getCollisionDispatcher()->getNumManifolds();
for( int i = 0; i < numManifolds; ++i )
{
btPersistentManifold* contactManifold = physics().getCollisionDispatcher()->getManifoldByIndexInternal(i);
int numContacts = contactManifold->getNumContacts();
btVector3 cP(0,0,0);
/// Each manifold has maximum 4 points. They are very close to each other
/// So find the medicenter of the manifold to reduce the number of the contact points
/// Maybe there is a smarter way to reduce their number ???
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
btVector3 ptA = pt.getPositionWorldOnA();
btVector3 ptB = pt.getPositionWorldOnB();
btVector3 median = (ptA + ptB) / 2;
cP += median;
}
cP /= (float)numContacts;
listResult.push_back( Vector3(cP.x(), cP.y(), cP.z()) );
}
Thanks