btConvexTriangleMeshShape raycasting question

RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

btConvexTriangleMeshShape raycasting question

Post by RJNelson68 »

I want to find out if there is some way to get the actual surface point with a raycast on a btConvexTriangleMeshShape? I am trying to place bullet decals on moveable objects.
Alkane
Posts: 7
Joined: Sat Jul 10, 2010 8:34 pm

Re: btConvexTriangleMeshShape raycasting question

Post by Alkane »

Of course, take a look at the RayCast demo :

Code: Select all

btCollisionWorld::ClosestRayResultCallback cb(source, destination);
collisionworld->rayTest (source, destination, cb);
Once you've done that, and if the ray hit something, "cb" contains everything you need such as the position of the hit, the normal of the plane, the rigid body etc.

Code: Select all

if (cb.hasHit ())
{
	body = cb.m_collisionObject;
	hit = cb.m_hitPointWorld;
	normal = cb.m_hitNormalWorld;
}
I'm not an expert with this ( :oops: ), but i think you should be able to implement what you want to do by saving those, and querying the rigid body every frame to retrieve an offset.
RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

Re: btConvexTriangleMeshShape raycasting question

Post by RJNelson68 »

Thanks a ton, I am going to try this out. It is different from the way I was trying, which means it will probably work perfectly LOL.
RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

Re: btConvexTriangleMeshShape raycasting question

Post by RJNelson68 »

Well I tried it and got the same results as when I was using rayCastSingle. It reads the collision just fine but the point it returns is not on the surface of the mesh, there seems to be some sort of contact distance buffer. Additionally the normal is sometimes not correct. I have verified through debug rendering that the mesh confirms exactly to shape of the object, so it isn't that.
RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

Re: btConvexTriangleMeshShape raycasting question

Post by RJNelson68 »

I also tried creating the mesh as a btBvhTriangleMeshShape. Of course it doesn't really work for my purposes but the raycast actually hit the surface.