finished game-engine-terrain-generation #2

Merged
sebastian merged 9 commits from game-engine-terrain-generation into game-engine 2023-10-05 14:00:29 +02:00
4 changed files with 12 additions and 6 deletions
Showing only changes of commit 9e09df3cf8 - Show all commits

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -124,7 +124,7 @@ public class Engine {
Light light = new Light(new Vector3f(0,0,-20), new Vector3f(1,1,1));
//Generate Simple, Flat Terrain
Terrain terrain = new Terrain( loader, new ModelTexture(loader.loadTexture("white")));
Terrain terrain = new Terrain( loader, new ModelTexture(loader.loadTexture("white")), 16, 32);
//Create Hexagon
HexagonModel hexagonModel = new HexagonModel();

View File

@ -17,7 +17,7 @@ out vec3 toLightVector;
void main(void) {
vec4 worldPosition = transformationMatrix * vec4(position, 1.0);
gl_Position = projectionMatrix * viewMatrix * worldPosition;
pass_textureCoords = textureCoords * 40;
pass_textureCoords = textureCoords;
surfaceNormal = (transformationMatrix * vec4(normal, 0.0)).xyz;
toLightVector = lightPosition - worldPosition.xyz;

View File

@ -14,13 +14,19 @@ public class Terrain {
private List<TerrainTile> terrainTiles = new ArrayList<>();
public Terrain(Loader loader, ModelTexture modelTexture) {
public Terrain(Loader loader, ModelTexture modelTexture, int rows, int columns) {
HexagonModel hexagonModel = new HexagonModel();
RawModel rawModel = loader.loadHexagon(hexagonModel);
TexturedModel texturedModel = new TexturedModel(rawModel, modelTexture);
for(int j=22; j>0; j--) {
for(int i=-8; i<8; i++) {
terrainTiles.add(new TerrainTile(texturedModel, new Vector3f(j - 0.75f *2,0, i* (float)(0.866*2)), 0, 30, 0, 1));
for(int row = 0; row < rows; row++) {
for(int column = 0; column < columns; column++) {
if(row % 2 == 1) {
terrainTiles.add(new TerrainTile(texturedModel, new Vector3f(column * 2* 0.866f, 0, row * 1.5f),0,0,0,1));
} else {
terrainTiles.add(new TerrainTile(texturedModel, new Vector3f(column *2 * 0.866f - 0.866f, 0, row * 1.5f),0,0,0,1));
}
}
}
}