diff --git a/src/main.ts b/src/main.ts index 1463282..f9e25f8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -24,8 +24,39 @@ function initGL(canvas: HTMLCanvasElement) { gl = gltemp; } -function genereateGrid(precision: number) { - +var gridIndices = []; +var gridVertices = []; +function genereateGrid(N: number) { + for (let j = 0; j <= N; ++j) + { + for (let i = 0; i <= N; ++i) + { + //Generate Vertices + let x = i / N; + let y = j / N; + let z = 0; + gridVertices.push(x); + gridVertices.push(y); + gridVertices.push(z); + + //Generate Indices + if (i < N && j < N) //Skip edges + { + let row1 = j * (N + 1); + let row2 = (j + 1) * (N + 1); + + // triangle 1 + gridIndices.push(row1 + i); + gridIndices.push(row1 + i + 1); + gridIndices.push(row2 + i + 1); + + // triangle 2 + gridIndices.push(row1 + i); + gridIndices.push(row2 + i + 1); + gridIndices.push(row2 + i); + } + } + } } /** Init Geomtry for an Triangle */