private bool InitializeBuffers(SharpDX.Direct3D11.Device device)
        {
            try
            {
                // Create the vertex array.
                var vertices = new DVertex[VertexCount];
                // Create the index array.
                var indices = new int[IndexCount];

                for (var i = 0; i < VertexCount; i++)
                {
                    vertices[i] = new DVertex()
                    {
                        position = new Vector3(ModelObject[i].x, ModelObject[i].y, ModelObject[i].z),
                        texture  = new Vector2(ModelObject[i].tu, ModelObject[i].tv),
                        normal   = new Vector3(ModelObject[i].nx, ModelObject[i].ny, ModelObject[i].nz)
                    };

                    indices[i] = i;
                }

                // Create the vertex buffer.
                VertexBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.VertexBuffer, vertices);

                // Create the index buffer.
                IndexBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.IndexBuffer, indices);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public void CalcPathLen(DVertex start)
        {
            //  Reinitialize vertices
            foreach (var v in Vertices)
            {
                v._pathLen = int.MaxValue / 2;
                v.Viewed   = false;
            }
            heap             = new BinaryHeap <DEdge>();
            heap.postProcess = (DEdge e, int oldIndex, int newIndex) =>
                               e._heapIndex = newIndex;
            foreach (var e in Edges)
            {
                heap.Insert(e);
            }
            var vCount = 1;

            ProcessVertex(start, 0);
            while (vCount < VerticesCount && !heap.IsEmpty)
            {
                var e = heap.ExtractMin();
                if (!e.Dest.Viewed)
                {
                    ProcessVertex((DVertex)e.Dest, e.PathLen);
                    vCount++;
                }
            }
        }
Beispiel #3
0
            public int CompareTo(object obj)
            {
                DVertex b = ( DVertex )obj;

                if (this.x > b.x)
                {
                    return(1);
                }
                return(-1);
            }
Beispiel #4
0
 private new void ProcessVertex(DVertex v, int pathLen)
 {
     v.Viewed   = true;
     v._pathLen = pathLen;
     foreach (var e in Outgoing(v.Key))
     {
         var dedge = (DEdge)e;
         heap.RemoveAt(dedge._heapIndex);
         heap.Insert(dedge);
     }
 }
Beispiel #5
0
        public static List <DTriangle> Triangulate(List <DVertex> vertices)
        {
            int n = vertices.Count;

            /* Bail if there aren't enough vertices to form any triangles. */
            if (n < 3)
            {
                return(new List <DTriangle>());
            }

            vertices.Sort();

            /* Next, find the vertices of the supertriangle (which contains all other
             * triangles), and append them onto the end of a (copy of) the vertex
             * array. */
            float[] st = SuperTriangle(vertices);
            vertices.Add(new DVertex(st[0], st[1]));
            vertices.Add(new DVertex(st[2], st[3]));
            vertices.Add(new DVertex(st[4], st[5]));

            /* Initialize the open list (containing the supertriangle and nothing
             * else) and the closed list (which is empty since we havn't processed
             * any triangles yet). */
            List <DTriangle> open = new List <DTriangle> {
                Circumcircle(vertices, n + 0, n + 1, n + 2)
            };
            List <DTriangle> closed = new List <DTriangle>();
            List <int>       edges  = new List <int>();

            /* Incrementally add each vertex to the mesh. */
            for (int i = 0; i < n; i++)
            {
                edges.Clear();

                /* For each open triangle, check to see if the current point is
                 * inside it's circumcircle. If it is, remove the triangle and add
                 * it's edges to an edge list. */
                for (int j = open.Count - 1; j >= 0; j--)
                {
                    /* If this point is to the right of this triangle's circumcircle,
                     * then this triangle should never get checked again. Remove it
                     * from the open list, add it to the closed list, and skip. */
                    DTriangle openTri   = open[j];
                    DVertex   curVertex = vertices[i];
                    float     dx        = curVertex.x - openTri.x;
                    if (dx > 0.0f && dx * dx > openTri.r)
                    {
                        closed.Add(openTri);
                        open.RemoveAt(j);
                        continue;
                    }

                    /* If we're outside the circumcircle, skip this triangle. */
                    float dy = curVertex.y - openTri.y;
                    if (dx * dx + dy * dy - openTri.r > EPSILON)
                    {
                        continue;
                    }

                    /* Remove the triangle and add it's edges to the edge list. */
                    edges.Add(openTri.v0);
                    edges.Add(openTri.v1);
                    edges.Add(openTri.v1);
                    edges.Add(openTri.v2);
                    edges.Add(openTri.v2);
                    edges.Add(openTri.v0);
                    open.RemoveAt(j);
                }

                /* Remove any doubled edges. */
                Dedup(edges);

                /* Add a new triangle for each edge. */
                for (int j = edges.Count; j > 0;)
                {
                    int b = edges[--j];
                    int a = edges[--j];
                    open.Add(Circumcircle(vertices, a, b, i));
                }
            }

            /* Copy any remaining open triangles to the closed list, and then
             * remove any triangles that share a vertex with the supertriangle,
             * building a list of triplets that represent triangles. */
            closed.AddRange(open);
            open.Clear();

            for (int i = closed.Count - 1; i >= 0; i--)
            {
                DTriangle triangle = closed[i];
                if (triangle.v0 < n && triangle.v1 < n && triangle.v2 < n)
                {
                    open.Add(triangle);
                }
            }

            /* Yay, we're done! */
            return(open);
        }
Beispiel #6
0
        // Пример отсюда https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%94%D0%B5%D0%B9%D0%BA%D1%81%D1%82%D1%80%D1%8B
        public static DGraph GenerateGraph()
        {
            DVertex one = new DVertex { Name = "1"};
              DVertex two = new DVertex {Name = "2"};
              DVertex three = new DVertex {Name = "3"};
              DVertex four = new DVertex {Name = "4"};
              DVertex five = new DVertex {Name = "5"};
              DVertex six = new DVertex {Name = "6"};

              var edges = new List<Edge<DVertex>>
              {
            new Edge<DVertex>
            {
              X = one,
              Y = two,
              Weight = 7
            },
            new Edge<DVertex>
            {
              X = one,
              Y = three,
              Weight = 9
            },
            new Edge<DVertex>
            {
              X = one,
              Y = six,
              Weight = 14
            },
            new Edge<DVertex>
            {
              X = two,
              Y = three,
              Weight = 10
            },
            new Edge<DVertex>
            {
              X = two,
              Y = four,
              Weight = 15
            },
            new Edge<DVertex>
            {
              X = three,
              Y = four,
              Weight = 11
            },
            new Edge<DVertex>
            {
              X = three,
              Y = six,
              Weight = 2
            },
            new Edge<DVertex>
            {
              X = four,
              Y = five,
              Weight = 6
            },
            new Edge<DVertex>
            {
              X = five,
              Y = six,
              Weight = 9
            }
              };

              var vertices = new List<DVertex>();
              vertices.AddRange(new[] { one, two, three, four, five, six });

              var graph = new DGraph
              {
            Edges = edges,
            Vertices = vertices
              };

              return graph;
        }