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
コード例 #1
0
ファイル: Polygon.cs プロジェクト: szlatyka/Sharpex2D
        /// <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);
        }
コード例 #2
0
ファイル: Polygon.cs プロジェクト: ThuCommix/Sharpex2D
        /// <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;
        }