diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index e5069d41..2d3c965e 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1236,6 +1236,7 @@ Fix cache key collision bug Fix homogenous flagging on cell managers Fix more cache key collision cases Store terrain chunk files in dedicated folder +Start to standardize on doubles for positional data diff --git a/src/main/java/electrosphere/audio/AudioEngine.java b/src/main/java/electrosphere/audio/AudioEngine.java index 598187ec..66e1b28a 100644 --- a/src/main/java/electrosphere/audio/AudioEngine.java +++ b/src/main/java/electrosphere/audio/AudioEngine.java @@ -193,7 +193,7 @@ public class AudioEngine { private void updateListener(){ if(Globals.playerCamera != null){ //position - Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); listener.setPosition(cameraPos); //orientation diff --git a/src/main/java/electrosphere/audio/AudioListener.java b/src/main/java/electrosphere/audio/AudioListener.java index 16db4cb1..fec77239 100644 --- a/src/main/java/electrosphere/audio/AudioListener.java +++ b/src/main/java/electrosphere/audio/AudioListener.java @@ -61,8 +61,8 @@ public class AudioListener { * Sets the position of the listener * @param position the position */ - protected void setPosition(Vector3f position) { - alListener3f(AL_POSITION, position.x, position.y, position.z); + protected void setPosition(Vector3d position) { + AL11.alListener3f(AL_POSITION, (float)position.x, (float)position.y, (float)position.z); Globals.audioEngine.checkError(); AL11.alGetListener3f(AL11.AL_POSITION, xB, yB, zB); Globals.audioEngine.checkError(); diff --git a/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java index d7fc05a8..9946514e 100644 --- a/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java +++ b/src/main/java/electrosphere/client/entity/camera/CameraEntityUtils.java @@ -11,11 +11,9 @@ import electrosphere.game.data.common.CommonEntityType; import electrosphere.util.math.SpatialMathUtils; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; -import org.joml.Vector3f; import org.joml.Vector4d; /** @@ -24,25 +22,25 @@ import org.joml.Vector4d; public class CameraEntityUtils { - public static Entity spawnBasicCameraEntity(Vector3f center, Vector3f eye){ + public static Entity spawnBasicCameraEntity(Vector3d center, Vector3d eye){ Entity rVal = EntityCreationUtils.createClientSpatialEntity(); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_BASIC); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center); rVal.putData(EntityDataStrings .DATA_STRING_CAMERA_EYE, eye); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, 2.0f); - rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f(0,1,0)); + rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3d(0,1,0)); rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f); rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f); return rVal; } - public static Entity spawnEntityTrackingCameraEntity(Vector3f center, Vector3f eye, Entity toTrack){ + public static Entity spawnEntityTrackingCameraEntity(Vector3d center, Vector3d eye, Entity toTrack){ Entity rVal = EntityCreationUtils.createClientSpatialEntity(); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_EYE, eye); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, 2.0f); - rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f(0,1,0)); + rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3d(0,1,0)); rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f); rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f); BehaviorTree entityTrackingTree = new BehaviorTree() { @@ -50,7 +48,7 @@ public class CameraEntityUtils { public void simulate(float deltaTime) { if(toTrack != null){ Vector3d entityPos = EntityUtils.getPosition(toTrack); - CameraEntityUtils.setCameraCenter(rVal, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(getOrbitalCameraRadialOffset(rVal))); + CameraEntityUtils.setCameraCenter(rVal, new Vector3d(entityPos).add(getOrbitalCameraRadialOffset(rVal))); } } }; @@ -69,14 +67,14 @@ public class CameraEntityUtils { * @return The camera entity */ public static Entity spawnPlayerEntityTrackingCameraEntity(){ - Vector3f center = new Vector3f(0,0,0); - Vector3f eye = SpatialMathUtils.getOriginVectorf(); + Vector3d center = new Vector3d(0,0,0); + Vector3d eye = SpatialMathUtils.getOriginVector(); Entity rVal = EntityCreationUtils.createClientSpatialEntity(); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_EYE, eye); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, 2.0f); - rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f(0,1,0)); + rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3d(0,1,0)); rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f); rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f); Globals.cameraHandler.setTrackPlayerEntity(true); @@ -84,7 +82,7 @@ public class CameraEntityUtils { if(Globals.playerEntity != null && CommonEntityUtils.getCommonData(Globals.playerEntity) != null){ CommonEntityType type = CommonEntityUtils.getCommonData(Globals.playerEntity); if(type.getCameraData() != null && type.getCameraData().getThirdPersonCameraOffset() != null){ - rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f( + rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3d( (float)type.getCameraData().getThirdPersonCameraOffset().x, (float)type.getCameraData().getThirdPersonCameraOffset().y, (float)type.getCameraData().getThirdPersonCameraOffset().z @@ -100,13 +98,13 @@ public class CameraEntityUtils { * @param eye the eye of the camera * @return the camera */ - public static Entity spawnPlayerEntityTrackingCameraFirstPersonEntity(Vector3f center, Vector3f eye){ + public static Entity spawnPlayerEntityTrackingCameraFirstPersonEntity(Vector3d center, Vector3d eye){ Entity rVal = EntityCreationUtils.createClientSpatialEntity(); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_EYE, eye); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, 0.01f); - rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f(0,1.3f,0)); + rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3d(0,1.3f,0)); rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f); rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f); Globals.cameraHandler.setTrackPlayerEntity(true); @@ -125,7 +123,7 @@ public class CameraEntityUtils { if(Globals.controlHandler.cameraIsThirdPerson()){ Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraEntity(); } else { - Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraFirstPersonEntity(new Vector3f(0,0,0), SpatialMathUtils.getOriginVectorf()); + Globals.playerCamera = CameraEntityUtils.spawnPlayerEntityTrackingCameraFirstPersonEntity(new Vector3d(0,0,0), SpatialMathUtils.getOriginVector()); } } @@ -141,34 +139,34 @@ public class CameraEntityUtils { camera.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, distance); } - public static Vector3f getOrbitalCameraRadialOffset(Entity camera){ - return (Vector3f)camera.getData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET); + public static Vector3d getOrbitalCameraRadialOffset(Entity camera){ + return (Vector3d)camera.getData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET); } - public static void setOrbitalCameraRadialOffset(Entity camera, Vector3f offset){ + public static void setOrbitalCameraRadialOffset(Entity camera, Vector3d offset){ camera.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, offset); } - public static void setCameraCenter(Entity camera, Vector3f center){ + public static void setCameraCenter(Entity camera, Vector3d center){ camera.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center); } - public static Vector3f getCameraCenter(Entity camera){ + public static Vector3d getCameraCenter(Entity camera){ if(camera == null){ return null; } - return (Vector3f)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_CENTER); + return (Vector3d)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_CENTER); } - public static void setCameraEye(Entity camera, Vector3f eye){ + public static void setCameraEye(Entity camera, Vector3d eye){ camera.putData(EntityDataStrings.DATA_STRING_CAMERA_EYE, eye); } - public static Vector3f getCameraEye(Entity camera){ + public static Vector3d getCameraEye(Entity camera){ if(camera == null){ return null; } - return (Vector3f)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_EYE); + return (Vector3d)camera.getData(EntityDataStrings.DATA_STRING_CAMERA_EYE); } public static void setCameraPitch(Entity camera, float pitch){ @@ -221,18 +219,18 @@ public class CameraEntityUtils { * @param camera The camera * @return The view matrix for the camera */ - public static Matrix4f getCameraViewMatrix(Entity camera){ - Vector3f cameraCenter = new Vector3f(0,0,0);//getViewMatrixCenterOffset(camera); - Vector3f cameraEye = new Vector3f(cameraCenter).add(getCameraEye(camera)); - Vector3f cameraUp = SpatialMathUtils.getUpVectorf(); + public static Matrix4d getCameraViewMatrix(Entity camera){ + Vector3d cameraCenter = new Vector3d(0,0,0);//getViewMatrixCenterOffset(camera); + Vector3d cameraEye = new Vector3d(cameraCenter).add(getCameraEye(camera)); + Vector3d cameraUp = SpatialMathUtils.getUpVector(); //!!before you make the same mistake I made, cameraEye is NOT NECESSARILY normalized/unit vector //the orbital distance and offset are included in this vector //TODO: refactor this to some other matrix of transforms or something?? - cameraEye = new Vector3f(getCameraEye(camera)); + cameraEye = new Vector3d(getCameraEye(camera)); // System.out.println("eye: " + cameraEye); // System.out.println("center: " + cameraCenter); // System.out.println("up: " + cameraUp); - Matrix4f rVal = new Matrix4f().setLookAt( + Matrix4d rVal = new Matrix4d().setLookAt( cameraEye, //eye cameraCenter, //center cameraUp // up diff --git a/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java b/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java index 31f12210..ef107221 100644 --- a/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java +++ b/src/main/java/electrosphere/client/foliagemanager/FoliageCell.java @@ -14,7 +14,6 @@ import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Sphered; import org.joml.Vector3d; -import org.joml.Vector3f; import org.joml.Vector3i; import org.lwjgl.BufferUtils; @@ -453,12 +452,12 @@ public class FoliageCell { protected void draw(){ if(this.containedEntities.size() > 0){ Matrix4d modelMatrix = new Matrix4d(); - Vector3f cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera); RenderPipelineState renderPipelineState = Globals.renderingEngine.getRenderPipelineState(); OpenGLState openGLState = Globals.renderingEngine.getOpenGLState(); - Vector3f cameraModifiedPosition = new Vector3f((float)realPosition.x,(float)realPosition.y,(float)realPosition.z).sub(cameraCenter); + Vector3d cameraModifiedPosition = new Vector3d(realPosition).sub(cameraCenter); //frustum check entire cell boolean shouldRender = renderPipelineState.getFrustumIntersection().testSphere((float)(cameraModifiedPosition.x + boundingSphere.x), (float)(cameraModifiedPosition.y + boundingSphere.y), (float)(cameraModifiedPosition.z + boundingSphere.z), (float)(boundingSphere.r)); if(shouldRender){ diff --git a/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java b/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java index 80d6d3c8..b50e3034 100644 --- a/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java +++ b/src/main/java/electrosphere/client/terrain/foliage/FoliageCell.java @@ -11,7 +11,6 @@ import java.util.Random; import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Vector3d; -import org.joml.Vector3f; import org.joml.Vector3i; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -475,13 +474,13 @@ public class FoliageCell { protected void draw(){ if(this.modelEntity != null){ Matrix4d modelMatrix = new Matrix4d(); - Vector3f cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera); RenderPipelineState renderPipelineState = Globals.renderingEngine.getRenderPipelineState(); OpenGLState openGLState = Globals.renderingEngine.getOpenGLState(); Vector3d realPosition = this.getRealPos(); - Vector3f cameraModifiedPosition = new Vector3f((float)realPosition.x,(float)realPosition.y,(float)realPosition.z).sub(cameraCenter); + Vector3d cameraModifiedPosition = new Vector3d(realPosition).sub(cameraCenter); //frustum check entire cell int size = (int)Math.pow(2,this.lod); boolean shouldRender = renderPipelineState.getFrustumIntersection().testSphere( diff --git a/src/main/java/electrosphere/client/ui/components/CharacterCustomizer.java b/src/main/java/electrosphere/client/ui/components/CharacterCustomizer.java index a633a4bf..09a08e8d 100644 --- a/src/main/java/electrosphere/client/ui/components/CharacterCustomizer.java +++ b/src/main/java/electrosphere/client/ui/components/CharacterCustomizer.java @@ -3,6 +3,7 @@ package electrosphere.client.ui.components; import java.util.function.Consumer; import java.util.stream.Collectors; +import org.joml.Vector3d; import org.joml.Vector3f; import org.joml.Vector4d; @@ -61,7 +62,7 @@ public class CharacterCustomizer { CreatureData selectedRaceType = Globals.gameConfigCurrent.getCreatureTypeLoader().getType(race); //spawn camera so renderer doesn't crash (once render pipeline is modularized this shouldn't be necessary) - Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(0,0.3f,1).normalize()); + Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3d(0,0,0), new Vector3d(0,0.3f,1).normalize()); Globals.viewMatrix = CameraEntityUtils.getCameraViewMatrix(Globals.playerCamera); //create actor panel diff --git a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java index 20f940b8..e5d196b6 100644 --- a/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java +++ b/src/main/java/electrosphere/client/ui/menu/mainmenu/MenuGeneratorsUITesting.java @@ -4,7 +4,7 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; -import org.joml.Vector3f; +import org.joml.Vector3d; import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.ui.components.CharacterCustomizer; @@ -99,7 +99,7 @@ public class MenuGeneratorsUITesting { //actor panel ActorPanel actorPanel = ActorPanel.create(ActorUtils.createActorFromModelPath(AssetDataStrings.UNITCUBE)); if(Globals.playerCamera == null){ - Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(-1,0,0)); + Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3d(0,0,0), new Vector3d(-1,0,0)); } formEl.addChild(actorPanel); diff --git a/src/main/java/electrosphere/controls/CameraHandler.java b/src/main/java/electrosphere/controls/CameraHandler.java index fa1123c2..e614542c 100644 --- a/src/main/java/electrosphere/controls/CameraHandler.java +++ b/src/main/java/electrosphere/controls/CameraHandler.java @@ -1,8 +1,7 @@ package electrosphere.controls; -import org.joml.Quaternionf; +import org.joml.Quaterniond; import org.joml.Vector3d; -import org.joml.Vector3f; import electrosphere.client.entity.camera.CameraEntityUtils; import electrosphere.client.entity.crosshair.Crosshair; @@ -35,9 +34,9 @@ public class CameraHandler { //the current pitch float pitch = 50; //the camera's rotation vector - Vector3f cameraRotationVector = new Vector3f(); + Vector3d cameraRotationVector = new Vector3d(); //the radial offset of the camera - Vector3f radialOffset = new Vector3f(0,1,0); + Vector3d radialOffset = new Vector3d(0,1,0); //if set to true, the camera will track the player's entity boolean trackPlayerEntity = true; @@ -69,7 +68,7 @@ public class CameraHandler { * Updates the radial offset * @param offset the radial offset */ - public void updateRadialOffset(Vector3f offset){ + public void updateRadialOffset(Vector3d offset){ radialOffset = offset; } @@ -84,11 +83,6 @@ public class CameraHandler { if(Crosshair.getCrosshairActive()){ - // if(Globals.playerCharacter != null){ - // Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter); - // CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z)); - // } - Vector3d characterPos = EntityUtils.getPosition(Globals.playerEntity); Vector3d targetPos = Crosshair.getTargetPosition(); Vector3d diffed = new Vector3d(targetPos).sub(characterPos).mul(-1).normalize(); @@ -103,38 +97,22 @@ public class CameraHandler { CameraEntityUtils.setCameraPitch(Globals.playerCamera, pitch); CameraEntityUtils.setCameraYaw(Globals.playerCamera, yaw); - // System.out.println(pitch); - // if(Globals.playerCharacter != null){ - // Vector3d charPos = EntityUtils.getPosition(Globals.playerCharacter); - // CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)charPos.x,(float)charPos.y,(float)charPos.z)); - // } + Quaterniond pitchQuat = new Quaterniond().fromAxisAngleDeg(SpatialMathUtils.getLeftVector(), -pitch); + Quaterniond yawQuat = new Quaterniond().fromAxisAngleDeg(SpatialMathUtils.getUpVector(), -yaw); - Quaternionf pitchQuat = new Quaternionf().fromAxisAngleDeg(SpatialMathUtils.getLeftVectorf(), -pitch); - Quaternionf yawQuat = new Quaternionf().fromAxisAngleDeg(SpatialMathUtils.getUpVectorf(), -yaw); - // float yawRad = yaw / 180.0f * (float)Math.PI; - // float pitchRad = pitch / 180.0f * (float)Math.PI; - // float rollRad = 0.0f; - // pitchQuat.mul(yawQuat); - cameraRotationVector = pitchQuat.transform(SpatialMathUtils.getOriginVectorf()); + cameraRotationVector = pitchQuat.transform(SpatialMathUtils.getOriginVector()); cameraRotationVector = yawQuat.transform(cameraRotationVector); cameraRotationVector.normalize(); - - - // cameraRotationVector.x = 0 + (float) Math.cos(yaw / 180.0f * Math.PI) * 1; - // cameraRotationVector.y = 0 + (float) Math.sin(pitch / 180.0f * Math.PI) * 1; - // cameraRotationVector.z = 0 + (float) Math.sin(yaw / 180.0f * Math.PI) * 1; - // cameraRotationVector.normalize(); - // System.out.println(yaw + " " + pitch); } if(trackPlayerEntity && Globals.playerEntity != null){ Vector3d entityPos = EntityUtils.getPosition(Globals.playerEntity); - CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f((float)entityPos.x,(float)entityPos.y,(float)entityPos.z).add(CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera))); + CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3d(entityPos).add(CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera))); } //update view matrix offset float xFactor = (float)Math.cos(yaw / 180.0f * Math.PI); float yFactor = (float)Math.sin(yaw / 180.0f * Math.PI); - Vector3f radialOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera); - Vector3f trueOffset = new Vector3f(radialOffset).mul(xFactor,1.0f,yFactor); + Vector3d radialOffset = CameraEntityUtils.getOrbitalCameraRadialOffset(Globals.playerCamera); + Vector3d trueOffset = new Vector3d(radialOffset).mul(xFactor,1.0f,yFactor); CameraEntityUtils.setOrbitalCameraRadialOffset(Globals.playerCamera, trueOffset); cameraRotationVector.mul(CameraEntityUtils.getOrbitalCameraDistance(Globals.playerCamera)); CameraEntityUtils.setCameraEye(Globals.playerCamera, cameraRotationVector); diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java b/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java index 90b3bcf3..89de15c9 100644 --- a/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryFreecam.java @@ -3,7 +3,7 @@ package electrosphere.controls.categories; import java.util.HashMap; import java.util.List; -import org.joml.Vector3f; +import org.joml.Vector3d; import org.lwjgl.glfw.GLFW; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -49,7 +49,7 @@ public class ControlCategoryFreecam { ){ freeCameraControlList.add(controlMap.get(FREECAM_UP)); controlMap.get(FREECAM_UP).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); playerCameraCenterPos.add(0,0.1f,0); CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); }}); @@ -57,7 +57,7 @@ public class ControlCategoryFreecam { freeCameraControlList.add(controlMap.get(FREECAM_DOWN)); controlMap.get(FREECAM_DOWN).setOnRepeat(new ControlMethod(){public void execute(MouseState mouseState){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); playerCameraCenterPos.add(0,-0.1f,0); CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); }}); @@ -65,9 +65,9 @@ public class ControlCategoryFreecam { freeCameraControlList.add(controlMap.get(FREECAM_FORWARD)); ControlMethod freeCamForwardCallback = new ControlMethod(){public void execute(MouseState mouseState){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - playerCameraCenterPos.add(new Vector3f(playerCameraEyePos).normalize().mul(-0.1f)); + Vector3d playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + playerCameraCenterPos.add(new Vector3d(playerCameraEyePos).normalize().mul(-0.1f)); CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); }}; controlMap.get(FREECAM_FORWARD).setOnClick(freeCamForwardCallback); @@ -75,9 +75,9 @@ public class ControlCategoryFreecam { freeCameraControlList.add(controlMap.get(FREECAM_BACKWARD)); ControlMethod freeCamBackwardCallback = new ControlMethod(){public void execute(MouseState mouseState){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - playerCameraCenterPos.add(new Vector3f(playerCameraEyePos).normalize().mul(0.1f)); + Vector3d playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + playerCameraCenterPos.add(new Vector3d(playerCameraEyePos).normalize().mul(0.1f)); CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); }}; controlMap.get(FREECAM_BACKWARD).setOnClick(freeCamBackwardCallback); @@ -85,10 +85,10 @@ public class ControlCategoryFreecam { freeCameraControlList.add(controlMap.get(FREECAM_LEFT)); ControlMethod freeCamLeftCallback = new ControlMethod(){public void execute(MouseState mouseState){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - Vector3f modifiedVec = new Vector3f(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(-90 * Math.PI / 180)).normalize(); - playerCameraCenterPos.add(new Vector3f(modifiedVec).mul(0.1f)); + Vector3d playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d modifiedVec = new Vector3d(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(-90 * Math.PI / 180)).normalize(); + playerCameraCenterPos.add(new Vector3d(modifiedVec).mul(0.1f)); CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); }}; controlMap.get(FREECAM_LEFT).setOnClick(freeCamLeftCallback); @@ -96,10 +96,10 @@ public class ControlCategoryFreecam { freeCameraControlList.add(controlMap.get(FREECAM_RIGHT)); ControlMethod freeCamRightCallback = new ControlMethod(){public void execute(MouseState mouseState){ - Vector3f playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); - Vector3f modifiedVec = new Vector3f(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(90 * Math.PI / 180)).normalize(); - playerCameraCenterPos.add(new Vector3f(modifiedVec).mul(0.1f)); + Vector3d playerCameraCenterPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d playerCameraEyePos = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d modifiedVec = new Vector3d(playerCameraEyePos.x,0,playerCameraEyePos.z).rotateY((float)(90 * Math.PI / 180)).normalize(); + playerCameraCenterPos.add(new Vector3d(modifiedVec).mul(0.1f)); CameraEntityUtils.setCameraCenter(Globals.playerCamera,playerCameraCenterPos); }}; controlMap.get(FREECAM_RIGHT).setOnClick(freeCamRightCallback); diff --git a/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java b/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java index 7270668f..901f787a 100644 --- a/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java +++ b/src/main/java/electrosphere/controls/categories/ControlCategoryMainGame.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.List; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.glfw.GLFW; import electrosphere.audio.VirtualAudioSourceManager.VirtualAudioSourceType; @@ -189,7 +188,7 @@ public class ControlCategoryMainGame { BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); if(movementTree instanceof ClientGroundMovementTree){ ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize()); groundTree.start(MovementRelativeFacing.BACKWARD_LEFT); @@ -212,7 +211,7 @@ public class ControlCategoryMainGame { BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); if(movementTree instanceof ClientGroundMovementTree){ ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); if(controlMap.get(DATA_STRING_INPUT_CODE_STRAFE_LEFT).isState()){ CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(3.0/4.0*Math.PI).normalize()); groundTree.start(MovementRelativeFacing.BACKWARD_LEFT); @@ -251,7 +250,7 @@ public class ControlCategoryMainGame { BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); if(movementTree instanceof ClientGroundMovementTree){ ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); if( (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) @@ -260,7 +259,7 @@ public class ControlCategoryMainGame { groundTree.start(MovementRelativeFacing.FORWARD); } } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); @@ -272,7 +271,7 @@ public class ControlCategoryMainGame { BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); if(movementTree instanceof ClientGroundMovementTree){ ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); if( (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) @@ -281,7 +280,7 @@ public class ControlCategoryMainGame { groundTree.start(MovementRelativeFacing.FORWARD); } } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(Math.PI/2.0).normalize()); clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); @@ -309,7 +308,7 @@ public class ControlCategoryMainGame { BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); if(movementTree instanceof ClientGroundMovementTree){ ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); if( (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) @@ -318,7 +317,7 @@ public class ControlCategoryMainGame { groundTree.start(MovementRelativeFacing.FORWARD); } } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); @@ -330,7 +329,7 @@ public class ControlCategoryMainGame { BehaviorTree movementTree = CreatureUtils.clientGetEntityMovementTree(Globals.playerEntity); if(movementTree instanceof ClientGroundMovementTree){ ClientGroundMovementTree groundTree = (ClientGroundMovementTree) movementTree; - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); if( (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) && (controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controlMap.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue())) @@ -339,7 +338,7 @@ public class ControlCategoryMainGame { groundTree.start(MovementRelativeFacing.FORWARD); } } else if(ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity) != null){ - Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); + Vector3d cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera); ClientEditorMovementTree clientEditorMovementTree = ClientEditorMovementTree.getClientEditorMovementTree(Globals.playerEntity); CreatureUtils.setFacingVector(Globals.playerEntity, new Vector3d(-cameraEyeVector.x,0,-cameraEyeVector.z).rotateY(-Math.PI/2.0).normalize()); clientEditorMovementTree.start(electrosphere.entity.state.movement.editor.ClientEditorMovementTree.MovementRelativeFacing.FORWARD); diff --git a/src/main/java/electrosphere/engine/Globals.java b/src/main/java/electrosphere/engine/Globals.java index f39af07b..9e525394 100644 --- a/src/main/java/electrosphere/engine/Globals.java +++ b/src/main/java/electrosphere/engine/Globals.java @@ -5,7 +5,6 @@ import java.lang.management.ManagementFactory; import java.util.ArrayList; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Vector3f; import electrosphere.audio.AudioEngine; @@ -265,9 +264,9 @@ public class Globals { public static float nearClip = 0.01f; //matrices for drawing models - public static Matrix4f viewMatrix = new Matrix4f(); + public static Matrix4d viewMatrix = new Matrix4d(); public static Matrix4d projectionMatrix; - public static Matrix4f lightDepthMatrix = new Matrix4f(); + public static Matrix4d lightDepthMatrix = new Matrix4d(); //locations for shadow map specific variables public static int depthMapShaderProgramLoc = 0; diff --git a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java index 8cdbf557..6d739d23 100644 --- a/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java +++ b/src/main/java/electrosphere/engine/loadingthreads/ClientLoading.java @@ -3,6 +3,7 @@ package electrosphere.engine.loadingthreads; import java.util.Arrays; import java.util.concurrent.TimeUnit; +import org.joml.Vector3d; import org.joml.Vector3f; import electrosphere.client.block.cells.ClientBlockCellManager; @@ -146,7 +147,7 @@ public class ClientLoading { Globals.controlHandler.hintUpdateControlState(ControlHandler.ControlsState.NO_INPUT); //init camera - Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3f(0,0,0), new Vector3f(-1,0,0)); + Globals.playerCamera = CameraEntityUtils.spawnBasicCameraEntity(new Vector3d(0,0,0), new Vector3d(-1,0,0)); Globals.cameraHandler.setTrackPlayerEntity(false); Globals.cameraHandler.setUpdate(false); //initialize the "real" objects simulation diff --git a/src/main/java/electrosphere/entity/state/attach/AttachUtils.java b/src/main/java/electrosphere/entity/state/attach/AttachUtils.java index 9603e12d..f15d0d6e 100644 --- a/src/main/java/electrosphere/entity/state/attach/AttachUtils.java +++ b/src/main/java/electrosphere/entity/state/attach/AttachUtils.java @@ -15,7 +15,6 @@ import java.util.LinkedList; import java.util.List; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Quaterniond; import org.joml.Vector3d; import org.joml.Vector3f; @@ -102,7 +101,7 @@ public class AttachUtils { Vector3d scaleRaw = new Vector3d(); Vector3f scale = new Vector3f(); Entity parent; - Matrix4f transform; + Matrix4d transform; //update entities attached to centerpoint + transform of other entities for(Entity currentEntity : cell.getScene().getEntitiesWithTag(EntityTags.TRANSFORM_ATTACHED)){ if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){ @@ -229,7 +228,7 @@ public class AttachUtils { Vector3d scaleRaw = new Vector3d(); Vector3f scale = new Vector3f(); Entity parent; - Matrix4f transform; + Matrix4d transform; //update entities attached to centerpoint + transform of other entities for(Entity currentEntity : Globals.clientSceneWrapper.getScene().getEntitiesWithTag(EntityTags.TRANSFORM_ATTACHED)){ if((parent = (Entity)currentEntity.getData(EntityDataStrings.ATTACH_PARENT))!=null){ @@ -481,7 +480,7 @@ public class AttachUtils { * @param toAttach The child entity * @param transform The transform */ - public static void clientAttachEntityAtTransform(Entity parent, Entity toAttach, Matrix4f transform){ + public static void clientAttachEntityAtTransform(Entity parent, Entity toAttach, Matrix4d transform){ Globals.clientSceneWrapper.getScene().registerEntityToTag(toAttach, EntityTags.TRANSFORM_ATTACHED); toAttach.putData(EntityDataStrings.ATTACH_ENTITY_IS_ATTACHED, true); toAttach.putData(EntityDataStrings.ATTACH_PARENT, parent); @@ -501,7 +500,7 @@ public class AttachUtils { * @param toAttach The entity that is attached * @param transform The transform */ - public static void updateAttachTransform(Entity toAttach, Matrix4f transform){ + public static void updateAttachTransform(Entity toAttach, Matrix4d transform){ toAttach.putData(EntityDataStrings.ATTACH_TRANSFORM, transform); } @@ -710,8 +709,8 @@ public class AttachUtils { * @param e The entity * @return The transform if it exists, false otherwise */ - protected static Matrix4f getTransformOffset(Entity e){ - return (Matrix4f)e.getData(EntityDataStrings.ATTACH_TRANSFORM); + protected static Matrix4d getTransformOffset(Entity e){ + return (Matrix4d)e.getData(EntityDataStrings.ATTACH_TRANSFORM); } /** diff --git a/src/main/java/electrosphere/entity/state/client/particle/ClientParticleTree.java b/src/main/java/electrosphere/entity/state/client/particle/ClientParticleTree.java index 1f7852fa..4ca6ac98 100644 --- a/src/main/java/electrosphere/entity/state/client/particle/ClientParticleTree.java +++ b/src/main/java/electrosphere/entity/state/client/particle/ClientParticleTree.java @@ -1,7 +1,9 @@ package electrosphere.entity.state.client.particle; import org.joml.AxisAngle4f; +import org.joml.Matrix4d; import org.joml.Matrix4f; +import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; @@ -98,7 +100,7 @@ public class ClientParticleTree implements BehaviorTree { public void simulate(float deltaTime){ InstancedActor instancedActor = InstancedActor.getInstancedActor(parent); Vector3d position = EntityUtils.getPosition(parent); - Vector3f cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); + Vector3d cameraPos = CameraEntityUtils.getCameraCenter(Globals.playerCamera); //update position position.add(velocity); @@ -154,10 +156,10 @@ public class ClientParticleTree implements BehaviorTree { if(instancedActor != null){ TextureAtlas particleTextureAtlas = Globals.particleService.getTextureAtlas(); int textureIndex = particleTextureAtlas.getTextureIndex(this.particleData.getTexture()); - instancedActor.setAttribute(Globals.particleService.getModelAttrib(), new Matrix4f().translationRotateScale( - new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(cameraPos.x, cameraPos.y, cameraPos.z), - new Quaternionf(rotation), - scale + instancedActor.setAttribute(Globals.particleService.getModelAttrib(), new Matrix4d().translationRotateScale( + new Vector3d((float)position.x,(float)position.y,(float)position.z).sub(cameraPos.x, cameraPos.y, cameraPos.z), + new Quaterniond(rotation), + new Vector3d(scale) )); instancedActor.setAttribute(Globals.particleService.getColorAttrib(), currentColor); diff --git a/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java b/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java index 0edaf568..9660d293 100644 --- a/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java +++ b/src/main/java/electrosphere/entity/state/hitbox/HitboxCollectionState.java @@ -7,7 +7,6 @@ import java.util.Map; import org.joml.Quaterniond; import org.joml.Vector3d; -import org.joml.Vector3f; import org.ode4j.ode.DBody; import org.ode4j.ode.DGeom; @@ -257,7 +256,7 @@ public class HitboxCollectionState { this.body.setPosition(PhysicsUtils.jomlVecToOdeVec(entityPosition)); for(String boneName : this.boneHitboxMap.keySet()){ if(EntityUtils.getActor(parent).containsBone(boneName)){ - Vector3f bonePosition = EntityUtils.getActor(parent).getBonePosition(boneName); + Vector3d bonePosition = EntityUtils.getActor(parent).getBonePosition(boneName); for(HitboxState state : this.boneHitboxMap.get(boneName)){ DGeom geom = this.stateGeomMap.get(state); HitboxState shapeStatus = this.geomStateMap.get(geom); @@ -298,7 +297,7 @@ public class HitboxCollectionState { // for(String boneName : this.boneHitboxMap.keySet()){ if(EntityUtils.getPoseActor(parent).containsBone(boneName)){ - Vector3f bonePosition = EntityUtils.getPoseActor(parent).getBonePosition(boneName); + Vector3d bonePosition = EntityUtils.getPoseActor(parent).getBonePosition(boneName); // for(HitboxState state : this.boneHitboxMap.get(boneName)){ if(state == null){ @@ -369,7 +368,7 @@ public class HitboxCollectionState { * @param boneName The name of the bone * @param bonePosition the position of the bone */ - private void updateSphereShapePosition(CollisionEngine collisionEngine, String boneName, HitboxState hitboxState, Vector3f bonePosition){ + private void updateSphereShapePosition(CollisionEngine collisionEngine, String boneName, HitboxState hitboxState, Vector3d bonePosition){ DGeom geom = this.stateGeomMap.get(hitboxState); //get offset's transform @@ -401,7 +400,7 @@ public class HitboxCollectionState { * @param boneName * @param bonePosition */ - private void updateCapsuleShapePosition(CollisionEngine collisionEngine, String boneName, HitboxState hitboxState, Vector3f bonePosition){ + private void updateCapsuleShapePosition(CollisionEngine collisionEngine, String boneName, HitboxState hitboxState, Vector3d bonePosition){ //get data about the hitbox DGeom geom = this.stateGeomMap.get(hitboxState); diff --git a/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java b/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java index 822f80f4..f9a0f7eb 100644 --- a/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java +++ b/src/main/java/electrosphere/entity/types/tree/ProceduralTree.java @@ -7,13 +7,11 @@ import java.util.Map; import java.util.Random; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; import org.joml.Vector3f; import org.joml.Vector4d; -import org.joml.Vector4f; import org.ode4j.ode.DBody; import electrosphere.client.entity.instance.InstanceTemplate; @@ -121,8 +119,8 @@ public class ProceduralTree { */ public static void setProceduralActor(Entity trunkChild, TreeModel treeModel, Random treeRandom){ InstancedActor instancedActor = InstancedEntityUtils.makeEntityInstancedWithModelTransform(trunkChild, branchInstanceTemplate, modelMatrixAttribute); - instancedActor.setAttribute(boneMatrixAttribute, new Matrix4f().identity()); - instancedActor.setAttribute(modelMatrixAttribute, new Matrix4f().identity()); + instancedActor.setAttribute(boneMatrixAttribute, new Matrix4d().identity()); + instancedActor.setAttribute(modelMatrixAttribute, new Matrix4d().identity()); instancedActor.setAttribute(baseSizeAttribute, 1.0f); //attach physics @@ -205,7 +203,7 @@ public class ProceduralTree { //calculate transform from parent entity //this is the transform that will be applied every time the attachutils updates - Matrix4f transformFromParent = new Matrix4f() + Matrix4d transformFromParent = new Matrix4d() .translate(new Vector3f( (float)segment.offsetFromParent.x, (float)segment.offsetFromParent.y, @@ -219,7 +217,7 @@ public class ProceduralTree { )); //calculate combined transform - Matrix4f combinedTransform = new Matrix4f().translate(new Vector3f( + Matrix4d combinedTransform = new Matrix4d().translate(new Vector3f( (float)segment.parentPosition.x, (float)segment.parentPosition.y, (float)segment.parentPosition.z @@ -238,7 +236,7 @@ public class ProceduralTree { //calculate current branch's stuff //get current position - Vector4f currentPositionf = combinedTransform.transform(new Vector4f( + Vector4d currentPositionf = combinedTransform.transform(new Vector4d( 0, 0, 0, @@ -253,12 +251,12 @@ public class ProceduralTree { Quaternionf boneRotation = new Quaternionf(0,0,0,1); //calculates the bone transform matrix - Matrix4f boneTransform = new Matrix4f().identity().rotate(boneRotation); + Matrix4d boneTransform = new Matrix4d().identity().rotate(boneRotation); //new position transform - Matrix4f newPositionTransform = new Matrix4f().rotate(boneRotation).translate(0,type.getBranchHeight(),0); + Matrix4d newPositionTransform = new Matrix4d().rotate(boneRotation).translate(0,type.getBranchHeight(),0); - Vector4f newPositionRaw = newPositionTransform.transform(new Vector4f(0,0,0,1)); + Vector4d newPositionRaw = newPositionTransform.transform(new Vector4d(0,0,0,1)); Vector3d newPosition = new Vector3d(newPositionRaw.x,newPositionRaw.y,newPositionRaw.z); //get new scalar @@ -270,7 +268,7 @@ public class ProceduralTree { InstancedActor instancedActor = InstancedEntityUtils.makeEntityInstancedWithModelTransform(trunkSegment, branchInstanceTemplate, modelMatrixAttribute); instancedActor.setAttribute(boneMatrixAttribute, boneTransform.scale(newScalar,1,newScalar)); instancedActor.setAttribute(baseSizeAttribute, segment.scalar); - instancedActor.setAttribute(modelMatrixAttribute, new Matrix4f().identity()); + instancedActor.setAttribute(modelMatrixAttribute, new Matrix4d().identity()); //set entity stuuff EntityUtils.getPosition(trunkSegment).set(currentPosition); @@ -350,7 +348,7 @@ public class ProceduralTree { //calculate transform from parent entity //this is the transform that will be applied every time the attachutils updates - Matrix4f transformFromParent = new Matrix4f() + Matrix4d transformFromParent = new Matrix4d() .translate(new Vector3f( (float)segment.offsetFromParent.x, (float)segment.offsetFromParent.y, @@ -364,7 +362,7 @@ public class ProceduralTree { )); //calculate combined transform - Matrix4f combinedTransform = new Matrix4f().translate(new Vector3f( + Matrix4d combinedTransform = new Matrix4d().translate(new Vector3f( (float)segment.parentPosition.x, (float)segment.parentPosition.y, (float)segment.parentPosition.z @@ -383,7 +381,7 @@ public class ProceduralTree { //calculate current branch's stuff //get current position - Vector4f currentPositionf = combinedTransform.transform(new Vector4f( + Vector4d currentPositionf = combinedTransform.transform(new Vector4d( 0, 0, 0, @@ -415,12 +413,12 @@ public class ProceduralTree { //calculates the bone transform matrix - Matrix4f boneTransform = new Matrix4f().identity().rotate(boneRotation); + Matrix4d boneTransform = new Matrix4d().identity().rotate(boneRotation); //new position transform - Matrix4f newPositionTransform = new Matrix4f().rotate(boneRotation).translate(0,treeSegmentHeight,0); + Matrix4d newPositionTransform = new Matrix4d().rotate(boneRotation).translate(0,treeSegmentHeight,0); - Vector4f newPositionRaw = newPositionTransform.transform(new Vector4f(0,0,0,1)); + Vector4d newPositionRaw = newPositionTransform.transform(new Vector4d(0,0,0,1)); Vector3d newPosition = new Vector3d(newPositionRaw.x,newPositionRaw.y,newPositionRaw.z); //get new scalar @@ -437,7 +435,7 @@ public class ProceduralTree { InstancedActor instancedActor = InstancedEntityUtils.makeEntityInstancedWithModelTransform(branch, branchInstanceTemplate, modelMatrixAttribute); instancedActor.setAttribute(boneMatrixAttribute, boneTransform.scale(newScalar,1,newScalar)); instancedActor.setAttribute(baseSizeAttribute, segment.scalar); - instancedActor.setAttribute(modelMatrixAttribute, new Matrix4f().identity()); + instancedActor.setAttribute(modelMatrixAttribute, new Matrix4d().identity()); //set entity stuuff EntityUtils.getPosition(branch).set(currentPosition); @@ -831,7 +829,7 @@ public class ProceduralTree { //calculate transform from parent entity //this is the transform that will be applied every time the attachutils updates - Matrix4f transformFromParent = new Matrix4f() + Matrix4d transformFromParent = new Matrix4d() .translate(new Vector3f( (float)transformedPos.x, (float)transformedPos.y, @@ -848,7 +846,7 @@ public class ProceduralTree { //create entity Entity leaf = EntityCreationUtils.createClientSpatialEntity(); InstancedActor leafInstancedActor = InstancedEntityUtils.makeEntityInstancedWithModelTransform(leaf, leafInstanceTemplate, modelMatrixAttribute); - leafInstancedActor.setAttribute(modelMatrixAttribute, new Matrix4f().identity()); + leafInstancedActor.setAttribute(modelMatrixAttribute, new Matrix4d().identity()); leafInstancedActor.setAttribute(leafColorAttribute, new Vector3f(36/255.0f,173/255.0f,31/255.0f)); //set entity stuuff @@ -1129,13 +1127,13 @@ public class ProceduralTree { //calculates the bone transform matrix - Matrix4f boneTransform = new Matrix4f().identity().rotate(boneRotation); + Matrix4d boneTransform = new Matrix4d().identity().rotate(boneRotation); //new position transform - Matrix4f newPositionTransform = new Matrix4f().rotate(boneRotation).translate(0,type.getBranchHeight(),0); - Vector4f newPositionRaw = newPositionTransform.transform(new Vector4f(0,0,0,1)); + Matrix4d newPositionTransform = new Matrix4d().rotate(boneRotation).translate(0,type.getBranchHeight(),0); + Vector4d newPositionRaw = newPositionTransform.transform(new Vector4d(0,0,0,1)); - Matrix4f transformFromParent = new Matrix4f() + Matrix4d transformFromParent = new Matrix4d() .translate(new Vector3f( (float)newPositionRaw.x, (float)newPositionRaw.y, @@ -1151,7 +1149,7 @@ public class ProceduralTree { //update branch actor branch matrix InstancedActor branchActor = InstancedActor.getInstancedActor(branch); - branchActor.setAttribute(boneMatrixAttribute, new Matrix4f(transformFromParent).scale((float)currentScalar,1,(float)currentScalar)); + branchActor.setAttribute(boneMatrixAttribute, new Matrix4d(transformFromParent).scale((float)currentScalar,1,(float)currentScalar)); //update children positions for(Entity child : children){ diff --git a/src/main/java/electrosphere/renderer/RenderPipelineState.java b/src/main/java/electrosphere/renderer/RenderPipelineState.java index 60c0d83a..bc66b68a 100644 --- a/src/main/java/electrosphere/renderer/RenderPipelineState.java +++ b/src/main/java/electrosphere/renderer/RenderPipelineState.java @@ -167,10 +167,10 @@ public class RenderPipelineState { * @param projectionMatrix the projection matrix * @param viewMatrix the view matrix */ - public void updateFrustumIntersection(Matrix4d projectionMatrix, Matrix4f viewMatrix){ + public void updateFrustumIntersection(Matrix4d projectionMatrix, Matrix4d viewMatrix){ Matrix4f projectionViewMatrix = new Matrix4f(); projectionViewMatrix.set(projectionMatrix); - projectionViewMatrix.mul(viewMatrix); + projectionViewMatrix.mul(new Matrix4f(viewMatrix)); this.frustumInt.set(projectionViewMatrix); } diff --git a/src/main/java/electrosphere/renderer/RenderingEngine.java b/src/main/java/electrosphere/renderer/RenderingEngine.java index b48c05d5..8409b4d8 100644 --- a/src/main/java/electrosphere/renderer/RenderingEngine.java +++ b/src/main/java/electrosphere/renderer/RenderingEngine.java @@ -11,8 +11,7 @@ import static org.lwjgl.system.MemoryUtil.NULL; import java.nio.IntBuffer; import org.joml.Matrix4d; -import org.joml.Matrix4f; -import org.joml.Vector3f; +import org.joml.Vector3d; import org.lwjgl.BufferUtils; import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFWErrorCallback; @@ -97,9 +96,9 @@ public class RenderingEngine { /* Perspective volumetrics */ - public static Matrix4f nearVolumeProjectionMatrix = new Matrix4f(); - public static Matrix4f midVolumeProjectionMatrix = new Matrix4f(); - public static Matrix4f farVolumeProjectionMatrix = new Matrix4f(); + public static Matrix4d nearVolumeProjectionMatrix = new Matrix4d(); + public static Matrix4d midVolumeProjectionMatrix = new Matrix4d(); + public static Matrix4d farVolumeProjectionMatrix = new Matrix4d(); public static VisualShader volumeDepthShaderProgram; public static Framebuffer volumeDepthBackfaceFramebuffer; public static Texture volumeDepthBackfaceTexture; @@ -454,12 +453,12 @@ public class RenderingEngine { // Projection and View matrix creation // Globals.projectionMatrix = new Matrix4d(); - Globals.viewMatrix = new Matrix4f(); + Globals.viewMatrix = new Matrix4d(); verticalFOV = (float)(Globals.verticalFOV * 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; Globals.projectionMatrix.setPerspective(verticalFOV, Globals.aspectRatio, Globals.nearClip, Globals.userSettings.getGraphicsViewDistance()); - Globals.viewMatrix.translation(new Vector3f(0.0f,0.0f,-3.0f)); + Globals.viewMatrix.translation(new Vector3d(0.0f,0.0f,-3.0f)); /** * Alert everyone that the rendering engine is ready diff --git a/src/main/java/electrosphere/renderer/actor/Actor.java b/src/main/java/electrosphere/renderer/actor/Actor.java index ca7501d6..56ed4572 100644 --- a/src/main/java/electrosphere/renderer/actor/Actor.java +++ b/src/main/java/electrosphere/renderer/actor/Actor.java @@ -18,13 +18,10 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import org.joml.AxisAngle4f; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Quaterniond; import org.joml.Sphered; import org.joml.Vector3d; -import org.joml.Vector3f; import org.joml.Vector4d; /** @@ -464,11 +461,11 @@ public class Actor { /** * Gets the position of a bone in local space * @param boneName The name of the bone - * @return The vector3f containing the position of the bone, or a vector of (0,0,0) if the model lookup fails + * @return The vector3d containing the position of the bone, or a vector of (0,0,0) if the model lookup fails * //TODO: refactor to make failure more transparent (both for model not existing and bone not existing) */ - public Vector3f getBonePosition(String boneName){ - Vector3f rVal = new Vector3f(); + public Vector3d getBonePosition(String boneName){ + Vector3d rVal = new Vector3d(); Model model = Globals.assetManager.fetchModel(modelPath); if(model != null){ applyAnimationMasks(model); @@ -504,9 +501,7 @@ public class Actor { calculateNodeTransforms(model); Bone currentBone = model.getBoneMap().get(boneName); if(currentBone != null){ - AxisAngle4f axisAngle = new AxisAngle4f(); - new Matrix4f(currentBone.getFinalTransform()).getRotation(axisAngle); - Quaterniond rotation = new Quaterniond(axisAngle); + Quaterniond rotation = new Matrix4d(currentBone.getFinalTransform()).getNormalizedRotation(new Quaterniond()); rVal.set(rotation); } else { String message = "Trying to get rotation of bone that does not exist on model!\n" + diff --git a/src/main/java/electrosphere/renderer/light/LightManager.java b/src/main/java/electrosphere/renderer/light/LightManager.java index 4ecc9dee..88100ef3 100644 --- a/src/main/java/electrosphere/renderer/light/LightManager.java +++ b/src/main/java/electrosphere/renderer/light/LightManager.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; import org.joml.Matrix4d; +import org.joml.Vector3d; import org.joml.Vector3f; import org.joml.Vector3i; @@ -238,10 +239,10 @@ public class LightManager { } // //position - Vector3f modifiedCameraPos = new Vector3f(light.getPosition()).sub(CameraEntityUtils.getCameraCenter(camera)); - pointLightBuffer.putFloat(modifiedCameraPos.x); - pointLightBuffer.putFloat(modifiedCameraPos.y); - pointLightBuffer.putFloat(modifiedCameraPos.z); + Vector3d modifiedCameraPos = new Vector3d(light.getPosition()).sub(CameraEntityUtils.getCameraCenter(camera)); + pointLightBuffer.putFloat((float)modifiedCameraPos.x); + pointLightBuffer.putFloat((float)modifiedCameraPos.y); + pointLightBuffer.putFloat((float)modifiedCameraPos.z); pointLightBuffer.putFloat(1); // diff --git a/src/main/java/electrosphere/renderer/model/Mesh.java b/src/main/java/electrosphere/renderer/model/Mesh.java index 7469d6ce..0096901e 100644 --- a/src/main/java/electrosphere/renderer/model/Mesh.java +++ b/src/main/java/electrosphere/renderer/model/Mesh.java @@ -41,7 +41,6 @@ import static org.lwjgl.opengl.GL20.glEnableVertexAttribArray; import static org.lwjgl.opengl.GL20.glGetUniformLocation; import static org.lwjgl.opengl.GL20.glUniform1i; import static org.lwjgl.opengl.GL20.glUniform3fv; -import static org.lwjgl.opengl.GL20.glUniformMatrix4fv; import static org.lwjgl.opengl.GL20.glVertexAttribPointer; import static org.lwjgl.opengl.GL30.glBindVertexArray; import static org.lwjgl.opengl.GL30.glGenVertexArrays; @@ -319,8 +318,11 @@ public class Mesh { for(String key : uniforms.keySet()){ Object currentUniformRaw = uniforms.get(key); if(currentUniformRaw instanceof Matrix4f){ - Matrix4f currentUniform = (Matrix4f)currentUniformRaw; - glUniformMatrix4fv(glGetUniformLocation(openGLState.getActiveShader().getId(), key), false, currentUniform.get(new float[16])); + throw new Error("Unsupported data type!"); + } + if(currentUniformRaw instanceof Matrix4d){ + Matrix4d currentUniform = (Matrix4d)currentUniformRaw; + GL40.glUniformMatrix4dv(glGetUniformLocation(openGLState.getActiveShader().getId(), key), false, currentUniform.get(new double[16])); Globals.renderingEngine.checkError(); } if(currentUniformRaw instanceof Vector3f){ @@ -460,7 +462,7 @@ public class Mesh { Matrix4d currentMat = currentBone.getFinalTransform(); openGLState.getActiveShader().setUniform(openGLState, currentUniform, currentMat); } else { - openGLState.getActiveShader().setUniform(openGLState, currentUniform, new Matrix4f()); + openGLState.getActiveShader().setUniform(openGLState, currentUniform, new Matrix4d()); } incrementer++; } diff --git a/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java b/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java index 46edb784..93d233d9 100644 --- a/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/FirstPersonItemsPipeline.java @@ -3,7 +3,6 @@ package electrosphere.renderer.pipelines; import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Vector3d; -import org.joml.Vector3f; import org.joml.Vector4d; import org.lwjgl.opengl.GL40; @@ -55,8 +54,8 @@ public class FirstPersonItemsPipeline implements RenderPipeline { { Vector3d position = EntityUtils.getPosition(Globals.firstPersonEntity); Actor actor = EntityUtils.getActor(Globals.firstPersonEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); @@ -72,8 +71,8 @@ public class FirstPersonItemsPipeline implements RenderPipeline { for(Entity child : AttachUtils.getChildrenList(Globals.firstPersonEntity)){ Vector3d position = EntityUtils.getPosition(child); Actor actor = EntityUtils.getActor(child); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); diff --git a/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java b/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java index f0f4b86a..0d9ba00e 100644 --- a/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/MainContentNoOITPipeline.java @@ -1,7 +1,6 @@ package electrosphere.renderer.pipelines; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -65,8 +64,8 @@ public class MainContentNoOITPipeline implements RenderPipeline { ){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform RenderingEngine.modelTransformMatrix.identity(); RenderingEngine.modelTransformMatrix.translate(cameraModifiedPosition); diff --git a/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java b/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java index 619c7ace..0b23c634 100644 --- a/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/MainContentPipeline.java @@ -1,11 +1,8 @@ package electrosphere.renderer.pipelines; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Quaterniond; -import org.joml.Quaternionf; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -77,8 +74,8 @@ public class MainContentPipeline implements RenderPipeline { if(shouldDrawSolidPass(currentEntity)){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); @@ -99,16 +96,16 @@ public class MainContentPipeline implements RenderPipeline { if(InstancedActor.getInstanceModelAttribute(currentEntity) != null){ ShaderAttribute modelAttribute = InstancedActor.getInstanceModelAttribute(currentEntity); //calculate model matrix - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Quaterniond rotation = EntityUtils.getRotation(currentEntity); // modelTransformMatrix.identity(); modelTransformMatrix.identity().translationRotateScale( cameraModifiedPosition, - new Quaternionf((float)rotation.x,(float)rotation.y,(float)rotation.z,(float)rotation.w), - new Vector3f(EntityUtils.getScale(currentEntity)) + new Quaterniond(rotation), + new Vector3d(EntityUtils.getScale(currentEntity)) ); //set actor value - currentActor.setAttribute(modelAttribute, new Matrix4f(modelTransformMatrix)); + currentActor.setAttribute(modelAttribute, new Matrix4d(modelTransformMatrix)); //draw currentActor.draw(renderPipelineState, new Vector3d(cameraModifiedPosition)); } else { @@ -158,8 +155,8 @@ public class MainContentPipeline implements RenderPipeline { if(shouldDrawTransparentPass(currentEntity)){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); @@ -179,16 +176,16 @@ public class MainContentPipeline implements RenderPipeline { if(InstancedActor.getInstanceModelAttribute(currentEntity) != null){ ShaderAttribute modelAttribute = InstancedActor.getInstanceModelAttribute(currentEntity); //calculate model matrix - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); Quaterniond rotation = EntityUtils.getRotation(currentEntity); // modelTransformMatrix.identity(); modelTransformMatrix.identity().translationRotateScale( cameraModifiedPosition, - new Quaternionf((float)rotation.x,(float)rotation.y,(float)rotation.z,(float)rotation.w), - new Vector3f(EntityUtils.getScale(currentEntity)) + new Quaterniond(rotation), + new Vector3d(EntityUtils.getScale(currentEntity)) ); //set actor value - currentActor.setAttribute(modelAttribute, new Matrix4f(modelTransformMatrix)); + currentActor.setAttribute(modelAttribute, new Matrix4d(modelTransformMatrix)); //draw currentActor.draw(renderPipelineState, new Vector3d(cameraModifiedPosition)); } else { diff --git a/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java b/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java index f2421f3d..9f94e30d 100644 --- a/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/NormalsForOutlinePipeline.java @@ -2,7 +2,6 @@ package electrosphere.renderer.pipelines; import org.joml.Matrix4d; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -68,8 +67,8 @@ public class NormalsForOutlinePipeline implements RenderPipeline { if(shouldDraw(currentEntity)){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); diff --git a/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java b/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java index 6653d49a..79155388 100644 --- a/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/ShadowMapPipeline.java @@ -1,9 +1,7 @@ package electrosphere.renderer.pipelines; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -78,11 +76,11 @@ public class ShadowMapPipeline implements RenderPipeline { // float sidesMagnitude = (float)Math.sqrt(eyeDist); float sidesMagnitude = sideLength; //set matrices for light render - Matrix4f lightProjection = new Matrix4f().setOrtho(-sidesMagnitude, sidesMagnitude, -sidesMagnitude, sidesMagnitude, nearPlane, farPlane);//glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); - Matrix4f lightView = new Matrix4f().setLookAt( - new Vector3f(eyeX, eyeY, eyeZ), - new Vector3f( 0.0f, 0.0f, 0.0f), - SpatialMathUtils.getUpVectorf() + Matrix4d lightProjection = new Matrix4d().setOrtho(-sidesMagnitude, sidesMagnitude, -sidesMagnitude, sidesMagnitude, nearPlane, farPlane);//glm::ortho(-10.0f, 10.0f, -10.0f, 10.0f, near_plane, far_plane); + Matrix4d lightView = new Matrix4d().setLookAt( + new Vector3d(eyeX, eyeY, eyeZ), + new Vector3d( 0.0f, 0.0f, 0.0f), + SpatialMathUtils.getUpVector() ); Globals.lightDepthMatrix = lightProjection.mul(lightView); @@ -112,9 +110,9 @@ public class ShadowMapPipeline implements RenderPipeline { ){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraCenter = CameraEntityUtils.getCameraCenter(Globals.playerCamera); - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(cameraCenter); + //calculate camera-modified vector3d + Vector3d cameraCenter = new Vector3d(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3d cameraModifiedPosition = new Vector3d(position).sub(cameraCenter); //calculate and apply model transform modelTransformMatrix = modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); diff --git a/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java b/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java index a08fc159..ed8df79a 100644 --- a/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/VolumeBufferPipeline.java @@ -2,7 +2,6 @@ package electrosphere.renderer.pipelines; import org.joml.Matrix4d; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -71,8 +70,8 @@ public class VolumeBufferPipeline implements RenderPipeline { ){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix = modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(EntityUtils.getRotation(currentEntity)); @@ -92,8 +91,8 @@ public class VolumeBufferPipeline implements RenderPipeline { ){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //set projection matrix modelTransformMatrix = modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); @@ -128,8 +127,8 @@ public class VolumeBufferPipeline implements RenderPipeline { ){ //fetch actor Actor currentActor = EntityUtils.getActor(currentEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); //calculate and apply model transform modelTransformMatrix = modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); diff --git a/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java b/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java index 1ee7219e..3c9eae93 100644 --- a/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/debug/DebugBonesPipeline.java @@ -3,7 +3,6 @@ package electrosphere.renderer.pipelines.debug; import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import electrosphere.client.entity.camera.CameraEntityUtils; @@ -76,7 +75,7 @@ public class DebugBonesPipeline implements RenderPipeline { Quaterniond boneRot = MathBones.getBoneWorldRotation(targetEntity, bone.boneID); //put pos + rot into model - Vector3f cameraModifiedPosition = new Vector3f((float)bonePos.x,(float)bonePos.y,(float)bonePos.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + Vector3d cameraModifiedPosition = new Vector3d(bonePos).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(boneRot); diff --git a/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java b/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java index ef8b3e7b..53348608 100644 --- a/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java +++ b/src/main/java/electrosphere/renderer/pipelines/debug/DebugContentPipeline.java @@ -4,7 +4,6 @@ import org.joml.Matrix4d; import org.joml.Quaterniond; import org.joml.Quaternionf; import org.joml.Vector3d; -import org.joml.Vector3f; import org.lwjgl.opengl.GL40; import org.ode4j.ode.DCapsule; import org.ode4j.ode.DGeom; @@ -86,8 +85,8 @@ public class DebugContentPipeline implements RenderPipeline { texture.bind(openGLState); } Vector3d position = PhysicsUtils.odeVecToJomlVec(sphereView.getPosition()); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.scale(sphereView.getRadius() * 2); @@ -105,8 +104,8 @@ public class DebugContentPipeline implements RenderPipeline { texture.bind(openGLState); } Vector3d position = PhysicsUtils.odeVecToJomlVec(capsuleView.getPosition()); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); //since you're directly accessing the quat from the body, need to adjust it to be in the correct orientation @@ -141,8 +140,8 @@ public class DebugContentPipeline implements RenderPipeline { texture.bind(openGLState); } Vector3d position = PhysicsUtils.odeVecToJomlVec(sphereView.getPosition()); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.scale(sphereView.getRadius() * 2); @@ -160,8 +159,8 @@ public class DebugContentPipeline implements RenderPipeline { texture.bind(openGLState); } Vector3d position = PhysicsUtils.odeVecToJomlVec(capsuleView.getPosition()); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); //since you're directly accessing the quat from the body, need to adjust it to be in the correct orientation @@ -195,8 +194,8 @@ public class DebugContentPipeline implements RenderPipeline { texture.bind(openGLState); } Vector3d position = EntityUtils.getPosition(physicsEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(EntityUtils.getRotation(physicsEntity)); @@ -213,10 +212,9 @@ public class DebugContentPipeline implements RenderPipeline { texture.bind(openGLState); } Vector3d position = EntityUtils.getPosition(physicsEntity); - // Vector3f scale = EntityUtils.getScale(physicsEntity); Quaterniond rotation = EntityUtils.getRotation(physicsEntity); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).add(template.getOffsetX(),template.getOffsetY(),template.getOffsetZ()).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(rotation); @@ -241,10 +239,10 @@ public class DebugContentPipeline implements RenderPipeline { if((shapeGraphicsModel = Globals.assetManager.fetchModel(AssetDataStrings.UNITCUBE)) != null){ NavCube cube = (NavCube)shape; Vector3d position = new Vector3d(cube.getMinPoint()).add(cube.getMaxPoint()).mul(0.5); - Vector3f scale = new Vector3f((float)(cube.getMaxPoint().x-cube.getMinPoint().x)/2,(float)(cube.getMaxPoint().y-cube.getMinPoint().y)/2,(float)(cube.getMaxPoint().z-cube.getMinPoint().z)/2); + Vector3d scale = new Vector3d((float)(cube.getMaxPoint().x-cube.getMinPoint().x)/2,(float)(cube.getMaxPoint().y-cube.getMinPoint().y)/2,(float)(cube.getMaxPoint().z-cube.getMinPoint().z)/2); Quaternionf rotation = new Quaternionf(); - //calculate camera-modified vector3f - Vector3f cameraModifiedPosition = new Vector3f((float)position.x,(float)position.y,(float)position.z).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); + //calculate camera-modified vector3d + Vector3d cameraModifiedPosition = new Vector3d(position).sub(CameraEntityUtils.getCameraCenter(Globals.playerCamera)); modelTransformMatrix.identity(); modelTransformMatrix.translate(cameraModifiedPosition); modelTransformMatrix.rotate(rotation); diff --git a/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java b/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java index c29f4f9d..fb5840fa 100644 --- a/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java +++ b/src/main/java/electrosphere/renderer/ui/elements/ActorPanel.java @@ -232,11 +232,11 @@ public class ActorPanel extends BufferedStandardDrawableContainerElement impleme } } if(!hasOffsetFromBoundingSphere && actorModel != null){ - Globals.cameraHandler.updateRadialOffset(actorPosition); + Globals.cameraHandler.updateRadialOffset(new Vector3d(actorPosition)); double radius = actorModel.getBoundingSphere().r; this.cameraRadius = radius + DEFAULT_STANDOFF_DIST; CameraEntityUtils.setOrbitalCameraDistance(Globals.playerCamera, (float)(this.cameraRadius)); - CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3f(0,(float)(this.cameraRadius - DEFAULT_STANDOFF_DIST),0)); + CameraEntityUtils.setCameraCenter(Globals.playerCamera, new Vector3d(0,(float)(this.cameraRadius - DEFAULT_STANDOFF_DIST),0)); hasOffsetFromBoundingSphere = true; } diff --git a/src/main/java/electrosphere/server/poseactor/PoseActor.java b/src/main/java/electrosphere/server/poseactor/PoseActor.java index fc85a8b0..3d2c8d62 100644 --- a/src/main/java/electrosphere/server/poseactor/PoseActor.java +++ b/src/main/java/electrosphere/server/poseactor/PoseActor.java @@ -7,11 +7,9 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import org.joml.AxisAngle4f; import org.joml.Matrix4d; -import org.joml.Matrix4f; import org.joml.Quaterniond; -import org.joml.Vector3f; +import org.joml.Vector3d; import org.joml.Vector4d; import electrosphere.engine.Globals; @@ -418,9 +416,7 @@ public class PoseActor { calculateNodeTransforms(model); Bone currentBone = model.boneMap.get(boneName); if(currentBone != null){ - AxisAngle4f axisAngle = new AxisAngle4f(); - new Matrix4f(currentBone.getFinalTransform()).getRotation(axisAngle); - Quaterniond rotation = new Quaterniond(axisAngle); + Quaterniond rotation = new Matrix4d(currentBone.getFinalTransform()).getNormalizedRotation(new Quaterniond()); rVal.set(rotation); } } @@ -453,8 +449,8 @@ public class PoseActor { * @param boneName * @return */ - public Vector3f getBonePosition(String boneName){ - Vector3f rVal = new Vector3f(); + public Vector3d getBonePosition(String boneName){ + Vector3d rVal = new Vector3d(); PoseModel model = Globals.assetManager.fetchPoseModel(modelPath); if(model != null){ applyAnimationMasks(model);