private List<Vertex> buildGraph(Vector3 start, Vector3 end)
{
//I can build the graph once in the future
List<Vertex> allVertices = new List<Vertex>();
int counter = 0;
double connectToStartDist = Double.MaxValue;
double connectToEndDist = Double.MaxValue;
Vertex connectToStart = null;
Vertex connectToEnd = null;
foreach (Transform t in transform) {
Waypoint w = t.gameObject.GetComponent<Waypoint>();
Vertex temp = new Vertex(w.location());
allVertices.Add (temp);
if(Vector3.Distance(start, w.location ()) < connectToStartDist) {
connectToStartDist = Vector3.Distance(start, w.location ());
connectToStart = temp;
}
if(Vector3.Distance(end, w.location ()) < connectToEndDist) {
connectToEndDist = Vector3.Distance(end, w.location ());
connectToEnd = temp;
}
}
//allVertices has all vertices in the graph
foreach (Transform t in transform) { //for each waypoint
Waypoint w = t.gameObject.GetComponent<Waypoint>();
foreach (Vector3 tempAdj in w.getAdjacent()) { //for each adjacent Vector3
foreach (Vertex vert in allVertices) {
if (vert.isSameLocation(tempAdj)) {
allVertices[counter].addAdjVert(vert);
break;
}
}
}
counter++;
}
startVertex = new Vertex(start);
endVertex = new Vertex(end);
startVertex.addAdjVert(connectToStart);
connectToEnd.addAdjVert(endVertex);
allVertices.Add(startVertex);
allVertices.Add(endVertex);
return allVertices;
}