Fix wierd looking terrain

This commit is contained in:
Sebastian 2023-10-05 12:14:06 +02:00
parent c5ca9f435e
commit 9e09df3cf8
4 changed files with 12 additions and 6 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 575 B

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)); Light light = new Light(new Vector3f(0,0,-20), new Vector3f(1,1,1));
//Generate Simple, Flat Terrain //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 //Create Hexagon
HexagonModel hexagonModel = new HexagonModel(); HexagonModel hexagonModel = new HexagonModel();

View File

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

View File

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