Exemple #1
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 = SplineMath.QuadBezier(origin.X, control.X, destination.X, t);
                vertices[i].Y = SplineMath.QuadBezier(origin.Y, control.Y, destination.Y, t);
            }

            vertices[segments - 1] = destination;

            DrawPolygon(vertices, vertices.Length, CCColor4B.Transparent, lineWidth, color, false);
        }
Exemple #2
0
        public void DrawCardinalSpline(List <CCPoint> config, float tension, int segments, CCColor4B color)
        {
            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] = SplineMath.CCCardinalSplineAt(pp0, pp1, pp2, pp3, tension, lt);
            }

            DrawPolygon(vertices, vertices.Length, CCColor4B.Transparent, 1, color, false);
        }
Exemple #3
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 = SplineMath.CubicBezier(origin.X, control1.X, control2.X, destination.X, t);
                vertices[i].Y = SplineMath.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, LineCap.Square);
            }

            //DrawPolygon(vertices, vertices.Length, color, lineWidth, color);
        }