Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualDirk Gregorius

Posted 26 August 2013 - 03:41 PM

Correct, you get the closest point between the sphere center (or capsule segment) and the polygon/polyhedra and then move the closest point onto the sphere (or capsule) surface.  

 

I think some sample code makes this clearer:

ClosestPointsResult result = FindClosestPoints( pSphere, pPolyhedra );

if ( result.m_flDistance > pSphere->Radius() )
{
   // Shallow penetration - correct for sphere radius and move closest point onto sphere surface
   float flSeparation = result.m_flDistance - pSphere->Radius();
   Vec3 vClosestPointOnSphere = result.m_vPoint1 + pShere->Radius() * Normalize( result.m_vPoint2 - result.m_vPoint1 );
   Vec3 vClosestPointOnPolyhedra = result.m_vPoint2;
}
else
{
    // Deep penetration -> do something else...
}

#1Dirk Gregorius

Posted 26 August 2013 - 03:40 PM

Correct, you get the closest point between the sphere center (or capsule segment) to the polygon/poyhedra and then move the closest point on the sphere (or capsule) in the direction of the difference of the closest points times the radius. 

 

I think some sample code makes this clearer:

ClosestPointsResult result = FindClosestPoints( pSphere, pPolyhedra );

if ( result.m_flDistance > pSphere->Radius() )
{
   // Shallow penetration - correct for sphere radius and move closest point onto sphere surface
   float flSeparation = result.m_flDistance - pSphere->Radius();
   Vec3 vClosestPointOnSphere = result.m_vPoint1 + pShere->Radius() * Normalize( result.m_vPoint2 - result.m_vPoint1 );
   Vec3 vClosestPointOnPolyhedra = result.m_vPoint2;
}
else
{
    // Deep penetration -> do something else...
}

PARTNERS