// Classify this bounding box as entirely in front of, in back of, or // intersecting the given plane. public PlaneIntersectionType Intersects(ref Plane plane) { float dist = plane.DotCoordinate(Center); // Transform the plane's normal into this box's space Vector3 localNormal = Vector3.Transform(plane.Normal, Quaternion.Conjugate(Orientation)); // Project the axes of the box onto the normal of the plane. Half the // length of the projection (sometime called the "radius") is equal to // h(u) * abs(n dot b(u))) + h(v) * abs(n dot b(v)) + h(w) * abs(n dot b(w)) // where h(i) are extents of the box, n is the plane normal, and b(i) are the // axes of the box. float r = Math.Abs(HalfExtent.X * localNormal.X) + Math.Abs(HalfExtent.Y * localNormal.Y) + Math.Abs(HalfExtent.Z * localNormal.Z); if (dist > r) { return(PlaneIntersectionType.Front); } else if (dist < -r) { return(PlaneIntersectionType.Back); } else { return(PlaneIntersectionType.Intersecting); } }
public PlaneIntersectionType Intersects(ref Plane plane) { float num = plane.DotCoordinate(this.Center); Vector3 vector = Vector3.Transform(plane.Normal, Quaternion.Conjugate(this.Orientation)); float introduced3 = Math.Abs((float)(this.HalfExtent.X * vector.X)); float num2 = (introduced3 + Math.Abs((float)(this.HalfExtent.Y * vector.Y))) + Math.Abs((float)(this.HalfExtent.Z * vector.Z)); if (num > num2) { return(PlaneIntersectionType.Front); } if (num < -num2) { return(PlaneIntersectionType.Back); } return(PlaneIntersectionType.Intersecting); }