Exemple #1
0
        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);
        }
Exemple #2
0
        /*
         *  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();
        }
        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);
        }
        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);
        }
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;
        }
Exemple #6
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;
        }
        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;
        }
Exemple #8
0
        private void RenderHexagon(Hexagon hexagon)
        {
            var visualSettings           = World.GameSettings.VisualSettings;
            var colorCollection          = visualSettings.ColorCollection;
            var layoutSettings           = World.GameSettings.LayoutSettings;
            var worldPosition            = hexagon.Position.GetWorldPosition(layoutSettings.HexagonRadius, layoutSettings.HexagonMargin);
            var corners                  = Corners.Select(c => c * layoutSettings.HexagonRadius + worldPosition).ToArray();
            var innerColor               = colorCollection.GetInnerHexagonColor(hexagon.ResourceType);
            var outerColor               = colorCollection.GetOuterHexagonColor(hexagon.ResourceType);
            var center                   = new CCV3F_C4B(worldPosition, innerColor);
            var adjacentHexagonPositions = hexagon.Position.GetAdjacentHexagonPositions();

            for (int i = 0; i < corners.Length; i++)
            {
                var p1 = new CCV3F_C4B(corners[i], outerColor);
                var p2 = new CCV3F_C4B(corners[(i + 1) % corners.Length], outerColor);
                DrawNode.DrawTriangle(p1, center, p2);
                if (World.HexagonManager[adjacentHexagonPositions[(6 - i + 2) % 6]]?.ResourceType != hexagon.ResourceType)
                {
                    DrawNode.DrawLine(corners[i], corners[(i + 1) % corners.Length], visualSettings.HexagonOuterBorderThickness, colorCollection.HexagonBorder);
                }
            }
            DrawNode.DrawText(worldPosition, hexagon.ResourceType.GetText(), Font.ArialFonts[32], new CCSize(layoutSettings.HexagonRadius * 2, layoutSettings.HexagonRadius * 2));
        }
Exemple #9
0
        /*
         *  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();
        }
Exemple #10
0
        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.DrawDot(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.DrawSegment(new CCPoint(20, windowSize.Height), new CCPoint(20, windowSize.Height / 2), 10, new CCColor4F(0, 1, 0, 1));

            draw.DrawSegment(new CCPoint(10, windowSize.Height / 2), new CCPoint(windowSize.Width / 2, windowSize.Height / 2), 40,
                             new CCColor4F(1, 0, 1, 0.5f));
        }
Exemple #11
0
 public void AddLineVertex(CCV3F_C4B lineVertex)
 {
     LineVertices.Add(lineVertex);
     dirty = true;
 }
Exemple #12
0
 public void AddTriangleVertex(CCV3F_C4B triangleVertex)
 {
     TriangleVertices.Add(triangleVertex);
     dirty = true;
 }
Exemple #13
0
 public void DrawTriangle(CCV3F_C4B p1, CCV3F_C4B p2, CCV3F_C4B p3) => DrawTriangle(p1, p2, p3, 0, CCColor4B.Transparent);
Exemple #14
0
 public void DrawTriangle(CCV3F_C4B p1, CCV3F_C4B p2, CCV3F_C4B p3, float borderThickness, CCColor4B borderColor) => DrawTriangle(new[]
 {
     p1,
     p2,
     p3
 }, borderThickness, borderColor);