public bool checkSame(scEdge _aEdge) { if ((node0 == _aEdge.getNode0() || node0 == _aEdge.getNode1()) && (node1 == _aEdge.getNode0() || node1 == _aEdge.getNode1())) { return(true); } return(false); }
public scTriangle(scEdge _edg0, scEdge _edg1, scEdge _edg2) { edgeList.Add(_edg0); edgeList.Add(_edg1); edgeList.Add(_edg2); /*for (int i = 0; i < 3; i++){ * lineList[i] = new GameObject().AddComponent<LineRenderer>(); * }*/ }
public bool checkTriangleContainsEdge(scEdge _aEdge) { foreach (scEdge myEdge in edgeList) { if (myEdge.checkSame(_aEdge)) { return(true); } } return(false); }
public void setEdges(scEdge _edge0, scEdge _edge1, scEdge _edge2) { foreach (scEdge aEdge in edgeList) { aEdge.stopDraw(); } edgeList.Clear(); edgeList.Add(_edge0); edgeList.Add(_edge1); edgeList.Add(_edge2); }
public void setEdges(scEdge _edge0, scEdge _edge1, scEdge _edge2) { foreach (scEdge aEdge in edgeList) { aEdge.stopDraw(); } edgeList.Clear(); edgeList.Add(_edge0); edgeList.Add(_edge1); edgeList.Add(_edge2); //reset the drawing lines /*for (int i = 0; i < 3; i++){ * GameObject.Destroy(lineList[i]); * lineList[i] = new GameObject().AddComponent<LineRenderer>(); * }*/ }
private void checkEdges(List <scEdge> _list) { //stores if a flip occured for mode control bool didFlip = false; //the current dirty edge if (_list.Count == 0) { stage = 0; if (animate || doStep) { if (toAddList.Count > 0) { addVertexToTriangulation(); } } return; } //get the next edge in the dirty list scEdge currentEdge = _list[0]; scTriangle[] connectedTris = new scTriangle[2]; int index = 0; foreach (scTriangle aTri in triangleList) { if (aTri.checkTriangleContainsEdge(currentEdge)) { connectedTris[index] = aTri; index++; } } //in first case (omega triangle) this will = 1 so dont flip if (index == 2) { //stores the two verticies from both triangles that arnt on the shared edge scVertexNode[] uniqueNodes = new scVertexNode[2]; int index1 = 0; //loop through the connected triangles and there edges. Checking for a vertex that isnt in the edge for (int i = 0; i < connectedTris.Length; i++) { foreach (scEdge aEdge in connectedTris[i].getEdges()) { if (!currentEdge.edgeContainsVertex(aEdge.getNode0())) { uniqueNodes[index1] = aEdge.getNode0(); index1++; break; } if (!currentEdge.edgeContainsVertex(aEdge.getNode1())) { uniqueNodes[index1] = aEdge.getNode1(); index1++; break; } } } //find the angles of the two unique verticies float angle0 = calculateVertexAngle(uniqueNodes[0].getVertexPosition(), currentEdge.getNode0().getVertexPosition(), currentEdge.getNode1().getVertexPosition()); float angle1 = calculateVertexAngle(uniqueNodes[1].getVertexPosition(), currentEdge.getNode0().getVertexPosition(), currentEdge.getNode1().getVertexPosition()); //Check if the target Edge needs flipping if (angle0 + angle1 > 180) { didFlip = true; //create the new edge after flipped scEdge flippedEdge = new scEdge(uniqueNodes[0], uniqueNodes[1]); //store the edges of both triangles in the Quad scEdge[] firstTriEdges = new scEdge[3]; scEdge[] secondTriEdges = new scEdge[3]; scVertexNode sharedNode0; scVertexNode sharedNode1; //set the shared nodes on the shared edge sharedNode0 = currentEdge.getNode0(); sharedNode1 = currentEdge.getNode1(); //construct a new triangle to update old triangle after flip firstTriEdges[0] = new scEdge(uniqueNodes[0], sharedNode0); firstTriEdges[1] = new scEdge(sharedNode0, uniqueNodes[1]); firstTriEdges[2] = flippedEdge; //construct a new triangle to update the other old triangle after flip secondTriEdges[0] = new scEdge(uniqueNodes[1], sharedNode1); secondTriEdges[1] = new scEdge(sharedNode1, uniqueNodes[0]); secondTriEdges[2] = flippedEdge; //update the edges of the triangles involved in the flip connectedTris[0].setEdges(firstTriEdges[0], firstTriEdges[1], firstTriEdges[2]); connectedTris[1].setEdges(secondTriEdges[0], secondTriEdges[1], secondTriEdges[2]); //Adds all edges to be potentially dirty. This is bad and should only add the edges that *could* be dirty foreach (scEdge eEdge in connectedTris[0].getEdges()) { _list.Add(eEdge); } foreach (scEdge eEdge in connectedTris[1].getEdges()) { _list.Add(eEdge); } //also add new edge to dirty list _list.Add(flippedEdge); } } //remove the current edge from the dirty list _list.Remove(currentEdge); if (doStep || animate) { if (!didFlip) { checkEdges(_list); } } else { checkEdges(_list); } }