Beispiel #1
0
        void SetTimeToLengthTables(TweenPlugPath p, int subdivisions)
        {
            TweenPlugPathPoint prevP = _cachePoint1, currP = _cachePoint2;

            var ptCount          = p.pathPointCount;

            float pathLen = 0;
            float incr           = 1f / subdivisions;

            float[] timesTable   = new float[subdivisions];
            float[] lengthsTable = new float[subdivisions];
            GetPoint(prevP, 0, p.wps, p);
            for (int i = 1; i < subdivisions + 1; ++i)
            {
                float perc = incr * i;
                GetPoint(currP, perc, p.wps, p);
                pathLen += TweenPlugPathPoint.Distance(currP, prevP, ptCount);
                prevP.Copy(currP, ptCount);
                timesTable[i - 1]   = perc;
                lengthsTable[i - 1] = pathLen;
            }

            // Assign
            p.length       = pathLen;
            p.timesTable   = timesTable;
            p.lengthsTable = lengthsTable;
        }
Beispiel #2
0
        public void GetPoint(TweenPlugPathPoint output, float perc, TweenPlugPathPoint[] wps, TweenPlugPath p)
        {
            var ptCount = p.pathPointCount;

            if (perc <= 0)
            {
                p.linearWPIndex = 1;
                output.Copy(wps[0], ptCount);
                return;
            }

            int startPIndex = 0;
            int endPIndex   = 0;
            int count       = p.timesTable.Length;

            for (int i = 1; i < count; i++)
            {
                if (p.timesTable[i] >= perc)
                {
                    startPIndex = i - 1;
                    endPIndex   = i;
                    break;
                }
            }

            float startPPerc  = p.timesTable[startPIndex];
            float partialPerc = perc - startPPerc;
            float partialLen  = p.length * partialPerc;
            var   wp0         = wps[startPIndex];
            var   wp1         = wps[endPIndex];

            p.linearWPIndex = endPIndex;

            //output = wp0 + clamp(wp1 - wp0, partialLen)

            for (int i = 0; i < ptCount; i++)
            {
                output.vals[i] = wp1.vals[i] - wp0.vals[i];
            }

            output.ClampMagnitude(partialLen, ptCount);

            for (int i = 0; i < ptCount; i++)
            {
                output.vals[i] += wp0.vals[i];
            }
        }
Beispiel #3
0
        void SetPathLength(TweenPlugPath p, int subdivisions)
        {
            TweenPlugPathPoint prevP = _cachePoint1, currP = _cachePoint2;

            var ptCount = p.pathPointCount;

            float pathLen = 0;
            float incr  = 1f / subdivisions;

            GetPoint(prevP, 0, p.wps, p);
            for (int i = 1; i < subdivisions + 1; ++i)
            {
                float perc = incr * i;
                GetPoint(currP, perc, p.wps, p);
                pathLen += TweenPlugPathPoint.Distance(currP, prevP, ptCount);
                prevP.Copy(currP, ptCount);
            }

            // Assign
            p.length       = pathLen;
            p.timesTable   = null;
            p.lengthsTable = null;
        }