private void DrawRoom(DTNode r) { int iMin = (int)(r.getNodePosition().x - r.getParentRoom().transform.localScale.x / 2 + 0.5f); int iMax = (int)(r.getNodePosition().x + r.getParentRoom().transform.localScale.x / 2 + 0.5f); int jMin = (int)(r.getNodePosition().y - r.getParentRoom().transform.localScale.y / 2 + 0.5f); int jMax = (int)(r.getNodePosition().y + r.getParentRoom().transform.localScale.y / 2 + 0.5f); for (int i = iMin; i < iMax; i++) { for (int j = jMin; j < jMax; j++) { if (i == iMin || i == iMax - 1 || j == jMin || j == jMax - 1) { if (CheckForTag(new Vector2(i, j), 0.1f, "Floor")) { continue; } else { InstantiateFromArray(wallTiles, i, j); } } else { InstantiateFromArray(floorTiles, i, j); } } } }
private void DrawConnection(DTEdge c) { DTNode room1 = c.getNodeA(); DTNode room2 = c.getNodeB(); Vector2 pos = new Vector2((float)Math.Round(room1.getNodePosition().x), (float)Math.Round(room1.getNodePosition().y)); float xDir = 0f, yDir = 0f; if (room1.getNodePosition().x <= room2.getNodePosition().x) { xDir = 1f; } else { xDir = -1f; } while (pos.x != (float)Math.Round(room2.getNodePosition().x)) { ConnectionFloor(pos.x, pos.y); ConnectionFloor(pos.x, pos.y + 1f); pos = new Vector2(pos.x + xDir, pos.y); } if (room1.getNodePosition().y <= room2.getNodePosition().y) { yDir = 1f; } else { yDir = -1f; } while (pos.y != (float)Math.Round(room2.getNodePosition().y)) { ConnectionFloor(pos.x, pos.y); ConnectionFloor(pos.x + 1f, pos.y); pos = new Vector2(pos.x, pos.y + yDir); } }
public void drawEdge(string name = "") { if (nodeA.getParentRoom() != null && nodeB.getParentRoom() != null) { if (theLine == null) { theLine = new GameObject().AddComponent <LineRenderer>(); theLine.name = "EdgeLine"; theLine.tag = "Line"; } if (name != "") { theLine = new GameObject().AddComponent <LineRenderer>(); theLine.name = name; if (name == "final tri") { theLine.startColor = new Color(255, 0, 0, 1); theLine.endColor = new Color(255, 0, 0, 1); } if (name == "path") { theLine.startColor = new Color(40, 255, 0, 1); theLine.endColor = new Color(40, 255, 0, 1); Debug.Log(theLine.name); Debug.Log(nodeA.getNodePosition().x + " " + nodeA.getNodePosition().y); Debug.Log(nodeB.getNodePosition().x + " " + nodeB.getNodePosition().y); } } theLine.startWidth = 0.7f; theLine.endWidth = 0.7f; //theLine.renderer.material.color = theDrawColor; theLine.startColor = theDrawColor; theLine.endColor = theDrawColor; theLine.positionCount = 2; theLine.SetPosition(0, new Vector3(nodeA.getNodePosition().x, nodeA.getNodePosition().y, -3)); theLine.SetPosition(1, new Vector3(nodeB.getNodePosition().x, nodeB.getNodePosition().y, -3)); } }
//Adds a verticies to the triangulation private void AddVertexToTriangulation() { //Find a Random verticie from the todo list int choice = pseudoRandom.Next(0, nodesToAddList.Count); //set next node to selected verticies nextNode = nodesToAddList[choice]; //remove selected verticies from todo list nodesToAddList.Remove(nextNode); //stores triangles created during the loop to be appended to main list after loop List <DTTriangle> tempTriList = new List <DTTriangle>(); //All edges are clean at this point. Remove any that may be left over from previous loop edgesToCheck.Clear(); float count = -1; foreach (DTTriangle aTri in triangleList) { List <DTEdge> triEdges = aTri.GetEdges(); count++; //Find which triangle the current vertex being add is located within if (LineIntersection.PointInTraingle(nextNode.getNodePosition(), triEdges[0].getNodeA().getNodePosition(), triEdges[0].getNodeB().getNodePosition(), triEdges[1].getNodeB().getNodePosition())) { //cache the triangle we are in so we can delete it after loop inTriangle = aTri; //create three new triangles from each edge of the triangle vertex is in to the new vertex foreach (DTEdge aEdge in aTri.GetEdges()) { DTTriangle nTri1 = new DTTriangle(new DTEdge(nextNode, aEdge.getNodeA()), new DTEdge(nextNode, aEdge.getNodeB()), new DTEdge(aEdge.getNodeB(), aEdge.getNodeA())); //cache created triangles so we can add to list after loop tempTriList.Add(nTri1); //mark the edges of the old triangle as dirty edgesToCheck.Add(new DTEdge(aEdge.getNodeA(), aEdge.getNodeB())); } break; } } //add the three new triangles to the triangle list foreach (DTTriangle aTri in tempTriList) { triangleList.Add(aTri); } //delete the old triangle that the vertex was inside of if (inTriangle != null) { triangleList.Remove(inTriangle); inTriangle.StopDraw(); inTriangle = null; } CheckEdges(edgesToCheck); }