Ejemplo n.º 1
0
        public List <Vector3> GenerateCalculatedVertices(List <Vector3> keyVertices)
        {
            List <Vector3>   allVerticies = new List <Vector3>();
            TransformHelpers th           = new TransformHelpers();

            //Start by inserting after the first key point
            int insertIndex = 1;

            for (int i = 0; i < keyVertices.Count - 1; i++)
            {
                //Add the key vert
                allVerticies.Add(keyVertices[i]);

                Vector3 currentVertex = keyVertices[i];
                Vector3 nextVertex    = keyVertices[i + 1];

                float x0 = currentVertex.x;
                float x1 = nextVertex.x;

                float y0 = currentVertex.y;
                float y1 = nextVertex.y;


                //How many segments between our two key points
                int totalSegments = Mathf.CeilToInt(Mathf.Ceil(x1 - x0) / CalculatedVertexSpacing);

                //The width of each of these segments
                float segmentWidth = (x1 - x0) / totalSegments;


                for (int j = 1; j < totalSegments; j++)
                {
                    float newX = x0 + j * segmentWidth;

                    //Calculate our new y value by cosine interpolation
                    float mu   = (float)j / (float)totalSegments;
                    float newY = th.CosineInterpolate(y0, y1, mu);

                    Vector3 newVert = new Vector3(newX, newY, settings.OriginalStartPoint.z);
                    allVerticies.Insert(insertIndex, newVert);

                    //Move to the next calculated point
                    insertIndex += 1;
                }

                //Jump over the key point and move on to the next calculated point
                insertIndex += 1;

                if (i == keyVertices.Count - 2)
                {
                    allVerticies.Add(nextVertex);
                }
            }



            return(allVerticies);
        }
Ejemplo n.º 2
0
        public List<Vector3> GenerateCalculatedVertices(List<Vector3> keyVertices)
        {
            List<Vector3> allVerticies = new List<Vector3>();
            TransformHelpers th = new TransformHelpers();

            //Start by inserting after the first key point
            int insertIndex = 1;

            for (int i = 0; i < keyVertices.Count - 1; i++)
            {

                //Add the key vert
                allVerticies.Add(keyVertices[i]);

                Vector3 currentVertex = keyVertices[i];
                Vector3 nextVertex = keyVertices[i + 1];

                float x0 = currentVertex.x;
                float x1 = nextVertex.x;

                float y0 = currentVertex.y;
                float y1 = nextVertex.y;

                //How many segments between our two key points
                int totalSegments = Mathf.CeilToInt(Mathf.Ceil(x1 - x0) / CalculatedVertexSpacing);

                //The width of each of these segments
                float segmentWidth = (x1 - x0) / totalSegments;

                for (int j = 1; j < totalSegments; j++)
                {
                    float newX = x0 + j * segmentWidth;

                    //Calculate our new y value by cosine interpolation
                    float mu = (float)j / (float)totalSegments;
                    float newY = th.CosineInterpolate(y0, y1, mu);

                    Vector3 newVert = new Vector3(newX, newY, settings.OriginalStartPoint.z);
                    allVerticies.Insert(insertIndex, newVert);

                    //Move to the next calculated point
                    insertIndex += 1;
                }

                //Jump over the key point and move on to the next calculated point
                insertIndex += 1;

                if (i == keyVertices.Count - 2)
                {
                    allVerticies.Add(nextVertex);
                }
            }

            return allVerticies;
        }