Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the result of adding two bounding volumes together.
        /// </summary>
        /// <param name="a">The first bounding volume.</param>
        /// <param name="b">The second bounding volume.</param>
        /// <returns>A new bounding volume.</returns>
        public static FSphere operator +(FSphere a, FSphere b)
        {
            if (a.W == 0.0f)
            {
                a = b;
            }
            else if (a.IsInside(b))
            {
                a = b;
            }
            else if (b.IsInside(a))
            {
                // no change
            }
            else
            {
                FSphere newSphere;

                FVector dirToOther     = b.Center - a.Center;
                FVector unitDirToOther = dirToOther;
                unitDirToOther.Normalize();

                float newRadius = (dirToOther.Size() + b.W + a.W) * 0.5f;

                // find end point
                FVector end1      = b.Center + unitDirToOther * b.W;
                FVector end2      = a.Center - unitDirToOther * a.W;
                FVector newCenter = (end1 + end2) * 0.5f;

                newSphere.Center = newCenter;
                newSphere.W      = newRadius;

                // make sure both are inside afterwards
                Debug.Assert(b.IsInside(newSphere, 1.0f));
                Debug.Assert(a.IsInside(newSphere, 1.0f));

                a = newSphere;
            }

            return(a);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Interpolate vector from Current to Target with constant step
        /// </summary>
        public static FVector VInterpConstantTo(FVector current, FVector target, float deltaTime, float interpSpeed)
        {
            FVector delta   = target - current;
            float   deltaM  = delta.Size();
            float   maxStep = interpSpeed * deltaTime;

            if (deltaM > maxStep)
            {
                if (maxStep > 0.0f)
                {
                    FVector deltaN = delta / deltaM;
                    return(current + deltaN * maxStep);
                }
                else
                {
                    return(current);
                }
            }

            return(target);
        }