public static BoxPlaneClassificationResult ClassifyBox(this Plane plane, Box box) { List <Vector3> boxCenterAndCornerPoints = box.GetCenterAndCornerPoints(); bool foundPointInFront = false; bool foundPointBehind = false; bool foundPointOnPlane = false; foreach (Vector3 boxPoint in boxCenterAndCornerPoints) { PointPlaneClassificationResult pointClassificationResult = plane.ClassifyPoint(boxPoint); if (pointClassificationResult == PointPlaneClassificationResult.InFront) { foundPointInFront = true; if (foundPointBehind) { return(BoxPlaneClassificationResult.Spanning); } } else if (pointClassificationResult == PointPlaneClassificationResult.Behind) { foundPointBehind = true; if (foundPointInFront) { return(BoxPlaneClassificationResult.Spanning); } } else { foundPointOnPlane = true; } } if (foundPointOnPlane && (!foundPointInFront && !foundPointBehind)) { return(BoxPlaneClassificationResult.OnPlane); } else { if (foundPointInFront) { return(BoxPlaneClassificationResult.InFront); } return(BoxPlaneClassificationResult.Behind); } }
public List <Vector3> GetCenterAndCornerPoints() { List <Vector3> points = _modelSpaceBox.GetCenterAndCornerPoints(); return(Vector3Extensions.GetTransformedPoints(points, TransformMatrix.ToMatrix4x4x)); }