Add grid genration function
This commit is contained in:
33
src/main.ts
33
src/main.ts
@@ -24,8 +24,39 @@ function initGL(canvas: HTMLCanvasElement) {
|
|||||||
gl = <WebGLRenderingContext>gltemp;
|
gl = <WebGLRenderingContext>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 */
|
/** Init Geomtry for an Triangle */
|
||||||
|
|||||||
Reference in New Issue
Block a user