[SOLVED] ClosestRayResultCallback not working

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

[SOLVED] ClosestRayResultCallback not working

Post by benelot »

Hello,

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);
			}
		}
Is there something wrong with my compile I do here or is there a bug in bullet revision 5e956154ce04bb3052b4f474e71c3550303d2aee? (It might be from long before, but I just want to say that I look at the newest revision to date).
You do not have the required permissions to view the files attached to this post.
Last edited by benelot on Tue Aug 18, 2015 1:29 pm, edited 1 time in total.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: ClosestRayResultCallback not working

Post by benelot »

I could make my program work with ClosestRayResultCallback. But why does it look in my modified demo example as if it was not working?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: ClosestRayResultCallback not working

Post by xexuxjy »

I could be missing something but it looks like in your first hit block of code you're not actually calling m_dynamicsWorld->rayTest ?
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: ClosestRayResultCallback not working

Post by benelot »

Oh wow, I did not see that. Interestingly that is precisely the problem in the bullet Raycast sample as well. Check it out, it does not do

Code: Select all

m_dynamicsWorld->rayTest(from,to,closestResults);
, so the

Code: Select all

if (closestResults.hasHit())

will never work.
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: ClosestRayResultCallback not working

Post by xexuxjy »

Hmm, just looked at my RayTestDemo.cpp from the svn repository(rev 2689( and it has the ray test in the first hit block :

Code: Select all

///first hit
		{
			btVector3 from(-30,1.2,0);
			btVector3 to(30,1.2,0);
			sDebugDraw.drawLine(from,to,btVector4(0,0,1,1));

			btCollisionWorld::ClosestRayResultCallback	closestResults(from,to);
			closestResults.m_flags |= btTriangleRaycastCallback::kF_FilterBackfaces;
			m_dynamicsWorld->rayTest(from,to,closestResults);


			if (closestResults.hasHit())
			{
				
				btVector3 p = from.lerp(to,closestResults.m_closestHitFraction);
				sDebugDraw.drawSphere(p,0.1,blue);
				sDebugDraw.drawLine(p,p+closestResults.m_hitNormalWorld,blue);

			}
		}

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

Re: ClosestRayResultCallback not working

Post by benelot »

But it is not here:

https://github.com/bulletphysics/bullet ... stDemo.cpp

Am I wrong here? What SVN repository are you looking at? I thought the official repository is the one on github, is that incorrect?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: ClosestRayResultCallback not working

Post by xexuxjy »

It used to be hosted at http://bullet.googlecode.com/svn/trunk and I guess I haven't updated for a while. It does look as though sometime during it's move over to GitHub that demo got broken slightly.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland

Re: ClosestRayResultCallback not working

Post by benelot »

It is now fixed already, I opened an issue and it is fixed and closed again.