Ejemplo n.º 1
0
        /// <summary>
        /// Converts the line segment into vertices and adds them to the geometry.
        /// </summary>
        public void Apply(LineGeometry geometry)
        {
            // F ------------------- G
            // |          /          |
            // A ------------------- C
            // |           /         |
            // |          /          |
            // |         /           |
            // B ------------------- D
            // |          /          |
            // H ------------------- I

            int steps            = 1;
            int colorsPerStep    = 8;
            int trianglesPerStep = 18;
            int verticesPerStep  = 8;

            geometry.AddColorCapacity(steps * colorsPerStep);
            geometry.AddTriangleCapacity(steps * trianglesPerStep);
            geometry.AddVertexCapacity(steps * verticesPerStep);

            LineVertex vertexA = new LineVertex();

            vertexA.Color    = PointA.Color;
            vertexA.Position = PointA.Position + NormalA * PointA.Weight;

            LineVertex vertexB = new LineVertex();

            vertexB.Color    = PointA.Color;
            vertexB.Position = PointA.Position - NormalA * PointA.Weight;

            LineVertex vertexC = new LineVertex();

            vertexC.Color    = PointB.Color;
            vertexC.Position = PointB.Position + NormalB * PointB.Weight;

            LineVertex vertexD = new LineVertex();

            vertexD.Color    = PointB.Color;
            vertexD.Position = PointB.Position - NormalB * PointB.Weight;

            LineVertex vertexF = new LineVertex();

            vertexF.Color    = PointA.Transparent;
            vertexF.Position = PointA.Position + NormalA * (PointA.Weight + Overdraw);

            LineVertex vertexG = new LineVertex();

            vertexG.Color    = PointB.Transparent;
            vertexG.Position = PointB.Position + NormalB * (PointB.Weight + Overdraw);

            LineVertex vertexH = new LineVertex();

            vertexH.Color    = PointA.Transparent;
            vertexH.Position = PointA.Position - NormalA * (PointA.Weight + Overdraw);

            LineVertex vertexI = new LineVertex();

            vertexI.Color    = PointB.Transparent;
            vertexI.Position = PointB.Position - NormalB * (PointB.Weight + Overdraw);

            // add colors
            geometry.Colors[geometry.ColorCount + 0] = vertexA.Color;
            geometry.Colors[geometry.ColorCount + 1] = vertexB.Color;
            geometry.Colors[geometry.ColorCount + 2] = vertexC.Color;
            geometry.Colors[geometry.ColorCount + 3] = vertexD.Color;
            geometry.Colors[geometry.ColorCount + 4] = vertexF.Color;
            geometry.Colors[geometry.ColorCount + 5] = vertexG.Color;
            geometry.Colors[geometry.ColorCount + 6] = vertexH.Color;
            geometry.Colors[geometry.ColorCount + 7] = vertexI.Color;

            // add vertices
            geometry.Vertices[geometry.VertexCount + 0] = vertexA.Position;
            geometry.Vertices[geometry.VertexCount + 1] = vertexB.Position;
            geometry.Vertices[geometry.VertexCount + 2] = vertexC.Position;
            geometry.Vertices[geometry.VertexCount + 3] = vertexD.Position;
            geometry.Vertices[geometry.VertexCount + 4] = vertexF.Position;
            geometry.Vertices[geometry.VertexCount + 5] = vertexG.Position;
            geometry.Vertices[geometry.VertexCount + 6] = vertexH.Position;
            geometry.Vertices[geometry.VertexCount + 7] = vertexI.Position;

            // add triangle - ACB
            geometry.Triangles[geometry.TriangleCount + 0] = geometry.VertexCount + 0;
            geometry.Triangles[geometry.TriangleCount + 1] = geometry.VertexCount + 2;
            geometry.Triangles[geometry.TriangleCount + 2] = geometry.VertexCount + 1;

            // add triangle - BCD
            geometry.Triangles[geometry.TriangleCount + 3] = geometry.VertexCount + 1;
            geometry.Triangles[geometry.TriangleCount + 4] = geometry.VertexCount + 2;
            geometry.Triangles[geometry.TriangleCount + 5] = geometry.VertexCount + 3;

            // add triangle - FGA
            geometry.Triangles[geometry.TriangleCount + 6] = geometry.VertexCount + 4;
            geometry.Triangles[geometry.TriangleCount + 7] = geometry.VertexCount + 5;
            geometry.Triangles[geometry.TriangleCount + 8] = geometry.VertexCount + 0;

            // add triangle - AGC
            geometry.Triangles[geometry.TriangleCount + 9]  = geometry.VertexCount + 0;
            geometry.Triangles[geometry.TriangleCount + 10] = geometry.VertexCount + 5;
            geometry.Triangles[geometry.TriangleCount + 11] = geometry.VertexCount + 2;

            // add triangle - BDH
            geometry.Triangles[geometry.TriangleCount + 12] = geometry.VertexCount + 1;
            geometry.Triangles[geometry.TriangleCount + 13] = geometry.VertexCount + 3;
            geometry.Triangles[geometry.TriangleCount + 14] = geometry.VertexCount + 6;

            // add triangle - HDI
            geometry.Triangles[geometry.TriangleCount + 15] = geometry.VertexCount + 6;
            geometry.Triangles[geometry.TriangleCount + 16] = geometry.VertexCount + 3;
            geometry.Triangles[geometry.TriangleCount + 17] = geometry.VertexCount + 7;

            // update counts
            geometry.ColorCount    += colorsPerStep;
            geometry.VertexCount   += verticesPerStep;
            geometry.TriangleCount += trianglesPerStep;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the cap into vertices and adds them to the geometry.
        /// </summary>
        public void Apply(LineGeometry geometry)
        {
            int   steps     = 30;
            float increment = 360f / (steps - 1);

            int colorsPerStep    = 5;
            int trianglesPerStep = 9;
            int verticesPerStep  = 5;

            geometry.AddColorCapacity(steps * colorsPerStep);
            geometry.AddTriangleCapacity(steps * trianglesPerStep);
            geometry.AddVertexCapacity(steps * verticesPerStep);

            for (int i = 0; i < steps; i++)
            {
                // F ----------- G
                //  \     /     /
                //   B ------- C
                //    \       /
                //     \     /
                //      \   /
                //       \ /
                //        A

                Color colorA = Point.Color;
                Color colorB = new Color(Point.Color.r, Point.Color.g, Point.Color.b, 0);

                Vector2 normalA = Quaternion.Euler(0, 0, increment * (i - 1)) * Vector2.right;
                Vector2 normalB = Quaternion.Euler(0, 0, increment * (i - 0)) * Vector2.right;

                float radiusA = Point.Weight;
                float radiusB = Point.Weight + Overdraw;

                LineVertex vertexA = new LineVertex();
                vertexA.Color    = colorA;
                vertexA.Position = Point.Position;

                LineVertex vertexB = new LineVertex();
                vertexB.Color    = colorA;
                vertexB.Position = Point.Position + normalA * radiusA;

                LineVertex vertexC = new LineVertex();
                vertexC.Color    = colorA;
                vertexC.Position = Point.Position + normalB * radiusA;

                LineVertex vertexF = new LineVertex();
                vertexF.Color    = colorB;
                vertexF.Position = Point.Position + normalA * radiusB;

                LineVertex vertexG = new LineVertex();
                vertexG.Color    = colorB;
                vertexG.Position = Point.Position + normalB * radiusB;

                // add colors
                geometry.Colors[geometry.ColorCount + 0] = vertexA.Color;
                geometry.Colors[geometry.ColorCount + 1] = vertexB.Color;
                geometry.Colors[geometry.ColorCount + 2] = vertexC.Color;
                geometry.Colors[geometry.ColorCount + 3] = vertexF.Color;
                geometry.Colors[geometry.ColorCount + 4] = vertexG.Color;

                // add vertices
                geometry.Vertices[geometry.VertexCount + 0] = vertexA.Position;
                geometry.Vertices[geometry.VertexCount + 1] = vertexB.Position;
                geometry.Vertices[geometry.VertexCount + 2] = vertexC.Position;
                geometry.Vertices[geometry.VertexCount + 3] = vertexF.Position;
                geometry.Vertices[geometry.VertexCount + 4] = vertexG.Position;

                // add triangle - ABC
                geometry.Triangles[geometry.TriangleCount + 0] = geometry.VertexCount + 0;
                geometry.Triangles[geometry.TriangleCount + 1] = geometry.VertexCount + 1;
                geometry.Triangles[geometry.TriangleCount + 2] = geometry.VertexCount + 2;

                // add triangle - FGB
                geometry.Triangles[geometry.TriangleCount + 3] = geometry.VertexCount + 3;
                geometry.Triangles[geometry.TriangleCount + 4] = geometry.VertexCount + 4;
                geometry.Triangles[geometry.TriangleCount + 5] = geometry.VertexCount + 1;

                // add triangle - BGC
                geometry.Triangles[geometry.TriangleCount + 6] = geometry.VertexCount + 1;
                geometry.Triangles[geometry.TriangleCount + 7] = geometry.VertexCount + 4;
                geometry.Triangles[geometry.TriangleCount + 8] = geometry.VertexCount + 2;

                // update stepss
                geometry.ColorCount    += colorsPerStep;
                geometry.VertexCount   += verticesPerStep;
                geometry.TriangleCount += trianglesPerStep;
            }
        }