Beispiel #1
0
        protected override CollisionResult ContactWithCircle(ConvexCircle otherCircle)
        {
            //We use circle collide rect to chcek
            //reduce duplicate code because code is all most the same only
            //rectangle inside circle need to be checked
            CollisionResult result = otherCircle.IntersectWithShape(this);

            //Check rectangle is inside circle when overlap
            if (result == CollisionResult.Overlap)
            {
                /**
                 * For each corner of recntangle
                 * we check if corner inside circle
                 *
                 * Return fit if all corner insdie circle
                 **/
                Vector2[] corners = AllCorners;

                IEnumerator ie = corners.GetEnumerator();
                while (ie.MoveNext())
                {
                    //projection axis from corner to circle center
                    Vector2 p = otherCircle.Center - (Vector2)ie.Current;

                    //corner projection
                    float cornerP = Vector2.Dot(p.normalized, (Vector2)ie.Current);

                    //circle center projection
                    float circleP = Vector2.Dot(p.normalized, otherCircle.Center);


                    //if corner projection is outside of circle return overlap
                    if ((circleP - otherCircle.Radius) > cornerP || (circleP + otherCircle.Radius) < cornerP)
                    {
                        return(result);
                    }
                }

                return(CollisionResult.Fit);
            }

            //If circle fit in this rectangle return overlap
            //as from rectangle poit of view rectangle overlap circle
            if (result == CollisionResult.Fit)
            {
                return(CollisionResult.Overlap);
            }

            return(result);
        }
Beispiel #2
0
 protected override CollisionResult ContactWithCircle(ConvexCircle otherCircle)
 {
     return(otherCircle.IntersectWithShape(this));
 }