Exemplo n.º 1
0
        public override void Update(float time)
        {
            if (Target != null)
            {
                float xa = 0;
                float xb = BezierConfig.ControlPoint1.X;
                float xc = BezierConfig.ControlPoint2.X;
                float xd = BezierConfig.EndPosition.X;

                float ya = 0;
                float yb = BezierConfig.ControlPoint1.Y;
                float yc = BezierConfig.ControlPoint2.Y;
                float yd = BezierConfig.EndPosition.Y;

                float x = CCSplineMath.CubicBezier(xa, xb, xc, xd, time);
                float y = CCSplineMath.CubicBezier(ya, yb, yc, yd, time);

                CCPoint currentPos = Target.Position;
                CCPoint diff       = currentPos - PreviousPosition;
                StartPosition = StartPosition + diff;

                CCPoint newPos = StartPosition + new CCPoint(x, y);
                Target.Position = newPos;

                PreviousPosition = newPos;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// draws a cubic bezier path
        /// @since v0.8
        /// </summary>
        public static void DrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, CCColor4B color)
        {
            float t         = 0;
            float increment = 1.0f / segments;

            var vertices = new CCPoint[segments];

            vertices[0] = origin;

            for (int i = 1; i < segments; ++i, t += increment)
            {
                vertices[i].X = CCSplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t);
                vertices[i].Y = CCSplineMath.CubicBezier(origin.Y, control1.Y, control2.Y, destination.Y, t);
            }

            vertices[segments - 1] = destination;
            DrawPoly(vertices, color);
        }
Exemplo n.º 3
0
        public void DrawQuadBezier(CCPoint origin, CCPoint control, CCPoint destination, int segments, float lineWidth, CCColor4B color)
        {
            float t         = 0;
            float increment = 1.0f / segments;

            var vertices = new CCPoint[segments];

            vertices[0] = origin;

            for (int i = 1; i < segments; ++i, t += increment)
            {
                vertices[i].X = CCSplineMath.QuadBezier(origin.X, control.X, destination.X, t);
                vertices[i].Y = CCSplineMath.QuadBezier(origin.Y, control.Y, destination.Y, t);
            }

            vertices[segments - 1] = destination;

            DrawPolygon(vertices, vertices.Length, CCColor4B.Transparent, lineWidth, color);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// draws a cubic bezier path
        /// @since v0.8
        /// </summary>
        public void DrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, float lineWidth, CCColor4B color)
        {
            float t         = 0;
            float increment = 1.0f / segments;

            var vertices = new CCPoint[segments];

            vertices[0] = origin;

            for (int i = 1; i < segments; ++i, t += increment)
            {
                vertices[i].X = CCSplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t);
                vertices[i].Y = CCSplineMath.CubicBezier(origin.Y, control1.Y, control2.Y, destination.Y, t);
            }

            vertices[segments - 1] = destination;

            for (int i = 0; i < vertices.Length - 1; i++)
            {
                DrawLine(vertices[i], vertices[i + 1], lineWidth, color);
            }

            //DrawPolygon(vertices, vertices.Length, color, 0, CCColor4B.Transparent);
        }