Closest point on a rigid body

Closest point on a rigid body

Hi,

I'm trying to find the point on a rigid body that is closest to a point in world space. I've tried using a hkpCachingShapePhantom, but that only got hits for objects that are inside a shape (that of the phantom).

Does anyone know how to do this as simple as possible?

Thanks,

Johan

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havokchris's picture
Best Reply

Hi Johan,
There's no interface for point queries, but you can fake it with a small sphere. I think what you want to do is:

  1. Make a temporary hkpSphereShape with a very small radius
  2. Make a temporary hkpCollidable using the hkpSphereShape
  3. Pass this collidable to hkpWorld::getClosestPoints

The gotcha here is that this will only search a region centered around the "point". The size of this region is determined by (AABB of the object + hkpCollisionInput::m_tolerance), where the hkpCollisionInput is the one that you pass to getClosestPoints. So if you need to search a large region, you can either change the world's collision tolerance, then change it back, or create a copy and modify its collision tolerance. The latter is much more threadsafe :)

If you have any trouble with that, let me know and I can try to whip up a quick demo.

-Chris

Wow, as usual great response in no time! Thatis exactly what I was looking for.

Thanks,

Johan

Just tried it and it works great.

Thanks,

Johan

havokchris's picture

Glad that works. If you're doing a lot of queries in the same area, you might be able to avoid some of the cost by using an hkpAabbPhantom to cache the broadphase overlaps, and then manually do the narrowphase ones. The code for that is a bit trickier but not too bad. But if it's running fine now, then there's probably not much need to worry.

-Chris

Login to leave a comment.