private BezierSpline BuildSplineToCenter(IHexCell cell, HexDirection fromEdge)
        {
            Vector3 start = cell.AbsolutePosition + RenderConfig.GetEdgeMidpoint(fromEdge);

            Vector3 controlOne = cell.AbsolutePosition + (
                RenderConfig.GetEdgeMidpoint(fromEdge) + RenderConfig.GetEdgeMidpoint(fromEdge.Previous())
                ) / 3f;

            var roadSpline = new BezierSpline(start);

            roadSpline.AddCubicCurve(controlOne, cell.AbsolutePosition, cell.AbsolutePosition);

            return(roadSpline);
        }
        private BezierSpline BuildSplineBetween(IHexCell cell, HexDirection directionOne, HexDirection directionTwo)
        {
            Vector3 controlOne = cell.AbsolutePosition + (
                RenderConfig.GetEdgeMidpoint(directionOne) + RenderConfig.GetFirstCorner(directionOne.Previous())
                ) / 3f;

            Vector3 controlTwo = cell.AbsolutePosition + (
                RenderConfig.GetEdgeMidpoint(directionTwo) + RenderConfig.GetFirstCorner(directionTwo.Previous())
                ) / 3f;

            var spline = new BezierSpline(cell.AbsolutePosition + RenderConfig.GetEdgeMidpoint(directionOne));

            spline.AddCubicCurve(controlOne, controlTwo, cell.AbsolutePosition + RenderConfig.GetEdgeMidpoint(directionTwo));

            return(spline);
        }
Пример #3
0
        private void AssembleRiverSplines()
        {
            RiverAssemblyCanon.RefreshRivers();

            foreach (var river in RiverAssemblyCanon.Rivers)
            {
                RiverSection section = river[0];

                var centerSpline = new BezierSpline(section.FlowFromOne == RiverFlow.Clockwise ? section.Start : section.End);

                Vector3 centerToV1Direction, centerToV4Direction;

                Vector3 v1Tangent, v4Tangent;

                Vector3 controlOne, controlTwo;

                Vector3 v1, v4;

                bool isV1Internal, isV4Internal;

                bool isControlOneNegative, isControlTwoNegative;

                for (int i = 0; i < river.Count; i++)
                {
                    section = river[i];

                    if (section.FlowFromOne == RiverFlow.Clockwise)
                    {
                        v1 = section.Start;
                        v4 = section.End;

                        isV1Internal = section.PreviousOnInternalCurve;
                        isV4Internal = section.NextOnInternalCurve;
                    }
                    else
                    {
                        v1 = section.End;
                        v4 = section.Start;

                        isV1Internal = section.NextOnInternalCurve;
                        isV4Internal = section.PreviousOnInternalCurve;
                    }

                    if (isV1Internal)
                    {
                        centerToV1Direction = (v1 - section.AdjacentCellOne.AbsolutePosition).normalized;
                    }
                    else
                    {
                        centerToV1Direction = (v1 - section.AdjacentCellTwo.AbsolutePosition).normalized;
                    }

                    if (isV4Internal)
                    {
                        centerToV4Direction = (v4 - section.AdjacentCellOne.AbsolutePosition).normalized;
                    }
                    else
                    {
                        centerToV4Direction = (v4 - section.AdjacentCellTwo.AbsolutePosition).normalized;
                    }

                    isControlOneNegative = (section.FlowFromOne == RiverFlow.Clockwise && isV1Internal) ||
                                           (section.FlowFromOne == RiverFlow.Counterclockwise && !isV1Internal);

                    isControlTwoNegative = (section.FlowFromOne == RiverFlow.Clockwise && !isV4Internal) ||
                                           (section.FlowFromOne == RiverFlow.Counterclockwise && isV4Internal);

                    v1Tangent = new Vector3(-centerToV1Direction.z, centerToV1Direction.y, centerToV1Direction.x);
                    v4Tangent = new Vector3(-centerToV4Direction.z, centerToV4Direction.y, centerToV4Direction.x);

                    controlOne = v1 + v1Tangent * RenderConfig.RiverCurveStrength * (isControlOneNegative ? -1f : 1f);
                    controlTwo = v4 + v4Tangent * RenderConfig.RiverCurveStrength * (isControlTwoNegative ? -1f : 1f);

                    centerSpline.AddCubicCurve(controlOne, controlTwo, v4);
                }

                var newRiverSpline = new RiverSpline()
                {
                    CenterSpline = centerSpline,
                    WesternCells = river.Select(riverSection => riverSection.AdjacentCellOne).ToList(),
                    EasternCells = river.Select(riverSection => riverSection.AdjacentCellTwo).ToList(),
                    Directions   = river.Select(riverSection => riverSection.DirectionFromOne).ToList(),
                    Flows        = river.Select(riverSection => riverSection.FlowFromOne).ToList()
                };

                RiverSplines.Add(newRiverSpline);
            }
        }