closestPointTo method

void closestPointTo (Vector3 p, Vector3 q)

Find the closest point q on the OBB to the point p and store it in q.

Implementation

void closestPointTo(Vector3 p, Vector3 q) {
  final Vector3 d = p - _center;

  q.setFrom(_center);

  double dist = d.dot(_axis0);
  dist = dist.clamp(-_halfExtents.x, _halfExtents.x).toDouble();
  q.addScaled(_axis0, dist);

  dist = d.dot(_axis1);
  dist = dist.clamp(-_halfExtents.y, _halfExtents.y).toDouble();
  q.addScaled(_axis1, dist);

  dist = d.dot(_axis2);
  dist = dist.clamp(-_halfExtents.z, _halfExtents.z).toDouble();
  q.addScaled(_axis2, dist);
}