I found an issue in Bullet. It is in the btCollisionWorld::ClosestRayResultCallback. I tried to use that raytesting in my program but it did not work. Now I looked into the RaytestDemo and saw that btCollisionWorld::AllHitsRayResultCallback works properly and shows the hits.Then I commented the debug output from that segment and added a drawSphere to the code, which draws a red sphere at the raytest "from' position in case the btCollisionWorld::ClosestRayResultCallback does not hit anything. The red sphere is always there, I never get a hit anywhere. I appended the modified RaytestDemo.cpp file.
The only thing that I really modified is this segment:
Code: Select all
///all hits
{
btVector3 from(-30,1+up,0);
btVector3 to(30,1,0);
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;
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);
}
}
///first hit
{
btVector3 from(-30,1.2,0);
btVector3 to(30,1.2,0);
m_dynamicsWorld->getDebugDrawer()->drawLine(from,to,btVector4(0,0,1,1));
btCollisionWorld::ClosestRayResultCallback closestResults(from,to);
// closestResults.m_flags |= btTriangleRaycastCallback::kF_FilterBackfaces;
if (closestResults.hasHit())
{
btVector3 p = from.lerp(to,closestResults.m_closestHitFraction);
m_dynamicsWorld->getDebugDrawer()->drawSphere(p,0.1,blue);
m_dynamicsWorld->getDebugDrawer()->drawLine(p,p+closestResults.m_hitNormalWorld,blue);
}
else{
m_dynamicsWorld->getDebugDrawer()->drawSphere(to,0.1,red);
}
}