-
Notifications
You must be signed in to change notification settings - Fork 0
/
terrainModeling.js
executable file
·54 lines (46 loc) · 1.51 KB
/
terrainModeling.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//-------------------------------------------------------------------------
function terrainFromIteration(n, minX,maxX,minY,maxY, vertexArray, faceArray,normalArray)
{
var deltaX=(maxX-minX)/n;
var deltaY=(maxY-minY)/n;
for(var i=0;i<=n;i++)
for(var j=0;j<=n;j++)
{
vertexArray.push(minX+deltaX*j);
vertexArray.push(minY+deltaY*i);
vertexArray.push(0);
normalArray.push(0);
normalArray.push(0);
normalArray.push(1);
}
var numT=0;
for(var i=0;i<n;i++)
for(var j=0;j<n;j++)
{
var vid = i*(n+1) + j;
faceArray.push(vid);
faceArray.push(vid+1);
faceArray.push(vid+n+1);
faceArray.push(vid+1);
faceArray.push(vid+1+n+1);
faceArray.push(vid+n+1);
numT+=2;
}
return numT;
}
//-------------------------------------------------------------------------
function generateLinesFromIndexedTriangles(faceArray,lineArray)
{
numTris=faceArray.length/3;
for(var f=0;f<numTris;f++)
{
var fid=f*3;
lineArray.push(faceArray[fid]);
lineArray.push(faceArray[fid+1]);
lineArray.push(faceArray[fid+1]);
lineArray.push(faceArray[fid+2]);
lineArray.push(faceArray[fid+2]);
lineArray.push(faceArray[fid]);
}
}
//-------------------------------------------------------------------------