/* The method isAllVerticesDifferent checks if all the vertices in the Vector3[] vericesToCheck array are * different * Parameters: Vector3[] verticesToCheck - array of vertices to be checked * Return: bool * true if the vertices are all different, false otherwise */ bool isAllVerticesDifferent(Vector3[] verticesToCheck) { for (int count1 = 0; count1 < verticesToCheck.Length; count1++) { for (int count2 = count1 + 1; count2 < verticesToCheck.Length; count2++) { if (AIPolygon.checkVertices(verticesToCheck [count1], verticesToCheck [count2]) == true) { return(false); } } } return(true); }
/* The method getArrayOfEdgeVertices constructs an array of edge vertices from the polygons * Return: Vector3[] * array of edge vertices */ Vector3[] getArrayOfEdgeVertices() { Vector3[] tempArray = new Vector3[arrayOfEdges.Length / 2]; tempArray[0] = new Vector3(arrayOfEdges[0, 0].x, arrayOfEdges[0, 0].y, arrayOfEdges[0, 0].z); tempArray[1] = new Vector3(arrayOfEdges[0, 1].x, arrayOfEdges[0, 1].y, arrayOfEdges[0, 1].z); bool flag = true; for (int count = 1, position = 2; count < tempArray.Length && position < tempArray.Length; count++) { for (int count2 = 0; count2 < position && position < tempArray.Length; count2++) { if (AIPolygon.checkVertices(tempArray [count2], arrayOfEdges [count, 0]) == true) { flag = false; } } if (flag == true) { tempArray [position] = new Vector3(arrayOfEdges [count, 0].x, arrayOfEdges [count, 0].y, arrayOfEdges [count, 0].z); position++; } flag = true; for (int count2 = 0; count2 < position && position < tempArray.Length; count2++) { if (AIPolygon.checkVertices(tempArray [count2], arrayOfEdges [count, 1]) == true) { flag = false; } } if (flag == true) { tempArray [position] = new Vector3(arrayOfEdges [count, 1].x, arrayOfEdges [count, 1].y, arrayOfEdges [count, 1].z); position++; } flag = false; } return(seperateEdgesIntoVectors(tempArray)); }
/* The method getTwoPolygons a.k.a. "The Beast" contructs two polygons from one. * Parameter: AIpolygon polygonToSplit - polygon that will be attempted to be split * int indexToUse - index of vetex to start split from * int startPosition - * Return: int * returns -1 if not possible, index to start next iteration from */ int getTwoPolygons(AIPolygon polygonToSplit, int indexToUse, int startPosition) { verticeToMakePolygonFrom = new Vector3[polygonToSplit.getVertices().Length * 3]; Vector3[] polygonVertices = polygonToSplit.getVertices(); Vector3 connecting; Vector3 notReal = new Vector3(1000f, 1000f, 1000f); int cutTimes = 0; int secondPositionStart = -1; verticesTomakePolygonFromCount = 0; int position = startPosition; int count = 0; verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(polygonVertices [position].x, polygonVertices [position].y, polygonVertices [position].z); verticesTomakePolygonFromCount++; position++; position = position % polygonVertices.Length; count++; if (indexToUse < 0 || indexToUse >= arrayOfEdges.Length / 2) { return(-1); } connecting = polygonToSplit.getIntersectingPoint(arrayOfEdges [indexToUse, 0], arrayOfEdges [indexToUse, 1], verticeToMakePolygonFrom [verticesTomakePolygonFromCount - 1], polygonVertices [position]); while ((count < polygonVertices.Length) && (AIPolygon.checkVertices(connecting, notReal) == true)) //chekcs to see if an intersecting point was found yet if not continue to add old vertices to first new polygon { verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(polygonVertices [position].x, polygonVertices [position].y, polygonVertices [position].z); verticesTomakePolygonFromCount++; position++; count++; if (position >= polygonVertices.Length) { position = 0; } connecting = polygonToSplit.getIntersectingPoint(arrayOfEdges [indexToUse, 0], arrayOfEdges [indexToUse, 1], verticeToMakePolygonFrom [verticesTomakePolygonFromCount - 1], polygonVertices [position]); } if (AIPolygon.checkVertices(connecting, notReal) == false) //checks to see if the inersecting point was a valid connection and if so add it to both the new polygons { cutTimes++; verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(connecting.x, connecting.y, connecting.z); verticesTomakePolygonFromCount++; secondPositionStart = verticesTomakePolygonFromCount; verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(connecting.x, connecting.y, connecting.z); verticesTomakePolygonFromCount++; verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(polygonVertices [position].x, polygonVertices [position].y, polygonVertices [position].z); verticesTomakePolygonFromCount++; } position++; count++; if (position >= polygonVertices.Length) { position = 0; } connecting = polygonToSplit.getIntersectingPoint(arrayOfEdges [indexToUse, 0], arrayOfEdges [indexToUse, 1], verticeToMakePolygonFrom [verticesTomakePolygonFromCount - 1], polygonVertices [position]); while ((count < polygonVertices.Length) && (AIPolygon.checkVertices(connecting, notReal) == true)) //checks to see if an intersecting pont was found yet if not continue to add old vertices to the second new polygon { verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(polygonVertices [position].x, polygonVertices [position].y, polygonVertices [position].z); verticesTomakePolygonFromCount++; position++; count++; if (position >= polygonVertices.Length) { position = 0; } connecting = polygonToSplit.getIntersectingPoint(arrayOfEdges [indexToUse, 0], arrayOfEdges [indexToUse, 1], verticeToMakePolygonFrom [verticesTomakePolygonFromCount - 1], polygonVertices [position]); } if (AIPolygon.checkVertices(connecting, notReal) == false) //checks to see if the intersecting point was a valid connection and if so add it to both the new polygons { cutTimes++; verticeToMakePolygonFrom [verticesTomakePolygonFromCount] = new Vector3(connecting.x, connecting.y, connecting.z); verticesTomakePolygonFromCount++; } if (count != polygonVertices.Length || cutTimes != 2) { return(-1); } return(secondPositionStart); }