Contact point extraction

lakeeast
Posts: 5
Joined: Sun Mar 30, 2008 7:07 am

Contact point extraction

Post by lakeeast »

As a new user of bullet, I have some questions about how to extract collision contact information from the physics library.

In my application, a static triangle mesh is loaded. I then create sphere objects that might collide with the mesh. I would like to know:
1. Whether a sphere-mesh collision happens.
2. If the sphere collides with the mesh, how can I retrieve the pointer to the triangle which is closest to the center of the sphere?

Another question is related to ray casting. I have two points in the space: PtStart and PtEnd. I would like to know:
1. If I draw a line between PtStart and PtEnd, how should I determine whether there's collision with the triangle mesh or not.
2. If the line segment intersects with the mesh, how to retrive the contact point? More interestingly, how to retrieve the pointer to the triangle which the contact point belongs to?

Thanks for your help!
lakeeast
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Contact point extraction

Post by Erwin Coumans »

lakeeast wrote:As a new user of bullet, I have some questions about how to extract collision contact information from the physics library.

In my application, a static triangle mesh is loaded. I then create sphere objects that might collide with the mesh. I would like to know:
1. Whether a sphere-mesh collision happens.
2. If the sphere collides with the mesh, how can I retrieve the pointer to the triangle which is closest to the center of the sphere?
This has been implemented in Bullet/Demos/ConcaveDemo/ConcaveCollisionDemo.cpp

Check out the callback CustomMaterialCombinerCallback, it reports a collision and includes part/triangle indices.
Another question is related to ray casting. I have two points in the space: PtStart and PtEnd. I would like to know:
1. If I draw a line between PtStart and PtEnd, how should I determine whether there's collision with the triangle mesh or not.
2. If the line segment intersects with the mesh, how to retrive the contact point? More interestingly, how to retrieve the pointer to the triangle which the contact point belongs to?
There is a rayTest method in Bullet dynamics/collision world. See Bullet/Demos/RayTracer or ConcaveRaycastDemo how to use ray tests. LocalRayResult contains the part and triangle index.

Hope this helps,
Erwin
lakeeast
Posts: 5
Joined: Sun Mar 30, 2008 7:07 am

Re: Contact point extraction

Post by lakeeast »

Thanks! It works for me :-)