Пример #1
0
		public static VertexGrid CreateGrid(int rows, int columns)
		{
			int numVertsX = rows + 1;
			int numVertsZ = columns + 1;

			VertexGrid grid = new VertexGrid(new Vector3[numVertsX * numVertsZ], new int[rows * columns * 2 * 3]);

			{
				for (int r = 0; r < numVertsX; r++)
				{
					for (int c = 0; c < numVertsZ; c++)
					{
						grid.Points[r * numVertsZ + c] = new Vector3(r, 0, c);
					}
				}
			}

			{
				int count = 0;
				int vi = 0;
				for (int z = 0; z < columns; z++)
				{
					for (int x = 0; x < rows; x++)
					{
						// First triangle
						grid.Indices[count++] = vi;
						grid.Indices[count++] = vi + 1;
						grid.Indices[count++] = vi + numVertsX;

						// Second triangle
						grid.Indices[count++] = vi + numVertsX;
						grid.Indices[count++] = vi + 1;
						grid.Indices[count++] = vi + numVertsX + 1;

						vi++;
					}
					vi++;
				}
			}

			return grid;
		}
Пример #2
0
        public static VertexGrid CreateGrid(int rows, int columns)
        {
            int numVertsX = rows + 1;
            int numVertsZ = columns + 1;

            VertexGrid grid = new VertexGrid(new Vector3[numVertsX * numVertsZ], new int[rows * columns * 2 * 3]);

            {
                for (int r = 0; r < numVertsX; r++)
                {
                    for (int c = 0; c < numVertsZ; c++)
                    {
                        grid.Points[r * numVertsZ + c] = new Vector3(r, 0, c);
                    }
                }
            }

            {
                int count = 0;
                int vi    = 0;
                for (int z = 0; z < columns; z++)
                {
                    for (int x = 0; x < rows; x++)
                    {
                        // First triangle
                        grid.Indices[count++] = vi;
                        grid.Indices[count++] = vi + 1;
                        grid.Indices[count++] = vi + numVertsX;

                        // Second triangle
                        grid.Indices[count++] = vi + numVertsX;
                        grid.Indices[count++] = vi + 1;
                        grid.Indices[count++] = vi + numVertsX + 1;

                        vi++;
                    }
                    vi++;
                }
            }

            return(grid);
        }