예제 #1
0
        public override void Update(float time)
        {
            int   p;
            float lt;

            // eg.
            // p..p..p..p..p..p..p
            // 1..2..3..4..5..6..7
            // want p to be 1, 2, 3, 4, 5, 6
            if (time == 1)
            {
                p  = Points.Count - 1;
                lt = 1;
            }
            else
            {
                p  = (int)(time / DeltaT);
                lt = (time - DeltaT * p) / DeltaT;
            }

            // Interpolate
            var     c   = Points.Count - 1;
            CCPoint pp0 = Points [Math.Min(c, Math.Max(p - 1, 0))];
            CCPoint pp1 = Points [Math.Min(c, Math.Max(p + 0, 0))];
            CCPoint pp2 = Points [Math.Min(c, Math.Max(p + 1, 0))];
            CCPoint pp3 = Points [Math.Min(c, Math.Max(p + 2, 0))];

            CCPoint newPos = CCSplineMath.CCCardinalSplineAt(pp0, pp1, pp2, pp3, Tension, lt);

            // Support for stacked actions
            CCNode  node = Target;
            CCPoint diff = node.Position - PreviousPosition;

            if (diff.X != 0 || diff.Y != 0)
            {
                AccumulatedDiff = AccumulatedDiff + diff;
                newPos          = newPos + AccumulatedDiff;
            }

            UpdatePosition(newPos);
        }
예제 #2
0
        public static void DrawCardinalSpline(List <CCPoint> config, float tension, int segments)
        {
            int   p;
            float lt;
            float deltaT = 1.0f / config.Count;

            int count = config.Count;

            var vertices = new CCPoint[segments + 1];

            for (int i = 0; i < segments + 1; i++)
            {
                float dt = (float)i / segments;

                // border
                if (dt == 1)
                {
                    p  = count - 1;
                    lt = 1;
                }
                else
                {
                    p  = (int)(dt / deltaT);
                    lt = (dt - deltaT * p) / deltaT;
                }

                // Interpolate
                int     c   = config.Count - 1;
                CCPoint pp0 = config[Math.Min(c, Math.Max(p - 1, 0))];
                CCPoint pp1 = config[Math.Min(c, Math.Max(p + 0, 0))];
                CCPoint pp2 = config[Math.Min(c, Math.Max(p + 1, 0))];
                CCPoint pp3 = config[Math.Min(c, Math.Max(p + 2, 0))];

                vertices[i] = CCSplineMath.CCCardinalSplineAt(pp0, pp1, pp2, pp3, tension, lt);
            }

            DrawPoly(vertices, DrawColor);
        }