From d5f2ccc4dccfe8dfd959c901fd80c21f743c667a Mon Sep 17 00:00:00 2001 From: austin Date: Thu, 15 May 2025 15:03:05 -0400 Subject: [PATCH] move more state into rendering engine --- .../entity/camera/CameraEntityUtils.java | 2 +- .../data/settings/UserSettings.java | 1 - .../java/electrosphere/engine/Globals.java | 4 --- .../renderer/RenderingEngine.java | 29 ++++++++++++------- .../renderer/ui/elements/ActorPanel.java | 14 ++++----- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java index de12bb3a..4e004448 100644 --- a/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java +++ b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java @@ -240,7 +240,7 @@ public class CameraEntityUtils { * @return The near clip */ public static float getNearClip(Entity camera){ - return Globals.nearClip; + return Globals.renderingEngine.getNearClip(); } /** diff --git a/src/main/java/electrosphere/data/settings/UserSettings.java b/src/main/java/electrosphere/data/settings/UserSettings.java index 07bb2512..14ff04dd 100644 --- a/src/main/java/electrosphere/data/settings/UserSettings.java +++ b/src/main/java/electrosphere/data/settings/UserSettings.java @@ -262,7 +262,6 @@ public class UserSettings { } Globals.WINDOW_WIDTH = Globals.userSettings.displayWidth; Globals.WINDOW_HEIGHT = Globals.userSettings.displayHeight; - Globals.verticalFOV = Globals.userSettings.graphicsFOV; } } diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index 1a1728fb..975e5fc4 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -194,10 +194,6 @@ public class Globals { //title bar dimensions public static int WINDOW_TITLE_BAR_HEIGHT = 0; - public static float verticalFOV = 90; - public static float aspectRatio = 2.0f; - public static float nearClip = 0.01f; - //locations for shadow map specific variables public static int depthMapShaderProgramLoc = 0; diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index a3d4e516..68e33a89 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -143,8 +143,9 @@ public class RenderingEngine { public static int outputFramebuffer = 0; //used in calculating projection matrix - static float aspectRatio = 1.0f; - static float verticalFOV = 90.0f; + float aspectRatio = 1.0f; + float verticalFOV = 90.0f; + float nearClip = 0.01f; //matrices for drawing models private Matrix4d viewMatrix = new Matrix4d(); @@ -401,7 +402,7 @@ public class RenderingEngine { } //projection matrices - nearVolumeProjectionMatrix.setPerspective((float)(Globals.verticalFOV * Math.PI /180.0f), (float)Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT, 0.1f, 100); + nearVolumeProjectionMatrix.setPerspective((float)(Globals.userSettings.getGraphicsFOV() * Math.PI /180.0f), (float)Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT, 0.1f, 100); // //Compositing textures and buffers @@ -471,10 +472,10 @@ public class RenderingEngine { // // Projection and View matrix creation // - verticalFOV = (float)(Globals.verticalFOV * Math.PI /180.0f); + this.verticalFOV = (float)(Globals.userSettings.getGraphicsFOV() * Math.PI /180.0f); //set local aspect ratio and global aspect ratio at the same time - aspectRatio = Globals.aspectRatio = Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT; - this.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, Globals.nearClip, Globals.userSettings.getGraphicsViewDistance()); + this.aspectRatio = Globals.WINDOW_WIDTH / (float)Globals.WINDOW_HEIGHT; + this.projectionMatrix.setPerspective(this.verticalFOV, this.aspectRatio, this.nearClip, Globals.userSettings.getGraphicsViewDistance()); this.viewMatrix.translation(new Vector3d(0.0f,0.0f,-3.0f)); /** @@ -616,12 +617,12 @@ public class RenderingEngine { } public static void setFOV(float verticalFOV){ - RenderingEngine.verticalFOV = verticalFOV; + Globals.renderingEngine.verticalFOV = verticalFOV; Globals.renderingEngine.calculateProjectionMatrix(); } public static void setAspectRatio(float aspectRatio){ - RenderingEngine.aspectRatio = aspectRatio; + Globals.renderingEngine.aspectRatio = aspectRatio; Globals.renderingEngine.calculateProjectionMatrix(); } @@ -629,9 +630,9 @@ public class RenderingEngine { * Calculates the projection matrix */ public void calculateProjectionMatrix(){ - float radVerticalFOV = (float)(RenderingEngine.verticalFOV * Math.PI /180.0f); + float radVerticalFOV = (float)(this.verticalFOV * Math.PI /180.0f); float nearClip = 0.001f; - this.projectionMatrix.setPerspective(radVerticalFOV, RenderingEngine.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance()); + this.projectionMatrix.setPerspective(radVerticalFOV, this.aspectRatio, nearClip, Globals.userSettings.getGraphicsViewDistance()); } /** @@ -730,6 +731,14 @@ public class RenderingEngine { return lightDepthMatrix; } + /** + * Gets the near clip of the engine + * @return The near clip + */ + public float getNearClip(){ + return this.nearClip; + } + /** * Tries to recapture the screen */ diff --git a/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java b/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java index d599e36e..2714cac0 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java +++ b/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java @@ -271,8 +271,8 @@ public class ActorPanel extends BufferedStandardDrawableContainerElement impleme actor.applySpatialData(modelMatrix,new Vector3d(actorPosition)); actor.draw(renderPipelineState,openGLState); - RenderingEngine.setFOV(Globals.verticalFOV); - RenderingEngine.setAspectRatio(Globals.aspectRatio); + RenderingEngine.setFOV(Globals.userSettings.getGraphicsFOV()); + RenderingEngine.setAspectRatio(2.0f); openGLState.glDepthTest(false); @@ -364,11 +364,11 @@ public class ActorPanel extends BufferedStandardDrawableContainerElement impleme * Recalculates the model matrix */ private void recalculateModelMatrix(){ - modelMatrix.identity(); - modelMatrix.translate(new Vector3d(actorPosition).sub(CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera))); - modelMatrix.rotate(actorRotation); - modelMatrix.scale(new Vector3d(actorScale)); - actor.applySpatialData(modelMatrix,new Vector3d(actorPosition)); + this.modelMatrix.identity(); + this.modelMatrix.translate(new Vector3d(actorPosition).sub(CameraEntityUtils.getCameraCenter(Globals.clientState.playerCamera))); + this.modelMatrix.rotate(actorRotation); + this.modelMatrix.scale(new Vector3d(actorScale)); + actor.applySpatialData(this.modelMatrix,new Vector3d(actorPosition)); } /**