private void RenderSpline(BezierSpline spline, IHexMesh mesh)
        {
            if (spline == null)
            {
                return;
            }

            float delta = 1f / RenderConfig.RoadQuadsPerCurve;

            float v1, v2 = 0;

            Vector3 lowerLeft, lowerRight, upperLeft, upperRight;

            for (float t = 0f; t < 1f; t += delta)
            {
                lowerLeft  = spline.GetPoint(t) + spline.GetNormalXZ(t).normalized *RenderConfig.RoadWidth / 2f;
                lowerRight = spline.GetPoint(t) - spline.GetNormalXZ(t).normalized *RenderConfig.RoadWidth / 2f;

                upperLeft  = spline.GetPoint(t + delta) + spline.GetNormalXZ(t + delta).normalized *RenderConfig.RoadWidth / 2f;
                upperRight = spline.GetPoint(t + delta) - spline.GetNormalXZ(t + delta).normalized *RenderConfig.RoadWidth / 2f;

                v1 = v2;

                v2 += (lowerLeft - lowerRight).magnitude / RenderConfig.RoadVRepeatLength;

                mesh.AddQuad(lowerLeft, lowerRight, upperLeft, upperRight);
                mesh.AddQuadUV(0f, 1f, v1, v2);
            }
        }
Beispiel #2
0
        private void TriangulateCultureAlongContour(
            IHexCell center, HexDirection direction, Color color, IHexMesh cultureMesh
            )
        {
            var contour = CellEdgeContourCanon.GetContourForCellEdge(center, direction);

            Vector2 innerCCW, innerCW, outerCCW, outerCW;

            for (int i = 0; i < contour.Count - 1; i++)
            {
                outerCCW = contour[i];
                outerCW  = contour[i + 1];

                innerCCW = Vector2.Lerp(outerCCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent);
                innerCW  = Vector2.Lerp(outerCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent);

                cultureMesh.AddQuad(
                    new Vector3(innerCCW.x, 0f, innerCCW.y), new Vector3(innerCW.x, 0f, innerCW.y),
                    new Vector3(outerCCW.x, 0f, outerCCW.y), new Vector3(outerCW.x, 0f, outerCW.y)
                    );

                cultureMesh.AddQuadUV(new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, 1f));

                cultureMesh.AddQuadColor(color);
            }
        }
        private void TriangulateMarshEdge(
            IHexCell center, IHexCell right, float centerV, float rightV, HexDirection direction, IHexMesh mesh
            )
        {
            mesh.AddQuad(
                center.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction),
                center.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction),
                right.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction.Opposite()),
                right.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction.Opposite())
                );

            mesh.AddQuadUV(0f, 0f, centerV, rightV);
        }
Beispiel #4
0
        private void TriangulateCultureCorners_River(
            IHexCell center, IHexCell left, IHexCell right, IHexCell nextRight, HexDirection direction,
            ICivilization centerOwner, ReadOnlyCollection <Vector2> centerRightContour, IHexMesh cultureMesh
            )
        {
            Color cultureColor = centerOwner.Template.Color;

            if (left != null && CivTerritoryLogic.GetCivClaimingCell(left) != centerOwner)
            {
                float ccwTransparency = 1f, cwTransparency;

                Vector2 innerCCW, innerCW, outerCCW, outerCW;

                float cultureWidth = (centerRightContour.First() - center.AbsolutePositionXZ).magnitude * RenderConfig.CultureWidthPercent;

                int i = 0;
                do
                {
                    outerCCW = centerRightContour[i];
                    outerCW  = centerRightContour[i + 1];

                    float distanceFromStart = (centerRightContour.First() - outerCW).magnitude;

                    cwTransparency = Mathf.Clamp01(1f - distanceFromStart / cultureWidth);

                    innerCCW = Vector2.Lerp(outerCCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent);
                    innerCW  = Vector2.Lerp(outerCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent);

                    cultureMesh.AddQuad(
                        new Vector3(innerCCW.x, 0f, innerCCW.y), new Vector3(innerCW.x, 0f, innerCW.y),
                        new Vector3(outerCCW.x, 0f, outerCCW.y), new Vector3(outerCW.x, 0f, outerCW.y)
                        );

                    cultureMesh.AddQuadUV(
                        new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, ccwTransparency), new Vector2(0f, cwTransparency)
                        );

                    cultureMesh.AddQuadColor(cultureColor);

                    ccwTransparency = cwTransparency;
                    i++;
                } while(cwTransparency > 0f && i < centerRightContour.Count - 1);
            }

            if (nextRight != null && CivTerritoryLogic.GetCivClaimingCell(nextRight) != centerOwner)
            {
                float cwTransparency = 1f, ccwTransparency;

                Vector2 innerCCW, innerCW, outerCCW, outerCW;

                float cultureWidth = (centerRightContour.Last() - center.AbsolutePositionXZ).magnitude * RenderConfig.CultureWidthPercent;

                int i = centerRightContour.Count - 1;
                do
                {
                    outerCCW = centerRightContour[i - 1];
                    outerCW  = centerRightContour[i];

                    float distanceFromStart = (centerRightContour.Last() - outerCCW).magnitude;

                    ccwTransparency = Mathf.Clamp01(1f - distanceFromStart / cultureWidth);

                    innerCCW = Vector2.Lerp(outerCCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent);
                    innerCW  = Vector2.Lerp(outerCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent);

                    cultureMesh.AddQuad(
                        new Vector3(innerCCW.x, 0f, innerCCW.y), new Vector3(innerCW.x, 0f, innerCW.y),
                        new Vector3(outerCCW.x, 0f, outerCCW.y), new Vector3(outerCW.x, 0f, outerCW.y)
                        );

                    cultureMesh.AddQuadUV(
                        new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, ccwTransparency), new Vector2(0f, cwTransparency)
                        );

                    cultureMesh.AddQuadColor(cultureColor);

                    cwTransparency = ccwTransparency;
                    i--;
                }while(ccwTransparency > 0f && i > 0);
            }
        }