raytest: disable backface hit

Lf3THn4D
Posts: 11
Joined: Tue Mar 11, 2008 4:14 am

raytest: disable backface hit

Post by Lf3THn4D »

Hi, I like to be able to have raytest that does not hit backface polygon. Unfortunately the triangle testing part can't be overriden. So the only way is to change the source.

I hope this request is sane. :P
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: raytest: disable backface hit

Post by sparkprime »

Can't you just use the nearest "hit", i.e. filter the results yourself.
Lf3THn4D
Posts: 11
Joined: Tue Mar 11, 2008 4:14 am

Re: raytest: disable backface hit

Post by Lf3THn4D »

That would be rather slow. I would have to get back the triangle info, regenerate the normal, then do the checking. If it's done inside btTriangleRaycastCallback::processTriangle() it would be pretty much more efficient.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: raytest: disable backface hit

Post by sparkprime »

You get back the distance along the ray so you can just use that
Lf3THn4D
Posts: 11
Joined: Tue Mar 11, 2008 4:14 am

Re: raytest: disable backface hit

Post by Lf3THn4D »

Umm.. what can distance tell me? It doesn't even tell me the triangle normal the ray is intersecting. Maybe you didn't quite understood me. What I want is to have a rayTest that ignores backfacing triangles; mainly static mesh shapes (btBvhTriangleMeshShape).

I still think it is better if bullet support it.
AlexSilverman
Posts: 141
Joined: Mon Jul 02, 2007 5:12 pm

Re: raytest: disable backface hit

Post by AlexSilverman »

I think the answer here is to override whichever classes you need and add the functionality to Bullet in your new class(es). btTriangleRaycastCallback seems like where you want to start, from what you say. One of the main strengths of Bullet, and most open source projects in my opinion, is the ability for special case solutions, or ones that just haven't been implemented yet, to be done by anyone. Have at it :)

- Alex
Lf3THn4D
Posts: 11
Joined: Tue Mar 11, 2008 4:14 am

Re: raytest: disable backface hit

Post by Lf3THn4D »

Yes, that would be right in most cases. Unfortunately, btCollisionWorld::rayTestSingle() is not overridable. It's a static function.

It seemed nobody seem to have cared for such feature. I guess I'll just hack in something and submit a patch.

Most likely add a m_ignoreBackface option in btCollisionWorld::RayResultCallback.
shogun
Posts: 34
Joined: Tue Mar 04, 2008 3:16 pm

Re: raytest: disable backface hit

Post by shogun »

And, did you succeed? I need an option like this, too ...
Lf3THn4D
Posts: 11
Joined: Tue Mar 11, 2008 4:14 am

Re: raytest: disable backface hit

Post by Lf3THn4D »

Yes, infact it's very easy to implement. However eventually I decided I don't need it anymore so I didn't really bothered with it.

If you want it, you can hack it in by opening btRaycastCallback.cpp:
Look for btTriangleRaycastCallback::processTriangle()

then change:

Code: Select all

	if ( dist_a * dist_b >= btScalar(0.0) )
	{
		return ; // same sign
	}
to

Code: Select all

	if ( dist_a * dist_b >= btScalar(0.0) || dist_b > dist_a)
	{
		return ; // same sign
	}
Maybe you can propose a way to set it as an option with it disabled by default. Would be cool to have it in the official build. :)