Fix rendering bug

This commit is contained in:
austin 2021-08-01 21:45:20 -04:00
parent dd51345a5a
commit 3388325838
10 changed files with 36 additions and 30 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@
/launcher/launcher.exe /launcher/launcher.exe
/dependency-reduced-pom.xml /dependency-reduced-pom.xml
/nb-configuration.xml
/Telephone-*.jar /Telephone-*.jar
/hs_err_pid* /hs_err_pid*

View File

@ -196,7 +196,9 @@ public class ControlHandler {
*/ */
if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){ if(controls.containsKey(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD)){
if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){ if(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && glfwGetKey(Globals.window, controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue()) == GLFW_PRESS){
CreatureUtils.setMovementVector(Globals.playerCharacter, new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize()); Vector3f newFacingVector = new Vector3f(-cameraEyeVector.x,0,-cameraEyeVector.z).normalize();
CreatureUtils.setMovementVector(Globals.playerCharacter, newFacingVector);
System.out.println("Movement vector: " + newFacingVector);
if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){ if(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN){
movementTree.start(); movementTree.start();
} }

View File

@ -240,6 +240,8 @@ public class LoadingThread extends Thread {
loadingBox.setDraw(false); loadingBox.setDraw(false);
RenderUtils.recaptureScreen();
Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true; Globals.RENDER_FLAG_RENDER_SHADOW_MAP = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true; Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER_CONTENT = true;
Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true; Globals.RENDER_FLAG_RENDER_SCREEN_FRAMEBUFFER = true;

View File

@ -61,7 +61,7 @@ public class CameraEntityUtils {
} }
public static Matrix4f getCameraViewMatrix(Entity camera){ public static Matrix4f getCameraViewMatrix(Entity camera){
Vector3f cameraCenter = new Vector3f(getCameraCenter(camera)).add(0,1,0); Vector3f cameraCenter = new Vector3f(0,1,0);
Vector3f cameraEye = new Vector3f(cameraCenter).add(getCameraEye(camera)); Vector3f cameraEye = new Vector3f(cameraCenter).add(getCameraEye(camera));
Vector3f cameraUp = new Vector3f(0,1.0f,0); Vector3f cameraUp = new Vector3f(0,1.0f,0);
// System.out.println("eye: " + cameraEye); // System.out.println("eye: " + cameraEye);

View File

@ -26,7 +26,7 @@ public class ClientFunctions {
// if(skyboxPos != null && playerCameraPos != null){ // if(skyboxPos != null && playerCameraPos != null){
// skyboxPos.set(playerCameraPos); // skyboxPos.set(playerCameraPos);
// } // }
EntityUtils.getPosition(Globals.skybox).set(EntityUtils.getPosition(Globals.playerCharacter)).mul(0.01f); EntityUtils.getPosition(Globals.skybox).set(EntityUtils.getPosition(Globals.playerCharacter));
} }
} }
} }

View File

@ -1,5 +1,7 @@
package electrosphere.game.collision; package electrosphere.game.collision;
import electrosphere.collision.dispatch.CollisionWorld.ClosestConvexResultCallback;
import electrosphere.collision.dispatch.CollisionWorld.LocalConvexResult;
import electrosphere.collision.broadphase.BroadphaseInterface; import electrosphere.collision.broadphase.BroadphaseInterface;
import electrosphere.collision.broadphase.BroadphasePair; import electrosphere.collision.broadphase.BroadphasePair;
import electrosphere.collision.broadphase.BroadphaseProxy; import electrosphere.collision.broadphase.BroadphaseProxy;
@ -9,22 +11,16 @@ import electrosphere.collision.broadphase.OverlappingPairCache;
import electrosphere.collision.dispatch.CollisionDispatcher; import electrosphere.collision.dispatch.CollisionDispatcher;
import electrosphere.collision.dispatch.CollisionObject; import electrosphere.collision.dispatch.CollisionObject;
import electrosphere.collision.dispatch.CollisionWorld.ClosestConvexResultCallback; import electrosphere.collision.dispatch.CollisionWorld.ClosestConvexResultCallback;
import electrosphere.collision.dispatch.CollisionWorld.ConvexResultCallback;
import electrosphere.collision.dispatch.CollisionWorld.LocalConvexResult; import electrosphere.collision.dispatch.CollisionWorld.LocalConvexResult;
import electrosphere.collision.dispatch.DefaultCollisionConfiguration; import electrosphere.collision.dispatch.DefaultCollisionConfiguration;
import electrosphere.collision.narrowphase.ManifoldPoint; import electrosphere.collision.narrowphase.ManifoldPoint;
import electrosphere.collision.narrowphase.PersistentManifold; import electrosphere.collision.narrowphase.PersistentManifold;
import electrosphere.collision.shapes.BoxShape;
import electrosphere.collision.shapes.CollisionShape;
import electrosphere.collision.shapes.SphereShape; import electrosphere.collision.shapes.SphereShape;
import electrosphere.dynamics.DiscreteDynamicsWorld; import electrosphere.dynamics.DiscreteDynamicsWorld;
import electrosphere.dynamics.DynamicsWorld; import electrosphere.dynamics.DynamicsWorld;
import electrosphere.dynamics.InternalTickCallback; import electrosphere.dynamics.InternalTickCallback;
import electrosphere.dynamics.RigidBody; import electrosphere.dynamics.RigidBody;
import electrosphere.dynamics.RigidBodyConstructionInfo;
import electrosphere.dynamics.constraintsolver.SequentialImpulseConstraintSolver; import electrosphere.dynamics.constraintsolver.SequentialImpulseConstraintSolver;
import electrosphere.linearmath.DefaultMotionState;
import electrosphere.linearmath.Transform;
import electrosphere.util.ObjectArrayList; import electrosphere.util.ObjectArrayList;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityDataStrings;
@ -32,7 +28,6 @@ import electrosphere.entity.EntityUtils;
import electrosphere.entity.state.movement.Impulse; import electrosphere.entity.state.movement.Impulse;
import electrosphere.entity.types.hitbox.HitboxData; import electrosphere.entity.types.hitbox.HitboxData;
import electrosphere.game.collision.collidable.Collidable; import electrosphere.game.collision.collidable.Collidable;
import electrosphere.game.server.world.ServerWorldData;
import static electrosphere.main.Main.deltaTime; import static electrosphere.main.Main.deltaTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -138,6 +138,7 @@ public class Globals {
public static int WINDOW_WIDTH = 1920; public static int WINDOW_WIDTH = 1920;
public static int WINDOW_HEIGHT = 1080; public static int WINDOW_HEIGHT = 1080;
public static float FOV = 90;
//matrices for drawing models //matrices for drawing models
public static Matrix4f viewMatrix = new Matrix4f(); public static Matrix4f viewMatrix = new Matrix4f();

View File

@ -6,12 +6,12 @@ import java.util.concurrent.Semaphore;
public class ByteStreamUtils { public class ByteStreamUtils {
static ByteBuffer integerCompactor; static ByteBuffer integerCompactor = ByteBuffer.allocate(8);
static Semaphore bufferLock = new Semaphore(1); static Semaphore bufferLock = new Semaphore(1);
static { // static {
integerCompactor = ByteBuffer.allocate(8); // integerCompactor = ByteBuffer.allocate(8);
} // }
public static int popIntFromByteQueue(List<Byte> queue){ public static int popIntFromByteQueue(List<Byte> queue){
int rVal = -1; int rVal = -1;

View File

@ -73,6 +73,7 @@ public class Actor {
public void draw(){ public void draw(){
Model model = Globals.assetManager.fetchModel(modelPath); Model model = Globals.assetManager.fetchModel(modelPath);
boolean hasDrawn = false;
if(model != null){ if(model != null){
if(animation != null){ if(animation != null){
model.playAnimation(animation); model.playAnimation(animation);
@ -86,10 +87,13 @@ public class Actor {
Texture overrideTextureObject = Globals.assetManager.fetchTexture(textureOverride); Texture overrideTextureObject = Globals.assetManager.fetchTexture(textureOverride);
if(overrideTextureObject != null){ if(overrideTextureObject != null){
overrideTextureObject.bind(); overrideTextureObject.bind();
hasDrawn = true;
model.draw(true, true, false, false, true, true, true); model.draw(true, true, false, false, true, true, true);
} }
} }
model.draw(true, true, false, true, true, true, true); if(!hasDrawn){
model.draw(true, true, false, true, true, true, true);
}
} }
} }

View File

@ -88,9 +88,6 @@ public class RenderingEngine {
public void createOpenglContext(){ public void createOpenglContext(){
//Sets the variables that control the window sizing
int screenWidth = Globals.WINDOW_WIDTH;
int screenHeight = Globals.WINDOW_HEIGHT;
//Initializes opengl //Initializes opengl
glfwInit(); glfwInit();
//Gives hints to glfw to control how opengl will be used //Gives hints to glfw to control how opengl will be used
@ -100,7 +97,7 @@ public class RenderingEngine {
// glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); Allows you to make the background transparent // glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE); Allows you to make the background transparent
// glfwWindowHint(GLFW_OPACITY, 23); // glfwWindowHint(GLFW_OPACITY, 23);
//Creates the window reference object //Creates the window reference object
Globals.window = glfwCreateWindow(screenWidth, screenHeight, "ORPG", NULL, NULL); Globals.window = glfwCreateWindow(Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT, "ORPG", NULL, NULL);
//Errors for failure to create window (IE: No GUI mode on linux ?) //Errors for failure to create window (IE: No GUI mode on linux ?)
if (Globals.window == NULL) { if (Globals.window == NULL) {
LoggerInterface.loggerEngine.ERROR("Failed to make window.", new Exception("Renderer Creation Failure")); LoggerInterface.loggerEngine.ERROR("Failed to make window.", new Exception("Renderer Creation Failure"));
@ -148,7 +145,7 @@ public class RenderingEngine {
// //
Globals.projectionMatrix = new Matrix4f(); Globals.projectionMatrix = new Matrix4f();
Globals.viewMatrix = new Matrix4f(); Globals.viewMatrix = new Matrix4f();
float FOV = (float)(120.0f * Math.PI /180.0f); float FOV = (float)(Globals.FOV * Math.PI /180.0f);
Globals.projectionMatrix.setPerspective(FOV, 1.0f, 0.1f, view_Range); Globals.projectionMatrix.setPerspective(FOV, 1.0f, 0.1f, view_Range);
Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f)); Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f));
} }
@ -176,7 +173,6 @@ public class RenderingEngine {
//bind default FBO //bind default FBO
glBindFramebuffer(GL_FRAMEBUFFER,0); glBindFramebuffer(GL_FRAMEBUFFER,0);
glDisable(GL_DEPTH_TEST);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -253,7 +249,7 @@ public class RenderingEngine {
Actor currentActor = EntityUtils.getActor(currentEntity); Actor currentActor = EntityUtils.getActor(currentEntity);
//calculate and apply model transform //calculate and apply model transform
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity))); modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
currentActor.applyModelMatrix(modelTransformMatrix); currentActor.applyModelMatrix(modelTransformMatrix);
@ -281,6 +277,7 @@ public class RenderingEngine {
//bind screen fbo //bind screen fbo
screenFramebuffer.bind(); screenFramebuffer.bind();
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glViewport(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
/// ///
/// R E N D E R I N G S T U F F /// R E N D E R I N G S T U F F
@ -305,7 +302,7 @@ public class RenderingEngine {
// } // }
//calculate and apply model transform //calculate and apply model transform
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity))); modelTransformMatrix.translate(new Vector3f(EntityUtils.getPosition(currentEntity)).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity));
modelTransformMatrix.scale(EntityUtils.getScale(currentEntity)); modelTransformMatrix.scale(EntityUtils.getScale(currentEntity));
currentActor.applyModelMatrix(modelTransformMatrix); currentActor.applyModelMatrix(modelTransformMatrix);
@ -334,7 +331,7 @@ public class RenderingEngine {
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){ if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox); Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position)); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2); modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix; hitboxModel.modelMatrix = modelTransformMatrix;
@ -344,7 +341,7 @@ public class RenderingEngine {
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){ if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_1.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox); Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position)); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2); modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix; hitboxModel.modelMatrix = modelTransformMatrix;
@ -355,7 +352,7 @@ public class RenderingEngine {
if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){ if((hitboxModel = Globals.assetManager.fetchModel("Models/unitsphere_grey.fbx")) != null){
Vector3f position = EntityUtils.getPosition(currentHitbox); Vector3f position = EntityUtils.getPosition(currentHitbox);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position)); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere // modelTransformMatrix.translate(-0.25f, 0.0f, 0.5f); //center sphere
modelTransformMatrix.scale(data.getRadius() * 2); modelTransformMatrix.scale(data.getRadius() * 2);
hitboxModel.modelMatrix = modelTransformMatrix; hitboxModel.modelMatrix = modelTransformMatrix;
@ -374,7 +371,7 @@ public class RenderingEngine {
if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){ if((physicsGraphicsModel = Globals.assetManager.fetchModel("Models/unitcylinder.fbx")) != null){
Vector3f position = EntityUtils.getPosition(physicsEntity); Vector3f position = EntityUtils.getPosition(physicsEntity);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ())); modelTransformMatrix.translate(new Vector3f(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3()); modelTransformMatrix.scale(template.getDimension1(),template.getDimension2(),template.getDimension3());
physicsGraphicsModel.modelMatrix = modelTransformMatrix; physicsGraphicsModel.modelMatrix = modelTransformMatrix;
@ -390,7 +387,7 @@ public class RenderingEngine {
Vector3f scale = EntityUtils.getScale(physicsEntity); Vector3f scale = EntityUtils.getScale(physicsEntity);
Quaternionf rotation = EntityUtils.getRotation(physicsEntity); Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position)); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.rotate(rotation); modelTransformMatrix.rotate(rotation);
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
modelTransformMatrix.scale(scale); modelTransformMatrix.scale(scale);
@ -403,7 +400,7 @@ public class RenderingEngine {
Vector3f scale = EntityUtils.getScale(physicsEntity); Vector3f scale = EntityUtils.getScale(physicsEntity);
Quaternionf rotation = EntityUtils.getRotation(physicsEntity); Quaternionf rotation = EntityUtils.getRotation(physicsEntity);
modelTransformMatrix.identity(); modelTransformMatrix.identity();
modelTransformMatrix.translate(new Vector3f(position)); modelTransformMatrix.translate(new Vector3f(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)));
modelTransformMatrix.rotate(rotation); modelTransformMatrix.rotate(rotation);
// modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere // modelTransformMatrix.translate(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()); //center sphere
modelTransformMatrix.scale(scale); modelTransformMatrix.scale(scale);
@ -438,6 +435,9 @@ public class RenderingEngine {
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glDisable(GL_DEPTH_TEST);
glViewport(0, 0, Globals.WINDOW_WIDTH, Globals.WINDOW_HEIGHT);
//render full screen quad //render full screen quad
@ -452,7 +452,7 @@ public class RenderingEngine {
static void renderUI(){ static void renderUI(){
Matrix4f modelTransformMatrix = new Matrix4f(); Matrix4f modelTransformMatrix = new Matrix4f();
glDisable(GL_DEPTH_TEST);
for(Widget currentWidget : Globals.widgetManager.getWidgetList()){ for(Widget currentWidget : Globals.widgetManager.getWidgetList()){
if(currentWidget.isDraw()){ if(currentWidget.isDraw()){
currentWidget.draw(); currentWidget.draw();
@ -473,6 +473,7 @@ public class RenderingEngine {
static void renderBlackBackground(){ static void renderBlackBackground(){
//render full screen quad //render full screen quad
glUseProgram(screenTextureShaders.shaderProgram); glUseProgram(screenTextureShaders.shaderProgram);
glDisable(GL_DEPTH_TEST);
glBindVertexArray(screenTextureVAO); glBindVertexArray(screenTextureVAO);
Texture blackTexture = Globals.assetManager.fetchTexture(Globals.blackTexture); Texture blackTexture = Globals.assetManager.fetchTexture(Globals.blackTexture);
if(blackTexture != null){ if(blackTexture != null){