Ejemplo n.º 1
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 topLeft, Vector2 bottomRight, int row, int column)
        {
            bool    colorSwap   = values[row, column] < 0;
            Color32 colorTop    = colors[row % colorCount, colorSwap ? 1 : 0] * color;
            Color32 colorBottom = colors[row % colorCount, colorSwap ? 0 : 1] * color;

            Bar bar = new Bar();

            bar.firstVertex = Vertices.Count;
            bar.row         = row;
            bar.column      = column;
            bar.rect        = new Rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
            bars.Add(bar);

            Vertices.Add(topLeft);
            VertexColors.Add(colorTop);

            Vertices.Add(new Vector3(bottomRight.x, topLeft.y, 0));
            VertexColors.Add(colorTop);

            Vertices.Add(bottomRight);
            VertexColors.Add(colorBottom);

            Vertices.Add(new Vector3(topLeft.x, bottomRight.y, 0));
            VertexColors.Add(colorBottom);

            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);

            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
            Triangles.Add(Vertices.Count - 4);
        }
Ejemplo n.º 2
0
 private void SetColors(int numOfVertexes)
 {
     for (int i = 0; i < numOfVertexes; i++)
     {
         Color color = Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));
         VertexColors.Add(color);
     }
 }
Ejemplo n.º 3
0
 ///<summary>
 /// Add triangle with colors
 ///</summary>
 void AddTriangle(Vector3 p1, Vector3 p2, Vector3 p3, Color32 color1, Color32 color2)
 {
     Vertices.Add(p1);
     Vertices.Add(p2);
     Vertices.Add(p3);
     VertexColors.Add(color1);
     VertexColors.Add(color2);
     VertexColors.Add(color2);
     Triangles.Add(Vertices.Count - 3);
     Triangles.Add(Vertices.Count - 2);
     Triangles.Add(Vertices.Count - 1);
 }
Ejemplo n.º 4
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, Color32 color1, Color32 color2)
        {
            float z = mode_3d ? -size.z / 2 : 0.0f;

            Vertices.Add(new Vector3(p0.x * size.x, p0.y * size.y, z));
            Vertices.Add(new Vector3(p1.x * size.x, p1.y * size.y, z));
            Vertices.Add(new Vector3(p2.x * size.x, p2.y * size.y, z));
            Vertices.Add(new Vector3(p3.x * size.x, p3.y * size.y, z));
            VertexColors.Add(color1);
            VertexColors.Add(color2);
            VertexColors.Add(color2);
            VertexColors.Add(color1);
            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
        }
Ejemplo n.º 5
0
		///<summary>
		/// Add a quad
		///</summary>
		void AddQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color32 color1, Color32 color2)
		{
			Vertices.Add(a);
			Vertices.Add(b);
			Vertices.Add(c);
			Vertices.Add(d);

			VertexColors.Add(color1);
			VertexColors.Add(color1);
			VertexColors.Add(color2);
			VertexColors.Add(color2);

			Triangles.Add(Vertices.Count - 4);
			Triangles.Add(Vertices.Count - 3);
			Triangles.Add(Vertices.Count - 2);

			Triangles.Add(Vertices.Count - 3);
			Triangles.Add(Vertices.Count - 1);
			Triangles.Add(Vertices.Count - 2);
		}
Ejemplo n.º 6
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, Color32 color1, Color32 color2)
        {
            Vertices.Add(new Vector3(p0.x * rectTransform.rect.width, p0.y * rectTransform.rect.height, 0));
            Vertices.Add(new Vector3(p1.x * rectTransform.rect.width, p1.y * rectTransform.rect.height, 0));
            Vertices.Add(new Vector3(p2.x * rectTransform.rect.width, p2.y * rectTransform.rect.height, 0));
            Vertices.Add(new Vector3(p3.x * rectTransform.rect.width, p3.y * rectTransform.rect.height, 0));

            VertexColors.Add(color1);
            VertexColors.Add(color2);
            VertexColors.Add(color2);
            VertexColors.Add(color1);

            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);

            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
            Triangles.Add(Vertices.Count - 4);
        }
Ejemplo n.º 7
0
        ///<summary>
        /// Add quad
        ///</summary>
        void AddQuad(Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3, Color32 color)
        {
            Vertices.Add(p0);
            VertexColors.Add(color);

            Vertices.Add(p1);
            VertexColors.Add(color);

            Vertices.Add(p2);
            VertexColors.Add(color);

            Vertices.Add(p3);
            VertexColors.Add(color);

            Triangles.Add(Vertices.Count - 4);
            Triangles.Add(Vertices.Count - 3);
            Triangles.Add(Vertices.Count - 2);

            Triangles.Add(Vertices.Count - 2);
            Triangles.Add(Vertices.Count - 1);
            Triangles.Add(Vertices.Count - 4);
        }
Ejemplo n.º 8
0
        ///<summary>
        /// Generate a point at given location
        ///</summary>
        void CreatePoint(Vector3 center, int row, int column)
        {
            float   r     = size.x * pointSize;
            Color32 color = colors[row % colorCount, 1];

            switch (point)
            {
            case PointType.CIRCLE:
            {
                Vector3 p1 = new Vector3(r, 0, 0);
                for (int i = 0; i < 360 / 30; i++)
                {
                    Vector3 p = p1;
                    p1 = Quaternion.Euler(0, 0, 30) * p1;

                    Vertices.Add(center);
                    Vertices.Add(center + p);
                    Vertices.Add(center + p1);
                    VertexColors.Add(color);
                    VertexColors.Add(color);
                    VertexColors.Add(color);
                    Triangles.Add(Vertices.Count - 3);
                    Triangles.Add(Vertices.Count - 2);
                    Triangles.Add(Vertices.Count - 1);

                    if (mode_3d)
                    {
                        Vector3 p3 = center; p3.z = z1;
                        Vector3 p4 = center + p; p4.z = z1;
                        Vector3 p5 = center + p1; p5.z = z1;

                        AddTriangle(p3, p5, p4, color, color);

                        AddTriangle(center + p, p4, center + p1, color, color);
                        AddTriangle(center + p1, p4, p5, color, color);
                    }
                }
            }
            break;

            case PointType.RECTANGLE:
            {
                Vector3 p0 = center + new Vector3(-r, -r, 0);
                Vector3 p1 = center + new Vector3(-r, r, 0);
                Vector3 p2 = center + new Vector3(r, r, 0);
                Vector3 p3 = center + new Vector3(r, -r, 0);

                // Vector3 p = new Vector3(0, r, 0);
                // Vector3 p0 = center + Quaternion.Euler(0, 0, 45) * p;
                // Vector3 p1 = center + Quaternion.Euler(0, 0, 135) * p;
                // Vector3 p2 = center + Quaternion.Euler(0, 0, 225) * p;
                // Vector3 p3 = center + Quaternion.Euler(0, 0, 315) * p;

                AddTriangle(p0, p1, p3, color, color);
                AddTriangle(p3, p1, p2, color, color);

                if (mode_3d)
                {
                    Vector3 p4 = p0; p4.z = z1;
                    Vector3 p5 = p1; p5.z = z1;
                    Vector3 p6 = p2; p6.z = z1;
                    Vector3 p7 = p3; p7.z = z1;

                    AddTriangle(p4, p7, p5, color, color);
                    AddTriangle(p7, p6, p5, color, color);

                    AddTriangle(p0, p4, p1, color, color);
                    AddTriangle(p5, p1, p4, color, color);

                    AddTriangle(p2, p1, p5, color, color);
                    AddTriangle(p2, p5, p6, color, color);

                    AddTriangle(p2, p6, p3, color, color);
                    AddTriangle(p7, p3, p6, color, color);

                    AddTriangle(p3, p7, p0, color, color);
                    AddTriangle(p0, p7, p4, color, color);
                }
            }
            break;

            case PointType.TRIANGLE:
            {
                Vector3 p0 = center + new Vector3(0, r, 0);
                Vector3 p1 = center + new Vector3(r, -r, 0);
                Vector3 p2 = center + new Vector3(-r, -r, 0);

                // Vector3 p = new Vector3(0, r, 0);
                // Vector3 p0 = center + p;
                // Vector3 p1 = center + Quaternion.Euler(0, 0, 120) * p;
                // Vector3 p2 = center + Quaternion.Euler(0, 0, 240) * p;

                AddTriangle(p0, p1, p2, color, color);

                if (mode_3d)
                {
                    Vector3 p3 = p0; p3.z = z1;
                    Vector3 p4 = p1; p4.z = z1;
                    Vector3 p5 = p2; p5.z = z1;

                    AddTriangle(p3, p5, p4, color, color);

                    AddTriangle(p0, p4, p1, color, color);
                    AddTriangle(p0, p3, p4, color, color);

                    AddTriangle(p1, p4, p2, color, color);
                    AddTriangle(p2, p4, p5, color, color);

                    AddTriangle(p2, p5, p0, color, color);
                    AddTriangle(p5, p3, p0, color, color);
                }
            }
            break;
            }
        }
Ejemplo n.º 9
0
        ///<summary>
        /// Close the line with given color
        ///</summary>
        void CloseLine(Color32 color)
        {
            if (vertices.Count == 0)
            {
                return;
            }

            int        offset        = Vertices.Count;
            int        triangleCount = vertices.Count - 2;
            List <int> triangles     = new List <int>();

            for (int i = 0; i < triangleCount / 2; i++)
            {
                triangles.Add(offset + i * 2);
                triangles.Add(offset + i * 2 + 2);
                triangles.Add(offset + i * 2 + 1);

                triangles.Add(offset + i * 2 + 2);
                triangles.Add(offset + i * 2 + 3);
                triangles.Add(offset + i * 2 + 1);
            }

            for (int i = 0; i < vertices.Count; i++)
            {
                VertexColors.Add(color);
            }

            if (mode_3d)
            {
                List <Vector3> v2 = new List <Vector3>();
                List <int>     t2 = new List <int>();

                for (int i = 0; i < vertices.Count; i++)
                {
                    v2.Add(new Vector3(vertices[i].x, vertices[i].y, z1));
                    VertexColors.Add(color);
                }

                for (int i = 0; i < triangleCount * 3; i += 3)
                {
                    t2.Add(triangles[i] + vertices.Count);
                    t2.Add(triangles[i + 2] + vertices.Count);
                    t2.Add(triangles[i + 1] + vertices.Count);
                }

                for (int i = 0; i < triangles.Count; i += 6)
                {
                    t2.Add(triangles[i + 4]);
                    t2.Add(t2[i + 1]);
                    t2.Add(triangles[i + 2]);

                    t2.Add(triangles[i + 4]);
                    t2.Add(t2[i + 5]);
                    t2.Add(t2[i + 1]);

                    t2.Add(triangles[i]);
                    t2.Add(t2[i]);
                    t2.Add(t2[i + 2]);

                    t2.Add(triangles[i + 1]);
                    t2.Add(triangles[i]);
                    t2.Add(t2[i + 2]);
                }

                t2.Add(offset);
                t2.Add(offset + 1);
                t2.Add(offset + vertices.Count);

                t2.Add(offset + vertices.Count + 1);
                t2.Add(offset + vertices.Count);
                t2.Add(offset + 1);

                t2.Add(offset + vertices.Count - 2);
                t2.Add(offset + vertices.Count * 2 - 1);
                t2.Add(offset + vertices.Count - 1);

                t2.Add(offset + vertices.Count * 2 - 1);
                t2.Add(offset + vertices.Count - 2);
                t2.Add(offset + vertices.Count * 2 - 2);

                vertices.AddRange(v2);
                triangles.AddRange(t2);
            }

            Vertices.AddRange(vertices);
            Triangles.AddRange(triangles);

            vertices.Clear();
        }
Ejemplo n.º 10
0
        ///<summary>
        /// Add a segment to chart
        ///</summary>
        void AddLineSegment(float x1, float y1, float x2, float y2, Color32 color)
        {
            float px     = y2 - y1;
            float py     = -(x2 - x1);
            float length = Mathf.Sqrt(px * px + py * py);

            float nx = (px / length) * rectTransform.rect.width * thickness;
            float ny = (py / length) * rectTransform.rect.width * thickness;

            Vector3 vert0 = new Vector3(x1 + nx, y1 + ny, 0);
            Vector3 vert1 = new Vector3(x2 + nx, y2 + ny, 0);
            Vector3 vert2 = new Vector3(x2 - nx, y2 - ny, 0);
            Vector3 vert3 = new Vector3(x1 - nx, y1 - ny, 0);

            if (Vertices.Count == 0 || newLine)
            {
                Vertices.Add(vert0);
                Vertices.Add(vert1);
                Vertices.Add(vert2);
                Vertices.Add(vert3);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);

                Triangles.Add(Vertices.Count - 4);
                Triangles.Add(Vertices.Count - 3);
                Triangles.Add(Vertices.Count - 2);

                Triangles.Add(Vertices.Count - 2);
                Triangles.Add(Vertices.Count - 1);
                Triangles.Add(Vertices.Count - 4);
                newLine = false;
                return;
            }

            Vector3 vertP0 = Vertices[Vertices.Count - 4];
            Vector3 vertP1 = Vertices[Vertices.Count - 3];
            Vector3 vertP2 = Vertices[Vertices.Count - 2];
            Vector3 vertP3 = Vertices[Vertices.Count - 1];

            bool intersect = lineSegmentIntersection(vertP0, vertP1, vert1, vert0) | lineSegmentIntersection(vertP3, vertP2, vert2, vert3);

            if (!intersect)
            {
                if (vectorIntersection(vertP0, vertP1, vert1, vert0))
                {
                    vert0 = lineIntersectionPoint(vertP0, vertP1, vert1, vert0);
                    Vertices[Vertices.Count - 3] = vert0;
                }
                if (vectorIntersection(vertP3, vertP2, vert2, vert3))
                {
                    vert3 = lineIntersectionPoint(vertP3, vertP2, vert2, vert3);
                    Vertices[Vertices.Count - 2] = vert3;
                }

                Vertices.Add(vert0);
                Vertices.Add(vert1);
                Vertices.Add(vert2);
                Vertices.Add(vert3);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);

                Triangles.Add(Vertices.Count - 4);
                Triangles.Add(Vertices.Count - 3);
                Triangles.Add(Vertices.Count - 2);

                Triangles.Add(Vertices.Count - 2);
                Triangles.Add(Vertices.Count - 1);
                Triangles.Add(Vertices.Count - 4);
            }
            else
            {
                vert0 = lineIntersectionPoint(vertP0, vertP1, vert1, vert0);
                vert3 = lineIntersectionPoint(vertP3, vertP2, vert2, vert3);
                Vertices[Vertices.Count - 3] = vert0;
                Vertices[Vertices.Count - 2] = vert3;
                Vertices.Add(vert0);
                Vertices.Add(vert1);
                Vertices.Add(vert2);
                Vertices.Add(vert3);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                VertexColors.Add(color);
                Triangles.Add(Vertices.Count - 4);
                Triangles.Add(Vertices.Count - 3);
                Triangles.Add(Vertices.Count - 2);

                Triangles.Add(Vertices.Count - 2);
                Triangles.Add(Vertices.Count - 1);
                Triangles.Add(Vertices.Count - 4);
            }
        }