Exemplo n.º 1
0
        public List <FVector3> SubdivideEvenly(int divisions)
        {
            List <FVector3> verts = new List <FVector3>();

            float length = GetLength();

            float deltaLength = length / divisions + 0.001f;
            float t           = 0.000f;

            // we always start at the first control point
            FVector2 start = ControlPoints[0];
            FVector2 end   = GetPosition(t);

            // increment t until we are at half the distance
            while (deltaLength * 0.5f >= FVector2.Distance(start, end))
            {
                end = GetPosition(t);
                t  += 0.0001f;

                if (t >= 1f)
                {
                    break;
                }
            }

            start = end;

            // for each box
            for (int i = 1; i < divisions; i++)
            {
                FVector2 normal = GetPositionNormal(t);
                float    angle  = (float)Math.Atan2(normal.Y, normal.X);

                verts.Add(new FVector3(end, angle));

                // until we reach the correct distance down the curve
                while (deltaLength >= FVector2.Distance(start, end))
                {
                    end = GetPosition(t);
                    t  += 0.00001f;

                    if (t >= 1f)
                    {
                        break;
                    }
                }
                if (t >= 1f)
                {
                    break;
                }

                start = end;
            }
            return(verts);
        }
Exemplo n.º 2
0
        public float GetLength()
        {
            List <FVector2> verts  = GetVertices(ControlPoints.Count * 25);
            float           length = 0;

            for (int i = 1; i < verts.Count; i++)
            {
                length += FVector2.Distance(verts[i - 1], verts[i]);
            }

            if (Closed)
            {
                length += FVector2.Distance(verts[ControlPoints.Count - 1], verts[0]);
            }

            return(length);
        }