示例#1
0
    void GetAdjacent(Vertex u)
    {
        Vector2 uPos = new Vector2(u.position.x, u.position.y);
        Vector2 vPos;

        foreach (Vertex v in graph.graph)
        {
            if (u == v || v.IsAdjacent(u.id))
            {
                continue;
            }

            vPos = new Vector2(v.position.x, v.position.y);
            Vector2 direction = vPos - uPos;
            float   distance  = direction.magnitude;
            direction.Normalize();
            RaycastHit2D obstacle = Physics2D.CircleCast(uPos + (direction * agentRadius), agentRadius, direction, distance, 1 << 8);

            if (!obstacle)
            {
                u.AddAdjacent(v.id);
                v.AddAdjacent(u.id);
            }
        }
    }
示例#2
0
        public AdjacencyMatrix(Mesh mesh)
        {
            vertexNumber = mesh.vertices.Length;
            Vector3[] vertices  = mesh.vertices;
            int[]     triangles = mesh.triangles;
            bounds = mesh.bounds;

            this.vertices = new List <Vertex>(vertexNumber);
            for (int i = 0; i < vertexNumber; i++)
            {
                this.vertices.Add(new Vertex {
                    vertex = vertices[i]
                });
            }

            for (int i = 0; i < triangles.Length - 3; i += 3)
            {
                Vertex v1 = this.vertices[triangles[i + 0]];
                Vertex v2 = this.vertices[triangles[i + 1]];
                Vertex v3 = this.vertices[triangles[i + 2]];
                Vertex.AddAdjacent(v1, v2);
                Vertex.AddAdjacent(v1, v3);
                Vertex.AddAdjacent(v2, v3);
            }
        }
示例#3
0
 // Adds and edge by setting start as adjacent to end and
 // viceversa
 public EdgeIfc AddEdge( Vertex start,  Vertex end )
 {
     start.AddAdjacent( end );
     end.AddAdjacent( start );
     return ( EdgeIfc ) start;
 }
示例#4
0
 // Adds and edge by setting end as adjacent to start vertices
 public EdgeIfc AddEdge(Vertex start, Vertex end)
 {
     start.AddAdjacent(end);
     return(start);
 }
示例#5
0
 // Adds and edge by setting end as adjacent to start vertices
 public EdgeIfc AddEdge( Vertex start,  Vertex end ) {
     start.AddAdjacent( end );
     return start;
 }