Esempio n. 1
0
        void Trianglulate(GridCell cell)
        {
            if (grid == null)
            {
                grid = GetComponentInParent <Grid>();
            }

            Vector3 center      = cell.transform.position;
            float   sectionSize = GridMetrics.squareSize / GridMetrics.sectionsPerSquare;
            Vector3 topLeft     = center + GridMetrics.corners[2];

            Vector3[] t1 =
            {
                topLeft,
                new Vector3(topLeft.x,              topLeft.y,  topLeft.z + sectionSize),
                new Vector3(topLeft.x + sectionSize,topLeft.y,  topLeft.z + sectionSize)
            };
            Vector3[] t2 =
            {
                new Vector3(topLeft.x + sectionSize, topLeft.y, topLeft.z + sectionSize),
                new Vector3(topLeft.x + sectionSize, topLeft.y, topLeft.z),
                topLeft
            };
            for (int i = 0; i < GridMetrics.sectionsPerSquare; i++)
            {
                for (int n = 0; n < GridMetrics.sectionsPerSquare; n++)
                {
                    //  Vector3[] heightOffsets = NeighborCompensatedHeightCalc(cell, new IntVector2(n, i));
                    Vector3 increment = new Vector3(sectionSize * n, cell.height * GridMetrics.heightIncrement, sectionSize * i);
                    AddTriangle(t1[0] + increment, t1[1] + increment, t1[2] + increment);
                    AddTriangleColor(cell.GetColor());
                    AddTriangle(t2[0] + increment, t2[1] + increment, t2[2] + increment);
                    AddTriangleColor(cell.GetColor());

                    /*
                     * AddTriangle(t1[0] + increment + heightOffsets[0], t1[1] + increment + heightOffsets[1], t1[2] + increment + heightOffsets[2]);
                     * AddTriangleColor(cell.GetColor());
                     * AddTriangle(t2[0] + increment + heightOffsets[2], t2[1] + increment + heightOffsets[3], t2[2] + increment + heightOffsets[0]);
                     * AddTriangleColor(cell.GetColor());
                     */
                }
            }

            //AddTriangle(center + GridMetrics.corners[2], center + GridMetrics.corners[1], center + GridMetrics.corners[0]);
            //AddTriangleColor(cell.GetColor());
            //AddTriangle(center + GridMetrics.corners[0], center + GridMetrics.corners[3], center + GridMetrics.corners[2]);
            //AddTriangleColor(cell.GetColor());
        }
Esempio n. 2
0
        public void DrawVerticalCellInteraction(GridCell up, GridCell down)
        {
            if (up.height == down.height)
            {
                return;
            }
            float   upHeight   = (float)up.height * GridMetrics.heightIncrement;
            float   downHeight = (float)down.height * GridMetrics.heightIncrement;
            Vector3 center     = up.transform.position;
            Vector3 v1         = center + GridMetrics.corners[0] + new Vector3(0, upHeight, 0);
            Vector3 v2         = center + GridMetrics.corners[1] + new Vector3(0, upHeight, 0);

            center = down.transform.position;
            Vector3 v3 = center + GridMetrics.corners[3] + new Vector3(0, downHeight, 0);
            Vector3 v4 = center + GridMetrics.corners[2] + new Vector3(0, downHeight, 0);

            AddTriangle(v1, v2, v3);
            AddTriangle(v2, v4, v3);
            AddTriangleColor(up.GetColor(), up.GetColor(), down.GetColor());
            AddTriangleColor(up.GetColor(), down.GetColor(), down.GetColor());
        }
Esempio n. 3
0
        public void DrawHorizontalCellInteraction(GridCell left, GridCell right)
        {
            if (left.height == right.height)
            {
                return;
            }
            float   leftHeight  = (float)left.height * GridMetrics.heightIncrement;
            float   rightHeight = (float)right.height * GridMetrics.heightIncrement;
            Vector3 center      = left.transform.position;
            Vector3 v1          = center + GridMetrics.corners[0] + new Vector3(0, leftHeight, 0);
            Vector3 v2          = center + GridMetrics.corners[3] + new Vector3(0, leftHeight, 0);

            center = right.transform.position;
            Vector3 v3 = center + GridMetrics.corners[1] + new Vector3(0, rightHeight, 0);
            Vector3 v4 = center + GridMetrics.corners[2] + new Vector3(0, rightHeight, 0);

            AddTriangle(v3, v2, v1);
            AddTriangle(v3, v4, v2);
            AddTriangleColor(right.GetColor(), left.GetColor(), left.GetColor());
            AddTriangleColor(right.GetColor(), right.GetColor(), left.GetColor());
        }