예제 #1
0
    //Is a point intersecting with a polygon
    private void PointPolygon()
    {
        List <Vector3> polygonPoints = GetVerticesFromParent(polygonPointsParentTrans);

        //To 2d
        List <MyVector2> polygonPoints_2d = new List <MyVector2>();

        for (int i = 0; i < polygonPoints.Count; i++)
        {
            polygonPoints_2d.Add(polygonPoints[i].ToMyVector2());
        }

        Vector3 testPoint = pointTrans.position;

        //Is the point inside the polygon
        bool isIntersecting = _Intersections.PointPolygon(polygonPoints_2d, testPoint.ToMyVector2());

        //Display
        //Gizmos.color = isIntersecting ? Color.red : Color.white;

        //for (int i = 0; i < polygonPoints.Count; i++)
        //{
        //    int iPlusOne = MathUtility.ClampListIndex(i + 1, polygonPoints.Count);

        //    Gizmos.DrawLine(polygonPoints[i], polygonPoints[iPlusOne]);
        //}

        //Gizmos.DrawWireSphere(testPoint, 0.1f);


        //With mesh to better see what's going on
        //Line
        TestAlgorithmsHelpMethods.DisplayConnectedLinesMesh(polygonPoints_2d, 0.5f, Color.white);

        //Point
        Color circleColor = isIntersecting ? Color.red : Color.white;

        TestAlgorithmsHelpMethods.DisplayCircleMesh(testPoint.ToMyVector2(), 1f, 20, circleColor);
    }