示例#1
0
    public void drawEdge()
    {
        if (node0.getParentCell() != null && node1.getParentCell() != null)
        {
            if (theLine == null)
            {
                theLine          = new GameObject().AddComponent <LineRenderer>();
                theLine.name     = "EdgeLine";
                theLine.material = new Material(Shader.Find("Particles/Additive"));
                theLine.tag      = "Lines";
            }

            theLine.SetWidth(0.7f, 0.7f);
            theLine.SetColors(theDrawColor, theDrawColor);
            theLine.SetVertexCount(2);
            theLine.SetPosition(0, new Vector3(node0.getVertex().x, node0.getVertex().y, -3));
            theLine.SetPosition(1, new Vector3(node1.getVertex().x, node1.getVertex().y, -3));
        }
    }
示例#2
0
    //Adds a verticies to the triangulation
    private void addVertexToTriangulation()
    {
        //check what mode the triangulation is running in
        if (stage == 0 || (!doStep && !animate))
        {
            //Find a Random verticie from the todo list
            int choice = Random.Range(0, toAddList.Count);

            //Change the color of all other verticies
            foreach (VertexNode aNode in toAddList)
            {
                aNode.getParentCell().GetComponent <Renderer>().material.color = new Color(255, 255, 255, 255);
            }

            //set next node to selected verticies
            nextNode = toAddList[choice];

            nextNode.getParentCell().GetComponent <Renderer>().material.color = new Color(0, 0, 255, 255);

            //remove selected verticies from todo list
            toAddList.Remove(nextNode);

            if (doStep || animate)
            {
                stage++;
                return;
            }
        }

        if (stage == 1 || (!doStep && !animate))
        {
            //stores triangles created during the loop to be appended to main list after loop
            List <Triangle> tempTriList = new List <Triangle>();

            //All edges are clean at this point. Remove any that may be left over from previous loop
            dirtyEdges.Clear();

            float count = -1;
            foreach (Triangle aTri in triangleList)
            {
                List <Edge> triEdges = aTri.getEdges();
                count++;
                //Find which triangle the current vertex being add is located within
                if (LineIntersection.PointInTraingle(nextNode.getVertex(), triEdges[0].getNode0().getVertex(),
                                                     triEdges[0].getNode1().getVertex(), triEdges[1].getNode1().getVertex()))
                {
                    //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 (Edge aEdge in aTri.getEdges())
                    {
                        Triangle nTri1 = new Triangle(new Edge(nextNode, aEdge.getNode0()),
                                                      new Edge(nextNode, aEdge.getNode1()),
                                                      new Edge(aEdge.getNode1(), aEdge.getNode0()));

                        //cache created triangles so we can add to list after loop
                        tempTriList.Add(nTri1);

                        //mark the edges of the old triangle as dirty
                        dirtyEdges.Add(new Edge(aEdge.getNode0(), aEdge.getNode1()));
                    }

                    break;
                }
            }

            //add the three new triangles to the triangle list
            foreach (Triangle 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;
            }

            if (doStep || animate)
            {
                stage++;
                return;
            }
        }

        if (stage == 2 || !doStep)
        {
            //recursively check the dirty edges to make sure they are still delaunay
            checkEdges(dirtyEdges);
        }
    }