Set size of terrain and initialize camera ad midpoint of terrain

This commit is contained in:
Sebastian 2023-08-24 15:57:12 +02:00
parent 98b6208c74
commit ba47896d88
3 changed files with 8 additions and 10 deletions

View File

@ -128,19 +128,16 @@ public class Engine {
//Generate Simple, Flat Terrain //Generate Simple, Flat Terrain
Terrain terrain = new Terrain(0,0, loader, new ModelTexture(loader.loadTexture("grass"))); Terrain terrain = new Terrain(0,0, loader, new ModelTexture(loader.loadTexture("grass")));
Terrain terrain1 = new Terrain(1,0, loader, new ModelTexture(loader.loadTexture("grass")));
// 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();
while ( !glfwWindowShouldClose(window) ) { while ( !glfwWindowShouldClose(window) ) {
//entity.increaseRotation(0,1,0); //entity.increaseRotation(0,1,0);
renderer.processTerrain(terrain1);
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
// Poll for window events. The key callback above will only be // Poll for window events. The key callback above will only be
// invoked during this call. // invoked during this call.
glfwPollEvents(); glfwPollEvents();

View File

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

View File

@ -6,7 +6,8 @@ import core.engine.textures.ModelTexture;
public class Terrain { public class Terrain {
private static final float SIZE = 800; private static final float WIDTH = 100;
private static final float DEPTH = 100;
private static final int VERTEX_COUNT = 128; private static final int VERTEX_COUNT = 128;
private float x; private float x;
@ -16,8 +17,8 @@ public class Terrain {
public Terrain(int gridX, int gridZ, Loader loader, ModelTexture modelTexture) { public Terrain(int gridX, int gridZ, Loader loader, ModelTexture modelTexture) {
this.texture = modelTexture; this.texture = modelTexture;
this.x = gridX * SIZE; this.x = gridX * WIDTH;
this.z = gridZ * SIZE; this.z = gridZ * DEPTH;
this.model = generateTerrain(loader); this.model = generateTerrain(loader);
} }
@ -30,9 +31,9 @@ public class Terrain {
int vertexPointer = 0; int vertexPointer = 0;
for(int i=0;i<VERTEX_COUNT;i++){ for(int i=0;i<VERTEX_COUNT;i++){
for(int j=0;j<VERTEX_COUNT;j++){ for(int j=0;j<VERTEX_COUNT;j++){
vertices[vertexPointer*3] = (float)j/((float)VERTEX_COUNT - 1) * SIZE; vertices[vertexPointer*3] = (float)j/((float)VERTEX_COUNT - 1) * WIDTH;
vertices[vertexPointer*3+1] = 0; vertices[vertexPointer*3+1] = 0;
vertices[vertexPointer*3+2] = (float)i/((float)VERTEX_COUNT - 1) * SIZE; vertices[vertexPointer*3+2] = (float)i/((float)VERTEX_COUNT - 1) * DEPTH;
normals[vertexPointer*3] = 0; normals[vertexPointer*3] = 0;
normals[vertexPointer*3+1] = 1; normals[vertexPointer*3+1] = 1;
normals[vertexPointer*3+2] = 0; normals[vertexPointer*3+2] = 0;