Esempio n. 1
0
        public void AddVertex(ref CCVector2 vertex, CCColor4B color, PrimitiveType primitiveType)
        {
            if (!hasBegun)
            {
                throw new InvalidOperationException("Begin must be called before AddVertex can be called.");
            }

            if (primitiveType == PrimitiveType.LineStrip || primitiveType == PrimitiveType.TriangleStrip)
            {
                throw new NotSupportedException("The specified primitiveType is not supported by PrimitiveBatch.");
            }

            if (primitiveType == PrimitiveType.TriangleList)
            {
                if (triangleVertsCount >= triangleVertices.Length)
                {
                    FlushTriangles();
                }
                triangleVertices[triangleVertsCount].Position = new Vector3(vertex.ToVector2(), -0.1f);
                triangleVertices[triangleVertsCount].Color    = color.ToColor();
                triangleVertsCount++;
            }

            if (primitiveType == PrimitiveType.LineList)
            {
                if (lineVertsCount >= lineVertices.Length)
                {
                    FlushLines();
                }
                lineVertices[lineVertsCount].Position = new Vector3(vertex.ToVector2(), 0f);
                lineVertices[lineVertsCount].Color    = color.ToColor();
                lineVertsCount++;
            }
        }
Esempio n. 2
0
        // Used for drawing line caps
        public void DrawSolidArc(CCPoint pos, float radius, float startAngle, float sweepAngle, CCColor4B color)
        {
            var cl = color.ToColor();

            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 VertexPositionColor(new Vector3(pos.X, pos.Y, 0), cl);
            var   vert1         = new VertexPositionColor(Vector3.Zero, cl);
            float tx            = 0;
            float ty            = 0;

            for (int i = 0; i < segments - 1; i++)
            {
                triangleVertices.Add(verticeCenter);

                vert1.Position.X = x + pos.X;
                vert1.Position.Y = y + pos.Y;
                triangleVertices.Add(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.Position.X = x + pos.X;
                vert1.Position.Y = y + pos.Y;
                triangleVertices.Add(vert1); // output vertex
            }

            dirty = true;
        }
Esempio n. 3
0
        public void SetTile(CCColor4B tile, CCGridSize position)
        {
            Debug.Assert(TGAInfo != null, "tgaInfo must not be nil");
            Debug.Assert(PositionToAtlasIndex != null, "posToAtlasIndex must not be nil");
            Debug.Assert(position.X < TGAInfo.Width, "Invalid position.x");
            Debug.Assert(position.Y < TGAInfo.Height, "Invalid position.x");
            Debug.Assert(tile.R != 0, "R component must be non 0");

            Color value = TGAInfo.ImageData[position.X + position.Y * TGAInfo.Width];

            if (value.R == 0)
            {
                CCLog.Log("CocosSharp: Value.r must be non 0.");
            }
            else
            {
                TGAInfo.ImageData[position.X + position.Y * TGAInfo.Width] = new Color(tile.R, tile.G, tile.B, tile.A);

                // XXX: this method consumes a lot of memory
                // XXX: a tree of something like that shall be implemented
                int num = PositionToAtlasIndex[position];
                UpdateAtlasValueAt(position, tile.ToColor(), num);
            }
        }
Esempio n. 4
0
        // Used for drawing line caps
        public void DrawSolidArc(CCPoint pos, float radius, float startAngle, float sweepAngle, CCColor4B color)
        {
            var cl = color.ToColor();

            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 VertexPositionColor(new Vector3(pos.X, pos.Y, 0), cl);
            var vert1 = new VertexPositionColor(Vector3.Zero, cl);
            float tx = 0;
            float ty = 0;

            for (int i = 0; i < segments - 1; i++)
            {
                triangleVertices.Add(verticeCenter);

                vert1.Position.X = x + pos.X;
                vert1.Position.Y = y + pos.Y;
                triangleVertices.Add(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.Position.X = x + pos.X;
                vert1.Position.Y = y + pos.Y;
                triangleVertices.Add(vert1); // output vertex
            }

            dirty = true;
        }
Esempio n. 5
0
 public void Clear(CCColor4B color, float depth, int stencil)
 {
     Clear(ClearOptions.Target | ClearOptions.Stencil | ClearOptions.DepthBuffer, color.ToColor(), depth, stencil);
 }
Esempio n. 6
0
 public void Clear(CCColor4B color)
 {
     graphicsDevice.Clear(color.ToColor());
 }
Esempio n. 7
0
 public void Clear(CCColor4B color, float depth)
 {
     graphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, color.ToColor(), depth, 0);
 }
Esempio n. 8
0
		public void AddVertex(ref CCVector2 vertex, CCColor4B color, PrimitiveType primitiveType)
        {
            if (!hasBegun)
            {
                throw new InvalidOperationException("Begin must be called before AddVertex can be called.");
            }

            if (primitiveType == PrimitiveType.LineStrip || primitiveType == PrimitiveType.TriangleStrip)
            {
                throw new NotSupportedException("The specified primitiveType is not supported by PrimitiveBatch.");
            }

            if (primitiveType == PrimitiveType.TriangleList)
            {
                if (triangleVertsCount >= triangleVertices.Length)
                {
                    FlushTriangles();
                }
				triangleVertices[triangleVertsCount].Position = new Vector3(vertex.ToVector2(), -0.1f);
				triangleVertices[triangleVertsCount].Color = color.ToColor();
                triangleVertsCount++;
            }

            if (primitiveType == PrimitiveType.LineList)
            {
                if (lineVertsCount >= lineVertices.Length)
                {
                    FlushLines();
                }
				lineVertices[lineVertsCount].Position = new Vector3(vertex.ToVector2(), 0f);
				lineVertices[lineVertsCount].Color = color.ToColor();
                lineVertsCount++;
            }
        }
Esempio n. 9
0
        public void SetTile(CCColor4B tile, CCGridSize position)
        {
            Debug.Assert(TGAInfo != null, "tgaInfo must not be nil");
            Debug.Assert(PositionToAtlasIndex != null, "posToAtlasIndex must not be nil");
            Debug.Assert(position.X < TGAInfo.Width, "Invalid position.x");
            Debug.Assert(position.Y < TGAInfo.Height, "Invalid position.x");
            Debug.Assert(tile.R != 0, "R component must be non 0");

            Color value = TGAInfo.ImageData[position.X + position.Y * TGAInfo.Width];
            if (value.R == 0)
            {
                CCLog.Log("CocosSharp: Value.r must be non 0.");
            }
            else
            {
                TGAInfo.ImageData[position.X + position.Y * TGAInfo.Width] = new Color(tile.R, tile.G, tile.B, tile.A);

                // XXX: this method consumes a lot of memory
                // XXX: a tree of something like that shall be implemented
                int num = PositionToAtlasIndex[position];
                UpdateAtlasValueAt(position, tile.ToColor(), num);
            }
        }