GetDistanceSquared() публичный Метод

public GetDistanceSquared ( Vec3 vec1 ) : float
vec1 Vec3
Результат float
Пример #1
0
        /// <summary>
        /// Constructs a <see cref="CryEngine.BoundingSphere"/> that fully contains the given points.
        /// </summary>
        /// <param name="points">The points that will be contained by the sphere.</param>
        /// <param name="result">When the method completes, contains the newly constructed bounding sphere.</param>
        public static void FromPoints(Vec3[] points, out BoundingSphere result)
        {
            // Find the center of all points.
            Vec3 center = Vec3.Zero;

            for (int i = 0; i < points.Length; ++i)
            {
                center += points[i];
            }

            // This is the center of our sphere.
            center /= (float)points.Length;

            // Find the radius of the sphere
            float radius = 0f;

            for (int i = 0; i < points.Length; ++i)
            {
                // We are doing a relative distance comparasin to find the maximum distance
                // from the center of our sphere.
                float distance = center.GetDistanceSquared(points[i]);

                if (distance > radius)
                {
                    radius = distance;
                }
            }

            // Find the real distance from the DistanceSquared.
            radius = (float)Math.Sqrt(radius);

            // Construct the sphere.
            result.Center = center;
            result.Radius = radius;
        }
Пример #2
0
 /// <summary>
 /// Determines whether a <see cref="CryEngine.BoundingSphere"/> contains a point.
 /// </summary>
 /// <param name="sphere">The sphere to test.</param>
 /// <param name="point">The point to test.</param>
 /// <returns>The type of containment the two objects have.</returns>
 public static bool SphereContainsPoint(ref BoundingSphere sphere, ref Vec3 point)
 {
     return (point.GetDistanceSquared(sphere.Center) <= sphere.Radius * sphere.Radius);
 }