#concarve collision detection

1 messages · Page 1 of 1 (latest)

lone pelican
#
for(int i=2;i< pointList.Count;i++)
        {

            Vector2 windingA = pointList[(i - 2) % pointList.Count];
            Vector2 windingB = pointList[(i - 1) % pointList.Count];
            Vector2 pointToBeAdded = pointList[(i)%pointList.Count];

            int currentWinding = GetSignedAngle(windingA,windingB,pointToBeAdded);
            bool windingIsCorrect = (int)winding * currentWinding == -1;

            if (!windingIsCorrect)
            {
                if(!subPolygonActive)
                {
                    subPolygonActive = true;
                    abortedPoints.Add(windingB);
                }
                abortedPoints.Add(pointToBeAdded);
            }
           
            if(windingIsCorrect)
            {
                keptPoints.Add(pointToBeAdded);
                if(subPolygonActive)
                {
                    abortedPoints.Add(pointToBeAdded);
                    
                    if(abortedPoints.Count < pointList.Count)
                    {
                        MyPolygon subPolygon = new MyPolygon(abortedPoints);
                        subPolygon.MakeConvex(winding,false);
                        subpolygons.Add(subPolygon);
                        abortedPoints.Clear();

                        subPolygonActive = false;
                    }
                    else break;
                }
            }
        }
        if(subPolygonActive)
        {
            
            if(looped)
            {
                Debug.LogError("Looped");
            }
            MakeConvex((Winding)((int)winding*-1),true);
            return;
        }
        pointList = keptPoints;
        
            
    }