예제 #1
0
        public Vector2 Distance(PolygonCollider other)
        {
            float   _ret = float.PositiveInfinity;
            Vector2 ret  = new Vector2(_ret, _ret);

            Vector2[] points = other.worldPoints;
            int       l      = points.Length;

            for (int i = 0; i < l; ++i)
            {
                Vector2 reti  = Distance(points [i]);
                float   _reti = reti.sqrMagnitude;
                if (_reti < _ret)
                {
                    ret  = reti;
                    _ret = _reti;
                }
            }
            return(ret);
        }
예제 #2
0
        public bool CheckTrigger(PolygonCollider other)
        {
            Vector2[] otherPoints = other.worldPoints;
            int       opl         = otherPoints.Length;

            for (int i = 0; i < opl; ++i)
            {
                if (this.IsPointInCollider(otherPoints[i]))
                {
                    return(true);
                }
            }
            Vector2[] myPoints = worldPoints;
            int       mpl      = myPoints.Length;

            for (int i = 0; i < mpl; ++i)
            {
                if (other.IsPointInCollider(myPoints[i]))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #3
0
        public bool CheckGraze(PolygonCollider other, out TwinCollisionChild result)
        {
            bool ret0 = false;

            result = null;

            Vector2 mov  = movement;
            Vector2 oMov = other.movement;

            Vector2[] myPoints         = worldPoints;
            Vector2[] otherPoints      = other.worldPoints;
            int       mpl              = myPoints.Length;
            int       mpl1             = mpl - 1;
            int       opl              = otherPoints.Length;
            int       opl1             = opl - 1;
            Vector2   prevContactPoint = Vector2.zero;

            DotToLineCollisionResult r = new DotToLineCollisionResult();

            for (int i = 0; i < mpl; ++i)
            {
                Vector2 p = myPoints [i];

                for (int j = 0; j < opl; ++j)
                {
                    int     j1 = Util.RotaryClamp(j - 1, 0, opl1);
                    Vector2 p1 = otherPoints [j1];
                    Vector2 p2 = otherPoints [j];
                    DotToLineCollisionResult rIJ;
                    if (Physics.MovingDotToMovingLineGraze(
                            p,
                            movement,
                            p1,
                            p2,
                            other.movement,
                            out rIJ) &&
                        (!ret0 || prevContactPoint != rIJ.collisionPoint))
                    {
                        if (!ret0 || rIJ.t < r.t ||
                            (
                                rIJ.t == r.t &&
                                rIJ.dotMovement.sqrMagnitude < r.dotMovement.sqrMagnitude

                                /*&& (
                                 * !r.CheckDotRequirement2(mov+rIJ.dotDepenetration - rIJ.thinDot)
                                 || !r.CheckLineRequirement2(oMov+rIJ.lineDepenetration - rIJ.thinLine)
                                 ||)*/
                            )
                            )
                        {
                            bool collidedIJ = false;
                            if (rIJ.r == 0)
                            {
                                if (Vector2.Dot(
                                        Util.Normal(myPoints[Util.RotaryClamp(i - 1, 0, mpl1)], p),
                                        rIJ.lineNormal
                                        ) == -1)
                                {
                                    collidedIJ = true;
                                }
                            }
                            else if (rIJ.r == 1)
                            {
                                if (Vector2.Dot(
                                        Util.Normal(p, myPoints[Util.RotaryClamp(i + 1, 0, mpl1)]),
                                        rIJ.lineNormal
                                        ) == -1)
                                {
                                    collidedIJ = true;
                                }
                            }
                            else
                            {
                                collidedIJ = true;
                            }
                            if (collidedIJ)
                            {
                                ret0 = true;
                                r    = rIJ;
                                //result = new TwinCollisionChild (this, other, rIJ);
                            }
                        }
                    }
                }
            }
            if (ret0)
            {
                result = new TwinCollisionChild(this, other, r);
            }
            if (ret0 && gameObject.name == "GreenBox" && (result.selfDepenetration.x == 0.3125f || result.selfDepenetration.x == 0.3124999f))
            {
                bool x = true;
            }
            if (ret0 && result.other.gameObject.name == "GreenBox" && (result.otherDepenetration.x == 0.3125f || result.otherDepenetration.x == 0.3124999f))
            {
                bool x = true;
            }
            return(ret0);
        }