/// <summary> /// Disjoint Returns true if disjoint. Returns false if intersecting, /// and sets the overlap depth, d scaled by the axis length /// </summary> /// <param name="d"></param> /// <param name="axis"></param> /// <param name="box"></param> /// <param name="triangle"></param> /// <param name="collTolerance"></param> /// <returns></returns> private static bool Disjoint(out float d, Vector3 axis, Box box, Triangle triangle, float collTolerance) { float min0, max0, min1, max1; box.GetSpan(out min0, out max0, axis); triangle.GetSpan(out min1, out max1, axis); if (min0 > (max1 + collTolerance + JiggleMath.Epsilon) || min1 > (max0 + collTolerance + JiggleMath.Epsilon)) { d = 0.0f; return true; } if ((max0 > max1) && (min1 > min0)) { // triangle is inside - choose the min dist to move it out d = System.Math.Min(max0 - min1, max1 - min0); } else if ((max1 > max0) && (min0 > min1)) { // box is inside - choose the min dist to move it out d = System.Math.Min(max1 - min0, max0 - min1); } else { // objects overlap d = (max0 < max1) ? max0 : max1; d -= (min0 > min1) ? min0 : min1; } return false; }
/// <summary> /// Disjoint Returns true if disjoint. Returns false if intersecting, /// and sets the overlap depth, d scaled by the axis length. /// </summary> private static bool Disjoint(out float d, ref Vector3 axis, Box box0, Box box1, float collTolerance) { float min0, max0, min1, max1; box0.GetSpan(out min0, out max0, axis); box1.GetSpan(out min1, out max1, axis); if (min0 > (max1 + collTolerance + JiggleMath.Epsilon) || min1 > (max0 + collTolerance + JiggleMath.Epsilon)) { d = 0.0f; return true; } if ((max0 > max1) && (min1 > min0)) { // box1 is inside - choose the min dist to move it out d = MathHelper.Min(max0 - min1, max1 - min0); } else if ((max1 > max0) && (min0 > min1)) { // box0 is inside - choose the min dist to move it out d = MathHelper.Min(max1 - min0, max0 - min1); } else { // boxes overlap d = (max0 < max1) ? max0 : max1; d -= (min0 > min1) ? min0 : min1; } return false; }