예제 #1
0
        /// <summary>
        /// Creates and initializes a new instance from the given Box and Sphere.
        /// </summary>
        /// <param name="box">The bounding box.</param>
        /// <param name="sphere">The bounding sphere.</param>
        public FBoxSphereBounds(FBox box, FSphere sphere)
        {
            box.GetCenterAndExtents(out Origin, out BoxExtent);
            SphereRadius = FMath.Min(BoxExtent.Size(), (sphere.Center - Origin).Size() + sphere.W);

            DiagnosticCheckNaN();
        }
예제 #2
0
        /// <summary>
        /// Creates and initializes a new instance the given Box.
        ///
        /// The sphere radius is taken from the extent of the box.
        /// </summary>
        /// <param name="box">The bounding box.</param>
        public FBoxSphereBounds(FBox box)
        {
            box.GetCenterAndExtents(out Origin, out BoxExtent);
            SphereRadius = BoxExtent.Size();

            DiagnosticCheckNaN();
        }
예제 #3
0
        /// <summary>
        /// Constructs a bounding volume containing both A and B.
        ///
        /// This is a legacy version of the function used to compute primitive bounds, to avoid the need to rebuild lighting after the change.
        /// </summary>
        public FBoxSphereBounds Union(FBoxSphereBounds a, FBoxSphereBounds b)
        {
            FBox boundingBox = new FBox();

            boundingBox += (a.Origin - a.BoxExtent);
            boundingBox += (a.Origin + a.BoxExtent);
            boundingBox += (b.Origin - b.BoxExtent);
            boundingBox += (b.Origin + b.BoxExtent);

            // Build a bounding sphere from the bounding box's origin and the radii of A and B.
            FBoxSphereBounds result = new FBoxSphereBounds(boundingBox);

            result.SphereRadius = FMath.Min(result.SphereRadius,
                                            FMath.Max((a.Origin - result.Origin).Size() + a.SphereRadius, (b.Origin - result.Origin).Size() + b.SphereRadius));
            result.DiagnosticCheckNaN();

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Creates and initializes a new instance from the given set of points.
        ///
        /// The sphere radius is taken from the extent of the box.
        /// </summary>
        /// <param name="points">The points to be considered for the bounding box.</param>
        public FBoxSphereBounds(FVector[] points)
        {
            FBox boundingBox = new FBox();

            // find an axis aligned bounding box for the points.
            for (uint pointIndex = 0; pointIndex < points.Length; pointIndex++)
            {
                boundingBox += points[pointIndex];
            }

            boundingBox.GetCenterAndExtents(out Origin, out BoxExtent);

            // using the center of the bounding box as the origin of the sphere, find the radius of the bounding sphere.
            SphereRadius = 0.0f;

            for (uint pointIndex = 0; pointIndex < points.Length; pointIndex++)
            {
                SphereRadius = FMath.Max(SphereRadius, (points[pointIndex] - Origin).Size());
            }

            DiagnosticCheckNaN();
        }
예제 #5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="pts">Pointer to list of points this sphere must contain.></param>
        public FSphere(FVector[] pts)
        {
            if (pts.Length > 0)
            {
                FBox Box = new FBox(pts);

                this = new FSphere((Box.Min + Box.Max) / 2, 0);

                for (int i = 0; i < pts.Length; i++)
                {
                    float dist = FVector.DistSquared(pts[i], Center);

                    if (dist > W)
                    {
                        W = dist;
                    }
                }
            }
            else
            {
                this = default(FSphere);
            }
        }