Raytest not working from inside collision shape

Post Reply
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Raytest not working from inside collision shape

Post by benelot »

It seems that the btRaytestCallback does not work properly with the kF_FilterBackfaces setting. I was experiencing this problem for a long time now, that is why I try to report a bug now by showing that it does not work. When trying to find the surface point of a collision shape when looking into a certain direction from its center of mass and therefore raycasting from inside the shape, I never get a hit on the surface. This made me use the workaround by inverting the ray I was using. But since I want to show that the kF_FilterBackfaces setting is not always working properly, I modified the raytest example. I included this after the "all hits example" in the code. It does raycasts from inside of each collision object. I even clear the filterBackfaces setting to be sure it is off, but it seems that the setting only works for the first object in the row (btBvhTriangleMeshShape I believe, the flat 2D rectangle).

Code: Select all

for (int i=0;i<6;i++)
{
			btVector3 from((i-3)*5,1,0);
			btVector3 to((i-3)*5,1,30);
			m_dynamicsWorld->getDebugDrawer()->drawLine(from,to,btVector4(0,0,0,1));
			btCollisionWorld::AllHitsRayResultCallback allResults(from,to);
			allResults.m_flags |= btTriangleRaycastCallback::kF_KeepUnflippedNormal;
			//kF_UseGjkConvexRaytest flag is now enabled by default, use the faster but more approximate algorithm
			//allResults.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest;
			allResults.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest;
			allResults.m_flags &= ~btTriangleRaycastCallback::kF_FilterBackfaces;
//			allResults.m_flags |= btTriangleRaycastCallback::kF_FilterBackfaces;
			
			m_dynamicsWorld->rayTest(from,to,allResults);

			for (int i=0;i<allResults.m_hitFractions.size();i++)
			{
				btVector3 p = from.lerp(to,allResults.m_hitFractions[i]);
				m_dynamicsWorld->getDebugDrawer()->drawSphere(p,0.1,red);
				m_dynamicsWorld->getDebugDrawer()->drawLine(p,p+allResults.m_hitNormalWorld[i],red);
			}
		}
Can somebody verify this bug so that I can report it on the repository tracker? I could see that in the btRaycastCallback the kF_FilterBackfaces flag is considered and does drop backfaces when enabled and should not when disabled, thus I do not know why it does not work correctly.

Edit: The bug is already in the issue tracker and will be addressed at some point.
https://github.com/bulletphysics/bullet3/issues/459
Post Reply