public static BoundingBox GetBoundingBox(IEnumerable<Point3D> points)
        {
            BoundingBox box = new BoundingBox();

            if (points != null)
            {
                box.Min = new Point3D(double.PositiveInfinity, double.PositiveInfinity, double.PositiveInfinity);
                box.Max = new Point3D(double.NegativeInfinity, double.NegativeInfinity, double.NegativeInfinity);
                foreach (Point3D point in points)
                {
                    if (point.X < box.Min.X)
                        box.Min.X = point.X;
                    if (point.Y < box.Min.Y)
                        box.Min.Y = point.Y;
                    if (point.Z < box.Min.Z)
                        box.Min.Z = point.Z;

                    if (point.X > box.Max.X)
                        box.Max.X = point.X;
                    if (point.Y > box.Max.Y)
                        box.Max.Y = point.Y;
                    if (point.Z > box.Max.Z)
                        box.Max.Z = point.Z;
                }
            }
            return box;
        }
        public static BoundingBox GetBoundingBox(Visual3DCollection visualItems)
        {
            BoundingBox result = new BoundingBox();

            foreach (Visual3D item in visualItems)
            {
                ModelVisual3D visual = (item as ModelVisual3D);
                if (visual != null)
                {
                    Body body = World.GetBody(visual);
                    if (body != null)
                    {
                        BoundingBox box = GetBoundingBox(body);

                        Matrix3D matrix = (body.Transform != null) ? body.Transform.Value : Matrix3D.Identity;
                        box.Min = matrix.Transform(box.Min);
                        box.Max = matrix.Transform(box.Max);

                        result.Union(box);
                    }
                }
            }

            return result;
        }
        public void Union(BoundingBox box)
        {
            if (box.Min.X < this.Min.X)
                this.Min.X = box.Min.X;
            if (box.Min.Y < this.Min.Y)
                this.Min.Y = box.Min.Y;
            if (box.Min.Z < this.Min.Z)
                this.Min.Z = box.Min.Z;

            if (box.Max.X > this.Max.X)
                this.Max.X = box.Max.X;
            if (box.Max.Y > this.Max.Y)
                this.Max.Y = box.Max.Y;
            if (box.Max.Z > this.Max.Z)
                this.Max.Z = box.Max.Z;
        }
        private void SetNewCenter(Point3D newCenter, BoundingBox box)
        {
            newCenter.Y *= -1;
            Point3D boxCenter = box.CenterPos;

            Vector3D offsetBy = ((Vector3D)newCenter - (Vector3D)boxCenter) - _offset;
            OffsetCollisionMask(offsetBy, this.Visual.Content != null);
            _offset += offsetBy;
        }