Beispiel #1
0
        private void TriangulateConnection(HexDirection direction, HexCell cell, HexEdgeVertices e1)
        {
            HexCell neighbor = cell.GetNeighbor(direction);

            if (neighbor == null)
            {
                return;
            }

            Vector3 bridge = HexMetrics.GetBridge(direction);

            bridge.y = neighbor.Position.y - cell.Position.y;

            HexEdgeVertices e2 = new HexEdgeVertices(
                e1.V1 + bridge,
                e1.V4 + bridge
                );

            if (cell.GetEdgeType(direction) == HexEdgeType.SLOPE)
            {
                TriangulateEdgeTerraces(e1, cell, e2, neighbor);
            }
            else
            {
                TriangulateEdgeStrip(e1, cell.Color, e2, neighbor.Color);
            }

            HexCell nextNeighbor = cell.GetNeighbor(direction.Next());

            if (direction > HexDirection.EAST || nextNeighbor == null)
            {
                return;
            }

            Vector3 v5 = e1.V4 + HexMetrics.GetBridge(direction.Next());

            v5.y = nextNeighbor.Position.y;

            if (cell.Elevation <= neighbor.Elevation)
            {
                if (cell.Elevation <= nextNeighbor.Elevation)
                {
                    TriangulateCorner(e1.V4, cell, e2.V4, neighbor, v5, nextNeighbor);
                }
                else
                {
                    TriangulateCorner(v5, nextNeighbor, e1.V4, cell, e2.V4, neighbor);
                }
            }
            else if (neighbor.Elevation <= nextNeighbor.Elevation)
            {
                TriangulateCorner(e2.V4, neighbor, v5, nextNeighbor, e1.V4, cell);
            }
            else
            {
                TriangulateCorner(v5, nextNeighbor, e1.V4, cell, e2.V4, neighbor);
            }
        }
Beispiel #2
0
        public static HexEdgeVertices TerraceLerp(HexEdgeVertices a, HexEdgeVertices b, int step)
        {
            HexEdgeVertices result;

            result.V1 = HexMetrics.TerraceLerp(a.V1, b.V1, step);
            result.V2 = HexMetrics.TerraceLerp(a.V2, b.V2, step);
            result.V3 = HexMetrics.TerraceLerp(a.V3, b.V3, step);
            result.V4 = HexMetrics.TerraceLerp(a.V4, b.V4, step);

            return(result);
        }
Beispiel #3
0
        private void TriangulateEdgeStrip(HexEdgeVertices e1, Color c1, HexEdgeVertices e2, Color c2)
        {
            AddQuad(e1.V1, e1.V2, e2.V1, e2.V2);
            AddQuadColor(c1, c2);

            AddQuad(e1.V2, e1.V3, e2.V2, e2.V3);
            AddQuadColor(c1, c2);

            AddQuad(e1.V3, e1.V4, e2.V3, e2.V4);
            AddQuadColor(c1, c2);
        }
Beispiel #4
0
        private void TriangulateEdgeFan(Vector3 center, HexEdgeVertices edge, Color color)
        {
            AddTriangle(center, edge.V1, edge.V2);
            AddTriangleColor(color);

            AddTriangle(center, edge.V2, edge.V3);
            AddTriangleColor(color);

            AddTriangle(center, edge.V3, edge.V4);
            AddTriangleColor(color);
        }
Beispiel #5
0
        private void Triangulate(HexDirection direction, HexCell cell)
        {
            Vector3         center = cell.Position;
            HexEdgeVertices e      = new HexEdgeVertices(
                center + HexMetrics.GetFirstSolidCorner(direction),
                center + HexMetrics.GetSecondSolidCorner(direction)
                );

            TriangulateEdgeFan(center, e, cell.Color);

            if (direction <= HexDirection.SOUTH_EAST)
            {
                TriangulateConnection(direction, cell, e);
            }
        }
Beispiel #6
0
        private void TriangulateEdgeTerraces(HexEdgeVertices begin, HexCell beginCell, HexEdgeVertices end, HexCell endCell)
        {
            HexEdgeVertices e2 = HexEdgeVertices.TerraceLerp(begin, end, 1);
            Color           c2 = HexMetrics.TerraceLerp(beginCell.Color, endCell.Color, 1);

            TriangulateEdgeStrip(begin, beginCell.Color, e2, c2);

            for (int i = 2; i < HexMetrics.TERRACE_STEPS; i++)
            {
                HexEdgeVertices e1 = e2;
                Color           c1 = c2;

                e2 = HexEdgeVertices.TerraceLerp(begin, end, i);
                c2 = HexMetrics.TerraceLerp(beginCell.Color, endCell.Color, i);

                TriangulateEdgeStrip(e2, c2, end, endCell.Color);
            }

            TriangulateEdgeStrip(e2, c2, end, endCell.Color);
        }