private IEnumerator LinkSpheres() { Debug.Log("Linking Spheres"); SphereGraph = new SimpleGraph(Spheres.Count, 2 * Portals.Count); // How much is our offset for the second arc int BidirectionOffset = Portals.Count; // Every portal is a connection between spheres, so lets do that foreach (CameraGraphPortalNode portal in Portals) { // Indices for the sphere nodes int SphereAIndex = Spheres.IndexOf(portal.A); int SphereBIndex = Spheres.IndexOf(portal.B); // Index for the portal int PortalIndex = Portals.IndexOf(portal); // Links are all bidirectional SphereGraph.SetNodeArc(SphereAIndex, PortalIndex, SphereBIndex); SphereGraph.SetNodeArc(SphereBIndex, PortalIndex + BidirectionOffset, SphereAIndex); // Gotta show off that cool debugging Debug.DrawLine(portal.A.transform.position, portal.B.transform.position, Color.red, 1.0f); if (ShouldOperationYield()) { yield return(new WaitForEndOfFrame()); } } Debug.Log("Linked " + SphereGraph.numNodes + " spheres with " + SphereGraph.numArcs + " arcs"); yield return(null); }
private IEnumerator LinkPortals() { Debug.Log("Linking Portals"); // Figure out how big our graph is int NumNodes = Portals.Count; int NumArcs = 0; // The number of arcs is equal to the sum of the number of spheres exit arcs - 1 for (int i = 0; i < SphereGraph.numNodes; ++i) { NumArcs += SphereGraph.NumArcsForNode(i) - 1; } // Remember to double your stuff int BidirectionOffset = NumArcs; NumArcs *= 2; PortalGraph = new SimpleGraph(NumNodes, NumArcs); // We can just look at all the spheres and connect their portals to make sure the web is complete foreach (CameraGraphSphereNode Sphere in Spheres) { int SphereIndex = Spheres.IndexOf(Sphere); for (int i = 0; i < Sphere.IntersectionPortals.Count; ++i) { CameraGraphPortalNode A = Sphere.IntersectionPortals[i] as CameraGraphPortalNode; for (int j = i; j < Sphere.IntersectionPortals.Count; ++j) { CameraGraphPortalNode B = Sphere.IntersectionPortals[j] as CameraGraphPortalNode; // Indices for the sphere nodes int PortalAIndex = Portals.IndexOf(A); int PortalBIndex = Portals.IndexOf(B); // Link A and B bidirectionally PortalGraph.SetNodeArc(PortalAIndex, SphereIndex, PortalBIndex); PortalGraph.SetNodeArc(PortalBIndex, SphereIndex + BidirectionOffset, PortalAIndex); // Debug draw Debug.DrawLine(A.transform.position, B.transform.position, Color.magenta, 1.0f); // Yield to draw if (ShouldOperationYield()) { yield return(new WaitForEndOfFrame()); } } } } Debug.Log("Linked " + PortalGraph.numNodes + " spheres with " + PortalGraph.numArcs + " arcs"); yield return(null); }