-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTerrain.java
46 lines (39 loc) · 1.93 KB
/
Terrain.java
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
import java.awt.Color;
public class Terrain extends Mesh
{
private Vector3[][] verticies;
public Terrain(double height, double waterLevel, double snowLevel, double gridInterval, int gridLength, int gridWidth, double frequency, double amplitude, Color waterColor, Color mountainColor, Color snowColor)
{
super(true, false);
verticies = new Vector3[gridWidth][gridLength];
for (int x = 0; x < verticies.length; x++)
{
for (int z = 0; z < verticies[x].length; z++)
{
verticies[x][z] = new Vector3((x-gridWidth/2.0)*gridInterval, Math.max(height + Math.pow(SimplexNoise.noise(x*frequency, z*frequency)*amplitude, 3) , height+waterLevel) , (z-gridLength/2.0)*gridInterval + 300000);
}
}
Triangle tempTriangle = null;
for (int i = 0; i < verticies.length-1; i++)
{
for (int j = 0; j < verticies[i].length-1; j++)
{
tempTriangle = new Triangle(this, verticies[i][j], verticies[i][j+1], verticies[i+1][j], mountainColor);
if (tempTriangle.getCenter().y <= height+waterLevel)
tempTriangle.setBaseColor(waterColor);
else if (tempTriangle.getCenter().y >= height+snowLevel)
tempTriangle.setBaseColor(snowColor);
super.getTriangles().add(tempTriangle);
}
for (int j = 0; j < verticies[i].length-1; j++)
{
tempTriangle = new Triangle(this, verticies[i+1][j], verticies[i][j+1], verticies[i+1][j+1], mountainColor);
if (tempTriangle.getCenter().y <= height+waterLevel)
tempTriangle.setBaseColor(waterColor);
else if (tempTriangle.getCenter().y >= height+snowLevel)
tempTriangle.setBaseColor(snowColor);
super.getTriangles().add(tempTriangle);
}
}
}
}