HasSeparatingAxisTo() private method

A value indicating whether the Polygon has a seperating axis.
private HasSeparatingAxisTo ( Polygon other, float &minOverlap, Vector2 &axis ) : bool
other Polygon The other Polygon.
minOverlap float The MinimumOverlap.
axis Vector2 The Axis.
return bool
Ejemplo n.º 1
0
        /// <summary>
        ///     Checks if this Polygon intersects with another Polygon.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minimumTranslationVector">
        ///     Returns a vector with which the Polygon has to be translated at minimum to not
        ///     collide with the second Polygon.
        /// </param>
        /// <returns>True of intersecting.</returns>
        public bool Intersects(Polygon other, out Vector2 minimumTranslationVector)
        {
            if (!IsValid || !other.IsValid)
            {
                throw new InvalidOperationException();
            }

            minimumTranslationVector = default(Vector2);
            float minOverlap = float.MaxValue;

            if (HasSeparatingAxisTo(other, ref minOverlap, ref minimumTranslationVector))
            {
                return(false);
            }

            if (other.HasSeparatingAxisTo(this, ref minOverlap, ref minimumTranslationVector))
            {
                return(false);
            }

            Vector2 d = Center - other.Center;

            if (Vector2.Dot(d, minimumTranslationVector) > 0)
            {
                minimumTranslationVector = -minimumTranslationVector;
            }
            minimumTranslationVector *= minOverlap;

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Checks if this Polygon intersects with another Polygon.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minimumTranslationVector">
        ///     Returns a vector with which the Polygon has to be translated at minimum to not
        ///     collide with the second Polygon.
        /// </param>
        /// <returns>True of intersecting.</returns>
        public bool Intersects(Polygon other, out Vector2 minimumTranslationVector)
        {
            if (!IsValid || !other.IsValid)
                throw new InvalidOperationException();

            minimumTranslationVector = default(Vector2);
            float minOverlap = float.MaxValue;

            if (HasSeparatingAxisTo(other, ref minOverlap, ref minimumTranslationVector))
                return false;

            if (other.HasSeparatingAxisTo(this, ref minOverlap, ref minimumTranslationVector))
                return false;

            Vector2 d = Center - other.Center;
            if (Vector2.Dot(d, minimumTranslationVector) > 0)
                minimumTranslationVector = -minimumTranslationVector;
            minimumTranslationVector *= minOverlap;

            return true;
        }