/*
         *  TL    TR
         *   0----1 0,1,2,3 = index offsets for vertex indices
         *   |   /|
         *   |  / |
         *   | /  |
         *   |/   |
         *   2----3
         *  BL    BR
         */
        void GenerateGradient(CCSize textureSizeInPixels)
        {
            var gradientNode = new CCDrawNode();

            var gradientAlpha = new CCColor4B(0, 0, 0,(byte)(0.7f * 255f));
            CCV3F_C4B[] vertices = new CCV3F_C4B[6];

            // Left triangle TL - 0
            vertices[0].Vertices = new CCVertex3F(0, textureSizeInPixels.Height, 0);
            vertices[0].Colors = CCColor4B.Transparent;

            // Left triangle BL - 2
            vertices[1].Vertices = new CCVertex3F(0, 0, 0);
            vertices[1].Colors = gradientAlpha;

            // Left triangle TR - 1
            vertices[2].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0);
            vertices[2].Colors = CCColor4B.Transparent;

            // Right triangle BL - 2
            vertices[3].Vertices = new CCVertex3F(0, 0, 0);
            vertices[3].Colors = gradientAlpha;

            // Right triangle BR - 3
            vertices[4].Vertices = new CCVertex3F(textureSizeInPixels.Width, 0, 0);
            vertices[4].Colors = gradientAlpha;

            // Right triangle TR - 1
            vertices[5].Vertices = new CCVertex3F(textureSizeInPixels.Width, textureSizeInPixels.Height, 0);
            vertices[5].Colors = CCColor4B.Transparent;

            gradientNode.DrawTriangleList(vertices);

            gradientNode.Visit();
        }
 public static CCV3F_C4B ToVectorC4B(this b2Vec2 vec, CCColor4B color, int PTMRatio)
 {
     var v3f_c4b = new CCV3F_C4B();
     v3f_c4b.Vertices.X = vec.x * PTMRatio;
     v3f_c4b.Vertices.Y = vec.y * PTMRatio;
     v3f_c4b.Colors = color;
     return v3f_c4b;
 }
        /*
         *  TL    TR
         *   0----1 0,1,2,3 = index offsets for vertex indices
         *   |   /| 
         *   |  / |
         *   | /  |
         *   |/   |
         *   2----3
         *  BL    BR
         */
        void GenerateStripes (CCSize textureSizeInPixels, CCColor4B c2, int numberOfStripes)
        {
            var gradientNode = new CCDrawNode();

            // Layer 1: Stripes
            CCV3F_C4B[] vertices = new CCV3F_C4B[numberOfStripes*6];

            var textureWidth = textureSizeInPixels.Width;
            var textureHeight = textureSizeInPixels.Height;

            int nVertices = 0;
            float x1 = -textureHeight;
            float x2;
            float y1 = textureHeight;
            float y2 = 0;
            float dx = textureWidth / numberOfStripes * 2;
            float stripeWidth = dx/2;

            for (int i=0; i<numberOfStripes; i++) 
            {

                x2 = x1 + textureHeight;

                // Left triangle TL - 0
                vertices[nVertices].Vertices = new CCVertex3F(x1, y1, 0);
                vertices[nVertices++].Colors = c2;

                // Left triangle BL - 2
                vertices[nVertices].Vertices = new CCVertex3F(x1+stripeWidth, y1, 0);
                vertices[nVertices++].Colors = c2;

                // Left triangle TR - 1
                vertices[nVertices].Vertices = new CCVertex3F(x2, y2, 0);
                vertices[nVertices++].Colors = c2;

                // Right triangle BL - 2
                vertices[nVertices].Vertices = vertices[nVertices-2].Vertices;
                vertices[nVertices++].Colors = c2;

                // Right triangle BR - 3
                vertices[nVertices].Vertices = vertices[nVertices-2].Vertices;
                vertices[nVertices++].Colors = c2;

                // Right triangle TR - 1
                vertices[nVertices].Vertices = new CCVertex3F(x2+stripeWidth, y2, 0);
                vertices[nVertices++].Colors = c2;

                x1 += dx;
            }

            gradientNode.DrawTriangleList(vertices);

            gradientNode.Visit();

        }
        public void Transform(ref CCV3F_C4B quadPoint)
        {
            var x = quadPoint.Vertices.X;
            var y = quadPoint.Vertices.Y;
            var z = quadPoint.Vertices.Z;

            Transform(ref x, ref y, ref z);
            quadPoint.Vertices.X = x;
            quadPoint.Vertices.Y = y;
            quadPoint.Vertices.Z = z;
        }
Exemple #5
0
        // Used for drawing line caps
        public void DrawSolidArc(CCPoint pos, float radius, float startAngle, float sweepAngle, CCColor4B color)
        {
            var cl = color;

            int segments = (int)(10 * (float)Math.Sqrt(radius));  //<- Let's try to guess at # segments for a reasonable smoothness

            float theta            = sweepAngle / (segments - 1); // MathHelper.Pi * 2.0f / segments;
            float tangetial_factor = (float)Math.Tan(theta);      //calculate the tangential factor

            float radial_factor = (float)Math.Cos(theta);         //calculate the radial factor

            float x = radius * (float)Math.Cos(startAngle);       //we now start at the start angle
            float y = radius * (float)Math.Sin(startAngle);

            var   verticeCenter = new CCV3F_C4B(pos, cl);
            var   vert1         = new CCV3F_C4B(CCVertex3F.Zero, cl);
            float tx            = 0;
            float ty            = 0;

            for (int i = 0; i < segments - 1; i++)
            {
                AddTriangleVertex(verticeCenter);

                vert1.Vertices.X = x + pos.X;
                vert1.Vertices.Y = y + pos.Y;
                AddTriangleVertex(vert1); // output vertex

                //calculate the tangential vector
                //remember, the radial vector is (x, y)
                //to get the tangential vector we flip those coordinates and negate one of them
                tx = -y;
                ty = x;

                //add the tangential vector
                x += tx * tangetial_factor;
                y += ty * tangetial_factor;

                //correct using the radial factor
                x *= radial_factor;
                y *= radial_factor;

                vert1.Vertices.X = x + pos.X;
                vert1.Vertices.Y = y + pos.Y;
                AddTriangleVertex(vert1); // output vertex
            }

            dirty = true;
        }
        public void DrawCircle(CCPoint center, float radius, int segments, CCColor4B color)
        {
            var cl = color;

            float theta = MathHelper.Pi * 2.0f / segments;
            float tangetial_factor = (float)Math.Tan(theta);   //calculate the tangential factor 

            float radial_factor = (float)Math.Cos(theta);   //calculate the radial factor 

            float x = radius;  //we start at angle = 0 
            float y = 0;

            var vert1 = new CCV3F_C4B(CCVertex3F.Zero, cl);
            float tx = 0;
            float ty = 0;

            for (int i = 0; i < segments; i++)
            {

                vert1.Vertices.X = x + center.X;
                vert1.Vertices.Y = y + center.Y;
                AddLineVertex(vert1); // output vertex

                //calculate the tangential vector 
                //remember, the radial vector is (x, y) 
                //to get the tangential vector we flip those coordinates and negate one of them 
                tx = -y;
                ty = x;

                //add the tangential vector 
                x += tx * tangetial_factor;
                y += ty * tangetial_factor;

                //correct using the radial factor 
                x *= radial_factor;
                y *= radial_factor;

                vert1.Vertices.X = x + center.X;
                vert1.Vertices.Y = y + center.Y;
                AddLineVertex(vert1); // output vertex

            }

            dirty = true;

        }
Exemple #7
0
        public void DrawCircle(CCPoint center, float radius, int segments, CCColor4B color)
        {
            var cl = color;

            float theta            = MathHelper.Pi * 2.0f / segments;
            float tangetial_factor = (float)Math.Tan(theta); //calculate the tangential factor

            float radial_factor = (float)Math.Cos(theta);    //calculate the radial factor

            float x = radius;                                //we start at angle = 0
            float y = 0;

            var   vert1 = new CCV3F_C4B(CCVertex3F.Zero, cl);
            float tx    = 0;
            float ty    = 0;

            for (int i = 0; i < segments; i++)
            {
                vert1.Vertices.X = x + center.X;
                vert1.Vertices.Y = y + center.Y;
                AddLineVertex(vert1); // output vertex

                //calculate the tangential vector
                //remember, the radial vector is (x, y)
                //to get the tangential vector we flip those coordinates and negate one of them
                tx = -y;
                ty = x;

                //add the tangential vector
                x += tx * tangetial_factor;
                y += ty * tangetial_factor;

                //correct using the radial factor
                x *= radial_factor;
                y *= radial_factor;

                vert1.Vertices.X = x + center.X;
                vert1.Vertices.Y = y + center.Y;
                AddLineVertex(vert1); // output vertex
            }

            dirty = true;
        }
        void FlushTriangles()
        {
            if (!hasBegun)
            {
                throw new InvalidOperationException("Begin must be called before Flush can be called.");
            }

            if (triangleVertsCount >= 3)
            {
                int primitiveCount = triangleVertsCount / 3;

                var triangles = new CCV3F_C4B[triangleVertsCount];
                Array.Copy(triangleVertices, triangles, triangleVertsCount);
                // add the Triangle List to our triangles list vertices for later rendering from the Renderer
                triangleVerts.Add(triangles);

                triangleVertsCount -= primitiveCount * 3;
            }
        }
        void FlushLines()
        {
            if (!hasBegun)
            {
                throw new InvalidOperationException("Begin must be called before Flush can be called.");
            }

            if (lineVertsCount >= 2)
            {
                int primitiveCount = lineVertsCount / 2;

                var lines = new CCV3F_C4B[lineVertsCount];
                Array.Copy(lineVertices, lines, triangleVertsCount);
                // add the Line Lists to our line list vertices for later rendering from the Renderer
                lineVerts.Add(lines);

                lineVertsCount -= primitiveCount * 2;
            }
        }
        public void DrawLineList (CCV3F_C4B[] verts)
        {

            for (int x = 0; x < verts.Length; x++)
            {
                AddLineVertex(verts[x]);

            }
        }
 public void DrawTriangleList (CCV3F_C4B[] verts)
 {
    
     for (int x = 0; x < verts.Length; x++)
     {
         AddTriangleVertex(verts[x]);
     }
 }
        // Used for drawing line caps
        public void DrawSolidArc(CCPoint pos, float radius, float startAngle, float sweepAngle, CCColor4B color)
        {
            var cl = color;

            int segments = (int)(10 * (float)Math.Sqrt(radius));  //<- Let's try to guess at # segments for a reasonable smoothness

            float theta = sweepAngle / (segments - 1);// MathHelper.Pi * 2.0f / segments;
            float tangetial_factor = (float)Math.Tan(theta);   //calculate the tangential factor 

            float radial_factor = (float)Math.Cos(theta);   //calculate the radial factor 

            float x = radius * (float)Math.Cos(startAngle);   //we now start at the start angle
            float y = radius * (float)Math.Sin(startAngle); 

            var verticeCenter = new CCV3F_C4B(pos, cl);
            var vert1 = new CCV3F_C4B(CCVertex3F.Zero, cl);
            float tx = 0;
            float ty = 0;

            for (int i = 0; i < segments - 1; i++)
            {
                AddTriangleVertex(verticeCenter);

                vert1.Vertices.X = x + pos.X;
                vert1.Vertices.Y = y + pos.Y;
                AddTriangleVertex(vert1); // output vertex

                //calculate the tangential vector 
                //remember, the radial vector is (x, y) 
                //to get the tangential vector we flip those coordinates and negate one of them 
                tx = -y;
                ty = x;

                //add the tangential vector 
                x += tx * tangetial_factor;
                y += ty * tangetial_factor;

                //correct using the radial factor 
                x *= radial_factor;
                y *= radial_factor;

                vert1.Vertices.X = x + pos.X;
                vert1.Vertices.Y = y + pos.Y;
                AddTriangleVertex(vert1); // output vertex
            }

            dirty = true;
        }
 public void AddLineVertex (CCV3F_C4B lineVertex)
 {
     lineVertices.Add(lineVertex);
 }
 public void Transform(ref CCV3F_C4B quadPoint)
 {
     var x = quadPoint.Vertices.X;
     var y = quadPoint.Vertices.Y;
     var z = quadPoint.Vertices.Z;
     Transform(ref x, ref y, ref z);
     quadPoint.Vertices.X = x;
     quadPoint.Vertices.Y = y;
     quadPoint.Vertices.Z = z;
 }
Exemple #15
0
 public void AddLineVertex(CCV3F_C4B lineVertex)
 {
     lineVertices.Add(lineVertex);
 }
        public void DrawLineList (CCV3F_C4B[] verts)
        {

            for (int x = 0; x < verts.Length; x++)
            {
                batch.AddVertex(verts[x].Vertices, verts[x].Colors, PrimitiveType.LineList);

            }
        }
 public void AddTriangleVertex(CCV3F_C4B triangleVertex)
 {
     TriangleVertices.Add(triangleVertex);
     dirty = true;
 }
        void FlushLines()
        {
            if (!hasBegun)
            {
                throw new InvalidOperationException("Begin must be called before Flush can be called.");
            }

            if (lineVertsCount >= 2)
            {
                int primitiveCount = lineVertsCount / 2;

                var lines = new CCV3F_C4B[lineVertsCount];
                Array.Copy(lineVertices, lines, triangleVertsCount);
                // add the Line Lists to our line list vertices for later rendering from the Renderer
                lineVerts.Add(lines);

                lineVertsCount -= primitiveCount * 2;

            }
        }
        void FlushTriangles()
        {
            if (!hasBegun)
            {
                throw new InvalidOperationException("Begin must be called before Flush can be called.");
            }

            if (triangleVertsCount >= 3)
            {
                int primitiveCount = triangleVertsCount / 3;

                var triangles = new CCV3F_C4B[triangleVertsCount];
                Array.Copy(triangleVertices, triangles, triangleVertsCount);
                // add the Triangle List to our triangles list vertices for later rendering from the Renderer
                triangleVerts.Add(triangles);

                triangleVertsCount -= primitiveCount * 3;

            }
        }
Exemple #20
0
 public void AddLineVertex(CCV3F_C4B lineVertex)
 {
     lineVertices.Add(lineVertex);
     dirty = true;
 }
Exemple #21
0
		void LineList ()
		{
			CCV3F_C4B[] verts = new CCV3F_C4B[] {
				// First line:
				new CCV3F_C4B (new CCPoint (0, 0), CCColor4B.White),
				new CCV3F_C4B (new CCPoint (30, 60), CCColor4B.White),
				// second line, will blend from white to red:
				new CCV3F_C4B (new CCPoint (60, 0), CCColor4B.White),
				new CCV3F_C4B (new CCPoint (120, 120), CCColor4B.Red)
			};

			drawNode.DrawLineList (verts);
		}
Exemple #22
0
		void TriangleList ()
		{
			CCV3F_C4B[] verts = new CCV3F_C4B[] {
				// First triangle:
				new CCV3F_C4B (new CCPoint (0, 0), CCColor4B.White),
				new CCV3F_C4B (new CCPoint (30, 60), CCColor4B.White),
				new CCV3F_C4B (new CCPoint (60, 0), CCColor4B.White),
				// second triangle, each point has different colors:
				new CCV3F_C4B (new CCPoint (90, 0), CCColor4B.Yellow),
				new CCV3F_C4B (new CCPoint (120, 60), CCColor4B.Red),
				new CCV3F_C4B (new CCPoint (150, 0), CCColor4B.Blue)
			};

			drawNode.DrawTriangleList (verts);

		}
        public override void OnEnter()
        {
            base.OnEnter(); 
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;
            CCDrawNode draw = new CCDrawNode();
            AddChild(draw, 10);

            var s = windowSize;

            // Draw 10 circles
            for (int i = 0; i < 10; i++)
            {
                draw.DrawSolidCircle(s.Center, 10 * (10 - i),
                    new CCColor4F(CCRandom.Float_0_1(), CCRandom.Float_0_1(), CCRandom.Float_0_1(), 1));
            }

            // Draw polygons
            CCV3F_C4B[] points = new CCV3F_C4B[3];

            points[0].Colors = CCColor4B.Red;
            points[0].Colors.A = 127;

            points[1].Colors = CCColor4B.Green;
            points[1].Colors.A = 127;

            points[2].Colors = CCColor4B.Blue;
            points[2].Colors.A = 127;

            points[0].Vertices.X = windowSize.Height / 4;
            points[0].Vertices.Y = 0;

            points[1].Vertices.X = windowSize.Width;
            points[1].Vertices.Y = windowSize.Height / 5;

            points[2].Vertices.X = windowSize.Width / 3 * 2;
            points[2].Vertices.Y = windowSize.Height;

            draw.DrawTriangleList(points);

            // star poly (triggers buggs)
            {
                const float o = 80;
                const float w = 20;
                const float h = 50;
                CCPoint[] star = new CCPoint[]
                    {
                        new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),                           // lower spike
                        new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),           // right spike
                    };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }

            // star poly (doesn't trigger bug... order is important un tesselation is supported.
            {
                const float o = 180;
                const float w = 20;
                const float h = 50;
                var star = new CCPoint[]
                    {
                        new CCPoint(o, o), new CCPoint(o + w, o - h), new CCPoint(o + w * 2, o),        // lower spike
                        new CCPoint(o + w * 2 + h, o + w), new CCPoint(o + w * 2, o + w * 2),           // right spike
                        new CCPoint(o + w, o + w * 2 + h), new CCPoint(o, o + w * 2),                   // top spike
                        new CCPoint(o - h, o + w), // left spike
                    };

                draw.DrawPolygon(star, star.Length, new CCColor4F(1, 0, 0, 0.5f), 1, new CCColor4F(0, 0, 1, 1));
            }


            // Draw segment
            draw.DrawLine(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1), CCLineCap.Round);

            draw.DrawLine(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                new CCColor4F(1, 0, 1, 0.5f), CCLineCap.Round);
        }
Exemple #24
0
 public void AddTriangleVertex(CCV3F_C4B triangleVertex)
 {
     triangleVertices.Add(triangleVertex);
 }
        public override void OnEnter()
        {
            base.OnEnter(); 
            CCSize windowSize = Layer.VisibleBoundsWorldspace.Size;


            var line = new CCDrawNode();
            line.DrawLine(new CCPoint(0, windowSize.Height / 2), new CCPoint(windowSize.Width, windowSize.Height / 2), 10);
            AddChild(line, 0);

            byte alpha = 100; // 255 is full opacity

            var green = new CCColor4B(0, 255, 0, alpha);

            CCV3F_C4B[] verts = new CCV3F_C4B[] {
                new CCV3F_C4B( new CCPoint(0,0), green),
                new CCV3F_C4B( new CCPoint(30,60), green),
                new CCV3F_C4B( new CCPoint(60,0), green)
            };

            triangleList1.DrawTriangleList (verts);

            triangleList1.Position = windowSize.Center;
            triangleList1.PositionX -= windowSize.Width / 4;
            triangleList1.PositionY -= triangleList1.ContentSize.Center.Y;

            // Because the default BlendFunc of our DrawNode is AlphaBlend we need
            // to pass the colors as pre multiplied alpha.
            var greenPreMultiplied = green;
            greenPreMultiplied.G = (byte)(greenPreMultiplied.G * alpha / 255.0f);

            verts[0].Colors = greenPreMultiplied;
            verts[1].Colors = greenPreMultiplied;
            verts[2].Colors = greenPreMultiplied;

            triangleList2.DrawTriangleList (verts);

            triangleList2.Position = windowSize.Center;
            triangleList2.PositionX += windowSize.Width / 4;
            triangleList2.PositionY -= triangleList2.BoundingRect.Size.Height / 2;
        }
 public void AddLineVertex (CCV3F_C4B lineVertex)
 {
     lineVertices.Add(lineVertex);
     dirty = true;
 }
 public void AddTriangleVertex (CCV3F_C4B triangleVertex)
 {
     triangleVertices.Add (triangleVertex);
 }