示例#1
0
		float[] ComputeWorldPositions (PathAttachment path, int spacesCount, bool tangents, bool percentPosition,
			bool percentSpacing) {

			Slot target = this.target;
			float position = this.position;
			float[] spaces = this.spaces.Items, output = this.positions.Resize(spacesCount * 3 + 2).Items, world;
			bool closed = path.Closed;
			int verticesLength = path.WorldVerticesLength, curveCount = verticesLength / 6, prevCurve = NONE;

			float pathLength;
			if (!path.ConstantSpeed) {
				float[] lengths = path.Lengths;
				curveCount -= closed ? 1 : 2;
				pathLength = lengths[curveCount];
				if (percentPosition) position *= pathLength;
				if (percentSpacing) {
					for (int i = 0; i < spacesCount; i++)
						spaces[i] *= pathLength;
				}
				world = this.world.Resize(8).Items;
				for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3) {
					float space = spaces[i];
					position += space;
					float p = position;

					if (closed) {
						p %= pathLength;
						if (p < 0) p += pathLength;
						curve = 0;
					} else if (p < 0) {
						if (prevCurve != BEFORE) {
							prevCurve = BEFORE;
							path.ComputeWorldVertices(target, 2, 4, world, 0);
						}
						AddBeforePosition(p, world, 0, output, o);
						continue;
					} else if (p > pathLength) {
						if (prevCurve != AFTER) {
							prevCurve = AFTER;
							path.ComputeWorldVertices(target, verticesLength - 6, 4, world, 0);
						}
						AddAfterPosition(p - pathLength, world, 0, output, o);
						continue;
					}

					// Determine curve containing position.
					for (;; curve++) {
						float length = lengths[curve];
						if (p > length) continue;
						if (curve == 0)
							p /= length;
						else {
							float prev = lengths[curve - 1];
							p = (p - prev) / (length - prev);
						}
						break;
					}
					if (curve != prevCurve) {
						prevCurve = curve;
						if (closed && curve == curveCount) {
							path.ComputeWorldVertices(target, verticesLength - 4, 4, world, 0);
							path.ComputeWorldVertices(target, 0, 4, world, 4);
						} else
							path.ComputeWorldVertices(target, curve * 6 + 2, 8, world, 0);
					}
					AddCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], output, o,
						tangents || (i > 0 && space == 0));
				}
				return output;
			}

			// World vertices.
			if (closed) {
				verticesLength += 2;
				world = this.world.Resize(verticesLength).Items;
				path.ComputeWorldVertices(target, 2, verticesLength - 4, world, 0);
				path.ComputeWorldVertices(target, 0, 2, world, verticesLength - 4);
				world[verticesLength - 2] = world[0];
				world[verticesLength - 1] = world[1];
			} else {
				curveCount--;
				verticesLength -= 4;
				world = this.world.Resize(verticesLength).Items;
				path.ComputeWorldVertices(target, 2, verticesLength, world, 0);
			}

			// Curve lengths.
			float[] curves = this.curves.Resize(curveCount).Items;
			pathLength = 0;
			float x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
			float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;
			for (int i = 0, w = 2; i < curveCount; i++, w += 6) {
				cx1 = world[w];
				cy1 = world[w + 1];
				cx2 = world[w + 2];
				cy2 = world[w + 3];
				x2 = world[w + 4];
				y2 = world[w + 5];
				tmpx = (x1 - cx1 * 2 + cx2) * 0.1875f;
				tmpy = (y1 - cy1 * 2 + cy2) * 0.1875f;
				dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375f;
				dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375f;
				ddfx = tmpx * 2 + dddfx;
				ddfy = tmpy * 2 + dddfy;
				dfx = (cx1 - x1) * 0.75f + tmpx + dddfx * 0.16666667f;
				dfy = (cy1 - y1) * 0.75f + tmpy + dddfy * 0.16666667f;
				pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
				dfx += ddfx;
				dfy += ddfy;
				ddfx += dddfx;
				ddfy += dddfy;
				pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
				dfx += ddfx;
				dfy += ddfy;
				pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
				dfx += ddfx + dddfx;
				dfy += ddfy + dddfy;
				pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
				curves[i] = pathLength;
				x1 = x2;
				y1 = y2;
			}
			if (percentPosition) position *= pathLength;
			if (percentSpacing) {
				for (int i = 0; i < spacesCount; i++)
					spaces[i] *= pathLength;
			}

			float[] segments = this.segments;
			float curveLength = 0;
			for (int i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3) {
				float space = spaces[i];
				position += space;
				float p = position;

				if (closed) {
					p %= pathLength;
					if (p < 0) p += pathLength;
					curve = 0;
				} else if (p < 0) {
					AddBeforePosition(p, world, 0, output, o);
					continue;
				} else if (p > pathLength) {
					AddAfterPosition(p - pathLength, world, verticesLength - 4, output, o);
					continue;
				}

				// Determine curve containing position.
				for (;; curve++) {
					float length = curves[curve];
					if (p > length) continue;
					if (curve == 0)
						p /= length;
					else {
						float prev = curves[curve - 1];
						p = (p - prev) / (length - prev);
					}
					break;
				}

				// Curve segment lengths.
				if (curve != prevCurve) {
					prevCurve = curve;
					int ii = curve * 6;
					x1 = world[ii];
					y1 = world[ii + 1];
					cx1 = world[ii + 2];
					cy1 = world[ii + 3];
					cx2 = world[ii + 4];
					cy2 = world[ii + 5];
					x2 = world[ii + 6];
					y2 = world[ii + 7];
					tmpx = (x1 - cx1 * 2 + cx2) * 0.03f;
					tmpy = (y1 - cy1 * 2 + cy2) * 0.03f;
					dddfx = ((cx1 - cx2) * 3 - x1 + x2) * 0.006f;
					dddfy = ((cy1 - cy2) * 3 - y1 + y2) * 0.006f;
					ddfx = tmpx * 2 + dddfx;
					ddfy = tmpy * 2 + dddfy;
					dfx = (cx1 - x1) * 0.3f + tmpx + dddfx * 0.16666667f;
					dfy = (cy1 - y1) * 0.3f + tmpy + dddfy * 0.16666667f;
					curveLength = (float)Math.Sqrt(dfx * dfx + dfy * dfy);
					segments[0] = curveLength;
					for (ii = 1; ii < 8; ii++) {
						dfx += ddfx;
						dfy += ddfy;
						ddfx += dddfx;
						ddfy += dddfy;
						curveLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
						segments[ii] = curveLength;
					}
					dfx += ddfx;
					dfy += ddfy;
					curveLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
					segments[8] = curveLength;
					dfx += ddfx + dddfx;
					dfy += ddfy + dddfy;
					curveLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
					segments[9] = curveLength;
					segment = 0;
				}

				// Weight by segment length.
				p *= curveLength;
				for (;; segment++) {
					float length = segments[segment];
					if (p > length) continue;
					if (segment == 0)
						p /= length;
					else {
						float prev = segments[segment - 1];
						p = segment + (p - prev) / (length - prev);
					}
					break;
				}
				AddCurvePosition(p * 0.1f, x1, y1, cx1, cy1, cx2, cy2, x2, y2, output, o, tangents || (i > 0 && space == 0));
			}
			return output;
		}
        float[] ComputeWorldPositions(PathAttachment path, int spacesCount, bool tangents, bool percentPosition,
                                      bool percentSpacing)
        {
            Slot  target   = this.target;
            float position = this.position;

            float[] spacesItems = this.spaces.Items, output = this.positions.Resize(spacesCount * 3 + 2).Items, world;
            bool    closed = path.Closed;
            int     verticesLength = path.WorldVerticesLength, curveCount = verticesLength / 6, prevCurve = NONE;
            float   pathLength = 0;

            if (!path.ConstantSpeed)
            {
                float[] lengths = path.Lengths;
                curveCount -= closed ? 1 : 2;
                pathLength  = lengths[curveCount];
                if (percentPosition)
                {
                    position *= pathLength;
                }
                if (percentSpacing)
                {
                    for (int i = 1; i < spacesCount; i++)
                    {
                        spacesItems[i] *= pathLength;
                    }
                }
                world = this.world.Resize(8).Items;
                for (int i = 0, o = 0, curve = 0; i < spacesCount; i++, o += 3)
                {
                    float space = spacesItems[i];
                    position += space;
                    float p = position;

                    if (closed)
                    {
                        p %= pathLength;
                        if (p < 0)
                        {
                            p += pathLength;
                        }
                        curve = 0;
                    }
                    else if (p < 0)
                    {
                        if (prevCurve != BEFORE)
                        {
                            prevCurve = BEFORE;
                            path.ComputeWorldVertices(target, 2, 4, world, 0, 2);
                        }
                        AddBeforePosition(p, world, 0, output, o);
                        continue;
                    }
                    else if (p > pathLength)
                    {
                        if (prevCurve != AFTER)
                        {
                            prevCurve = AFTER;
                            path.ComputeWorldVertices(target, verticesLength - 6, 4, world, 0, 2);
                        }
                        AddAfterPosition(p - pathLength, world, 0, output, o);
                        continue;
                    }

                    // Determine curve containing position.
                    for (;; curve++)
                    {
                        float length = lengths[curve];
                        if (p > length)
                        {
                            continue;
                        }
                        if (curve == 0)
                        {
                            p /= length;
                        }
                        else
                        {
                            float prev = lengths[curve - 1];
                            p = (p - prev) / (length - prev);
                        }
                        break;
                    }
                    if (curve != prevCurve)
                    {
                        prevCurve = curve;
                        if (closed && curve == curveCount)
                        {
                            path.ComputeWorldVertices(target, verticesLength - 4, 4, world, 0, 2);
                            path.ComputeWorldVertices(target, 0, 4, world, 4, 2);
                        }
                        else
                        {
                            path.ComputeWorldVertices(target, curve * 6 + 2, 8, world, 0, 2);
                        }
                    }
                    AddCurvePosition(p, world[0], world[1], world[2], world[3], world[4], world[5], world[6], world[7], output, o,
                                     tangents || (i > 0 && space < PathConstraint.Epsilon));
                }
                return(output);
            }

            // World vertices.
            if (closed)
            {
                verticesLength += 2;
                world           = this.world.Resize(verticesLength).Items;
                path.ComputeWorldVertices(target, 2, verticesLength - 4, world, 0, 2);
                path.ComputeWorldVertices(target, 0, 2, world, verticesLength - 4, 2);
                world[verticesLength - 2] = world[0];
                world[verticesLength - 1] = world[1];
            }
            else
            {
                curveCount--;
                verticesLength -= 4;
                world           = this.world.Resize(verticesLength).Items;
                path.ComputeWorldVertices(target, 2, verticesLength, world, 0, 2);
            }

            // Curve lengths.
            float[] curves = this.curves.Resize(curveCount).Items;
            pathLength = 0;
            float x1 = world[0], y1 = world[1], cx1 = 0, cy1 = 0, cx2 = 0, cy2 = 0, x2 = 0, y2 = 0;
            float tmpx, tmpy, dddfx, dddfy, ddfx, ddfy, dfx, dfy;

            for (int i = 0, w = 2; i < curveCount; i++, w += 6)
            {
                cx1         = world[w];
                cy1         = world[w + 1];
                cx2         = world[w + 2];
                cy2         = world[w + 3];
                x2          = world[w + 4];
                y2          = world[w + 5];
                tmpx        = (x1 - cx1 * 2 + cx2) * 0.1875f;
                tmpy        = (y1 - cy1 * 2 + cy2) * 0.1875f;
                dddfx       = ((cx1 - cx2) * 3 - x1 + x2) * 0.09375f;
                dddfy       = ((cy1 - cy2) * 3 - y1 + y2) * 0.09375f;
                ddfx        = tmpx * 2 + dddfx;
                ddfy        = tmpy * 2 + dddfy;
                dfx         = (cx1 - x1) * 0.75f + tmpx + dddfx * 0.16666667f;
                dfy         = (cy1 - y1) * 0.75f + tmpy + dddfy * 0.16666667f;
                pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                dfx        += ddfx;
                dfy        += ddfy;
                ddfx       += dddfx;
                ddfy       += dddfy;
                pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                dfx        += ddfx;
                dfy        += ddfy;
                pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                dfx        += ddfx + dddfx;
                dfy        += ddfy + dddfy;
                pathLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                curves[i]   = pathLength;
                x1          = x2;
                y1          = y2;
            }
            if (percentPosition)
            {
                position *= pathLength;
            }
            else
            {
                position *= pathLength / path.lengths[curveCount - 1];
            }

            if (percentSpacing)
            {
                for (int i = 1; i < spacesCount; i++)
                {
                    spacesItems[i] *= pathLength;
                }
            }

            float[] segments    = this.segments;
            float   curveLength = 0;

            for (int i = 0, o = 0, curve = 0, segment = 0; i < spacesCount; i++, o += 3)
            {
                float space = spacesItems[i];
                position += space;
                float p = position;

                if (closed)
                {
                    p %= pathLength;
                    if (p < 0)
                    {
                        p += pathLength;
                    }
                    curve = 0;
                }
                else if (p < 0)
                {
                    AddBeforePosition(p, world, 0, output, o);
                    continue;
                }
                else if (p > pathLength)
                {
                    AddAfterPosition(p - pathLength, world, verticesLength - 4, output, o);
                    continue;
                }

                // Determine curve containing position.
                for (;; curve++)
                {
                    float length = curves[curve];
                    if (p > length)
                    {
                        continue;
                    }
                    if (curve == 0)
                    {
                        p /= length;
                    }
                    else
                    {
                        float prev = curves[curve - 1];
                        p = (p - prev) / (length - prev);
                    }
                    break;
                }

                // Curve segment lengths.
                if (curve != prevCurve)
                {
                    prevCurve = curve;
                    int ii = curve * 6;
                    x1          = world[ii];
                    y1          = world[ii + 1];
                    cx1         = world[ii + 2];
                    cy1         = world[ii + 3];
                    cx2         = world[ii + 4];
                    cy2         = world[ii + 5];
                    x2          = world[ii + 6];
                    y2          = world[ii + 7];
                    tmpx        = (x1 - cx1 * 2 + cx2) * 0.03f;
                    tmpy        = (y1 - cy1 * 2 + cy2) * 0.03f;
                    dddfx       = ((cx1 - cx2) * 3 - x1 + x2) * 0.006f;
                    dddfy       = ((cy1 - cy2) * 3 - y1 + y2) * 0.006f;
                    ddfx        = tmpx * 2 + dddfx;
                    ddfy        = tmpy * 2 + dddfy;
                    dfx         = (cx1 - x1) * 0.3f + tmpx + dddfx * 0.16666667f;
                    dfy         = (cy1 - y1) * 0.3f + tmpy + dddfy * 0.16666667f;
                    curveLength = (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                    segments[0] = curveLength;
                    for (ii = 1; ii < 8; ii++)
                    {
                        dfx         += ddfx;
                        dfy         += ddfy;
                        ddfx        += dddfx;
                        ddfy        += dddfy;
                        curveLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                        segments[ii] = curveLength;
                    }
                    dfx         += ddfx;
                    dfy         += ddfy;
                    curveLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                    segments[8]  = curveLength;
                    dfx         += ddfx + dddfx;
                    dfy         += ddfy + dddfy;
                    curveLength += (float)Math.Sqrt(dfx * dfx + dfy * dfy);
                    segments[9]  = curveLength;
                    segment      = 0;
                }

                // Weight by segment length.
                p *= curveLength;
                for (;; segment++)
                {
                    float length = segments[segment];
                    if (p > length)
                    {
                        continue;
                    }
                    if (segment == 0)
                    {
                        p /= length;
                    }
                    else
                    {
                        float prev = segments[segment - 1];
                        p = segment + (p - prev) / (length - prev);
                    }
                    break;
                }
                AddCurvePosition(p * 0.1f, x1, y1, cx1, cy1, cx2, cy2, x2, y2, output, o, tangents || (i > 0 && space < PathConstraint.Epsilon));
            }
            return(output);
        }
示例#3
0
        private float[] ComputeWorldPositions(PathAttachment path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing)
        {
            float[] numArray3;
            float   num5;
            float   num22;
            float   num23;
            float   num24;
            float   num25;
            float   num26;
            float   num27;
            float   num28;
            float   num29;
            Slot    target   = this.target;
            float   position = this.position;

            float[] items  = this.spaces.Items;
            float[] output = this.positions.Resize((spacesCount * 3) + 2).Items;
            bool    closed = path.Closed;
            int     worldVerticesLength = path.WorldVerticesLength;
            int     index = worldVerticesLength / 6;
            int     num4  = -1;

            if (!path.ConstantSpeed)
            {
                float[] lengths = path.Lengths;
                index -= !closed ? 2 : 1;
                num5   = lengths[index];
                if (percentPosition)
                {
                    position *= num5;
                }
                if (percentSpacing)
                {
                    for (int j = 0; j < spacesCount; j++)
                    {
                        items[j] *= num5;
                    }
                }
                numArray3 = this.world.Resize(8).Items;
                int num7 = 0;
                int num8 = 0;
                int num9 = 0;
                while (num7 < spacesCount)
                {
                    float num12;
                    float num10 = items[num7];
                    position += num10;
                    float p = position;
                    if (closed)
                    {
                        p = p % num5;
                        if (p < 0f)
                        {
                            p += num5;
                        }
                        num9 = 0;
                    }
                    else
                    {
                        if (p < 0f)
                        {
                            if (num4 != -2)
                            {
                                num4 = -2;
                                path.ComputeWorldVertices(target, 2, 4, numArray3, 0, 2);
                            }
                            AddBeforePosition(p, numArray3, 0, output, num8);
                            goto Label_0263;
                        }
                        if (p > num5)
                        {
                            if (num4 != -3)
                            {
                                num4 = -3;
                                path.ComputeWorldVertices(target, worldVerticesLength - 6, 4, numArray3, 0, 2);
                            }
                            AddAfterPosition(p - num5, numArray3, 0, output, num8);
                            goto Label_0263;
                        }
                    }
Label_017D:
                    num12 = lengths[num9];
                    if (p <= num12)
                    {
                        if (num9 == 0)
                        {
                            p /= num12;
                        }
                        else
                        {
                            float num13 = lengths[num9 - 1];
                            p = (p - num13) / (num12 - num13);
                        }
                    }
                    else
                    {
                        num9++;
                        goto Label_017D;
                    }
                    if (num9 != num4)
                    {
                        num4 = num9;
                        if (closed && (num9 == index))
                        {
                            path.ComputeWorldVertices(target, worldVerticesLength - 4, 4, numArray3, 0, 2);
                            path.ComputeWorldVertices(target, 0, 4, numArray3, 4, 2);
                        }
                        else
                        {
                            path.ComputeWorldVertices(target, (num9 * 6) + 2, 8, numArray3, 0, 2);
                        }
                    }
                    AddCurvePosition(p, numArray3[0], numArray3[1], numArray3[2], numArray3[3], numArray3[4], numArray3[5], numArray3[6], numArray3[7], output, num8, tangents || ((num7 > 0) && (num10 < 1E-05f)));
Label_0263:
                    num7++;
                    num8 += 3;
                }
                return(output);
            }
            if (closed)
            {
                worldVerticesLength += 2;
                numArray3            = this.world.Resize(worldVerticesLength).Items;
                path.ComputeWorldVertices(target, 2, worldVerticesLength - 4, numArray3, 0, 2);
                path.ComputeWorldVertices(target, 0, 2, numArray3, worldVerticesLength - 4, 2);
                numArray3[worldVerticesLength - 2] = numArray3[0];
                numArray3[worldVerticesLength - 1] = numArray3[1];
            }
            else
            {
                index--;
                worldVerticesLength -= 4;
                numArray3            = this.world.Resize(worldVerticesLength).Items;
                path.ComputeWorldVertices(target, 2, worldVerticesLength, numArray3, 0, 2);
            }
            float[] numArray5 = this.curves.Resize(index).Items;
            num5 = 0f;
            float num14 = numArray3[0];
            float num15 = numArray3[1];
            float num16 = 0f;
            float num17 = 0f;
            float num18 = 0f;
            float num19 = 0f;
            float num20 = 0f;
            float num21 = 0f;
            int   num30 = 0;

            for (int i = 2; num30 < index; i += 6)
            {
                num16            = numArray3[i];
                num17            = numArray3[i + 1];
                num18            = numArray3[i + 2];
                num19            = numArray3[i + 3];
                num20            = numArray3[i + 4];
                num21            = numArray3[i + 5];
                num22            = ((num14 - (num16 * 2f)) + num18) * 0.1875f;
                num23            = ((num15 - (num17 * 2f)) + num19) * 0.1875f;
                num24            = ((((num16 - num18) * 3f) - num14) + num20) * 0.09375f;
                num25            = ((((num17 - num19) * 3f) - num15) + num21) * 0.09375f;
                num26            = (num22 * 2f) + num24;
                num27            = (num23 * 2f) + num25;
                num28            = (((num16 - num14) * 0.75f) + num22) + (num24 * 0.1666667f);
                num29            = (((num17 - num15) * 0.75f) + num23) + (num25 * 0.1666667f);
                num5            += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                num28           += num26;
                num29           += num27;
                num26           += num24;
                num27           += num25;
                num5            += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                num28           += num26;
                num29           += num27;
                num5            += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                num28           += num26 + num24;
                num29           += num27 + num25;
                num5            += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                numArray5[num30] = num5;
                num14            = num20;
                num15            = num21;
                num30++;
            }
            if (percentPosition)
            {
                position *= num5;
            }
            if (percentSpacing)
            {
                for (int j = 0; j < spacesCount; j++)
                {
                    items[j] *= num5;
                }
            }
            float[] segments = this.segments;
            float   num33    = 0f;
            int     num34    = 0;
            int     o        = 0;
            int     num36    = 0;
            int     num37    = 0;

            while (num34 < spacesCount)
            {
                float num40;
                float num38 = items[num34];
                position += num38;
                float p = position;
                if (closed)
                {
                    p = p % num5;
                    if (p < 0f)
                    {
                        p += num5;
                    }
                    num36 = 0;
                }
                else
                {
                    if (p < 0f)
                    {
                        AddBeforePosition(p, numArray3, 0, output, o);
                        goto Label_0883;
                    }
                    if (p > num5)
                    {
                        AddAfterPosition(p - num5, numArray3, worldVerticesLength - 4, output, o);
                        goto Label_0883;
                    }
                }
Label_05CD:
                num40 = numArray5[num36];
                if (p <= num40)
                {
                    if (num36 == 0)
                    {
                        p /= num40;
                    }
                    else
                    {
                        float num41 = numArray5[num36 - 1];
                        p = (p - num41) / (num40 - num41);
                    }
                }
                else
                {
                    num36++;
                    goto Label_05CD;
                }
                if (num36 != num4)
                {
                    num4 = num36;
                    int num42 = num36 * 6;
                    num14       = numArray3[num42];
                    num15       = numArray3[num42 + 1];
                    num16       = numArray3[num42 + 2];
                    num17       = numArray3[num42 + 3];
                    num18       = numArray3[num42 + 4];
                    num19       = numArray3[num42 + 5];
                    num20       = numArray3[num42 + 6];
                    num21       = numArray3[num42 + 7];
                    num22       = ((num14 - (num16 * 2f)) + num18) * 0.03f;
                    num23       = ((num15 - (num17 * 2f)) + num19) * 0.03f;
                    num24       = ((((num16 - num18) * 3f) - num14) + num20) * 0.006f;
                    num25       = ((((num17 - num19) * 3f) - num15) + num21) * 0.006f;
                    num26       = (num22 * 2f) + num24;
                    num27       = (num23 * 2f) + num25;
                    num28       = (((num16 - num14) * 0.3f) + num22) + (num24 * 0.1666667f);
                    num29       = (((num17 - num15) * 0.3f) + num23) + (num25 * 0.1666667f);
                    num33       = (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                    segments[0] = num33;
                    for (num42 = 1; num42 < 8; num42++)
                    {
                        num28          += num26;
                        num29          += num27;
                        num26          += num24;
                        num27          += num25;
                        num33          += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                        segments[num42] = num33;
                    }
                    num28      += num26;
                    num29      += num27;
                    num33      += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                    segments[8] = num33;
                    num28      += num26 + num24;
                    num29      += num27 + num25;
                    num33      += (float)Math.Sqrt((double)((num28 * num28) + (num29 * num29)));
                    segments[9] = num33;
                    num37       = 0;
                }
                p *= num33;
                while (true)
                {
                    float num43 = segments[num37];
                    if (p <= num43)
                    {
                        if (num37 == 0)
                        {
                            p /= num43;
                        }
                        else
                        {
                            float num44 = segments[num37 - 1];
                            p = num37 + ((p - num44) / (num43 - num44));
                        }
                        break;
                    }
                    num37++;
                }
                AddCurvePosition(p * 0.1f, num14, num15, num16, num17, num18, num19, num20, num21, output, o, tangents || ((num34 > 0) && (num38 < 1E-05f)));
Label_0883:
                num34++;
                o += 3;
            }
            return(output);
        }
示例#4
0
        private float[] ComputeWorldPositions(PathAttachment path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing)
        {
            Slot  slot = this.target;
            float num  = this.position;

            float[] items  = this.spaces.Items;
            float[] items2 = this.positions.Resize(spacesCount * 3 + 2).Items;
            bool    closed = path.Closed;
            int     num2   = path.WorldVerticesLength;
            int     num3   = num2 / 6;
            int     num4   = -1;
            float   num5;

            float[] items3;
            if (!path.ConstantSpeed)
            {
                float[] array = path.Lengths;
                num3 -= ((!closed) ? 2 : 1);
                num5  = array[num3];
                if (percentPosition)
                {
                    num *= num5;
                }
                if (percentSpacing)
                {
                    for (int i = 0; i < spacesCount; i++)
                    {
                        items[i] *= num5;
                    }
                }
                items3 = this.world.Resize(8).Items;
                int j    = 0;
                int num6 = 0;
                int num7 = 0;
                while (j < spacesCount)
                {
                    float num8 = items[j];
                    num += num8;
                    float num9 = num;
                    if (closed)
                    {
                        num9 %= num5;
                        if (num9 < 0f)
                        {
                            num9 += num5;
                        }
                        num7 = 0;
                        goto IL_178;
                    }
                    if (num9 < 0f)
                    {
                        if (num4 != -2)
                        {
                            num4 = -2;
                            path.ComputeWorldVertices(slot, 2, 4, items3, 0);
                        }
                        this.AddBeforePosition(num9, items3, 0, items2, num6);
                    }
                    else
                    {
                        if (num9 <= num5)
                        {
                            goto IL_178;
                        }
                        if (num4 != -3)
                        {
                            num4 = -3;
                            path.ComputeWorldVertices(slot, num2 - 6, 4, items3, 0);
                        }
                        this.AddAfterPosition(num9 - num5, items3, 0, items2, num6);
                    }
IL_261:
                    j++;
                    num6 += 3;
                    continue;
IL_178:
                    float num10;
                    for (;;)
                    {
                        num10 = array[num7];
                        if (num9 <= num10)
                        {
                            break;
                        }
                        num7++;
                    }
                    if (num7 == 0)
                    {
                        num9 /= num10;
                    }
                    else
                    {
                        float num11 = array[num7 - 1];
                        num9 = (num9 - num11) / (num10 - num11);
                    }
                    if (num7 != num4)
                    {
                        num4 = num7;
                        if (closed && num7 == num3)
                        {
                            path.ComputeWorldVertices(slot, num2 - 4, 4, items3, 0);
                            path.ComputeWorldVertices(slot, 0, 4, items3, 4);
                        }
                        else
                        {
                            path.ComputeWorldVertices(slot, num7 * 6 + 2, 8, items3, 0);
                        }
                    }
                    this.AddCurvePosition(num9, items3[0], items3[1], items3[2], items3[3], items3[4], items3[5], items3[6], items3[7], items2, num6, tangents || (j > 0 && num8 == 0f));
                    goto IL_261;
                }
                return(items2);
            }
            if (closed)
            {
                num2  += 2;
                items3 = this.world.Resize(num2).Items;
                path.ComputeWorldVertices(slot, 2, num2 - 4, items3, 0);
                path.ComputeWorldVertices(slot, 0, 2, items3, num2 - 4);
                items3[num2 - 2] = items3[0];
                items3[num2 - 1] = items3[1];
            }
            else
            {
                num3--;
                num2  -= 4;
                items3 = this.world.Resize(num2).Items;
                path.ComputeWorldVertices(slot, 2, num2, items3, 0);
            }
            float[] items4 = this.curves.Resize(num3).Items;
            num5 = 0f;
            float num12 = items3[0];
            float num13 = items3[1];
            float num14 = 0f;
            float num15 = 0f;
            float num16 = 0f;
            float num17 = 0f;
            float num18 = 0f;
            float num19 = 0f;
            int   k     = 0;
            int   num20 = 2;

            while (k < num3)
            {
                num14 = items3[num20];
                num15 = items3[num20 + 1];
                num16 = items3[num20 + 2];
                num17 = items3[num20 + 3];
                num18 = items3[num20 + 4];
                num19 = items3[num20 + 5];
                float num21 = (num12 - num14 * 2f + num16) * 0.1875f;
                float num22 = (num13 - num15 * 2f + num17) * 0.1875f;
                float num23 = ((num14 - num16) * 3f - num12 + num18) * 0.09375f;
                float num24 = ((num15 - num17) * 3f - num13 + num19) * 0.09375f;
                float num25 = num21 * 2f + num23;
                float num26 = num22 * 2f + num24;
                float num27 = (num14 - num12) * 0.75f + num21 + num23 * 0.166666672f;
                float num28 = (num15 - num13) * 0.75f + num22 + num24 * 0.166666672f;
                num5     += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                num27    += num25;
                num28    += num26;
                num25    += num23;
                num26    += num24;
                num5     += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                num27    += num25;
                num28    += num26;
                num5     += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                num27    += num25 + num23;
                num28    += num26 + num24;
                num5     += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                items4[k] = num5;
                num12     = num18;
                num13     = num19;
                k++;
                num20 += 6;
            }
            if (percentPosition)
            {
                num *= num5;
            }
            if (percentSpacing)
            {
                for (int l = 0; l < spacesCount; l++)
                {
                    items[l] *= num5;
                }
            }
            float[] array2 = this.segments;
            float   num29  = 0f;
            int     m      = 0;
            int     num30  = 0;
            int     num31  = 0;
            int     num32  = 0;

            while (m < spacesCount)
            {
                float num33 = items[m];
                num += num33;
                float num34 = num;
                if (closed)
                {
                    num34 %= num5;
                    if (num34 < 0f)
                    {
                        num34 += num5;
                    }
                    num31 = 0;
                    goto IL_5C5;
                }
                if (num34 < 0f)
                {
                    this.AddBeforePosition(num34, items3, 0, items2, num30);
                }
                else
                {
                    if (num34 <= num5)
                    {
                        goto IL_5C5;
                    }
                    this.AddAfterPosition(num34 - num5, items3, num2 - 4, items2, num30);
                }
IL_881:
                m++;
                num30 += 3;
                continue;
IL_5C5:
                float num35;
                for (;;)
                {
                    num35 = items4[num31];
                    if (num34 <= num35)
                    {
                        break;
                    }
                    num31++;
                }
                if (num31 == 0)
                {
                    num34 /= num35;
                }
                else
                {
                    float num36 = items4[num31 - 1];
                    num34 = (num34 - num36) / (num35 - num36);
                }
                if (num31 != num4)
                {
                    num4 = num31;
                    int n = num31 * 6;
                    num12 = items3[n];
                    num13 = items3[n + 1];
                    num14 = items3[n + 2];
                    num15 = items3[n + 3];
                    num16 = items3[n + 4];
                    num17 = items3[n + 5];
                    num18 = items3[n + 6];
                    num19 = items3[n + 7];
                    float num21 = (num12 - num14 * 2f + num16) * 0.03f;
                    float num22 = (num13 - num15 * 2f + num17) * 0.03f;
                    float num23 = ((num14 - num16) * 3f - num12 + num18) * 0.006f;
                    float num24 = ((num15 - num17) * 3f - num13 + num19) * 0.006f;
                    float num25 = num21 * 2f + num23;
                    float num26 = num22 * 2f + num24;
                    float num27 = (num14 - num12) * 0.3f + num21 + num23 * 0.166666672f;
                    float num28 = (num15 - num13) * 0.3f + num22 + num24 * 0.166666672f;
                    num29     = (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                    array2[0] = num29;
                    for (n = 1; n < 8; n++)
                    {
                        num27    += num25;
                        num28    += num26;
                        num25    += num23;
                        num26    += num24;
                        num29    += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                        array2[n] = num29;
                    }
                    num27    += num25;
                    num28    += num26;
                    num29    += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                    array2[8] = num29;
                    num27    += num25 + num23;
                    num28    += num26 + num24;
                    num29    += (float)Math.Sqrt((double)(num27 * num27 + num28 * num28));
                    array2[9] = num29;
                    num32     = 0;
                }
                num34 *= num29;
                float num37;
                for (;;)
                {
                    num37 = array2[num32];
                    if (num34 <= num37)
                    {
                        break;
                    }
                    num32++;
                }
                if (num32 == 0)
                {
                    num34 /= num37;
                }
                else
                {
                    float num38 = array2[num32 - 1];
                    num34 = (float)num32 + (num34 - num38) / (num37 - num38);
                }
                this.AddCurvePosition(num34 * 0.1f, num12, num13, num14, num15, num16, num17, num18, num19, items2, num30, tangents || (m > 0 && num33 == 0f));
                goto IL_881;
            }
            return(items2);
        }
示例#5
0
        private float[] ComputeWorldPositions(PathAttachment path, int spacesCount, bool tangents, bool percentPosition, bool percentSpacing)
        {
            Slot  slot = target;
            float num  = position;

            float[] items  = spaces.Items;
            float[] items2 = positions.Resize(spacesCount * 3 + 2).Items;
            bool    closed = path.Closed;
            int     worldVerticesLength = path.WorldVerticesLength;
            int     num2 = worldVerticesLength / 6;
            int     num3 = -1;

            float[] items3;
            float   num4;

            if (!path.ConstantSpeed)
            {
                float[] array = path.Lengths;
                num2 -= (closed ? 1 : 2);
                num4  = array[num2];
                if (percentPosition)
                {
                    num *= num4;
                }
                if (percentSpacing)
                {
                    for (int i = 0; i < spacesCount; i++)
                    {
                        items[i] *= num4;
                    }
                }
                items3 = world.Resize(8).Items;
                int j    = 0;
                int k    = 0;
                int num5 = 0;
                for (; j < spacesCount; j++, k += 3)
                {
                    float num6 = items[j];
                    num += num6;
                    float num7 = num;
                    if (closed)
                    {
                        num7 %= num4;
                        if (num7 < 0f)
                        {
                            num7 += num4;
                        }
                        num5 = 0;
                    }
                    else
                    {
                        if (num7 < 0f)
                        {
                            if (num3 != -2)
                            {
                                num3 = -2;
                                path.ComputeWorldVertices(slot, 2, 4, items3, 0);
                            }
                            AddBeforePosition(num7, items3, 0, items2, k);
                            continue;
                        }
                        if (num7 > num4)
                        {
                            if (num3 != -3)
                            {
                                num3 = -3;
                                path.ComputeWorldVertices(slot, worldVerticesLength - 6, 4, items3, 0);
                            }
                            AddAfterPosition(num7 - num4, items3, 0, items2, k);
                            continue;
                        }
                    }
                    float num8;
                    while (true)
                    {
                        num8 = array[num5];
                        if (!(num7 > num8))
                        {
                            break;
                        }
                        num5++;
                    }
                    if (num5 == 0)
                    {
                        num7 /= num8;
                    }
                    else
                    {
                        float num9 = array[num5 - 1];
                        num7 = (num7 - num9) / (num8 - num9);
                    }
                    if (num5 != num3)
                    {
                        num3 = num5;
                        if (closed && num5 == num2)
                        {
                            path.ComputeWorldVertices(slot, worldVerticesLength - 4, 4, items3, 0);
                            path.ComputeWorldVertices(slot, 0, 4, items3, 4);
                        }
                        else
                        {
                            path.ComputeWorldVertices(slot, num5 * 6 + 2, 8, items3, 0);
                        }
                    }
                    AddCurvePosition(num7, items3[0], items3[1], items3[2], items3[3], items3[4], items3[5], items3[6], items3[7], items2, k, tangents || (j > 0 && num6 == 0f));
                }
                return(items2);
            }
            if (closed)
            {
                worldVerticesLength += 2;
                items3 = world.Resize(worldVerticesLength).Items;
                path.ComputeWorldVertices(slot, 2, worldVerticesLength - 4, items3, 0);
                path.ComputeWorldVertices(slot, 0, 2, items3, worldVerticesLength - 4);
                items3[worldVerticesLength - 2] = items3[0];
                items3[worldVerticesLength - 1] = items3[1];
            }
            else
            {
                num2--;
                worldVerticesLength -= 4;
                items3 = world.Resize(worldVerticesLength).Items;
                path.ComputeWorldVertices(slot, 2, worldVerticesLength, items3, 0);
            }
            float[] items4 = curves.Resize(num2).Items;
            num4 = 0f;
            float num10 = items3[0];
            float num11 = items3[1];
            float num12 = 0f;
            float num13 = 0f;
            float num14 = 0f;
            float num15 = 0f;
            float num16 = 0f;
            float num17 = 0f;
            int   num18 = 0;
            int   num19 = 2;

            while (num18 < num2)
            {
                num12 = items3[num19];
                num13 = items3[num19 + 1];
                num14 = items3[num19 + 2];
                num15 = items3[num19 + 3];
                num16 = items3[num19 + 4];
                num17 = items3[num19 + 5];
                float num20 = (num10 - num12 * 2f + num14) * 0.1875f;
                float num21 = (num11 - num13 * 2f + num15) * 0.1875f;
                float num22 = ((num12 - num14) * 3f - num10 + num16) * (3f / 32f);
                float num23 = ((num13 - num15) * 3f - num11 + num17) * (3f / 32f);
                float num24 = num20 * 2f + num22;
                float num25 = num21 * 2f + num23;
                float num26 = (num12 - num10) * 0.75f + num20 + num22 * (355f / (678f * (float)Math.PI));
                float num27 = (num13 - num11) * 0.75f + num21 + num23 * (355f / (678f * (float)Math.PI));
                num4  += (float)Math.Sqrt(num26 * num26 + num27 * num27);
                num26 += num24;
                num27 += num25;
                num24 += num22;
                num25 += num23;
                num4  += (float)Math.Sqrt(num26 * num26 + num27 * num27);
                num26 += num24;
                num27 += num25;
                num4  += (float)Math.Sqrt(num26 * num26 + num27 * num27);
                num26 += num24 + num22;
                num27 += num25 + num23;
                num4   = (items4[num18] = num4 + (float)Math.Sqrt(num26 * num26 + num27 * num27));
                num10  = num16;
                num11  = num17;
                num18++;
                num19 += 6;
            }
            if (percentPosition)
            {
                num *= num4;
            }
            if (percentSpacing)
            {
                for (int l = 0; l < spacesCount; l++)
                {
                    items[l] *= num4;
                }
            }
            float[] array2 = segments;
            float   num28  = 0f;
            int     m      = 0;
            int     n      = 0;
            int     num29  = 0;
            int     num30  = 0;

            for (; m < spacesCount; m++, n += 3)
            {
                float num31 = items[m];
                num += num31;
                float num32 = num;
                if (closed)
                {
                    num32 %= num4;
                    if (num32 < 0f)
                    {
                        num32 += num4;
                    }
                    num29 = 0;
                }
                else
                {
                    if (num32 < 0f)
                    {
                        AddBeforePosition(num32, items3, 0, items2, n);
                        continue;
                    }
                    if (num32 > num4)
                    {
                        AddAfterPosition(num32 - num4, items3, worldVerticesLength - 4, items2, n);
                        continue;
                    }
                }
                float num33;
                while (true)
                {
                    num33 = items4[num29];
                    if (!(num32 > num33))
                    {
                        break;
                    }
                    num29++;
                }
                if (num29 == 0)
                {
                    num32 /= num33;
                }
                else
                {
                    float num34 = items4[num29 - 1];
                    num32 = (num32 - num34) / (num33 - num34);
                }
                if (num29 != num3)
                {
                    num3 = num29;
                    int num35 = num29 * 6;
                    num10 = items3[num35];
                    num11 = items3[num35 + 1];
                    num12 = items3[num35 + 2];
                    num13 = items3[num35 + 3];
                    num14 = items3[num35 + 4];
                    num15 = items3[num35 + 5];
                    num16 = items3[num35 + 6];
                    num17 = items3[num35 + 7];
                    float num20 = (num10 - num12 * 2f + num14) * 0.03f;
                    float num21 = (num11 - num13 * 2f + num15) * 0.03f;
                    float num22 = ((num12 - num14) * 3f - num10 + num16) * 0.006f;
                    float num23 = ((num13 - num15) * 3f - num11 + num17) * 0.006f;
                    float num24 = num20 * 2f + num22;
                    float num25 = num21 * 2f + num23;
                    float num26 = (num12 - num10) * 0.3f + num20 + num22 * (355f / (678f * (float)Math.PI));
                    float num27 = (num13 - num11) * 0.3f + num21 + num23 * (355f / (678f * (float)Math.PI));
                    num28 = (array2[0] = (float)Math.Sqrt(num26 * num26 + num27 * num27));
                    for (num35 = 1; num35 < 8; num35++)
                    {
                        num26 += num24;
                        num27 += num25;
                        num24 += num22;
                        num25 += num23;
                        num28  = (array2[num35] = num28 + (float)Math.Sqrt(num26 * num26 + num27 * num27));
                    }
                    num26 += num24;
                    num27 += num25;
                    num28  = (array2[8] = num28 + (float)Math.Sqrt(num26 * num26 + num27 * num27));
                    num26 += num24 + num22;
                    num27 += num25 + num23;
                    num28  = (array2[9] = num28 + (float)Math.Sqrt(num26 * num26 + num27 * num27));
                    num30  = 0;
                }
                num32 *= num28;
                float num36;
                while (true)
                {
                    num36 = array2[num30];
                    if (!(num32 > num36))
                    {
                        break;
                    }
                    num30++;
                }
                if (num30 == 0)
                {
                    num32 /= num36;
                }
                else
                {
                    float num37 = array2[num30 - 1];
                    num32 = (float)num30 + (num32 - num37) / (num36 - num37);
                }
                AddCurvePosition(num32 * 0.1f, num10, num11, num12, num13, num14, num15, num16, num17, items2, n, tangents || (m > 0 && num31 == 0f));
            }
            return(items2);
        }
		public static void DrawPath (Slot s, PathAttachment p, Transform t, bool includeName) {
			int worldVerticesLength = p.WorldVerticesLength;

			if (pathVertexBuffer == null || pathVertexBuffer.Length < worldVerticesLength)
				pathVertexBuffer = new float[worldVerticesLength];

			float[] pv = pathVertexBuffer;
			p.ComputeWorldVertices(s, pv);

			var ocolor = Handles.color;
			Handles.color = SpineHandles.PathColor;

			Matrix4x4 m = t.localToWorldMatrix;
			const int step = 6;
			int n = worldVerticesLength - step;
			Vector3 p0, p1, p2, p3;
			for (int i = 2; i < n; i += step) {
				p0 = m.MultiplyPoint(new Vector3(pv[i], pv[i+1]));
				p1 = m.MultiplyPoint(new Vector3(pv[i+2], pv[i+3]));
				p2 = m.MultiplyPoint(new Vector3(pv[i+4], pv[i+5]));
				p3 = m.MultiplyPoint(new Vector3(pv[i+6], pv[i+7]));
				DrawCubicBezier(p0, p1, p2, p3);
			}

			n += step;
			if (p.Closed) {
				p0 = m.MultiplyPoint(new Vector3(pv[n - 4], pv[n - 3]));
				p1 = m.MultiplyPoint(new Vector3(pv[n - 2], pv[n - 1]));
				p2 = m.MultiplyPoint(new Vector3(pv[0], pv[1]));
				p3 = m.MultiplyPoint(new Vector3(pv[2], pv[3]));
				DrawCubicBezier(p0, p1, p2, p3);
			}

			const float endCapSize = 0.05f;
			Vector3 firstPoint = m.MultiplyPoint(new Vector3(pv[2], pv[3]));
			Handles.DotCap(0, firstPoint, Quaternion.identity, endCapSize * HandleUtility.GetHandleSize(firstPoint));
			//			if (!p.Closed) Handles.DotCap(0, m.MultiplyPoint(new Vector3(pv[n - 4], pv[n - 3])), q, endCapSize);
			if (includeName) Handles.Label(firstPoint + new Vector3(0,0.1f), p.Name, PathNameStyle);

			Handles.color = ocolor;
		}