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 99 additions and 2 deletions
Showing only changes of commit 466a15f160 - Show all commits

BIN
client/res/white.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 575 B

View File

@ -3,6 +3,7 @@ package core.engine;
import core.engine.entity.Camera; import core.engine.entity.Camera;
import core.engine.entity.Entity; import core.engine.entity.Entity;
import core.engine.entity.Light; import core.engine.entity.Light;
import core.engine.model.HexagonModel;
import core.engine.model.RawModel; import core.engine.model.RawModel;
import core.engine.model.TexturedModel; import core.engine.model.TexturedModel;
import core.engine.renderer.MasterRenderer; import core.engine.renderer.MasterRenderer;
@ -129,13 +130,21 @@ public class Engine {
//Generate Simple, Flat Terrain //Generate Simple, Flat Terrain
Terrain terrain = new Terrain( loader, new ModelTexture(loader.loadTexture("grass"))); Terrain terrain = new Terrain( loader, new ModelTexture(loader.loadTexture("grass")));
//Create Hexagon
HexagonModel hexagonModel = new HexagonModel();
RawModel hexagonRawModel = loader.loadToVAO(hexagonModel.getVertices(), hexagonModel.getTextureCoords(), hexagonModel.getNormals(), hexagonModel.getIndices());
ModelTexture hexagonTexture = new ModelTexture(loader.loadTexture("white"));
TexturedModel hexagontexturedModel = new TexturedModel(hexagonRawModel, hexagonTexture);
Entity hexagonEntity = new Entity(hexagontexturedModel, new Vector3f(0,1,0), 0,0,0,1);
// Run the rendering loop until the user has attempted to close // Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key. // the window or has pressed the ESCAPE key.
MasterRenderer renderer = new MasterRenderer(); MasterRenderer renderer = new MasterRenderer();
input(camera, renderer); input(camera, renderer);
while ( !glfwWindowShouldClose(window) ) { while ( !glfwWindowShouldClose(window) ) {
renderer.processEntity(hexagonEntity);
//entity.increaseRotation(0,1,0); //entity.increaseRotation(0,1,0);
renderer.processTerrain(terrain); //renderer.processTerrain(terrain);
//renderer.processEntity(entity); //renderer.processEntity(entity);
renderer.render(light, camera); renderer.render(light, camera);
glfwSwapBuffers(window); // swap the color buffers glfwSwapBuffers(window); // swap the color buffers

View File

@ -4,7 +4,7 @@ import utils.vectors.Vector3f;
public class Camera { public class Camera {
private Vector3f position = new Vector3f(50,100,50); private Vector3f position = new Vector3f(0,2,0);
private float pitch = 90; private float pitch = 90;
private float yaw = 180; private float yaw = 180;
private float roll; private float roll;

View File

@ -0,0 +1,88 @@
package core.engine.model;
import utils.vectors.Vector3f;
public class HexagonModel {
private float[] vertices;
private float[] normals;
private float[] textureCoords;
private int[] indices;
public HexagonModel() {
// Vertices (including the center)
vertices = new float[]{
0.0f, 0.0f, 0.0f, // Center
0.0f, 0.0f, 1.0f, // Top Vertex
0.866f, 0.0f, 0.5f, // Upper Right Vertex
0.866f, 0.0f, -0.5f, // Lower Right Vertex
0.0f, 0.0f, -1.0f, // Bottom Vertex
-0.866f, 0.0f, -0.5f, // Lower Left Vertex
-0.866f, 0.0f, 0.5f // Upper Left Vertex
};
// Normals
normals = new float[]{
0, 1, 0, // Center
0, 1, 0, // Top Vertex
0, 1, 0, // Upper Right Vertex
0, 1, 0, // Lower Right Vertex
0, 1, 0, // Bottom Vertex
0, 1, 0, // Lower Left Vertex
0, 1, 0 // Upper Left Vertex
};
// Texture Coordinates
textureCoords = new float[]{
0.5f, 0.5f, // Center
0.5f, 0.0f, // Top Vertex
1.0f, 0.25f, // Upper Right Vertex
1.0f, 0.75f, // Lower Right Vertex
0.5f, 1.0f, // Bottom Vertex
0.0f, 0.75f, // Lower Left Vertex
0.0f, 0.25f // Upper Left Vertex
};
// Indices
indices = new int[]{
0, 1, 2, // Center to Top Vertex to Upper Right Vertex
0, 2, 3, // Center to Upper Right Vertex to Lower Right Vertex
0, 3, 4, // Center to Lower Right Vertex to Bottom Vertex
0, 4, 5, // Center to Bottom Vertex to Lower Left Vertex
0, 5, 6, // Center to Lower Left Vertex to Upper Left Vertex
0, 6, 1 // Center to Upper Left Vertex to Top Vertex
};
}
public float[] getVertices() {
return vertices;
}
public void setVertices(float[] vertices) {
this.vertices = vertices;
}
public float[] getNormals() {
return normals;
}
public void setNormals(float[] normals) {
this.normals = normals;
}
public float[] getTextureCoords() {
return textureCoords;
}
public void setTextureCoords(float[] textureCoords) {
this.textureCoords = textureCoords;
}
public int[] getIndices() {
return indices;
}
public void setIndices(int[] indices) {
this.indices = indices;
}
}