Пример #1
0
        public static BoundingBox CreateFromPoints(IEnumerable <Vector3> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException();
            }

            // TODO: Just check that Count > 0
            bool    empty   = true;
            Vector3 vector2 = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Vector3 vector1 = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            foreach (Vector3 vector3 in points)
            {
                vector2 = Vector3Extensions.Min(vector2, vector3);
                vector1 = Vector3Extensions.Max(vector1, vector3);
                empty   = false;
            }
            if (empty)
            {
                throw new ArgumentException();
            }

            return(new BoundingBox(vector2, vector1));
        }
Пример #2
0
        public bool Intersects(BoundingSphere sphere)
        {
            float val = Vector3Extensions.Distance(sphere.Center, Center);

            if (val > sphere.Radius + Radius)
            {
                return(false);
            }
            return(true);
        }
Пример #3
0
        public static BoundingSphere CreateFromBoundingBox(BoundingBox box)
        {
            // Find the center of the box.
            Vector3 center = new Vector3((box.Min.X + box.Max.X) / 2.0f,
                                         (box.Min.Y + box.Max.Y) / 2.0f,
                                         (box.Min.Z + box.Max.Z) / 2.0f);

            // Find the distance between the center and one of the corners of the box.
            float radius = Vector3Extensions.Distance(center, box.Max);

            return(new BoundingSphere(center, radius));
        }
Пример #4
0
        public ContainmentType Contains(Vector3 point)
        {
            float distance = Vector3Extensions.Distance(point, Center);

            if (distance > this.Radius)
            {
                return(ContainmentType.Disjoint);
            }

            else if (distance < this.Radius)
            {
                return(ContainmentType.Contains);
            }

            return(ContainmentType.Intersects);
        }
Пример #5
0
        public ContainmentType Contains(BoundingSphere sphere)
        {
            float val = Vector3Extensions.Distance(sphere.Center, Center);

            if (val > sphere.Radius + Radius)
            {
                return(ContainmentType.Disjoint);
            }

            else if (val <= Radius - sphere.Radius)
            {
                return(ContainmentType.Contains);
            }

            else
            {
                return(ContainmentType.Intersects);
            }
        }
Пример #6
0
 public static BoundingBox CreateMerged(BoundingBox original, BoundingBox additional)
 {
     return(new BoundingBox(
                Vector3Extensions.Min(original.Min, additional.Min), Vector3Extensions.Max(original.Max, additional.Max)));
 }