rayTest and multiple intersections per object

n0n
Posts: 3
Joined: Thu Aug 19, 2010 2:11 pm

rayTest and multiple intersections per object

Post by n0n »

Hello,
I was wondering if it is possible to get more than just one ray-object intersection point per object. Currently my RayResultCallback only seems to get one result for each object in the scene.

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

Re: rayTest and multiple intersections per object

Post by Erwin Coumans »

By default, Bullet rayTest will provide you with the closest hit.

You can get all hits, by changing the return value of the ray callback in 1. We should provide a demo how to do this,
Thanks,
Erwin
n0n
Posts: 3
Joined: Thu Aug 19, 2010 2:11 pm

Re: rayTest and multiple intersections per object

Post by n0n »

I apologise for being a bit unclear in my question. Changing the return value to 1 in the callback indeed produces all the closest intersections on all the objects.

But what I wish to achieve is to get more than one intersection point per object; i.e. when testing a ray against a single sphere in the world I would get the entry and exit point of the ray on the given sphere.

I hope this clarifies the issue and it's possible to perform such query in Bullet.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: rayTest and multiple intersections per object

Post by Erwin Coumans »

Added the btCollisionWorld::AllHitsRayResultCallback in latest Bullet trunk.

If you want to have the enter and exit hit you will need to call the rayTest a second time, with the begin/end reversed.
Thanks,
Erwin
n0n
Posts: 3
Joined: Thu Aug 19, 2010 2:11 pm

Re: rayTest and multiple intersections per object

Post by n0n »

Thanks. The reversing of the ray was my backup plan as well. :)

By the way, I discovered that while ray-testing against primitives and such always produces only one intersection, the ray-test against static geometry in a btBvhTriangleMeshShape seems to produce exactly 20 results (10 with the entry point and 10 with the exit point, but each result has a different normal).
This doesn't really affect anything of mine, but I figured that I'd report such strange behaviour.

All the best,
n0n
hengcheng
Posts: 1
Joined: Tue Nov 22, 2011 9:13 pm

Re: rayTest and multiple intersections per object

Post by hengcheng »

My guess is that when the ray hits an edge or a vertex, which is shared by multiple triangles, it will generated duplicated hits from different triangles (with different normal).