Beispiel #1
0
        public static ContainmentType Contains(BoundingSphere sphere, BoundingBox box)
        {
            Vector3 vector;

            if (!BoundingBox.Intersects(box, sphere))
            {
                return(ContainmentType.Disjoint);
            }

            float radius = sphere.Radius * sphere.Radius;

            vector.X = sphere.Center.X - box.Minimum.X;
            vector.Y = sphere.Center.Y - box.Maximum.Y;
            vector.Z = sphere.Center.Z - box.Maximum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Maximum.X;
            vector.Y = sphere.Center.Y - box.Maximum.Y;
            vector.Z = sphere.Center.Z - box.Maximum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Maximum.X;
            vector.Y = sphere.Center.Y - box.Minimum.Y;
            vector.Z = sphere.Center.Z - box.Maximum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Minimum.X;
            vector.Y = sphere.Center.Y - box.Minimum.Y;
            vector.Z = sphere.Center.Z - box.Maximum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Minimum.X;
            vector.Y = sphere.Center.Y - box.Maximum.Y;
            vector.Z = sphere.Center.Z - box.Minimum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Maximum.X;
            vector.Y = sphere.Center.Y - box.Maximum.Y;
            vector.Z = sphere.Center.Z - box.Minimum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Maximum.X;
            vector.Y = sphere.Center.Y - box.Minimum.Y;
            vector.Z = sphere.Center.Z - box.Minimum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            vector.X = sphere.Center.X - box.Minimum.X;
            vector.Y = sphere.Center.Y - box.Minimum.Y;
            vector.Z = sphere.Center.Z - box.Minimum.Z;

            if (vector.LengthSquared() > radius)
            {
                return(ContainmentType.Intersects);
            }

            return(ContainmentType.Contains);
        }
Beispiel #2
0
 public static bool Intersects(BoundingSphere sphere, BoundingBox box)
 {
     return(BoundingBox.Intersects(box, sphere));
 }