0

To get relative points on a collision shape (compound shape), I have tried the raytest from inside-out of the shape, but never worked from inside. it only worked from outside.

Here is my setup and the code:

  • C++ openframeworks bullet physics addson
  • Visual studio 2012
  • made a rigidbody called "shape"
  • made a btDiscreteDynamicsWorld called "world"

Here is a raytest code sample:

btVector3 ray_from = shape->getCenterOfMassPosition() ; //  center of mass of the shape called stones[0]
btVector3 ray_to = ray_from + btVector3(0, -100., 0); // ray to the top

btCollisionWorld::AllHitsRayResultCallback allResults(ray_from, ray_to);
world->rayTest(ray_from, ray_to, allResults);

for (int i = 0; i < allResults.m_hitFractions.size(); i++)
 {
   btVector3 p = ray_from.lerp(ray_to, allResults.m_hitFractions[i]);
   ray_all_results.push_back(new btVector3(p.getX(), p.getY(), p.getZ()));
 }

1 Answers1

0

Many people experience this problem and it seems that this is wrongly implemented in the current revision. I experienced the same problem when I tried to get positions on the surface of a shape.

So do not worry, it is not a problem in your setup, it is the Bullet Physics library.

Is also seems that

rayCallback.m_flags &= !btTriangleRaycastCallback::kF_FilterBackfaces;

is not checked ever in the code.

So my suggestion is that you just invert your ray and test the surface from the outside. The bug will probably get fixed at some point in the future.

http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=10722&p=35992&hilit=ray#p35992

https://github.com/bulletphysics/bullet3/issues/459

Ben
  • 2,314
  • 1
  • 19
  • 36
  • `rayCallback.m_flags &= !btTriangleRaycastCallback::kF_FilterBackfaces;` is not doing what you expect it to do (removing the flag)! you actually meant: `rayCallback.m_flags &= ~btTriangleRaycastCallback::kF_FilterBackfaces;` – BeyelerStudios Aug 24 '15 at 10:51
  • Oh, right. But it does not change the fact that the flag's setting is never checked again in the code. – Ben Aug 24 '15 at 13:35