From bb192e0710ccdf42a3e066372bfd318f9d3f1185 Mon Sep 17 00:00:00 2001 From: halotroop2288 Date: Thu, 27 Feb 2020 18:46:49 -0800 Subject: [PATCH] [Deprecation] Removed (unused) deprecated terrain --- .../hydos/ginger/engine/api/Ginger.java | 4 +- .../ginger/engine/api/game/GameData.java | 3 - .../ginger/engine/math/matrixes/Matrix3f.java | 3 +- .../ginger/engine/render/MasterRenderer.java | 15 +- .../engine/render/tools/MousePicker.java | 31 +--- .../hydos/ginger/engine/terrain/Terrain.java | 161 ------------------ 6 files changed, 7 insertions(+), 210 deletions(-) delete mode 100644 src/main/java/com/github/hydos/ginger/engine/terrain/Terrain.java diff --git a/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java b/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java index 484ebd2..6868381 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/Ginger.java @@ -83,7 +83,7 @@ public class Ginger { GingerUtils.preRenderScene(gingerRegister.masterRenderer); contrastFbo.bindFBO(); - gingerRegister.masterRenderer.renderSceneNoTerrain(game.data.entities, game.data.normalMapEntities, game.data.lights, game.data.camera, game.data.clippingPlane, world); + gingerRegister.masterRenderer.renderScene(game.data.entities, game.data.normalMapEntities, game.data.lights, game.data.camera, game.data.clippingPlane, world); ParticleMaster.renderParticles(game.data.camera); contrastFbo.unbindFBO(); PostProcessing.doPostProcessing(contrastFbo.colorTexture); @@ -104,7 +104,7 @@ public class Ginger timer.addTickListener(gameTickListener); contrastFbo = new Fbo(new ContrastChanger()); gingerRegister.masterRenderer = masterRenderer; - picker = new MousePicker(game.data.camera, masterRenderer.getProjectionMatrix(), null); + picker = new MousePicker(game.data.camera, masterRenderer.getProjectionMatrix()); PostProcessing.init(); ParticleMaster.init(masterRenderer.getProjectionMatrix()); } diff --git a/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java b/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java index 3db5d46..8c1f5f9 100644 --- a/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java +++ b/src/main/java/com/github/hydos/ginger/engine/api/game/GameData.java @@ -7,7 +7,6 @@ import org.joml.Vector4f; import com.github.hydos.ginger.engine.cameras.Camera; import com.github.hydos.ginger.engine.elements.GuiTexture; import com.github.hydos.ginger.engine.elements.objects.*; -import com.github.hydos.ginger.engine.terrain.Terrain; /* * Used for storing essential engine game data so main class isn't messy @@ -19,7 +18,6 @@ public class GameData public List entities; public List lights; public List normalMapEntities; - public List flatTerrains; public Player player; public Camera camera; public Vector4f clippingPlane; @@ -33,7 +31,6 @@ public class GameData entities = new ArrayList(); lights = new ArrayList(); normalMapEntities = new ArrayList(); - flatTerrains = new ArrayList(); this.player = player; this.camera = camera; this.tickSpeed = tickSpeed; diff --git a/src/main/java/com/github/hydos/ginger/engine/math/matrixes/Matrix3f.java b/src/main/java/com/github/hydos/ginger/engine/math/matrixes/Matrix3f.java index cce8e21..9a0fb9a 100644 --- a/src/main/java/com/github/hydos/ginger/engine/math/matrixes/Matrix3f.java +++ b/src/main/java/com/github/hydos/ginger/engine/math/matrixes/Matrix3f.java @@ -252,8 +252,7 @@ public class Matrix3f extends Matrix implements Serializable * @return the destination vector */ public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) { - if (dest == null) - dest = new Vector3f(); + if (dest == null) dest = new Vector3f(); float x = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z; float y = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z; float z = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z; diff --git a/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java b/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java index 68fb528..0a450d2 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/MasterRenderer.java @@ -16,7 +16,6 @@ import com.github.hydos.ginger.engine.render.models.TexturedModel; import com.github.hydos.ginger.engine.render.renderers.*; import com.github.hydos.ginger.engine.render.shaders.*; import com.github.hydos.ginger.engine.shadow.ShadowMapMasterRenderer; -import com.github.hydos.ginger.engine.terrain.Terrain; public class MasterRenderer { @@ -159,16 +158,7 @@ public class MasterRenderer normalRenderer.render(normalMapEntities, clipPlane, lights, camera); } - public void renderScene(List entities, List normalEntities, List terrains, List lights, Camera camera, Vector4f clipPlane) - { - prepare(); - renderEntities(entities, camera, lights); - renderNormalEntities(normalEntities, lights, camera, clipPlane); - renderTerrains(terrains, lights, camera); - skyboxRenderer.render(camera); - } - - public void renderSceneNoTerrain(List entities, List normalEntities, List lights, Camera camera, Vector4f clipPlane, World world) + public void renderScene(List entities, List normalEntities, List lights, Camera camera, Vector4f clipPlane, World world) { prepare(); renderEntities(entities, camera, lights); @@ -184,7 +174,4 @@ public class MasterRenderer shadowMapRenderer.render(entities, sun); entities.clear(); } - - private void renderTerrains(List terrains, List lights, Camera camera) - {} } diff --git a/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java b/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java index bc923ad..965a115 100644 --- a/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java +++ b/src/main/java/com/github/hydos/ginger/engine/render/tools/MousePicker.java @@ -7,7 +7,6 @@ import com.github.hydos.ginger.engine.io.Window; import com.github.hydos.ginger.engine.math.Maths; import com.github.hydos.ginger.engine.math.matrixes.Matrix4f; import com.github.hydos.ginger.engine.math.vectors.*; -import com.github.hydos.ginger.engine.terrain.Terrain; public class MousePicker { @@ -17,15 +16,13 @@ public class MousePicker private Matrix4f projectionMatrix; private Matrix4f viewMatrix; private Camera camera; - private Terrain terrain; private Vector3f currentTerrainPoint; - public MousePicker(Camera cam, Matrix4f projection, Terrain terrain) + public MousePicker(Camera cam, Matrix4f projection) { camera = cam; projectionMatrix = projection; viewMatrix = Maths.createViewMatrix(camera); - this.terrain = terrain; } private Vector3f binarySearch(int count, float start, float finish, Vector3f ray) @@ -33,16 +30,7 @@ public class MousePicker float half = start + ((finish - start) / 2f); if (count >= RECURSION_COUNT) { - Vector3f endPoint = getPointOnRay(ray, half); - Terrain terrain = getTerrain(endPoint.getX(), endPoint.getZ()); - if (terrain != null) - { - return endPoint; - } - else - { - return null; - } + return null; } if (intersectionInRange(start, half, ray)) { @@ -87,9 +75,6 @@ public class MousePicker return Vector3f.add(start, scaledRay, null); } - private Terrain getTerrain(float worldX, float worldZ) - { return terrain; } - private boolean intersectionInRange(float start, float finish, Vector3f ray) { Vector3f startPoint = getPointOnRay(ray, start); @@ -106,18 +91,8 @@ public class MousePicker private boolean isUnderGround(Vector3f testPoint) { - Terrain terrain = getTerrain(testPoint.getX(), testPoint.getZ()); float height = 0; - if (terrain != null) - { height = terrain.getHeightOfTerrain(testPoint.getX(), testPoint.getZ()); } - if (testPoint.y < height) - { - return true; - } - else - { - return false; - } + return false; } private Vector4f toEyeCoords(Vector4f clipCoords) diff --git a/src/main/java/com/github/hydos/ginger/engine/terrain/Terrain.java b/src/main/java/com/github/hydos/ginger/engine/terrain/Terrain.java deleted file mode 100644 index 51df4e1..0000000 --- a/src/main/java/com/github/hydos/ginger/engine/terrain/Terrain.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.github.hydos.ginger.engine.terrain; - -import java.awt.image.BufferedImage; -import java.io.IOException; - -import javax.imageio.ImageIO; - -import com.github.hydos.ginger.engine.math.Maths; -import com.github.hydos.ginger.engine.math.vectors.*; -import com.github.hydos.ginger.engine.render.models.RawModel; -import com.github.hydos.ginger.engine.utils.Loader; -import com.github.hydos.ginger.main.settings.Constants; -/* - * wtf - */ -@Deprecated -public class Terrain -{ - private static final float MAX_PIXEL_COLOUR = 256 * 256 * 256; - private float[][] heights; - private float x, z; - private RawModel model; - private TerrainTexturePack texturePack; - private TerrainTexture blendMap; - - public Terrain(float gridX, float gridZ, TerrainTexturePack texturePack, TerrainTexture blendMap, String heightMapLocation) - { - this.texturePack = texturePack; - this.blendMap = blendMap; - this.x = gridX * Constants.terrainSize; - this.z = gridZ * Constants.terrainSize; - this.model = generateTerrain(heightMapLocation); - } - - private Vector3f calculateNormal(int x, int z, BufferedImage image) - { - float heightL = getHeight(x - 1, z, image); - float heightR = getHeight(x + 1, z, image); - float heightD = getHeight(x, z - 1, image); - float heightU = getHeight(x, z + 1, image); - Vector3f normal = new Vector3f(heightL - heightR, 2f, heightD - heightU); - normal.normalise(); - return normal; - } - - private RawModel generateTerrain(String heightMap) - { - BufferedImage image = null; - try - { - image = ImageIO.read(Terrain.class.getResourceAsStream("/textures/terrain/" + heightMap)); - } - catch (IOException e) - { - e.printStackTrace(); - } - int VERTEX_COUNT = image.getHeight(); - heights = new float[VERTEX_COUNT][VERTEX_COUNT]; - int count = VERTEX_COUNT * VERTEX_COUNT; - float[] vertices = new float[count * 3]; - float[] normals = new float[count * 3]; - float[] textureCoords = new float[count * 2]; - int[] indices = new int[6 * (VERTEX_COUNT - 1) * (VERTEX_COUNT - 1)]; - int vertexPointer = 0; - for (int i = 0; i < VERTEX_COUNT; i++) - { - for (int j = 0; j < VERTEX_COUNT; j++) - { - vertices[vertexPointer * 3] = j / ((float) VERTEX_COUNT - 1) * Constants.terrainSize; - float height = getHeight(j, i, image); - heights[j][i] = height; - vertices[vertexPointer * 3 + 1] = height; - vertices[vertexPointer * 3 + 2] = i / ((float) VERTEX_COUNT - 1) * Constants.terrainSize; - Vector3f normal = calculateNormal(j, i, image); - normals[vertexPointer * 3] = normal.x; - normals[vertexPointer * 3 + 1] = normal.y; - normals[vertexPointer * 3 + 2] = normal.z; - textureCoords[vertexPointer * 2] = j / ((float) VERTEX_COUNT - 1); - textureCoords[vertexPointer * 2 + 1] = i / ((float) VERTEX_COUNT - 1); - vertexPointer++; - } - } - int pointer = 0; - for (int gz = 0; gz < VERTEX_COUNT - 1; gz++) - { - for (int gx = 0; gx < VERTEX_COUNT - 1; gx++) - { - int topLeft = (gz * VERTEX_COUNT) + gx; - int topRight = topLeft + 1; - int bottomLeft = ((gz + 1) * VERTEX_COUNT) + gx; - int bottomRight = bottomLeft + 1; - indices[pointer++] = topLeft; - indices[pointer++] = bottomLeft; - indices[pointer++] = topRight; - indices[pointer++] = topRight; - indices[pointer++] = bottomLeft; - indices[pointer++] = bottomRight; - } - } - return Loader.loadToVAO(vertices, indices, normals, textureCoords); - } - - public TerrainTexture getBlendMap() - { return blendMap; } - - private float getHeight(int x, int z, BufferedImage image) - { - if (x < 0 || x >= image.getHeight() || z < 0 || z >= image.getHeight()) - { return 0; } - float height = image.getRGB(x, z); - height += MAX_PIXEL_COLOUR / 2f; - height /= MAX_PIXEL_COLOUR / 2f; - height *= Constants.terrainMaxHeight; - return height; - } - - public float getHeightOfTerrain(float worldX, float worldZ) - { - float terrainX = worldX - this.x; - float terrainZ = worldZ - this.z; - float gridSquareSize = Constants.terrainSize / ((float) heights.length - 1); - int gridX = (int) Math.floor(terrainX / gridSquareSize); - int gridZ = (int) Math.floor(terrainZ / gridSquareSize); - if (gridX >= heights.length - 1 || gridZ >= heights.length - 1 || gridX < 0 || gridZ < 0) - { return 0; } - float xCoord = (terrainX % gridSquareSize) / gridSquareSize; - float zCoord = (terrainZ % gridSquareSize) / gridSquareSize; - float answer; - if (xCoord <= (1 - zCoord)) - { - answer = Maths - .barryCentric(new Vector3f(0, heights[gridX][gridZ], 0), new Vector3f(1, - heights[gridX + 1][gridZ], 0), - new Vector3f(0, - heights[gridX][gridZ + 1], 1), - new Vector2f(xCoord, zCoord)); - } - else - { - answer = Maths - .barryCentric(new Vector3f(1, heights[gridX + 1][gridZ], 0), new Vector3f(1, - heights[gridX + 1][gridZ + 1], 1), - new Vector3f(0, - heights[gridX][gridZ + 1], 1), - new Vector2f(xCoord, zCoord)); - } - return answer; - } - - public RawModel getModel() - { return model; } - - public TerrainTexturePack getTexturePack() - { return texturePack; } - - public float getX() - { return x; } - - public float getZ() - { return z; } -}