Beispiel #1
0
        /// <summary>
        /// This method utilizes the Delaunay Triangulation.
        /// </summary>
        public void DelaunayTriangulation()
        {
            // This is here because we're going to refresh the delaunator every time
            // it finishes doing the calculation.
            delaunator = new Delaunator(cells.Select(
                                            o => (IPoint) new DelaunayTriangulation.Models.Point(o.LocationCenter.X, o.LocationCenter.Y, o.GetHashCode())).ToArray());

            // Process the result.
            delaunator.ForEachTriangleEdge(edge => {
                foreach (Cell cell in cells)
                {
                    //if (edge.P.CellReference == cell.GetHashCode()) {
                    //    cell.ConnectedCell.Add(cells.Single(o => o.GetHashCode() == edge.Q.CellReference).GetHashCode());
                    //}
                    //break;

                    // You probably don't want to do this. This is a temporary fix.
                    if (cell.LocationCenter.X == (int)edge.Q.X && cell.LocationCenter.Y == (int)edge.Q.Y)
                    {
                        cell.ConnectedCell.Add(edge.P.CellReference);
                    }
                    if (cell.LocationCenter.X == (int)edge.P.X && cell.LocationCenter.Y == (int)edge.P.Y)
                    {
                        cell.ConnectedCell.Add(edge.Q.CellReference);
                    }
                }
            });
        }
Beispiel #2
0
    void DrawDelaunay()
    {
        if (delaunator == null)
        {
            return;
        }

        if (delaunayVisualsContainer == null)
        {
            delaunayVisualsContainer = new GameObject("Delaunay Visuals").transform;
        }

        if (drawDelaunayPoints)
        {
            foreach (var point in blueNoisePoints)
            {
                Instantiate(delaunayPointPrefab, new Vector3(point.x, 0, point.y), Quaternion.identity, delaunayVisualsContainer);
            }
        }

        if (drawDelaunayEdges)
        {
            delaunator.ForEachTriangleEdge(edge =>
            {
                CreateLine(delaunayVisualsContainer, $"TriangleEdge - {edge.Index}", new Vector3[] { new Vector3((float)edge.P.X, 0, (float)edge.P.Y), new Vector3((float)edge.Q.X, 0, (float)edge.Q.Y) }, delaunayEdgeColor, 0.1f, 0);
            });
        }
    }
 private void DrawDelaunay()
 {
     RefreshDelaunator();
     delaunator.ForEachTriangleEdge(edge =>
     {
         DrawLine(edge.P, edge.Q, TriangleBrush);
     });
 }
Beispiel #4
0
        private void CreateTriangle()
        {
            if (delaunator == null)
            {
                return;
            }

            delaunator.ForEachTriangleEdge(edge =>
            {
                if (drawTriangleEdges)
                {
                    CreateLine(TrianglesContainer, $"TriangleEdge - {edge.Index}", new Vector3[] { edge.P.ToVector3(), edge.Q.ToVector3() }, triangleEdgeColor, triangleEdgeWidth, 0);
                }

                if (drawTrianglePoints)
                {
                    var pointGameObject = Instantiate(trianglePointPrefab, PointsContainer);
                    pointGameObject.transform.SetPositionAndRotation(edge.P.ToVector3(), Quaternion.identity);
                }
            });
        }