closestPointTo method

void closestPointTo(
  1. Vector3 p,
  2. Vector3 q

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


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


  var dist =;
  dist = dist.clamp(-_halfExtents.x, _halfExtents.x).toDouble();
  q.addScaled(_axis0, dist);

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

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