diff --git a/common/src/main/java/org/vivecraft/client/VRPlayersClient.java b/common/src/main/java/org/vivecraft/client/VRPlayersClient.java index aa607f0a3..75bf9529c 100644 --- a/common/src/main/java/org/vivecraft/client/VRPlayersClient.java +++ b/common/src/main/java/org/vivecraft/client/VRPlayersClient.java @@ -6,12 +6,13 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.utils.Utils; +import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRData; import org.vivecraft.common.network.VrPlayerState; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; import java.util.*; import java.util.Map.Entry; @@ -54,10 +55,9 @@ public void disableVR(UUID player) { public void Update(UUID uuid, VrPlayerState vrPlayerState, float worldScale, float heightScale, boolean localPlayer) { if (localPlayer || !this.mc.player.getUUID().equals(uuid)) { - Vector3 forward = new Vector3(0.0F, 0.0F, -1.0F); - Vector3 hmdDir = vrPlayerState.hmd().orientation().multiply(forward); - Vector3 controller0Dir = vrPlayerState.controller0().orientation().multiply(forward); - Vector3 controller1Dir = vrPlayerState.controller1().orientation().multiply(forward); + Vector3f hmdDir = vrPlayerState.hmd().orientation().transformUnit(Utils.forward, new Vector3f()); + Vector3f controller0Dir = vrPlayerState.controller0().orientation().transformUnit(Utils.forward, new Vector3f()); + Vector3f controller1Dir = vrPlayerState.controller1().orientation().transformUnit(Utils.forward, new Vector3f()); var rotInfo = new RotInfo(); rotInfo.reverse = vrPlayerState.reverseHands(); rotInfo.seated = vrPlayerState.seated(); @@ -66,9 +66,9 @@ public void Update(UUID uuid, VrPlayerState vrPlayerState, float worldScale, flo rotInfo.hmd = this.donors.get(uuid); } - rotInfo.leftArmRot = new Vec3(controller1Dir.getX(), controller1Dir.getY(), controller1Dir.getZ()); - rotInfo.rightArmRot = new Vec3(controller0Dir.getX(), controller0Dir.getY(), controller0Dir.getZ()); - rotInfo.headRot = new Vec3(hmdDir.getX(), hmdDir.getY(), hmdDir.getZ()); + rotInfo.leftArmRot = new Vec3(controller1Dir.x(), controller1Dir.y(), controller1Dir.z()); + rotInfo.rightArmRot = new Vec3(controller0Dir.x(), controller0Dir.y(), controller0Dir.z()); + rotInfo.headRot = new Vec3(hmdDir.x(), hmdDir.y(), hmdDir.z()); rotInfo.Headpos = vrPlayerState.hmd().position(); rotInfo.leftArmPos = vrPlayerState.controller1().position(); rotInfo.rightArmPos = vrPlayerState.controller0().position(); @@ -184,10 +184,10 @@ public RotInfo getRotationsForPlayer(UUID uuid) { playermodelcontroller$rotinfo2.leftArmQuat = playermodelcontroller$rotinfo.leftArmQuat; playermodelcontroller$rotinfo2.rightArmQuat = playermodelcontroller$rotinfo.rightArmQuat; playermodelcontroller$rotinfo2.headQuat = playermodelcontroller$rotinfo.headQuat; - Vector3 vector3 = new Vector3(0.0F, 0.0F, -1.0F); - playermodelcontroller$rotinfo2.leftArmRot = Utils.vecLerp(playermodelcontroller$rotinfo1.leftArmRot, Utils.convertToVector3d(playermodelcontroller$rotinfo2.leftArmQuat.multiply(vector3)), f); - playermodelcontroller$rotinfo2.rightArmRot = Utils.vecLerp(playermodelcontroller$rotinfo1.rightArmRot, Utils.convertToVector3d(playermodelcontroller$rotinfo2.rightArmQuat.multiply(vector3)), f); - playermodelcontroller$rotinfo2.headRot = Utils.vecLerp(playermodelcontroller$rotinfo1.headRot, Utils.convertToVector3d(playermodelcontroller$rotinfo2.headQuat.multiply(vector3)), f); + Vector3f vector3 = new Vector3f(0.0F, 0.0F, -1.0F); + playermodelcontroller$rotinfo2.leftArmRot = Utils.vecLerp(playermodelcontroller$rotinfo1.leftArmRot, Utils.convertToVec3(playermodelcontroller$rotinfo2.leftArmQuat.transformUnit(vector3, new Vector3f())), f); + playermodelcontroller$rotinfo2.rightArmRot = Utils.vecLerp(playermodelcontroller$rotinfo1.rightArmRot, Utils.convertToVec3(playermodelcontroller$rotinfo2.rightArmQuat.transformUnit(vector3, new Vector3f())), f); + playermodelcontroller$rotinfo2.headRot = Utils.vecLerp(playermodelcontroller$rotinfo1.headRot, Utils.convertToVec3(playermodelcontroller$rotinfo2.headQuat.transformUnit(vector3, new Vector3f())), f); playermodelcontroller$rotinfo2.heightScale = playermodelcontroller$rotinfo.heightScale; playermodelcontroller$rotinfo2.worldScale = playermodelcontroller$rotinfo.worldScale; return playermodelcontroller$rotinfo2; @@ -198,12 +198,9 @@ public RotInfo getRotationsForPlayer(UUID uuid) { public static RotInfo getMainPlayerRotInfo(VRData data) { RotInfo playermodelcontroller$rotinfo = new RotInfo(); - Quaternion quaternion = new Quaternion(data.getController(1).getMatrix()); - Quaternion quaternion1 = new Quaternion(data.getController(0).getMatrix()); - Quaternion quaternion2 = new Quaternion(data.hmd.getMatrix()); - playermodelcontroller$rotinfo.headQuat = quaternion2; - playermodelcontroller$rotinfo.leftArmQuat = quaternion; - playermodelcontroller$rotinfo.rightArmQuat = quaternion1; + playermodelcontroller$rotinfo.headQuat = new Quaternionf().setFromNormalized(data.hmd.getMatrix(new Matrix4f())).invert(); + playermodelcontroller$rotinfo.leftArmQuat = new Quaternionf().setFromNormalized(data.getController(1).getMatrix(new Matrix4f())).invert(); + playermodelcontroller$rotinfo.rightArmQuat = new Quaternionf().setFromNormalized(data.getController(0).getMatrix(new Matrix4f())).invert(); playermodelcontroller$rotinfo.seated = ClientDataHolderVR.getInstance().vrSettings.seated; playermodelcontroller$rotinfo.leftArmPos = data.getController(1).getPosition(); playermodelcontroller$rotinfo.rightArmPos = data.getController(0).getPosition(); @@ -221,8 +218,10 @@ public static float getFacingYaw(RotInfo rotInfo) { return (float) Math.toDegrees(Math.atan2(vec3.x, vec3.z)); } - public static Vec3 getOrientVec(Quaternion quat) { - Vec3 vec3 = quat.multiply(new Vec3(0.0D, 0.0D, -1.0D)).cross(quat.multiply(new Vec3(0.0D, 1.0D, 0.0D))).normalize(); + public static Vec3 getOrientVec(Quaternionf quat) { + Vec3 vec = new Vec3(0.0D, 1.0D, 0.0D); + Vec3 vec1 = new Vec3(0.0D, 0.0D, -1.0D); + Vec3 vec3 = Utils.convertToVec3(quat.transformUnit(new Vector3f((float) vec1.x, (float) vec1.y, (float) vec1.z), new Vector3f())).cross(Utils.convertToVec3(quat.transform(new Vector3f((float) vec.x, (float) vec.y, (float) vec.z), new Vector3f()))).normalize(); return (new Vec3(0.0D, 1.0D, 0.0D)).cross(vec3).normalize(); } @@ -230,9 +229,9 @@ public static class RotInfo { public boolean seated; public boolean reverse; public int hmd = 0; - public Quaternion leftArmQuat; - public Quaternion rightArmQuat; - public Quaternion headQuat; + public Quaternionf leftArmQuat; + public Quaternionf rightArmQuat; + public Quaternionf headQuat; public Vec3 leftArmRot; public Vec3 rightArmRot; public Vec3 headRot; diff --git a/common/src/main/java/org/vivecraft/client/utils/Debug.java b/common/src/main/java/org/vivecraft/client/utils/Debug.java index b3cc7917e..c9251dd3d 100644 --- a/common/src/main/java/org/vivecraft/client/utils/Debug.java +++ b/common/src/main/java/org/vivecraft/client/utils/Debug.java @@ -10,15 +10,19 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; +import org.joml.Math; +import org.joml.Quaternionf; +import org.joml.Vector3f; +import org.vivecraft.common.utils.Utils; import java.awt.*; import java.util.ArrayList; +import static java.lang.Math.pow; + public class Debug { Vec3 root; - Quaternion rotation; + Quaternionf rotation; public static boolean isEnabled = true; static Polygon cross = new Polygon(6); static Polygon arrowHead = new Polygon(8); @@ -26,16 +30,16 @@ public class Debug { public Debug(Vec3 root) { this.root = root; - this.rotation = new Quaternion(); + this.rotation = new Quaternionf(); } - public Debug(Vec3 root, Quaternion rotation) { + public Debug(Vec3 root, Quaternionf rotation) { this.root = root; this.rotation = rotation; } public void drawPoint(Vec3 point, Color color) { - point = this.rotation.multiply(point); + point = Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) point.x, (float) point.y, (float) point.z), new Vector3f())); Vec3 vec3 = this.root.add(point); Polygon debug$polygon = cross.offset(vec3); @@ -50,13 +54,27 @@ public void drawPoint(Vec3 point, Color color) { public void drawVector(Vec3 start, Vec3 direction, Color color) { Polygon debug$polygon = new Polygon(2); - start = this.rotation.multiply(start); - direction = this.rotation.multiply(direction); + start = Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) start.x, (float) start.y, (float) start.z), new Vector3f())); + direction = Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) direction.x, (float) direction.y, (float) direction.z), new Vector3f())); debug$polygon.vertices[0] = this.root.add(start); debug$polygon.colors[0] = new Color(0, 0, 0, 0); debug$polygon.vertices[1] = this.root.add(start).add(direction); debug$polygon.colors[1] = color; - Quaternion quaternion = Quaternion.createFromToVector(new Vector3(0.0F, 1.0F, 0.0F), new Vector3(direction.normalize())); + Vec3 normalized = direction.normalize(); + Vector3f to = new Vector3f((float) normalized.x(), (float) normalized.y(), (float) normalized.z()); + Vector3f vector3 = Utils.up.cross(to, new Vector3f()); + float f = (float) (Math.sqrt(pow(Utils.up.length(), 2.0D) * pow(to.length(), 2.0D)) + (double) Utils.up.dot(to)); + Quaternionf quaternion1 = (new Quaternionf(vector3.x, vector3.y, vector3.z, f)); + Quaternionf dest = new Quaternionf(); + float f4 = Math.sqrt(quaternion1.lengthSquared()); + + if (f4 > 0.0F) { + dest.normalize(); + } else { + dest.identity(); + } + + Quaternionf quaternion = dest; Polygon debug$polygon1 = arrowHead.rotated(quaternion).offset(this.root.add(start).add(direction)); for (int i = 0; i < debug$polygon1.colors.length; ++i) { @@ -70,8 +88,8 @@ public void drawVector(Vec3 start, Vec3 direction, Color color) { } public void drawLine(Vec3 start, Vec3 end, Color color) { - start = this.rotation.multiply(start); - end = this.rotation.multiply(end); + start = Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) start.x, (float) start.y, (float) start.z), new Vector3f())); + end = Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) end.x, (float) end.y, (float) end.z), new Vector3f())); Polygon debug$polygon = new Polygon(2); debug$polygon.vertices[0] = this.root.add(start); debug$polygon.colors[0] = new Color(0, 0, 0, 0); @@ -95,8 +113,8 @@ public void drawBoundingBox(AABB box, Color color) { avec31[3] = new Vec3(box.maxX, box.maxY, box.minZ); for (int j = 0; j < 4; ++j) { - avec3[j] = this.root.add(this.rotation.multiply(avec3[j])); - avec31[j] = this.root.add(this.rotation.multiply(avec31[j])); + avec3[j] = this.root.add(Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) avec3[j].x, (float) avec3[j].y, (float) avec3[j].z), new Vector3f()))); + avec31[j] = this.root.add(Utils.convertToVec3(this.rotation.transformUnit(new Vector3f((float) avec31[j].x, (float) avec31[j].y, (float) avec31[j].z), new Vector3f()))); } for (int k = 0; k < 5; ++k) { @@ -221,11 +239,11 @@ public Polygon offset(Vec3 offset) { return debug$polygon; } - public Polygon rotated(Quaternion quat) { + public Polygon rotated(Quaternionf quat) { Polygon debug$polygon = new Polygon(this.vertices.length); for (int i = 0; i < this.vertices.length; ++i) { - debug$polygon.vertices[i] = quat.multiply(new Vector3(this.vertices[i])).toVector3d(); + debug$polygon.vertices[i] = Utils.convertToVec3(quat.transformUnit(new Vector3f((float) this.vertices[i].x, (float) this.vertices[i].y, (float) this.vertices[i].z), new Vector3f())); debug$polygon.colors[i] = this.colors[i]; } diff --git a/common/src/main/java/org/vivecraft/client/utils/Utils.java b/common/src/main/java/org/vivecraft/client/utils/Utils.java deleted file mode 100644 index d8baba3f4..000000000 --- a/common/src/main/java/org/vivecraft/client/utils/Utils.java +++ /dev/null @@ -1,881 +0,0 @@ -package org.vivecraft.client.utils; - -import com.google.common.base.Charsets; -import com.google.common.collect.Lists; -import com.google.common.io.Files; -import com.mojang.blaze3d.pipeline.RenderTarget; -import net.minecraft.ChatFormatting; -import net.minecraft.client.ComponentCollector; -import net.minecraft.client.Minecraft; -import net.minecraft.client.Screenshot; -import net.minecraft.client.gui.Font; -import net.minecraft.client.renderer.LevelRenderer; -import net.minecraft.core.BlockPos; -import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.network.chat.FormattedText; -import net.minecraft.network.chat.Style; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.Resource; -import net.minecraft.world.level.BlockAndTintGetter; -import net.minecraft.world.phys.Vec3; -import org.apache.commons.io.IOUtils; -import org.apache.logging.log4j.LogManager; -import org.lwjgl.openvr.HmdMatrix44; -import org.vivecraft.client.Xplat; -import org.vivecraft.client_vr.render.VRShaders; -import org.vivecraft.client_vr.utils.LoaderUtils; -import org.vivecraft.common.utils.lwjgl.*; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector2; -import org.vivecraft.common.utils.math.Vector3; - -import javax.annotation.Nullable; -import java.io.*; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class Utils { - private static final char[] illegalChars = new char[]{'"', '<', '>', '|', '\u0000', '\u0001', '\u0002', '\u0003', '\u0004', '\u0005', '\u0006', '\u0007', '\b', '\t', '\n', '\u000b', '\f', '\r', '\u000e', '\u000f', '\u0010', '\u0011', '\u0012', '\u0013', '\u0014', '\u0015', '\u0016', '\u0017', '\u0018', '\u0019', '\u001a', '\u001b', '\u001c', '\u001d', '\u001e', '\u001f', ':', '*', '?', '\\', '/'}; - private static final int CONNECT_TIMEOUT = 5000; - private static final int READ_TIMEOUT = 20000; - private static final Random avRandomizer = new Random(); - - public static String sanitizeFileName(String fileName) { - StringBuilder stringbuilder = new StringBuilder(); - - for (int i = 0; i < fileName.length(); ++i) { - char c0 = fileName.charAt(i); - - if (Arrays.binarySearch(illegalChars, c0) < 0) { - stringbuilder.append(c0); - } else { - stringbuilder.append('_'); - } - } - - return stringbuilder.toString(); - } - - public static Vector3 convertToOVRVector(Vector3f vector) { - return new Vector3(vector.x, vector.y, vector.z); - } - - public static Vector3 convertToOVRVector(Vec3 vector) { - return new Vector3((float) vector.x, (float) vector.y, (float) vector.z); - } - - public static Matrix4f convertOVRMatrix(org.vivecraft.common.utils.math.Matrix4f matrix) { - Matrix4f matrix4f = new Matrix4f(); - matrix4f.m00 = matrix.M[0][0]; - matrix4f.m01 = matrix.M[0][1]; - matrix4f.m02 = matrix.M[0][2]; - matrix4f.m03 = matrix.M[0][3]; - matrix4f.m10 = matrix.M[1][0]; - matrix4f.m11 = matrix.M[1][1]; - matrix4f.m12 = matrix.M[1][2]; - matrix4f.m13 = matrix.M[1][3]; - matrix4f.m20 = matrix.M[2][0]; - matrix4f.m21 = matrix.M[2][1]; - matrix4f.m22 = matrix.M[2][2]; - matrix4f.m23 = matrix.M[2][3]; - matrix4f.m30 = matrix.M[3][0]; - matrix4f.m31 = matrix.M[3][1]; - matrix4f.m32 = matrix.M[3][2]; - matrix4f.m33 = matrix.M[3][3]; - matrix4f.transpose(matrix4f); - return matrix4f; - } - - public static org.vivecraft.common.utils.math.Matrix4f convertToOVRMatrix(Matrix4f matrixIn) { - Matrix4f matrix4f = new Matrix4f(); - matrixIn.transpose(matrix4f); - org.vivecraft.common.utils.math.Matrix4f matrix4f1 = new org.vivecraft.common.utils.math.Matrix4f(); - matrix4f1.M[0][0] = matrix4f.m00; - matrix4f1.M[0][1] = matrix4f.m01; - matrix4f1.M[0][2] = matrix4f.m02; - matrix4f1.M[0][3] = matrix4f.m03; - matrix4f1.M[1][0] = matrix4f.m10; - matrix4f1.M[1][1] = matrix4f.m11; - matrix4f1.M[1][2] = matrix4f.m12; - matrix4f1.M[1][3] = matrix4f.m13; - matrix4f1.M[2][0] = matrix4f.m20; - matrix4f1.M[2][1] = matrix4f.m21; - matrix4f1.M[2][2] = matrix4f.m22; - matrix4f1.M[2][3] = matrix4f.m23; - matrix4f1.M[3][0] = matrix4f.m30; - matrix4f1.M[3][1] = matrix4f.m31; - matrix4f1.M[3][2] = matrix4f.m32; - matrix4f1.M[3][3] = matrix4f.m33; - return matrix4f1; - } - - public static double lerp(double from, double to, double percent) { - return from + (to - from) * percent; - } - - public static double lerpMod(double from, double to, double percent, double mod) { - return Math.abs(to - from) < mod / 2.0D ? from + (to - from) * percent : from + (to - from - Math.signum(to - from) * mod) * percent; - } - - public static double absLerp(double value, double target, double stepSize) { - double d0 = Math.abs(stepSize); - - if (target - value > d0) { - return value + d0; - } else { - return target - value < -d0 ? value - d0 : target; - } - } - - public static float angleDiff(float a, float b) { - float f = Math.abs(a - b) % 360.0F; - float f1 = f > 180.0F ? 360.0F - f : f; - int i = (!(a - b >= 0.0F) || !(a - b <= 180.0F)) && (!(a - b <= -180.0F) || !(a - b >= -360.0F)) ? -1 : 1; - return f1 * (float) i; - } - - public static float angleNormalize(float angle) { - angle = angle % 360.0F; - - if (angle < 0.0F) { - angle += 360.0F; - } - - return angle; - } - - public static Vector3f directionFromMatrix(Matrix4f matrix, float x, float y, float z) { - Vector4f vector4f = new Vector4f(x, y, z, 0.0F); - Matrix4f.transform(matrix, vector4f, vector4f); - vector4f.normalise(vector4f); - return new Vector3f(vector4f.x, vector4f.y, vector4f.z); - } - - public static void wordWrap(String in, int length, ArrayList wrapped) { - // can't wrap with length 0, so return the original string - if (length == 0) { - wrapped.add(in); - return; - } - String s = "\n"; - boolean flag = false; - in = in.replace("\r", ""); - - if (in.length() < length) { - flag = true; - length = in.length(); - } - - if (in.substring(0, length).contains(s)) { - String s2 = in.substring(0, in.indexOf(s)).trim(); - wrapped.add(s2); - wordWrap(in.substring(in.indexOf(s) + 1), length, wrapped); - } else if (flag) { - wrapped.add(in); - } else { - int i = Math.max(Math.max(in.lastIndexOf(" ", length), in.lastIndexOf("\t", length)), in.lastIndexOf("-", length)); - - if (i == -1) { - i = length; - } - - String s1 = in.substring(0, i).trim(); - wrapped.add(s1); - wordWrap(in.substring(i), length, wrapped); - } - } - - public static Vector2f convertVector(Vector2 vector) { - return new Vector2f(vector.getX(), vector.getY()); - } - - public static Vector2 convertVector(Vector2f vector) { - return new Vector2(vector.getX(), vector.getY()); - } - - public static Vector3f convertVector(Vector3 vector) { - return new Vector3f(vector.getX(), vector.getY(), vector.getZ()); - } - - public static Vector3 convertVector(Vector3f vector) { - return new Vector3(vector.getX(), vector.getY(), vector.getZ()); - } - - public static Vector3 convertVector(Vec3 vector) { - return new Vector3((float) vector.x, (float) vector.y, (float) vector.z); - } - - public static Vector3f convertToVector3f(Vec3 vector) { - return new Vector3f((float) vector.x, (float) vector.y, (float) vector.z); - } - - public static Vec3 convertToVector3d(Vector3 vector) { - return new Vec3(vector.getX(), vector.getY(), vector.getZ()); - } - - public static Vec3 convertToVector3d(Vector3f vector) { - return new Vec3(vector.x, vector.y, vector.z); - } - - public static Vector3f transformVector(Matrix4f matrix, Vector3f vector, boolean point) { - Vector4f vector4f = Matrix4f.transform(matrix, new Vector4f(vector.x, vector.y, vector.z, point ? 1.0F : 0.0F), null); - return new Vector3f(vector4f.x, vector4f.y, vector4f.z); - } - - public static Quaternion quatLerp(Quaternion start, Quaternion end, float fraction) { - Quaternion quaternion = new Quaternion(); - quaternion.w = start.w + (end.w - start.w) * fraction; - quaternion.x = start.x + (end.x - start.x) * fraction; - quaternion.y = start.y + (end.y - start.y) * fraction; - quaternion.z = start.z + (end.z - start.z) * fraction; - return quaternion; - } - - public static Matrix4f matrix3to4(Matrix3f matrix) { - Matrix4f matrix4f = new Matrix4f(); - matrix4f.m00 = matrix.m00; - matrix4f.m01 = matrix.m01; - matrix4f.m02 = matrix.m02; - matrix4f.m10 = matrix.m10; - matrix4f.m11 = matrix.m11; - matrix4f.m12 = matrix.m12; - matrix4f.m20 = matrix.m20; - matrix4f.m21 = matrix.m21; - matrix4f.m22 = matrix.m22; - return matrix4f; - } - - public static InputStream getAssetAsStream(String name, boolean required) { - InputStream inputstream = null; - - try { - try { - Optional resource = Minecraft.getInstance().getResourceManager().getResource(new ResourceLocation("vivecraft", name)); - if (resource.isPresent()) { - inputstream = resource.get().open(); - } - } catch (NullPointerException | FileNotFoundException filenotfoundexception) { - inputstream = VRShaders.class.getResourceAsStream("/assets/vivecraft/" + name); - } - - if (inputstream == null) { - Path path1 = Paths.get(System.getProperty("user.dir")); - - if (path1.getParent() != null) { - Path path = path1.getParent().resolve("src/resources/assets/vivecraft/" + name); - - if (!path.toFile().exists() && path1.getParent().getParent() != null) { - path = path1.getParent().getParent().resolve("resources/assets/vivecraft/" + name); - } - - if (path.toFile().exists()) { - inputstream = new FileInputStream(path.toFile()); - } - } - } - } catch (Exception exception) { - handleAssetException(exception, name, required); - return null; - } - - if (inputstream == null) { - handleAssetException(new FileNotFoundException(name), name, required); - } - - return inputstream; - } - - public static byte[] loadAsset(String name, boolean required) { - InputStream inputstream = getAssetAsStream(name, required); - - if (inputstream == null) { - return null; - } else { - try { - byte[] abyte = IOUtils.toByteArray(inputstream); - inputstream.close(); - return abyte; - } catch (Exception exception) { - handleAssetException(exception, name, required); - return null; - } - } - } - - public static String loadAssetAsString(String name, boolean required) { - byte[] abyte = loadAsset(name, required); - return abyte == null ? null : new String(abyte, Charsets.UTF_8); - } - - public static void loadAssetToFile(String name, File file, boolean required) { - InputStream inputstream = getAssetAsStream(name, required); - - if (inputstream != null) { - try { - writeStreamToFile(inputstream, file); - inputstream.close(); - } catch (Exception exception) { - handleAssetException(exception, name, required); - } - } - } - - private static void handleAssetException(Throwable e, String name, boolean required) { - if (required) { - throw new RuntimeException("Failed to load asset: " + name, e); - } else { - System.out.println("Failed to load asset: " + name); - e.printStackTrace(); - } - } - - public static void unpackNatives(String directory) { - try { - (new File("openvr/" + directory)).mkdirs(); - - try { - Path path = Paths.get(System.getProperty("user.dir")); - Path path1 = path.getParent().resolve("src/resources/natives/" + directory); - - if (!path1.toFile().exists()) { - path1 = path.getParent().getParent().resolve("resources/natives/" + directory); - } - - if (path1.toFile().exists()) { - System.out.println("Copying " + directory + " natives..."); - - for (File file1 : path1.toFile().listFiles()) { - System.out.println(file1.getName()); - Files.copy(file1, new File("openvr/" + directory + "/" + file1.getName())); - } - - return; - } - } catch (Exception exception) { - } - - System.out.println("Unpacking " + directory + " natives..."); - - Path jarPath = Xplat.getJarPath(); - boolean didExtractSomething = false; - try (Stream natives = java.nio.file.Files.list(jarPath.resolve("natives/" + directory))) { - for (Path file : natives.collect(Collectors.toCollection(ArrayList::new))) { - didExtractSomething = true; - System.out.println(file); - java.nio.file.Files.copy(file, new File("openvr/" + directory + "/" + file.getFileName()).toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); - } - } catch (IOException e) { - System.out.println("Failed to unpack natives from jar"); - } - if (!didExtractSomething) { - ZipFile zipfile = LoaderUtils.getVivecraftZip(); - Enumeration enumeration = zipfile.entries(); - - while (enumeration.hasMoreElements()) { - ZipEntry zipentry = enumeration.nextElement(); - - if (zipentry.getName().startsWith("natives/" + directory)) { - String s = Paths.get(zipentry.getName()).getFileName().toString(); - System.out.println(s); - writeStreamToFile(zipfile.getInputStream(zipentry), new File("openvr/" + directory + "/" + s)); - } - } - - zipfile.close(); - } - } catch (Exception exception1) { - System.out.println("Failed to unpack natives"); - exception1.printStackTrace(); - } - } - - - public static void writeStreamToFile(InputStream is, File file) throws IOException { - FileOutputStream fileoutputstream = new FileOutputStream(file); - byte[] abyte = new byte[4096]; - int i; - - while ((i = is.read(abyte, 0, abyte.length)) != -1) { - fileoutputstream.write(abyte, 0, i); - } - - fileoutputstream.flush(); - fileoutputstream.close(); - is.close(); - } - - public static String httpReadLine(String url) throws IOException { - HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); - httpurlconnection.setConnectTimeout(5000); - httpurlconnection.setReadTimeout(20000); - httpurlconnection.setUseCaches(false); - httpurlconnection.setDoInput(true); - BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream())); - String s = bufferedreader.readLine(); - bufferedreader.close(); - httpurlconnection.disconnect(); - return s; - } - - public static List httpReadAllLines(String url) throws IOException { - HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); - httpurlconnection.setConnectTimeout(5000); - httpurlconnection.setReadTimeout(20000); - httpurlconnection.setUseCaches(false); - httpurlconnection.setDoInput(true); - BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream())); - ArrayList arraylist = new ArrayList<>(); - String s; - - while ((s = bufferedreader.readLine()) != null) { - arraylist.add(s); - } - - bufferedreader.close(); - httpurlconnection.disconnect(); - return arraylist; - } - - public static byte[] httpReadAll(String url) throws IOException { - HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); - httpurlconnection.setConnectTimeout(5000); - httpurlconnection.setReadTimeout(20000); - httpurlconnection.setUseCaches(false); - httpurlconnection.setDoInput(true); - InputStream inputstream = httpurlconnection.getInputStream(); - ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(httpurlconnection.getContentLength()); - byte[] abyte = new byte[4096]; - int i; - - while ((i = inputstream.read(abyte, 0, abyte.length)) != -1) { - bytearrayoutputstream.write(abyte, 0, i); - } - - inputstream.close(); - httpurlconnection.disconnect(); - return bytearrayoutputstream.toByteArray(); - } - - public static String httpReadAllString(String url) throws IOException { - return new String(httpReadAll(url), StandardCharsets.UTF_8); - } - - public static void httpReadToFile(String url, File file, boolean writeWhenComplete) throws IOException { - HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); - httpurlconnection.setConnectTimeout(5000); - httpurlconnection.setReadTimeout(20000); - httpurlconnection.setUseCaches(false); - httpurlconnection.setDoInput(true); - InputStream inputstream = httpurlconnection.getInputStream(); - - if (writeWhenComplete) { - ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(httpurlconnection.getContentLength()); - byte[] abyte = new byte[4096]; - int i; - - while ((i = inputstream.read(abyte, 0, abyte.length)) != -1) { - bytearrayoutputstream.write(abyte, 0, i); - } - - OutputStream outputstream = new FileOutputStream(file); - outputstream.write(bytearrayoutputstream.toByteArray()); - outputstream.flush(); - outputstream.close(); - } else { - OutputStream outputstream1 = new FileOutputStream(file); - byte[] abyte1 = new byte[4096]; - int j; - - while ((j = inputstream.read(abyte1, 0, abyte1.length)) != -1) { - outputstream1.write(abyte1, 0, j); - } - - outputstream1.flush(); - outputstream1.close(); - } - - inputstream.close(); - httpurlconnection.disconnect(); - } - - public static void httpReadToFile(String url, File file) throws IOException { - httpReadToFile(url, file, false); - } - - public static List httpReadList(String url) throws IOException { - HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); - httpurlconnection.setConnectTimeout(5000); - httpurlconnection.setReadTimeout(20000); - httpurlconnection.setUseCaches(false); - httpurlconnection.setDoInput(true); - BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream())); - List list = new ArrayList<>(); - String s; - - while ((s = bufferedreader.readLine()) != null) { - list.add(s); - } - - bufferedreader.close(); - httpurlconnection.disconnect(); - return list; - } - - public static String getFileChecksum(File file, String algorithm) throws IOException, NoSuchAlgorithmException { - InputStream inputstream = new FileInputStream(file); - byte[] abyte = new byte[(int) file.length()]; - inputstream.read(abyte); - inputstream.close(); - MessageDigest messagedigest = MessageDigest.getInstance(algorithm); - messagedigest.update(abyte); - Formatter formatter = new Formatter(); - - for (byte b0 : messagedigest.digest()) { - formatter.format("%02x", b0); - } - - String s = formatter.toString(); - formatter.close(); - return s; - } - - public static byte[] readFile(File file) throws IOException { - FileInputStream fileinputstream = new FileInputStream(file); - return readFully(fileinputstream); - } - - public static String readFileString(File file) throws IOException { - return new String(readFile(file), StandardCharsets.UTF_8); - } - - public static byte[] readFully(InputStream in) throws IOException { - ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); - byte[] abyte = new byte[4096]; - int i; - - while ((i = in.read(abyte, 0, abyte.length)) != -1) { - bytearrayoutputstream.write(abyte, 0, i); - } - - in.close(); - return bytearrayoutputstream.toByteArray(); - } - - public static Quaternion slerp(Quaternion start, Quaternion end, float alpha) { - float f = start.x * end.x + start.y * end.y + start.z * end.z + start.w * end.w; - float f1 = f < 0.0F ? -f : f; - float f2 = 1.0F - alpha; - float f3 = alpha; - - if ((double) (1.0F - f1) > 0.1D) { - float f4 = (float) Math.acos(f1); - float f5 = 1.0F / (float) Math.sin(f4); - f2 = (float) Math.sin((1.0F - alpha) * f4) * f5; - f3 = (float) Math.sin(alpha * f4) * f5; - } - - if (f < 0.0F) { - f3 = -f3; - } - - float f8 = f2 * start.x + f3 * end.x; - float f9 = f2 * start.y + f3 * end.y; - float f6 = f2 * start.z + f3 * end.z; - float f7 = f2 * start.w + f3 * end.w; - return new Quaternion(f7, f8, f9, f6); - } - - public static Vec3 vecLerp(Vec3 start, Vec3 end, double fraction) { - double d0 = start.x + (end.x - start.x) * fraction; - double d1 = start.y + (end.y - start.y) * fraction; - double d2 = start.z + (end.z - start.z) * fraction; - return new Vec3(d0, d1, d2); - } - - public static float applyDeadzone(float axis, float deadzone) { - float f = 1.0F / (1.0F - deadzone); - float f1 = 0.0F; - - if (Math.abs(axis) > deadzone) { - f1 = (Math.abs(axis) - deadzone) * f * Math.signum(axis); - } - - return f1; - } - - public static void spawnParticles(ParticleOptions type, int count, Vec3 position, Vec3 size, double speed) { - Minecraft minecraft = Minecraft.getInstance(); - - for (int i = 0; i < count; ++i) { - double d0 = avRandomizer.nextGaussian() * size.x; - double d1 = avRandomizer.nextGaussian() * size.y; - double d2 = avRandomizer.nextGaussian() * size.z; - double d3 = avRandomizer.nextGaussian() * speed; - double d4 = avRandomizer.nextGaussian() * speed; - double d5 = avRandomizer.nextGaussian() * speed; - - try { - minecraft.level.addParticle(type, position.x + d0, position.y + d1, position.z + d2, d3, d4, d5); - } catch (Throwable throwable) { - LogManager.getLogger().warn("Could not spawn particle effect {}", type); - return; - } - } - } - - public static int getCombinedLightWithMin(BlockAndTintGetter lightReader, BlockPos pos, int minLight) { - int i = LevelRenderer.getLightColor(lightReader, pos); - int j = i >> 4 & 15; - - if (j < minLight) { - i = i & -256; - i = i | minLight << 4; - } - - return i; - } - - public static void takeScreenshot(RenderTarget fb) { - Minecraft minecraft = Minecraft.getInstance(); - Screenshot.grab(minecraft.gameDirectory, fb, (text) -> - { - minecraft.execute(() -> { - minecraft.gui.getChat().addMessage(text); - }); - }); - } - - public static List wrapText(FormattedText text, int width, Font fontRenderer, @Nullable FormattedText linePrefix) { - ComponentCollector componentcollector = new ComponentCollector(); - text.visit((style, str) -> - { - componentcollector.append(FormattedText.of(str, style)); - return Optional.empty(); - }, Style.EMPTY); - List list = Lists.newArrayList(); - fontRenderer.getSplitter().splitLines(componentcollector.getResultOrEmpty(), width, Style.EMPTY, (lineText, sameLine) -> - { - list.add(sameLine && linePrefix != null ? FormattedText.composite(linePrefix, lineText) : lineText); - }); - return list.isEmpty() ? Lists.newArrayList(FormattedText.EMPTY) : list; - } - - public static List styleToFormats(Style style) { - if (style.isEmpty()) { - return new ArrayList<>(); - } else { - ArrayList arraylist = new ArrayList<>(); - - if (style.getColor() != null) { - arraylist.add(ChatFormatting.getByName(style.getColor().serialize())); - } - - if (style.isBold()) { - arraylist.add(ChatFormatting.BOLD); - } - - if (style.isItalic()) { - arraylist.add(ChatFormatting.ITALIC); - } - - if (style.isStrikethrough()) { - arraylist.add(ChatFormatting.STRIKETHROUGH); - } - - if (style.isUnderlined()) { - arraylist.add(ChatFormatting.UNDERLINE); - } - - if (style.isObfuscated()) { - arraylist.add(ChatFormatting.OBFUSCATED); - } - - return arraylist; - } - } - - public static String formatsToString(List formats) { - if (formats.size() == 0) { - return ""; - } else { - StringBuilder stringbuilder = new StringBuilder(); - formats.forEach(stringbuilder::append); - return stringbuilder.toString(); - } - } - - public static String styleToFormatString(Style style) { - return formatsToString(styleToFormats(style)); - } - - public static long microTime() { - return System.nanoTime() / 1000L; - } - - public static long milliTime() { - return System.nanoTime() / 1000000L; - } - - public static void printStackIfContainsClass(String className) { - StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace(); - boolean flag = false; - - for (StackTraceElement stacktraceelement : astacktraceelement) { - if (stacktraceelement.getClassName().equals(className)) { - flag = true; - break; - } - } - - if (flag) { - Thread.dumpStack(); - } - } - - public static org.joml.Matrix4f Matrix4fFromOpenVR(HmdMatrix44 in) { - return new org.joml.Matrix4f(in.m(0), in.m(4), in.m(8), in.m(12), - in.m(1), in.m(5), in.m(9), in.m(13), - in.m(2), in.m(6), in.m(10), in.m(14), - in.m(3), in.m(7), in.m(11), in.m(15)); - } - - public static Quaternion convertMatrix4ftoRotationQuat(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22) { - double d0 = m00 * m00 + m10 * m10 + m20 * m20; - - if (d0 != 1.0D && d0 != 0.0D) { - d0 = 1.0D / Math.sqrt(d0); - m00 = (float) ((double) m00 * d0); - m10 = (float) ((double) m10 * d0); - m20 = (float) ((double) m20 * d0); - } - - d0 = m01 * m01 + m11 * m11 + m21 * m21; - - if (d0 != 1.0D && d0 != 0.0D) { - d0 = 1.0D / Math.sqrt(d0); - m01 = (float) ((double) m01 * d0); - m11 = (float) ((double) m11 * d0); - m21 = (float) ((double) m21 * d0); - } - - d0 = m02 * m02 + m12 * m12 + m22 * m22; - - if (d0 != 1.0D && d0 != 0.0D) { - d0 = 1.0D / Math.sqrt(d0); - m02 = (float) ((double) m02 * d0); - m12 = (float) ((double) m12 * d0); - m22 = (float) ((double) m22 * d0); - } - - float f = m00 + m11 + m22; - Quaternion quaternion = new Quaternion(); - - if (f >= 0.0F) { - double d1 = Math.sqrt(f + 1.0F); - quaternion.w = (float) (0.5D * d1); - d1 = 0.5D / d1; - quaternion.x = (float) ((double) (m21 - m12) * d1); - quaternion.y = (float) ((double) (m02 - m20) * d1); - quaternion.z = (float) ((double) (m10 - m01) * d1); - } else if (m00 > m11 && m00 > m22) { - double d4 = Math.sqrt(1.0D + (double) m00 - (double) m11 - (double) m22); - quaternion.x = (float) (d4 * 0.5D); - d4 = 0.5D / d4; - quaternion.y = (float) ((double) (m10 + m01) * d4); - quaternion.z = (float) ((double) (m02 + m20) * d4); - quaternion.w = (float) ((double) (m21 - m12) * d4); - } else if (m11 > m22) { - double d2 = Math.sqrt(1.0D + (double) m11 - (double) m00 - (double) m22); - quaternion.y = (float) (d2 * 0.5D); - d2 = 0.5D / d2; - quaternion.x = (float) ((double) (m10 + m01) * d2); - quaternion.z = (float) ((double) (m21 + m12) * d2); - quaternion.w = (float) ((double) (m02 - m20) * d2); - } else { - double d3 = Math.sqrt(1.0D + (double) m22 - (double) m00 - (double) m11); - quaternion.z = (float) (d3 * 0.5D); - d3 = 0.5D / d3; - quaternion.x = (float) ((double) (m02 + m20) * d3); - quaternion.y = (float) ((double) (m21 + m12) * d3); - quaternion.w = (float) ((double) (m10 - m01) * d3); - } - - return quaternion; - } - - public static org.vivecraft.common.utils.math.Matrix4f rotationXMatrix(float angle) { - float f = (float) Math.sin(angle); - float f1 = (float) Math.cos(angle); - return new org.vivecraft.common.utils.math.Matrix4f(1.0F, 0.0F, 0.0F, 0.0F, f1, -f, 0.0F, f, f1); - } - - public static org.vivecraft.common.utils.math.Matrix4f rotationZMatrix(float angle) { - float f = (float) Math.sin(angle); - float f1 = (float) Math.cos(angle); - return new org.vivecraft.common.utils.math.Matrix4f(f1, -f, 0.0F, f, f1, 0.0F, 0.0F, 0.0F, 1.0F); - } - - public static Vector3 convertMatrix4ftoTranslationVector(org.vivecraft.common.utils.math.Matrix4f mat) { - return new Vector3(mat.M[0][3], mat.M[1][3], mat.M[2][3]); - } - - public static void Matrix4fSet(org.vivecraft.common.utils.math.Matrix4f mat, float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { - mat.M[0][0] = m11; - mat.M[0][1] = m12; - mat.M[0][2] = m13; - mat.M[0][3] = m14; - mat.M[1][0] = m21; - mat.M[1][1] = m22; - mat.M[1][2] = m23; - mat.M[1][3] = m24; - mat.M[2][0] = m31; - mat.M[2][1] = m32; - mat.M[2][2] = m33; - mat.M[2][3] = m34; - mat.M[3][0] = m41; - mat.M[3][1] = m42; - mat.M[3][2] = m43; - mat.M[3][3] = m44; - } - - public static void Matrix4fCopy(org.vivecraft.common.utils.math.Matrix4f source, org.vivecraft.common.utils.math.Matrix4f dest) { - dest.M[0][0] = source.M[0][0]; - dest.M[0][1] = source.M[0][1]; - dest.M[0][2] = source.M[0][2]; - dest.M[0][3] = source.M[0][3]; - dest.M[1][0] = source.M[1][0]; - dest.M[1][1] = source.M[1][1]; - dest.M[1][2] = source.M[1][2]; - dest.M[1][3] = source.M[1][3]; - dest.M[2][0] = source.M[2][0]; - dest.M[2][1] = source.M[2][1]; - dest.M[2][2] = source.M[2][2]; - dest.M[2][3] = source.M[2][3]; - dest.M[3][0] = source.M[3][0]; - dest.M[3][1] = source.M[3][1]; - dest.M[3][2] = source.M[3][2]; - dest.M[3][3] = source.M[3][3]; - } - - public static org.vivecraft.common.utils.math.Matrix4f Matrix4fSetIdentity(org.vivecraft.common.utils.math.Matrix4f mat) { - mat.M[0][0] = mat.M[1][1] = mat.M[2][2] = mat.M[3][3] = 1.0F; - mat.M[0][1] = mat.M[1][0] = mat.M[2][3] = mat.M[3][1] = 0.0F; - mat.M[0][2] = mat.M[1][2] = mat.M[2][0] = mat.M[3][2] = 0.0F; - mat.M[0][3] = mat.M[1][3] = mat.M[2][1] = mat.M[3][0] = 0.0F; - return mat; - } - - static { - Arrays.sort(illegalChars); - } -} diff --git a/common/src/main/java/org/vivecraft/client/utils/math/BezierCurve.java b/common/src/main/java/org/vivecraft/client/utils/math/BezierCurve.java deleted file mode 100644 index 20659e889..000000000 --- a/common/src/main/java/org/vivecraft/client/utils/math/BezierCurve.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.vivecraft.client.utils.math; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.BufferBuilder; -import com.mojang.blaze3d.vertex.DefaultVertexFormat; -import com.mojang.blaze3d.vertex.Tesselator; -import com.mojang.blaze3d.vertex.VertexFormat.Mode; -import net.minecraft.client.Minecraft; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.phys.Vec3; - -import java.awt.*; -import java.util.ArrayList; -import java.util.Arrays; - -public class BezierCurve { - public ArrayList nodes = new ArrayList<>(); - boolean circular; - - public BezierCurve(Node[] nodes, boolean circular) { - this.nodes.addAll(Arrays.asList(nodes)); - this.circular = circular; - } - - public BezierCurve(boolean circular) { - this.circular = circular; - } - - Vec3 getIntermediate(Node n1, Node n2, double perc) { - Vec3 vec3 = n1.vertex; - Vec3 vec31 = n1.controlOut; - Vec3 vec32 = n2.controlIn; - Vec3 vec33 = n2.vertex; - return vec3.scale(Math.pow(1.0D - perc, 3.0D)).add(vec31.scale(3.0D * Math.pow(1.0D - perc, 2.0D) * perc)).add(vec32.scale(3.0D * (1.0D - perc) * Math.pow(perc, 2.0D))).add(vec33.scale(Math.pow(perc, 3.0D))); - } - - public Vec3 getPointOnPath(double perc) { - int i = this.circular ? this.nodes.size() : this.nodes.size() - 1; - double d0 = perc * (double) i; - int j = (int) Math.floor(d0) % this.nodes.size(); - int k = (int) Math.ceil(d0) % this.nodes.size(); - - if (j == k) { - return (this.nodes.get(j)).vertex; - } else { - Node beziercurve$node = this.nodes.get(j); - Node beziercurve$node1 = this.nodes.get(k); - return this.getIntermediate(beziercurve$node, beziercurve$node1, d0 - (double) j); - } - } - - public Vec3[] getLinearInterpolation(int verticesPerNode) { - if (this.nodes.size() == 0) { - return new Vec3[0]; - } else { - int i = verticesPerNode * (this.circular ? this.nodes.size() : this.nodes.size() - 1) + 1; - Vec3[] avec3 = new Vec3[i]; - - for (int j = 0; j < i; ++j) { - double d0 = (double) j / (double) Math.max(1, i - 1); - avec3[j] = this.getPointOnPath(d0); - } - - return avec3; - } - } - - public void render(int vertexCount, Color c, float partialTicks) { - Player player = Minecraft.getInstance().player; - double d0 = player.xOld + (player.getX() - player.xOld) * (double) partialTicks; - double d1 = player.yOld + (player.getY() - player.yOld) * (double) partialTicks; - double d2 = player.zOld + (player.getZ() - player.zOld) * (double) partialTicks; - //GlStateManager._disableLighting(); - RenderSystem.depthMask(false); - Tesselator tesselator = Tesselator.getInstance(); - BufferBuilder bufferbuilder = tesselator.getBuilder(); - bufferbuilder.begin(Mode.LINES, DefaultVertexFormat.POSITION_COLOR); - Vec3[] avec3 = this.getLinearInterpolation(vertexCount / this.nodes.size()); - - for (int i = 0; i < avec3.length; ++i) { - this.renderVertex(bufferbuilder, avec3[i], c, d0, d1, d2); - } - - tesselator.end(); - //GlStateManager._enableLighting(); - RenderSystem.depthMask(true); - } - - void renderVertex(BufferBuilder buffer, Vec3 vert, Color color, double offX, double offY, double offZ) { - buffer.vertex(vert.x - offX, vert.y - offY, vert.z - offZ).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex(); - } - - public static class Node { - Vec3 vertex; - Vec3 controlIn; - Vec3 controlOut; - - public Node(Vec3 vertex, Vec3 controlIn, Vec3 controlOut) { - this.vertex = vertex; - this.controlIn = controlIn; - this.controlOut = controlOut; - } - - public Node(Vec3 vertex, Vec3 controlDir, double controlLenIn, double controlLenOut) { - this(vertex, vertex.add(controlDir.normalize().scale(-controlLenIn)), vertex.add(controlDir.normalize().scale(controlLenOut))); - } - } -} diff --git a/common/src/main/java/org/vivecraft/client_vr/VRData.java b/common/src/main/java/org/vivecraft/client_vr/VRData.java index 410962566..afddd5308 100644 --- a/common/src/main/java/org/vivecraft/client_vr/VRData.java +++ b/common/src/main/java/org/vivecraft/client_vr/VRData.java @@ -1,12 +1,10 @@ package org.vivecraft.client_vr; -import net.minecraft.client.Minecraft; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.utils.Utils; +import org.joml.*; +import org.joml.Math; import org.vivecraft.client_vr.render.RenderPass; -import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; public class VRData { public VRDevicePose hmd; @@ -32,47 +30,50 @@ public VRData(Vec3 origin, float walkMul, float worldScale, float rotation) { Vec3 vec3 = dataholder.vr.getCenterEyePosition(); Vec3 vec31 = new Vec3(vec3.x * (double) walkMul, vec3.y, vec3.z * (double) walkMul); this.hmd = new VRDevicePose(this, dataholder.vr.hmdRotation, vec31, dataholder.vr.getHmdVector()); - this.eye0 = new VRDevicePose(this, dataholder.vr.getEyeRotation(RenderPass.LEFT), dataholder.vr.getEyePosition(RenderPass.LEFT).subtract(vec3).add(vec31), dataholder.vr.getHmdVector()); - this.eye1 = new VRDevicePose(this, dataholder.vr.getEyeRotation(RenderPass.RIGHT), dataholder.vr.getEyePosition(RenderPass.RIGHT).subtract(vec3).add(vec31), dataholder.vr.getHmdVector()); - this.c0 = new VRDevicePose(this, dataholder.vr.getAimRotation(0), dataholder.vr.getAimSource(0).subtract(vec3).add(vec31), dataholder.vr.getAimVector(0)); - this.c1 = new VRDevicePose(this, dataholder.vr.getAimRotation(1), dataholder.vr.getAimSource(1).subtract(vec3).add(vec31), dataholder.vr.getAimVector(1)); - this.h0 = new VRDevicePose(this, dataholder.vr.getHandRotation(0), dataholder.vr.getAimSource(0).subtract(vec3).add(vec31), dataholder.vr.getHandVector(0)); - this.h1 = new VRDevicePose(this, dataholder.vr.getHandRotation(1), dataholder.vr.getAimSource(1).subtract(vec3).add(vec31), dataholder.vr.getHandVector(1)); + this.eye0 = new VRDevicePose(this, dataholder.vr.getEyeRotation(RenderPass.LEFT, new Matrix4f()), dataholder.vr.getEyePosition(RenderPass.LEFT).subtract(vec3).add(vec31), dataholder.vr.getHmdVector()); + this.eye1 = new VRDevicePose(this, dataholder.vr.getEyeRotation(RenderPass.RIGHT, new Matrix4f()), dataholder.vr.getEyePosition(RenderPass.RIGHT).subtract(vec3).add(vec31), dataholder.vr.getHmdVector()); + this.c0 = new VRDevicePose(this, dataholder.vr.getAimRotation(0, new Matrix4f()), dataholder.vr.getAimSource(0).subtract(vec3).add(vec31), dataholder.vr.getAimVector(0)); + this.c1 = new VRDevicePose(this, dataholder.vr.getAimRotation(1, new Matrix4f()), dataholder.vr.getAimSource(1).subtract(vec3).add(vec31), dataholder.vr.getAimVector(1)); + this.h0 = new VRDevicePose(this, dataholder.vr.getHandRotation(0, new Matrix4f()), dataholder.vr.getAimSource(0).subtract(vec3).add(vec31), dataholder.vr.getHandVector(0)); + this.h1 = new VRDevicePose(this, dataholder.vr.getHandRotation(1, new Matrix4f()), dataholder.vr.getAimSource(1).subtract(vec3).add(vec31), dataholder.vr.getHandVector(1)); if (dataholder.vrSettings.seated) { this.t0 = eye0; this.t1 = eye1; } else { - Matrix4f matrix4f = this.getSmoothedRotation(0, 0.2F); - Matrix4f matrix4f1 = this.getSmoothedRotation(1, 0.2F); - this.t0 = new VRDevicePose(this, matrix4f, dataholder.vr.getAimSource(0).subtract(vec3).add(vec31), matrix4f.transform(Vector3.forward()).toVector3d()); - this.t1 = new VRDevicePose(this, matrix4f1, dataholder.vr.getAimSource(1).subtract(vec3).add(vec31), matrix4f1.transform(Vector3.forward()).toVector3d()); + Matrix4f matrix4f = this.getSmoothedRotation(0, 0.2F, new Matrix4f()); + Matrix4f matrix4f1 = this.getSmoothedRotation(1, 0.2F, new Matrix4f()); + this.t0 = new VRDevicePose(this, matrix4f, dataholder.vr.getAimSource(0).subtract(vec3).add(vec31), Utils.convertToVec3(matrix4f.transformProject(Utils.forward, new Vector3f()))); + this.t1 = new VRDevicePose(this, matrix4f1, dataholder.vr.getAimSource(1).subtract(vec3).add(vec31), Utils.convertToVec3(matrix4f1.transformProject(Utils.forward, new Vector3f()))); } - Matrix4f matrix4f2 = Matrix4f.multiply(Matrix4f.rotationY(-rotation), (new Matrix4f(ClientDataHolderVR.getInstance().cameraTracker.getRotation())).transposed()); + Matrix4f matrix4f2 = new Matrix4f().rotation(dataholder.cameraTracker.getRotation()).rotateLocalY(-rotation); float inverseWorldScale = 1.0F / worldScale; - this.cam = new VRData.VRDevicePose(this, matrix4f2, ClientDataHolderVR.getInstance().cameraTracker.getPosition().subtract(origin).yRot(-rotation).multiply(inverseWorldScale, inverseWorldScale, inverseWorldScale).subtract(vec3).add(vec31), matrix4f2.transform(Vector3.forward()).toVector3d()); + this.cam = new VRDevicePose(this, matrix4f2, dataholder.cameraTracker.getPosition().subtract(origin).yRot(-rotation).multiply(inverseWorldScale, inverseWorldScale, inverseWorldScale).subtract(vec3).add(vec31), Utils.convertToVec3(matrix4f2.transformProject(Utils.forward, new Vector3f()))); if (dataholder.vr.mrMovingCamActive) { - this.c2 = new VRDevicePose(this, dataholder.vr.getAimRotation(2), dataholder.vr.getAimSource(2).subtract(vec3).add(vec31), dataholder.vr.getAimVector(2)); + this.c2 = new VRDevicePose(this, dataholder.vr.getAimRotation(2, new Matrix4f()), dataholder.vr.getAimSource(2).subtract(vec3).add(vec31), dataholder.vr.getAimVector(2)); } else { - VRSettings vrsettings = ClientDataHolderVR.getInstance().vrSettings; - Matrix4f matrix4f3 = (new Matrix4f(vrsettings.vrFixedCamrotQuat)).transposed(); - Vec3 vec32 = new Vec3(vrsettings.vrFixedCamposX, vrsettings.vrFixedCamposY, vrsettings.vrFixedCamposZ); - Vec3 vec33 = matrix4f3.transform(Vector3.forward()).toVector3d(); + Matrix4f matrix4f3 = new Matrix4f().rotation(dataholder.vrSettings.vrFixedCamrotQuat); + Vec3 vec32 = Utils.convertToVec3(dataholder.vrSettings.vrFixedCampos); + Vec3 vec33 = Utils.convertToVec3(matrix4f3.transformProject(Utils.forward, new Vector3f())); this.c2 = new VRDevicePose(this, matrix4f3, vec32.subtract(vec3).add(vec31), vec33); } } - private Matrix4f getSmoothedRotation(int c, float lenSec) { - Minecraft minecraft = Minecraft.getInstance(); + private Matrix4f getSmoothedRotation(int c, float lenSec, Matrix4f dest) { ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); Vec3 vec3 = dataholder.vr.controllerHistory[c].averagePosition(lenSec); Vec3 vec31 = dataholder.vr.controllerForwardHistory[c].averagePosition(lenSec); Vec3 vec32 = dataholder.vr.controllerUpHistory[c].averagePosition(lenSec); Vec3 vec33 = vec31.cross(vec32); - return new Matrix4f((float) vec33.x, (float) vec31.x, (float) vec32.x, (float) vec33.y, (float) vec31.y, (float) vec32.y, (float) vec33.z, (float) vec31.z, (float) vec32.z); + return dest.set( + (float) vec33.x, (float) vec33.y, (float) vec33.z, 0, + (float) vec31.x, (float) vec31.y, (float) vec31.z, 0, + (float) vec32.x, (float) vec32.y, (float) vec32.z, 0, + 0, 0, 0, 1 + ); } public VRDevicePose getController(int c) { @@ -111,14 +112,16 @@ public float getFacingYaw() { public Vec3 getHeadPivot() { Vec3 vec3 = this.hmd.getPosition(); // scale pivot point with world scale, to prevent unwanted player movement - Vector3 vector3 = this.hmd.getMatrix().transform(new Vector3(0.0F, -0.1F * worldScale, 0.1F * worldScale)); - return new Vec3((double) vector3.getX() + vec3.x, (double) vector3.getY() + vec3.y, (double) vector3.getZ() + vec3.z); + Matrix4f matrix4f = this.hmd.getMatrix(new Matrix4f()); + Vector3f vector3 = matrix4f.transformProject(new Vector3f(0.0F, -0.1F * worldScale, 0.1F * worldScale), new Vector3f()); + return new Vec3((double) vector3.x() + vec3.x, (double) vector3.y() + vec3.y, (double) vector3.z() + vec3.z); } public Vec3 getHeadRear() { Vec3 vec3 = this.hmd.getPosition(); - Vector3 vector3 = this.hmd.getMatrix().transform(new Vector3(0.0F, -0.2F, 0.2F)); - return new Vec3((double) vector3.getX() + vec3.x, (double) vector3.getY() + vec3.y, (double) vector3.getZ() + vec3.z); + Matrix4f matrix4f = this.hmd.getMatrix(new Matrix4f()); + Vector3f vector3 = matrix4f.transformProject(new Vector3f(0.0F, -0.2F, 0.2F), new Vector3f()); + return new Vec3((double) vector3.x() + vec3.x, (double) vector3.y() + vec3.y, (double) vector3.z() + vec3.z); } public VRDevicePose getEye(RenderPass pass) { @@ -153,25 +156,21 @@ public String toString() { return "data:\r\n \t\t origin: " + this.origin + "\r\n \t\t rotation: " + String.format("%.2f", this.rotation_radians) + "\r\n \t\t scale: " + String.format("%.2f", this.worldScale) + "\r\n \t\t hmd " + this.hmd + "\r\n \t\t c0 " + this.c0 + "\r\n \t\t c1 " + this.c1 + "\r\n \t\t c2 " + this.c2; } - protected Vec3 vecMult(Vec3 in, float factor) { - return new Vec3(in.x * (double) factor, in.y * (double) factor, in.z * (double) factor); - } - public class VRDevicePose { - final VRData data; - final Vec3 pos; - final Vec3 dir; - final Matrix4f matrix; + public final VRData data; + public final Vec3 pos; + public final Vec3 dir; + public final Matrix4fc matrix; public VRDevicePose(VRData data, Matrix4f matrix, Vec3 pos, Vec3 dir) { this.data = data; - this.matrix = matrix.transposed().transposed(); + this.matrix = matrix; this.pos = new Vec3(pos.x, pos.y, pos.z); this.dir = new Vec3(dir.x, dir.y, dir.z); } public Vec3 getPosition() { - Vec3 vec3 = this.pos.scale(VRData.this.worldScale); + Vec3 vec3 = this.pos.scale(this.data.worldScale); vec3 = vec3.yRot(this.data.rotation_radians); return vec3.add(this.data.origin.x, this.data.origin.y, this.data.origin.z); } @@ -181,8 +180,7 @@ public Vec3 getDirection() { } public Vec3 getCustomVector(Vec3 axis) { - Vector3 vector3 = this.matrix.transform(new Vector3((float) axis.x, (float) axis.y, (float) axis.z)); - return vector3.toVector3d().yRot(this.data.rotation_radians); + return Utils.convertToVec3(this.matrix.transformProject(new Vector3f((float) axis.x(), (float) axis.y(), (float) axis.z())).rotateY(this.data.rotation_radians)); } public float getYaw() { @@ -196,12 +194,11 @@ public float getPitch() { } public float getRoll() { - return (float) (-Math.toDegrees(Math.atan2(this.matrix.M[1][0], this.matrix.M[1][1]))); + return (float) (-Math.toDegrees(Math.atan2(this.matrix.m01(), this.matrix.m11()))); } - public Matrix4f getMatrix() { - Matrix4f matrix4f = Matrix4f.rotationY(VRData.this.rotation_radians); - return Matrix4f.multiply(matrix4f, this.matrix); + public Matrix4f getMatrix(Matrix4f dest) { + return this.matrix.rotateLocalY(this.data.rotation_radians, dest); } public String toString() { diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java index 4bce7ac77..5b345c196 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java @@ -261,8 +261,8 @@ public void tick(LocalPlayer player, Minecraft mc, RandomSource rand) { System.out.println("Room origin: " + this.vrdata_world_pre.origin); System.out.println("Hmd position room: " + this.vrdata_room_pre.hmd.getPosition()); System.out.println("Hmd position world: " + this.vrdata_world_pre.hmd.getPosition()); - System.out.println("Hmd Projection Left: " + dh.vrRenderer.eyeproj[0]); - System.out.println("Hmd Projection Right: " + dh.vrRenderer.eyeproj[1]); + System.out.println("Hmd Projection Left: " + dh.vrRenderer.eyeproj0); + System.out.println("Hmd Projection Right: " + dh.vrRenderer.eyeproj1); System.out.println(""); this.initdone = true; } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java index 7cf0cea4b..4bef4d03f 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java @@ -14,8 +14,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.entity.vehicle.ContainerEntity; import net.minecraft.world.phys.*; -import org.joml.Vector2f; -import org.vivecraft.client.utils.Utils; +import org.joml.*; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRData; import org.vivecraft.client_vr.VRState; @@ -26,13 +25,12 @@ import org.vivecraft.client_vr.provider.HandedKeyBinding; import org.vivecraft.client_vr.provider.InputSimulator; import org.vivecraft.client_vr.provider.MCVR; -import org.vivecraft.client_vr.provider.openvr_lwjgl.OpenVRUtil; import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_vr.render.helpers.RenderHelper; import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; + +import java.lang.Math; public class GuiHandler { public static Minecraft mc = Minecraft.getInstance(); @@ -202,15 +200,14 @@ public static void processGui() { } } - public static Vec2 getTexCoordsForCursor(Vec3 guiPos_room, Matrix4f guiRotation_room, Screen screen, float guiScale, VRData.VRDevicePose controller) { + public static Vec2 getTexCoordsForCursor(Vec3 guiPos_room, Matrix4fc guiRotation_room, Screen screen, float guiScale, VRData.VRDevicePose controller) { Vec3 vec3 = controller.getPosition(); - Vector3 vector3 = new Vector3(vec3); + Vector3f vector3 = new Vector3f().set(vec3.x, vec3.y, vec3.z); Vec3 vec31 = controller.getDirection(); - Vector3 vector31 = new Vector3((float) vec31.x, (float) vec31.y, (float) vec31.z); - Vector3 vector32 = new Vector3(0.0F, 0.0F, 1.0F); - Vector3 vector33 = guiRotation_room.transform(vector32); - Vector3 vector34 = guiRotation_room.transform(new Vector3(1.0F, 0.0F, 0.0F)); - Vector3 vector35 = guiRotation_room.transform(new Vector3(0.0F, 1.0F, 0.0F)); + Vector3f vector31 = new Vector3f((float) vec31.x, (float) vec31.y, (float) vec31.z); + Vector3f vector33 = guiRotation_room.transformProject(Utils.ROLL, new Vector3f()); + Vector3f vector34 = guiRotation_room.transformProject(Utils.PITCH, new Vector3f()); + Vector3f vector35 = guiRotation_room.transformProject(Utils.YAW, new Vector3f()); float f = vector33.dot(vector31); if (Math.abs(f) > 1.0E-5F) { @@ -218,18 +215,15 @@ public static Vec2 getTexCoordsForCursor(Vec3 guiPos_room, Matrix4f guiRotation_ float f2 = f1 * 0.5F; float f3 = 1.0F; float f4 = f3 * 0.5F; - Vector3 vector36 = new Vector3(); - vector36.setX((float) guiPos_room.x); - vector36.setY((float) guiPos_room.y); - vector36.setZ((float) guiPos_room.z); - Vector3 vector37 = vector36.subtract(vector35.divide(1.0F / f4)).subtract(vector34.divide(1.0F / f2)); - float f5 = -vector33.dot(vector3.subtract(vector37)) / f; + Vector3f vector36 = new Vector3f().set(guiPos_room.x, guiPos_room.y, guiPos_room.z); + Vector3f vector37 = vector36.sub(vector35.div(1.0F / f4, new Vector3f()), new Vector3f()).sub(vector34.div(1.0F / f2, new Vector3f()), new Vector3f()); + float f5 = -vector33.dot(vector3.sub(vector37, new Vector3f())) / f; if (f5 > 0.0F) { - Vector3 vector38 = vector3.add(vector31.divide(1.0F / f5)); - Vector3 vector39 = vector38.subtract(vector37); - float f6 = vector39.dot(vector34.divide(1.0F / f1)); - float f7 = vector39.dot(vector35.divide(1.0F / f1)); + Vector3f vector38 = vector3.add(vector31.div(1.0F / f5, new Vector3f())); + Vector3f vector39 = vector38.sub(vector37, new Vector3f()); + float f6 = vector39.dot(vector34.div(1.0F / f1, new Vector3f())); + float f7 = vector39.dot(vector35.div(1.0F / f1, new Vector3f())); float f8 = (float) mc.getWindow().getGuiScaledHeight() / (float) mc.getWindow().getGuiScaledWidth(); f6 = (f6 - 0.5F) / 1.5F / guiScale + 0.5F; f7 = (f7 - 0.5F) / f8 / 1.5F / guiScale + 0.5F; @@ -358,10 +352,6 @@ public static void onScreenChanged(Screen previousGuiScreen, Screen newScreen, b // slight offset to center of the room, to prevent z fighting guiPos_room = new Vec3(0.02D, 1.3F, -Math.max(afloat != null ? afloat.y / 2.0F : 0.0F, 1.5F)); guiRotation_room = new Matrix4f(); - guiRotation_room.M[0][0] = guiRotation_room.M[1][1] = guiRotation_room.M[2][2] = guiRotation_room.M[3][3] = 1.0F; - guiRotation_room.M[0][1] = guiRotation_room.M[1][0] = guiRotation_room.M[2][3] = guiRotation_room.M[3][1] = 0.0F; - guiRotation_room.M[0][2] = guiRotation_room.M[1][2] = guiRotation_room.M[2][0] = guiRotation_room.M[3][2] = 0.0F; - guiRotation_room.M[0][3] = guiRotation_room.M[1][3] = guiRotation_room.M[2][1] = guiRotation_room.M[3][0] = 0.0F; } else { if (previousGuiScreen == null && newScreen != null || newScreen instanceof ChatScreen || newScreen instanceof BookEditScreen || newScreen instanceof AbstractSignEditScreen) { // check if screen is a container screen @@ -414,15 +404,14 @@ public static void onScreenChanged(Screen previousGuiScreen, Screen newScreen, b // orient screen Vec3 hmdPos = facingDevice.getPosition(); - Vector3 look = new Vector3(); - look.setX((float) (guiPos_room.x - hmdPos.x)); - look.setY((float) (guiPos_room.y - hmdPos.y)); - look.setZ((float) (guiPos_room.z - hmdPos.z)); - float pitch = (float) Math.asin((look.getY() / look.length())); - float yaw = (float) (Math.PI + Math.atan2(look.getX(), look.getZ())); - guiRotation_room = Matrix4f.rotationY(yaw); - Matrix4f tilt = Utils.rotationXMatrix(pitch); - guiRotation_room = Matrix4f.multiply(guiRotation_room, tilt); + Vector3f look = new Vector3f().set( + guiPos_room.x - hmdPos.x, + guiPos_room.y - hmdPos.y, + guiPos_room.z - hmdPos.z + ); + float pitch = (float) Math.asin((look.y() / look.length())); + float yaw = (float) (Math.PI + Math.atan2(look.x(), look.z())); + guiRotation_room = new Matrix4f().rotationY(yaw).rotateX(pitch); } KeyboardHandler.orientOverlay(newScreen != null); @@ -449,12 +438,11 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack pMatrixSt } Vec3 guipos = guiPos_room; - Matrix4f guirot = guiRotation_room; + Matrix4f guirot = new Matrix4f(); Vec3 guilocal = new Vec3(0.0D, 0.0D, 0.0D); float scale = guiScale; if (guipos == null) { - guirot = null; scale = 1.0F; if (mc.level != null && (mc.screen == null || !dh.vrSettings.floatInventory)) { @@ -464,52 +452,52 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack pMatrixSt i = -1; } - if (!dh.vrSettings.seated && dh.vrSettings.vrHudLockMode != VRSettings.HUDLock.HEAD) { - if (dh.vrSettings.vrHudLockMode == VRSettings.HUDLock.HAND) { - Matrix4f matrix4f5 = dh.vr.getAimRotation(1); - Matrix4f matrix4f7 = Matrix4f.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians); - Matrix4f matrix4f9 = Matrix4f.multiply(matrix4f7, matrix4f5); - guirot = Matrix4f.multiply(matrix4f9, Utils.rotationXMatrix((-(float) Math.PI / 5F))); - guirot = Matrix4f.multiply(guirot, Matrix4f.rotationY(((float) Math.PI / 10F) * (float) i)); + guirot.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians); + + switch (dh.vrSettings.seated ? VRSettings.HUDLock.HEAD : dh.vrSettings.vrHudLockMode) { + case HAND -> { + guirot.mul(dh.vr.getAimRotation(1, new Matrix4f())) + .rotateX((-(float) Math.PI / 5F)) + .rotateY(((float) Math.PI / 10F) * (float) i) + ; scale = 0.58823526F; guilocal = new Vec3(guilocal.x, 0.32D * (double) dh.vrPlayer.vrdata_world_render.worldScale, guilocal.z); guipos = RenderHelper.getControllerRenderPos(1); dh.vr.hudPopup = true; - } else if (dh.vrSettings.vrHudLockMode == VRSettings.HUDLock.WRIST) { - Matrix4f matrix4f6 = dh.vr.getAimRotation(1); - Matrix4f matrix4f8 = Matrix4f.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians); - guirot = Matrix4f.multiply(matrix4f8, matrix4f6); - guirot = Matrix4f.multiply(guirot, Utils.rotationZMatrix(((float) Math.PI / 2F) * (float) i)); - guirot = Matrix4f.multiply(guirot, Matrix4f.rotationY(0.9424779F * (float) i)); + } + case WRIST -> { + guirot.mul(dh.vr.getAimRotation(1, new Matrix4f())) + .rotateZ(((float) Math.PI / 2F) * (float) i) + .rotateY(0.9424779F * (float) i) + .rotateY(((float) Math.PI / 5F) * (float) i) + ; guipos = RenderHelper.getControllerRenderPos(1); dh.vr.hudPopup = true; boolean flag = mc.player.getModelName().equals("slim"); scale = 0.4F; guilocal = new Vec3((float) i * -0.136F * dh.vrPlayer.vrdata_world_render.worldScale, (flag ? 0.13D : 0.12D) * (double) dh.vrPlayer.vrdata_world_render.worldScale, 0.06D * (double) dh.vrPlayer.vrdata_world_render.worldScale); - guirot = Matrix4f.multiply(guirot, Matrix4f.rotationY(((float) Math.PI / 5F) * (float) i)); } - } else { - Matrix4f matrix4f1 = Matrix4f.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians); - Matrix4f matrix4f2 = Matrix4f.multiply(matrix4f1, dh.vr.hmdRotation); + case HEAD -> { Vec3 vec33 = dh.vrPlayer.vrdata_world_render.hmd.getPosition(); - Vec3 vec34 = dh.vrPlayer.vrdata_world_render.hmd.getDirection(); + Vec3 vec34; if (dh.vrSettings.seated && dh.vrSettings.seatedHudAltMode) { vec34 = dh.vrPlayer.vrdata_world_render.getController(0).getDirection(); - matrix4f2 = Matrix4f.multiply(matrix4f1, dh.vr.getAimRotation(0)); + guirot.mul(dh.vr.getAimRotation(0, new Matrix4f())); + } else { + vec34 = dh.vrPlayer.vrdata_world_render.hmd.getDirection(); + guirot.mul(dh.vr.hmdRotation); } guipos = new Vec3(vec33.x + vec34.x * (double) dh.vrPlayer.vrdata_world_render.worldScale * (double) dh.vrSettings.hudDistance, vec33.y + vec34.y * (double) dh.vrPlayer.vrdata_world_render.worldScale * (double) dh.vrSettings.hudDistance, vec33.z + vec34.z * (double) dh.vrPlayer.vrdata_world_render.worldScale * (double) dh.vrSettings.hudDistance); - Quaternion quaternion = OpenVRUtil.convertMatrix4ftoRotationQuat(matrix4f2); - guirot = new Matrix4f(quaternion); + guirot.rotation(new Quaternionf().setFromNormalized(guirot.normalize3x3(new Matrix3f()))); scale = dh.vrSettings.hudScale; + } } } } else { - VRPlayer vrplayer1 = dh.vrPlayer; guipos = VRPlayer.room_to_world_pos(guipos, dh.vrPlayer.vrdata_world_render); - Matrix4f matrix4f4 = Matrix4f.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians); - guirot = Matrix4f.multiply(matrix4f4, guirot); + guiRotation_room.rotateLocalY(dh.vrPlayer.vrdata_world_render.rotation_radians, guirot); } if ((dh.vrSettings.seated || dh.vrSettings.menuAlwaysFollowFace) && ((GameRendererExtension) mc.gameRenderer).vivecraft$isInMenuRoom()) { @@ -533,11 +521,9 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack pMatrixSt float f4 = ((GameRendererExtension) mc.gameRenderer).vivecraft$isInMenuRoom() ? 2.5F * dh.vrPlayer.vrdata_world_render.worldScale : dh.vrSettings.hudDistance; Vec3 vec39 = vec35.add(new Vec3(vec38.x * (double) f4, vec38.y * (double) f4, vec38.z * (double) f4)); Vec3 vec310 = new Vec3(vec39.x, vec39.y, vec39.z); - Matrix4f matrix4f3 = Matrix4f.rotationY((float) Math.PI - f1); - guirot = Matrix4f.multiply(matrix4f3, Matrix4f.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians)); - VRPlayer vrplayer = dh.vrPlayer; + (guiRotation_room = new Matrix4f()).rotationY((float) Math.PI - f1) + .rotateY(dh.vrPlayer.vrdata_world_render.rotation_radians, guirot); guipos = VRPlayer.room_to_world_pos(vec310, dh.vrPlayer.vrdata_world_render); - guiRotation_room = matrix4f3; guiScale = 2.0F; guiPos_room = vec310; } @@ -550,13 +536,12 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack pMatrixSt guiPos_room = new Vec3(0, 0, 0); guipos = VRPlayer.room_to_world_pos(guiPos_room, dh.vrPlayer.vrdata_world_render); guiRotation_room = new Matrix4f(); - guirot = new Matrix4f(); guiScale = 1.0F; } Vec3 vec36 = guipos.subtract(vec3); pMatrixStack.translate(vec36.x, vec36.y, vec36.z); - pMatrixStack.mulPoseMatrix(guirot.toMCMatrix()); + pMatrixStack.mulPoseMatrix(guirot); pMatrixStack.translate(guilocal.x, guilocal.y, guilocal.z); float f2 = scale * dh.vrPlayer.vrdata_world_render.worldScale; pMatrixStack.scale(f2, f2, f2); diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/KeyboardHandler.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/KeyboardHandler.java index 5e711c149..8c58645a4 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/KeyboardHandler.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/KeyboardHandler.java @@ -4,14 +4,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.utils.Utils; +import org.joml.Matrix4f; +import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gui.GuiKeyboard; import org.vivecraft.client_vr.gui.PhysicalKeyboard; import org.vivecraft.client_vr.provider.ControllerType; -import org.vivecraft.common.utils.lwjgl.Matrix4f; -import org.vivecraft.common.utils.lwjgl.Vector3f; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; public class KeyboardHandler { public static Minecraft mc = Minecraft.getInstance(); @@ -20,7 +19,7 @@ public class KeyboardHandler { public static GuiKeyboard UI = new GuiKeyboard(); public static PhysicalKeyboard physicalKeyboard = new PhysicalKeyboard(); public static Vec3 Pos_room = new Vec3(0.0D, 0.0D, 0.0D); - public static org.vivecraft.common.utils.math.Matrix4f Rotation_room = new org.vivecraft.common.utils.math.Matrix4f(); + public static final Matrix4f Rotation_room = new Matrix4f(); private static boolean PointedL; private static boolean PointedR; public static boolean keyboardForGui; @@ -69,56 +68,52 @@ public static void processGui() { PointedL = false; PointedR = false; - if (Showing) { - if (!dh.vrSettings.seated) { - if (Rotation_room != null) { - if (dh.vrSettings.physicalKeyboard) { - physicalKeyboard.process(); + if (Showing && !dh.vrSettings.seated) { + if (dh.vrSettings.physicalKeyboard) { + physicalKeyboard.process(); + } else { + Vec2 vec2 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(1)); + Vec2 vec21 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(0)); + float f = vec21.x; + float f1 = vec21.y; + + if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { + if (UI.cursorX2 == -1.0F) { + UI.cursorX2 = (float) ((int) (f * (float) GuiHandler.guiWidth)); + UI.cursorY2 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); + PointedR = true; + } else { + float f2 = (float) ((int) (f * (float) GuiHandler.guiWidth)); + float f3 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); + UI.cursorX2 = UI.cursorX2 * 0.7F + f2 * 0.3F; + UI.cursorY2 = UI.cursorY2 * 0.7F + f3 * 0.3F; + PointedR = true; + } + } else { + UI.cursorX2 = -1.0F; + UI.cursorY2 = -1.0F; + PointedR = false; + } + + f = vec2.x; + f1 = vec2.y; + + if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { + if (UI.cursorX1 == -1.0F) { + UI.cursorX1 = (float) ((int) (f * (float) GuiHandler.guiWidth)); + UI.cursorY1 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); + PointedL = true; } else { - Vec2 vec2 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(1)); - Vec2 vec21 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(0)); - float f = vec21.x; - float f1 = vec21.y; - - if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { - if (UI.cursorX2 == -1.0F) { - UI.cursorX2 = (float) ((int) (f * (float) GuiHandler.guiWidth)); - UI.cursorY2 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); - PointedR = true; - } else { - float f2 = (float) ((int) (f * (float) GuiHandler.guiWidth)); - float f3 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); - UI.cursorX2 = UI.cursorX2 * 0.7F + f2 * 0.3F; - UI.cursorY2 = UI.cursorY2 * 0.7F + f3 * 0.3F; - PointedR = true; - } - } else { - UI.cursorX2 = -1.0F; - UI.cursorY2 = -1.0F; - PointedR = false; - } - - f = vec2.x; - f1 = vec2.y; - - if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { - if (UI.cursorX1 == -1.0F) { - UI.cursorX1 = (float) ((int) (f * (float) GuiHandler.guiWidth)); - UI.cursorY1 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); - PointedL = true; - } else { - float f4 = (float) ((int) (f * (float) GuiHandler.guiWidth)); - float f5 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); - UI.cursorX1 = UI.cursorX1 * 0.7F + f4 * 0.3F; - UI.cursorY1 = UI.cursorY1 * 0.7F + f5 * 0.3F; - PointedL = true; - } - } else { - UI.cursorX1 = -1.0F; - UI.cursorY1 = -1.0F; - PointedL = false; - } + float f4 = (float) ((int) (f * (float) GuiHandler.guiWidth)); + float f5 = (float) ((int) (f1 * (float) GuiHandler.guiHeight)); + UI.cursorX1 = UI.cursorX1 * 0.7F + f4 * 0.3F; + UI.cursorY1 = UI.cursorY1 * 0.7F + f5 * 0.3F; + PointedL = true; } + } else { + UI.cursorX1 = -1.0F; + UI.cursorY1 = -1.0F; + PointedL = false; } } } @@ -129,7 +124,6 @@ public static void orientOverlay(boolean guiRelative) { if (Showing) { keyboardForGui = guiRelative; - Matrix4f matrix4f = new Matrix4f(); if (dh.vrSettings.physicalKeyboard) { Vec3 vec3 = dh.vrPlayer.vrdata_room_pre.hmd.getPosition(); @@ -137,35 +131,33 @@ public static void orientOverlay(boolean guiRelative) { vec31 = vec31.yRot((float) Math.toRadians(-dh.vrPlayer.vrdata_room_pre.hmd.getYaw())); Pos_room = new Vec3(vec3.x + vec31.x, vec3.y + vec31.y, vec3.z + vec31.z); float f = (float) Math.PI + (float) Math.toRadians(-dh.vrPlayer.vrdata_room_pre.hmd.getYaw()); - Rotation_room = org.vivecraft.common.utils.math.Matrix4f.rotationY(f); - Rotation_room = org.vivecraft.common.utils.math.Matrix4f.multiply(Rotation_room, Utils.rotationXMatrix(2.5132742F)); + Rotation_room.rotationY(f).rotateX(2.5132742F); } else if (guiRelative && GuiHandler.guiRotation_room != null) { - Matrix4f matrix4f1 = Utils.convertOVRMatrix(GuiHandler.guiRotation_room); - Vec3 vec35 = new Vec3(matrix4f1.m10, matrix4f1.m11, matrix4f1.m12); - Vec3 vec37 = (new Vec3(matrix4f1.m20, matrix4f1.m21, matrix4f1.m22)).scale(0.25D * GuiHandler.guiScale); + Vec3 vec35 = new Vec3(GuiHandler.guiRotation_room.m10(), GuiHandler.guiRotation_room.m11(), GuiHandler.guiRotation_room.m12()); + Vec3 vec37 = (new Vec3(GuiHandler.guiRotation_room.m20(), GuiHandler.guiRotation_room.m21(), GuiHandler.guiRotation_room.m22())).scale(0.25D * GuiHandler.guiScale); vec35 = vec35.scale(0.8F); - matrix4f.translate(new Vector3f((float) (GuiHandler.guiPos_room.x - vec35.x), (float) (GuiHandler.guiPos_room.y - vec35.y), (float) (GuiHandler.guiPos_room.z - vec35.z))); - matrix4f.translate(new Vector3f((float) vec37.x, (float) vec37.y, (float) vec37.z)); - Matrix4f.mul(matrix4f, matrix4f1, matrix4f); - matrix4f.rotate((float) Math.toRadians(30.0D), new Vector3f(-1.0F, 0.0F, 0.0F)); - Rotation_room = Utils.convertToOVRMatrix(matrix4f); - Pos_room = new Vec3(Rotation_room.M[0][3], Rotation_room.M[1][3], Rotation_room.M[2][3]); - Rotation_room.M[0][3] = 0.0F; - Rotation_room.M[1][3] = 0.0F; - Rotation_room.M[2][3] = 0.0F; + Rotation_room + .translation((float) (GuiHandler.guiPos_room.x - vec35.x), (float) (GuiHandler.guiPos_room.y - vec35.y), (float) (GuiHandler.guiPos_room.z - vec35.z)) + .translate((float) vec37.x, (float) vec37.y, (float) vec37.z) + .mul(GuiHandler.guiRotation_room) + .rotate((float) Math.toRadians(30.0F), -1.0F, 0.0F, 0.0F) + ; + Pos_room = Utils.convertToVec3(Rotation_room.getTranslation(new Vector3f())); + Rotation_room.setTranslation(0.0F, 0.0F, 0.0F); } else { Vec3 vec33 = dh.vrPlayer.vrdata_room_pre.hmd.getPosition(); Vec3 vec34 = new Vec3(0.0D, -0.5D, -2.0D); Vec3 vec36 = dh.vrPlayer.vrdata_room_pre.hmd.getCustomVector(vec34); Pos_room = new Vec3(vec36.x / 2.0D + vec33.x, vec36.y / 2.0D + vec33.y, vec36.z / 2.0D + vec33.z); Vec3 vec32 = dh.vrPlayer.vrdata_room_pre.hmd.getPosition(); - Vector3 vector3 = new Vector3(); - vector3.setX((float) (Pos_room.x - vec32.x)); - vector3.setY((float) (Pos_room.y - vec32.y)); - vector3.setZ((float) (Pos_room.z - vec32.z)); - float f1 = (float) Math.asin(vector3.getY() / vector3.length()); - float f2 = (float) ((double) (float) Math.PI + Math.atan2(vector3.getX(), vector3.getZ())); - Rotation_room = org.vivecraft.common.utils.math.Matrix4f.rotationY(f2); + Vector3f vector3 = new Vector3f( + (float) (Pos_room.x - vec32.x), + (float) (Pos_room.y - vec32.y), + (float) (Pos_room.z - vec32.z) + ); + float f1 = (float) Math.asin(vector3.y() / vector3.length()); + float f2 = (float) ((double) (float) Math.PI + Math.atan2(vector3.x(), vector3.z())); + Rotation_room.rotationY(f2); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/RadialHandler.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/RadialHandler.java index f9923ea28..48621dd66 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/RadialHandler.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/RadialHandler.java @@ -4,14 +4,13 @@ import net.minecraft.client.Minecraft; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; +import org.joml.Matrix4f; +import org.joml.Vector3f; import org.vivecraft.client.VivecraftVRMod; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRData; import org.vivecraft.client_vr.gui.GuiRadial; import org.vivecraft.client_vr.provider.ControllerType; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Vector3; public class RadialHandler { public static Minecraft mc = Minecraft.getInstance(); @@ -19,7 +18,7 @@ public class RadialHandler { private static boolean Showing = false; public static GuiRadial UI = new GuiRadial(); public static Vec3 Pos_room = new Vec3(0.0D, 0.0D, 0.0D); - public static Matrix4f Rotation_room = new Matrix4f(); + public static final Matrix4f Rotation_room = new Matrix4f(); private static boolean PointedL; private static boolean PointedR; public static RenderTarget Framebuffer = null; @@ -57,53 +56,49 @@ public static void processGui() { PointedL = false; PointedR = false; - if (isShowing()) { - if (!dh.vrSettings.seated) { - if (Rotation_room != null) { - Vec2 vec2 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(1)); - Vec2 vec21 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(0)); - float f = vec21.x; - float f1 = vec21.y; - - if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { - if (UI.cursorX2 == -1.0F) { - UI.cursorX2 = (float) ((int) (f * GuiHandler.guiWidth)); - UI.cursorY2 = (float) ((int) (f1 * GuiHandler.guiHeight)); - PointedR = true; - } else { - float f2 = (float) ((int) (f * GuiHandler.guiWidth)); - float f3 = (float) ((int) (f1 * GuiHandler.guiHeight)); - UI.cursorX2 = UI.cursorX2 * 0.7F + f2 * 0.3F; - UI.cursorY2 = UI.cursorY2 * 0.7F + f3 * 0.3F; - PointedR = true; - } - } else { - UI.cursorX2 = -1.0F; - UI.cursorY2 = -1.0F; - PointedR = false; - } + if (isShowing() && !dh.vrSettings.seated) { + Vec2 vec2 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(1)); + Vec2 vec21 = GuiHandler.getTexCoordsForCursor(Pos_room, Rotation_room, mc.screen, GuiHandler.guiScale, dh.vrPlayer.vrdata_room_pre.getController(0)); + float f = vec21.x; + float f1 = vec21.y; + + if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { + if (UI.cursorX2 == -1.0F) { + UI.cursorX2 = (float) ((int) (f * GuiHandler.guiWidth)); + UI.cursorY2 = (float) ((int) (f1 * GuiHandler.guiHeight)); + PointedR = true; + } else { + float f2 = (float) ((int) (f * GuiHandler.guiWidth)); + float f3 = (float) ((int) (f1 * GuiHandler.guiHeight)); + UI.cursorX2 = UI.cursorX2 * 0.7F + f2 * 0.3F; + UI.cursorY2 = UI.cursorY2 * 0.7F + f3 * 0.3F; + PointedR = true; + } + } else { + UI.cursorX2 = -1.0F; + UI.cursorY2 = -1.0F; + PointedR = false; + } - f = vec2.x; - f1 = vec2.y; - - if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { - if (UI.cursorX1 == -1.0F) { - UI.cursorX1 = (float) ((int) (f * GuiHandler.guiWidth)); - UI.cursorY1 = (float) ((int) (f1 * GuiHandler.guiHeight)); - PointedL = true; - } else { - float f4 = (float) ((int) (f * GuiHandler.guiWidth)); - float f5 = (float) ((int) (f1 * GuiHandler.guiHeight)); - UI.cursorX1 = UI.cursorX1 * 0.7F + f4 * 0.3F; - UI.cursorY1 = UI.cursorY1 * 0.7F + f5 * 0.3F; - PointedL = true; - } - } else { - UI.cursorX1 = -1.0F; - UI.cursorY1 = -1.0F; - PointedL = false; - } + f = vec2.x; + f1 = vec2.y; + + if (!(f < 0.0F) && !(f1 < 0.0F) && !(f > 1.0F) && !(f1 > 1.0F)) { + if (UI.cursorX1 == -1.0F) { + UI.cursorX1 = (float) ((int) (f * GuiHandler.guiWidth)); + UI.cursorY1 = (float) ((int) (f1 * GuiHandler.guiHeight)); + PointedL = true; + } else { + float f4 = (float) ((int) (f * GuiHandler.guiWidth)); + float f5 = (float) ((int) (f1 * GuiHandler.guiHeight)); + UI.cursorX1 = UI.cursorX1 * 0.7F + f4 * 0.3F; + UI.cursorY1 = UI.cursorY1 * 0.7F + f5 * 0.3F; + PointedL = true; } + } else { + UI.cursorX1 = -1.0F; + UI.cursorY1 = -1.0F; + PointedL = false; } } } @@ -128,15 +123,14 @@ public static void orientOverlay(ControllerType controller) { Vec3 vec31 = new Vec3(0.0D, 0.0D, -f); Vec3 vec32 = vrdata$vrdevicepose.getCustomVector(vec31); Pos_room = new Vec3(vec32.x / 2.0D + vec3.x, vec32.y / 2.0D + vec3.y, vec32.z / 2.0D + vec3.z); - Vector3 vector3 = new Vector3(); - vector3.setX((float) (Pos_room.x - vec3.x)); - vector3.setY((float) (Pos_room.y - vec3.y)); - vector3.setZ((float) (Pos_room.z - vec3.z)); - float f1 = (float) Math.asin(vector3.getY() / vector3.length()); - float f2 = (float) ((double) (float) Math.PI + Math.atan2(vector3.getX(), vector3.getZ())); - Rotation_room = Matrix4f.rotationY(f2); - Matrix4f matrix4f = Utils.rotationXMatrix(f1); - Rotation_room = Matrix4f.multiply(Rotation_room, matrix4f); + Vector3f vector3 = new Vector3f( + (float) (Pos_room.x - vec3.x), + (float) (Pos_room.y - vec3.y), + (float) (Pos_room.z - vec3.z) + ); + float f1 = (float) Math.asin(vector3.y() / vector3.length()); + float f2 = (float) ((double) (float) Math.PI + Math.atan2(vector3.x(), vector3.z())); + Rotation_room.rotationY(f2).rotateX(f1); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java index 0a87abeb6..1a224fbb3 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/BowTracker.java @@ -11,6 +11,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.UseAnim; import net.minecraft.world.phys.Vec3; +import org.joml.Vector3f; import org.vivecraft.client.Xplat; import org.vivecraft.client.network.ClientNetworking; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -19,7 +20,6 @@ import org.vivecraft.client_vr.gameplay.VRPlayer; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.common.network.CommonNetworkHelper; -import org.vivecraft.common.utils.math.Vector3; import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper; import java.nio.ByteBuffer; @@ -139,9 +139,9 @@ public void doProcess(LocalPlayer player) { double d0 = vec3.distanceTo(vec33); this.aim = vec3.subtract(vec31).normalize(); Vec3 vec34 = vrdata.getController(0).getCustomVector(new Vec3(0.0D, 0.0D, -1.0D)); - Vector3 vector3 = new Vector3((float) vec34.x, (float) vec34.y, (float) vec34.z); + Vector3f vector3 = new Vector3f((float) vec34.x, (float) vec34.y, (float) vec34.z); Vec3 vec35 = vrdata.getHand(1).getCustomVector(new Vec3(0.0D, -1.0D, 0.0D)); - Vector3 vector31 = new Vector3((float) vec35.x, (float) vec35.y, (float) vec35.z); + Vector3f vector31 = new Vector3f((float) vec35.x, (float) vec35.y, (float) vec35.z); this.controllersDot = (180D / Math.PI) * Math.acos(vector31.dot(vector3)); this.pressed = this.mc.options.keyAttack.isDown(); float f = 0.15F * vrdata.worldScale; diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java index bd8247d71..7df344c7f 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/CameraTracker.java @@ -4,24 +4,24 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.utils.Utils; +import org.joml.Matrix4f; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRData; import org.vivecraft.client_vr.render.RenderPass; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; public class CameraTracker extends Tracker { public static final ModelResourceLocation cameraModel = new ModelResourceLocation("vivecraft", "camera", ""); public static final ModelResourceLocation cameraDisplayModel = new ModelResourceLocation("vivecraft", "camera_display", ""); private boolean visible = false; - private Vec3 position = new Vec3(0.0D, 0.0D, 0.0D); - private Quaternion rotation = new Quaternion(); + private final Vector3f position = new Vector3f(); + private final Quaternionf rotation = new Quaternionf(); private int startController; private VRData.VRDevicePose startControllerPose; - private Vec3 startPosition; - private Quaternion startRotation; + private final Vector3f startPosition = new Vector3f(); + private final Quaternionf startRotation = new Quaternionf(); private boolean quickMode; public CameraTracker(Minecraft mc, ClientDataHolderVR dh) { @@ -40,21 +40,19 @@ public boolean isActive(LocalPlayer player) { public void doProcess(LocalPlayer player) { if (this.startControllerPose != null) { - VRData.VRDevicePose vrdata$vrdevicepose = this.dh.vrPlayer.vrdata_world_render.getController(this.startController); - Vec3 vec3 = this.startControllerPose.getPosition(); - Vec3 vec31 = vrdata$vrdevicepose.getPosition().subtract(vec3); - Matrix4f matrix4f = Matrix4f.multiply(vrdata$vrdevicepose.getMatrix(), this.startControllerPose.getMatrix().inverted()); - Vector3 vector3 = new Vector3((float) this.startPosition.x - (float) vec3.x, (float) this.startPosition.y - (float) vec3.y, (float) this.startPosition.z - (float) vec3.z); - Vector3 vector31 = matrix4f.transform(vector3); - this.position = new Vec3(this.startPosition.x + (double) ((float) vec31.x) + (double) (vector31.getX() - vector3.getX()), this.startPosition.y + (double) ((float) vec31.y) + (double) (vector31.getY() - vector3.getY()), this.startPosition.z + (double) ((float) vec31.z) + (double) (vector31.getZ() - vector3.getZ())); - this.rotation = this.startRotation.multiply(new Quaternion(Utils.convertOVRMatrix(matrix4f))); + VRData.VRDevicePose vrDevPose = this.dh.vrPlayer.vrdata_world_render.getController(this.startController); + Vector3f vrOldPosition = Utils.convertToVector3f(this.startControllerPose.getPosition(), new Vector3f()); + Vector3f vrDevPosition = Utils.convertToVector3f(vrDevPose.getPosition(), new Vector3f()).sub(vrOldPosition); + Matrix4f matrix4f = vrDevPose.getMatrix(new Matrix4f()).mul(this.startControllerPose.getMatrix(new Matrix4f()).invert()); + matrix4f.transformProject(this.startPosition.sub(vrOldPosition, vrOldPosition), this.position).sub(vrOldPosition).add(vrDevPosition).add(this.startPosition); + this.rotation.setFromUnnormalized(matrix4f).mul(this.startRotation); } if (this.quickMode && !this.isMoving() && !this.dh.grabScreenShot) { this.visible = false; } - if (this.dh.vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition().distanceTo(this.position) > (double) (this.mc.options.getEffectiveRenderDistance() * 12)) { + if (Utils.convertToVector3f(this.dh.vrPlayer.vrdata_world_render.getEye(RenderPass.CENTER).getPosition(), new Vector3f()).distance(this.position) > (double) (this.mc.options.getEffectiveRenderDistance() * 12)) { this.visible = false; } } @@ -78,19 +76,19 @@ public void toggleVisibility() { } public Vec3 getPosition() { - return this.position; + return Utils.convertToVec3(this.position); } public void setPosition(Vec3 position) { - this.position = position; + Utils.convertToVector3f(position, this.position); } - public Quaternion getRotation() { + public Quaternionf getRotation() { return this.rotation; } - public void setRotation(Quaternion rotation) { - this.rotation = rotation; + public void setRotation(Quaternionf rotation) { + this.rotation.set(rotation); } public boolean isMoving() { @@ -108,8 +106,8 @@ public boolean isQuickMode() { public void startMoving(int controller, boolean quickMode) { this.startController = controller; this.startControllerPose = this.dh.vrPlayer.vrdata_world_pre.getController(controller); - this.startPosition = this.position; - this.startRotation = this.rotation.copy(); + this.startPosition.set(this.position); + this.startRotation.set(this.rotation); this.quickMode = quickMode; } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java index 1a17d162e..a3a1c2923 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java @@ -4,11 +4,13 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.entity.animal.horse.Horse; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.utils.Utils; +import org.joml.Math; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.VRPlayer; import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.common.utils.math.Quaternion; +import org.vivecraft.common.utils.Utils; public class HorseTracker extends Tracker { double boostTrigger = 1.4D; @@ -52,13 +54,26 @@ public void doProcess(LocalPlayer player) { this.boost(); } - Quaternion quaternion = new Quaternion(0.0F, -this.horse.yBodyRot, 0.0F); - Vec3 vec32 = quaternion.multiply(new Vec3(0.0D, 0.0D, -1.0D)); - Vec3 vec33 = quaternion.multiply(new Vec3(1.0D, 0.0D, 0.0D)); - Vec3 vec34 = quaternion.multiply(new Vec3(-1.0D, 0.0D, 0.0D)); - Quaternion quaternion1 = new Quaternion(0.0F, VRSettings.inst.worldRotation, 0.0F); - Vec3 vec35 = VRPlayer.get().roomOrigin.add(quaternion1.multiply(this.dh.vr.controllerHistory[1].latest())); - Vec3 vec36 = VRPlayer.get().roomOrigin.add(quaternion1.multiply(this.dh.vr.controllerHistory[0].latest())); + Quaternionf quaternion41 = new Quaternionf(); + float yaw = Math.toRadians(-this.horse.yBodyRot); + Quaternionf quaternion5 = new Quaternionf().fromAxisAngleRad(Utils.PITCH, 0.0F); + Quaternionf quaternion12 = new Quaternionf().fromAxisAngleRad(Utils.YAW, yaw); + Quaternionf quaternion22 = new Quaternionf().fromAxisAngleRad(Utils.ROLL, 0.0F); + Quaternionf quaternion31 = quaternion12.mul(quaternion5, new Quaternionf()).mul(quaternion22, new Quaternionf()); + Quaternionf quaternion = quaternion41.set(quaternion31); + Vec3 vec32 = Utils.convertToVec3(quaternion.transformUnit(Utils.forward, new Vector3f())); + Vec3 vec33 = Utils.convertToVec3(quaternion.transformUnit(Utils.right, new Vector3f())); + Vec3 vec34 = Utils.convertToVec3(quaternion.transformUnit(Utils.left, new Vector3f())); + Quaternionf quaternion4 = new Quaternionf(); + Quaternionf quaternion21 = new Quaternionf().fromAxisAngleRad(Utils.PITCH, 0.0F); + Quaternionf quaternion11 = new Quaternionf().fromAxisAngleRad(Utils.YAW, Math.toRadians(VRSettings.inst.worldRotation)); + Quaternionf quaternion2 = new Quaternionf().fromAxisAngleRad(Utils.ROLL, 0.0F); + Quaternionf quaternion3 = quaternion11.mul(quaternion21, new Quaternionf()).mul(quaternion2, new Quaternionf()); + Quaternionf quaternion1 = quaternion4.set(quaternion3); + Vec3 vec2 = this.dh.vr.controllerHistory[1].latest(); + Vec3 vec35 = VRPlayer.get().roomOrigin.add(Utils.convertToVec3(quaternion1.transformUnit(new Vector3f((float) vec2.x, (float) vec2.y, (float) vec2.z), new Vector3f()))); + Vec3 vec1 = this.dh.vr.controllerHistory[0].latest(); + Vec3 vec36 = VRPlayer.get().roomOrigin.add(Utils.convertToVec3(quaternion1.transformUnit(new Vector3f((float) vec1.x, (float) vec1.y, (float) vec1.z), new Vector3f()))); double d1 = vec35.subtract(this.info.leftReinPos).dot(vec32) + vec35.subtract(this.info.leftReinPos).dot(vec33); double d2 = vec36.subtract(this.info.rightReinPos).dot(vec32) + vec36.subtract(this.info.rightReinPos).dot(vec34); @@ -87,9 +102,10 @@ public void doProcess(LocalPlayer player) { this.horse.setYRot((float) ((double) f + (d4 - d3) * this.turnspeed)); } - this.horse.yBodyRot = (float) Utils.lerpMod(f1, f, this.bodyturnspeed, 360.0D); + this.horse.yBodyRot = (float) (Math.abs((double) f - (double) f1) < 360.0D / 2.0D ? (double) f1 + ((double) f - (double) f1) * this.bodyturnspeed : (double) f1 + ((double) f - (double) f1 - Math.signum((double) f - (double) f1) * 360.0D) * this.bodyturnspeed); this.horse.yHeadRot = f; - Vec3 vec37 = quaternion.multiply(new Vec3(0.0D, 0.0D, (double) this.speedLevel * this.baseSpeed)); + Vec3 vec = new Vec3(0.0D, 0.0D, (double) this.speedLevel * this.baseSpeed); + Vec3 vec37 = Utils.convertToVec3(quaternion.transformUnit(new Vector3f((float) vec.x, (float) vec.y, (float) vec.z), new Vector3f())); this.horse.setDeltaMovement(vec37.x, this.horse.getDeltaMovement().y, vec37.z); } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java index f5cf563db..fd5e8c05c 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/RowTracker.java @@ -5,10 +5,13 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.entity.vehicle.Boat; import net.minecraft.world.phys.Vec3; +import org.joml.Math; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.VRPlayer; import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.common.utils.math.Quaternion; +import org.vivecraft.common.utils.Utils; public class RowTracker extends Tracker { Vec3[] lastUWPs = new Vec3[2]; @@ -76,7 +79,24 @@ public void doProcess(LocalPlayer player) { public void doProcessFinaltransmithastofixthis(LocalPlayer player) { Boat boat = (Boat) player.getVehicle(); - Quaternion quaternion = (new Quaternion(boat.getXRot(), -(boat.getYRot() % 360.0F), 0.0F)).normalized(); + Quaternionf quaternion4 = new Quaternionf(); + float pitch = Math.toRadians(boat.getXRot()); + float yaw = Math.toRadians(-(boat.getYRot() % 360.0F)); + Quaternionf quaternion21 = new Quaternionf().fromAxisAngleRad(Utils.PITCH, pitch); + Quaternionf quaternion11 = new Quaternionf().fromAxisAngleRad(Utils.YAW, yaw); + Quaternionf quaternion2 = new Quaternionf().fromAxisAngleRad(Utils.ROLL, 0.0F); + Quaternionf quaternion3 = quaternion11.mul(quaternion21, new Quaternionf()).mul(quaternion2, new Quaternionf()); + Quaternionf quaternion1 = (quaternion4.set(quaternion3)); + Quaternionf dest = new Quaternionf(); + float f4 = Math.sqrt(quaternion1.lengthSquared()); + + if (f4 > 0.0F) { + dest.normalize(); + } else { + dest.identity(); + } + + Quaternionf quaternion = dest; for (int i = 0; i <= 1; ++i) { if (!this.isPaddleUnderWater(i, boat)) { @@ -90,7 +110,8 @@ public void doProcessFinaltransmithastofixthis(LocalPlayer player) { if (this.lastUWPs[i] != null) { Vec3 vec33 = this.lastUWPs[i].subtract(vec32); vec33 = vec33.subtract(boat.getDeltaMovement()); - Vec3 vec34 = quaternion.multiply(new Vec3(0.0D, 0.0D, 1.0D)); + Vec3 vec = new Vec3(0.0D, 0.0D, 1.0D); + Vec3 vec34 = Utils.convertToVec3(quaternion.transformUnit(new Vector3f((float) vec.x, (float) vec.y, (float) vec.z), new Vector3f())); double d0 = vec33.dot(vec34) * this.transmissionEfficiency / 5.0D; if ((!(d0 < 0.0D) || !(this.forces[i] > 0.0D)) && (!(d0 > 0.0D) || !(this.forces[i] < 0.0D))) { @@ -113,14 +134,36 @@ Vec3 getArmToPaddleVector(int paddle, Boat boat) { Vec3 getAttachmentPoint(int paddle, Boat boat) { Vec3 vec3 = new Vec3((paddle == 0 ? 9.0F : -9.0F) / 16.0F, 0.625D, 0.1875D); - Quaternion quaternion = (new Quaternion(boat.getXRot(), -(boat.getYRot() % 360.0F), 0.0F)).normalized(); - return boat.position().add(quaternion.multiply(vec3)); + Quaternionf quaternion4 = new Quaternionf(); + float pitch = Math.toRadians(boat.getXRot()); + float yaw = Math.toRadians(-(boat.getYRot() % 360.0F)); + Quaternionf quaternion21 = new Quaternionf().fromAxisAngleRad(Utils.PITCH, pitch); + Quaternionf quaternion11 = new Quaternionf().fromAxisAngleRad(Utils.YAW, yaw); + Quaternionf quaternion2 = new Quaternionf().fromAxisAngleRad(Utils.ROLL, 0.0F); + Quaternionf quaternion3 = quaternion11.mul(quaternion21, new Quaternionf()).mul(quaternion2, new Quaternionf()); + Quaternionf quaternion1 = (quaternion4.set(quaternion3)); + Quaternionf dest = new Quaternionf(); + float f4 = Math.sqrt(quaternion1.lengthSquared()); + + if (f4 > 0.0F) { + dest.normalize(); + } else { + dest.identity(); + } + + Quaternionf quaternion = dest; + return boat.position().add(Utils.convertToVec3(quaternion.transformUnit(new Vector3f((float) vec3.x, (float) vec3.y, (float) vec3.z), new Vector3f()))); } Vec3 getAbsArmPos(int side) { Vec3 vec3 = this.dh.vr.controllerHistory[side].averagePosition(0.1D); - Quaternion quaternion = new Quaternion(0.0F, VRSettings.inst.worldRotation, 0.0F); - return VRPlayer.get().roomOrigin.add(quaternion.multiply(vec3)); + Quaternionf quaternion4 = new Quaternionf(); + Quaternionf quaternion11 = new Quaternionf().fromAxisAngleRad(Utils.PITCH, 0.0F); + Quaternionf quaternion1 = new Quaternionf().fromAxisAngleRad(Utils.YAW, Math.toRadians(VRSettings.inst.worldRotation)); + Quaternionf quaternion2 = new Quaternionf().fromAxisAngleRad(Utils.ROLL, 0.0F); + Quaternionf quaternion3 = quaternion1.mul(quaternion11, new Quaternionf()).mul(quaternion2, new Quaternionf()); + Quaternionf quaternion = quaternion4.set(quaternion3); + return VRPlayer.get().roomOrigin.add(Utils.convertToVec3(quaternion.transformUnit(new Vector3f((float) vec3.x, (float) vec3.y, (float) vec3.z), new Vector3f()))); } boolean isPaddleUnderWater(int paddle, Boat boat) { diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java index ed49906f4..43e9d9a36 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/TeleportTracker.java @@ -15,20 +15,17 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; +import org.joml.Math; +import org.joml.*; import org.vivecraft.client.VivecraftVRMod; import org.vivecraft.client.network.ClientNetworking; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.BlockTags; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.extensions.GameRendererExtension; import org.vivecraft.client_vr.extensions.PlayerExtension; import org.vivecraft.client_vr.gameplay.VRMovementStyle; -import org.vivecraft.client_vr.provider.openvr_lwjgl.OpenVRUtil; import org.vivecraft.client_vr.render.helpers.RenderHelper; -import org.vivecraft.common.utils.math.Angle; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; import java.util.Random; @@ -218,31 +215,30 @@ public void updateTeleportDestinations(GameRenderer renderer, Minecraft mc, Loca } private void updateTeleportArc(Minecraft mc, LocalPlayer player) { - Vec3 vec3 = dh.vrPlayer.vrdata_world_render.getController(1).getPosition(); - Vec3 vec31 = dh.vrPlayer.vrdata_world_render.getController(1).getDirection(); - Matrix4f matrix4f = dh.vr.getAimRotation(1); + Vec3 vec3; + Vec3 vec31; + Matrix4f matrix4f; if (dh.vrSettings.seated) { vec3 = RenderHelper.getControllerRenderPos(0); vec31 = dh.vrPlayer.vrdata_world_render.getController(0).getDirection(); - matrix4f = dh.vr.getAimRotation(0); + matrix4f = dh.vr.getAimRotation(0, new Matrix4f()); + } else { + vec3 = dh.vrPlayer.vrdata_world_render.getController(1).getPosition(); + vec31 = dh.vrPlayer.vrdata_world_render.getController(1).getDirection(); + matrix4f = dh.vr.getAimRotation(1, new Matrix4f()); } - Matrix4f matrix4f1 = Matrix4f.rotationY(dh.vrPlayer.vrdata_world_render.rotation_radians); - matrix4f = Matrix4f.multiply(matrix4f1, matrix4f); - Quaternion quaternion = OpenVRUtil.convertMatrix4ftoRotationQuat(matrix4f); - Angle angle = quaternion.toEuler(); + matrix4f.rotateLocalY(dh.vrPlayer.vrdata_world_render.rotation_radians); + Quaternionf quaternion = new Quaternionf().setFromNormalized(matrix4f.normalize3x3(new Matrix3f())); int i = 50; this.movementTeleportArc[0] = new Vec3(vec3.x, vec3.y, vec3.z); this.movementTeleportArcSteps = 1; - float f = 0.098F; - Matrix4f matrix4f2 = Utils.rotationZMatrix((float) Math.toRadians(-angle.getRoll())); - Matrix4f matrix4f3 = Utils.rotationXMatrix(-2.5132742F); - Matrix4f matrix4f4 = Matrix4f.multiply(matrix4f, matrix4f2); - Vector3 vector3 = new Vector3(0.0F, 1.0F, 0.0F); - Vector3 vector31 = matrix4f4.transform(vector3); - Vec3 vec32 = vector31.negate().toVector3d(); - vec32 = vec32.scale(f); + float angle = Math.toRadians(-(float) Math.toDegrees(Math.atan2(2.0F * (quaternion.x * quaternion.y + quaternion.w * quaternion.z), quaternion.w * quaternion.w - quaternion.x * quaternion.x + quaternion.y * quaternion.y - quaternion.z * quaternion.z))); + // TODO: unused rotation X + // Matrix4f matrix4f3 = new Matrix4f().rotationX(-2.5132742F); + Vector3f vector31 = matrix4f.rotateZ(angle).transformProject(Utils.YAW, new Vector3f()); + Vec3 vec32 = Utils.convertToVec3(vector31.negate(new Vector3f()).mul(0.098F)); float f1 = 0.5F; Vec3 vec33 = new Vec3(vec31.x * (double) f1, vec31.y * (double) f1, vec31.z * (double) f1); Vec3 vec34 = new Vec3(vec3.x, vec3.y, vec3.z); diff --git a/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java b/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java index dd5a0d69b..711df5f49 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java +++ b/common/src/main/java/org/vivecraft/client_vr/gui/GuiKeyboard.java @@ -5,7 +5,6 @@ import net.minecraft.network.chat.Component; import org.lwjgl.glfw.GLFW; import org.vivecraft.client.gui.framework.TwoHandedScreen; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.provider.InputSimulator; public class GuiKeyboard extends TwoHandedScreen { diff --git a/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java b/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java index 6821b2026..38e495417 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java +++ b/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java @@ -12,16 +12,16 @@ import net.minecraft.client.renderer.GameRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.util.Mth; import net.minecraft.util.Tuple; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import org.joml.Matrix4f; +import org.joml.Vector3f; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler; @@ -30,8 +30,7 @@ import org.vivecraft.client_vr.provider.MCVR; import org.vivecraft.client_vr.settings.OptionEnum; import org.vivecraft.client_vr.utils.RGBAColor; -import org.vivecraft.common.utils.lwjgl.Matrix4f; -import org.vivecraft.common.utils.lwjgl.Vector3f; +import org.vivecraft.common.utils.Utils; import java.io.File; import java.io.FileWriter; @@ -416,14 +415,12 @@ private Vector3f getCenterPos() { } private KeyButton findTouchedKey(ControllerType controller) { - Matrix4f matrix4f = new Matrix4f(); - matrix4f.translate(this.getCenterPos()); - Matrix4f.mul(matrix4f, (Matrix4f) Utils.convertOVRMatrix(KeyboardHandler.Rotation_room).invert(), matrix4f); - matrix4f.translate((Vector3f) Utils.convertToVector3f(KeyboardHandler.Pos_room).negate()); - Vec3 vec3 = Utils.convertToVector3d(Utils.transformVector(matrix4f, Utils.convertToVector3f(this.dh.vrPlayer.vrdata_room_pre.getController(controller.ordinal()).getPosition()), true)); + Matrix4f matrix4f = KeyboardHandler.Rotation_room.invertAffine(new Matrix4f()).translateLocal(this.getCenterPos()).translate(new Vector3f((float) KeyboardHandler.Pos_room.x, (float) KeyboardHandler.Pos_room.y, (float) KeyboardHandler.Pos_room.z).negate()); + Vec3 vector = this.dh.vrPlayer.vrdata_room_pre.getController(controller.ordinal()).getPosition(); + Vector3f vec3 = matrix4f.transformPosition(new Vector3f((float) vector.x, (float) vector.y, (float) vector.z)); for (KeyButton physicalkeyboard$keybutton : this.keys) { - if (physicalkeyboard$keybutton.getCollisionBoundingBox().contains(vec3)) { + if (physicalkeyboard$keybutton.getCollisionBoundingBox().contains(vec3.x, vec3.y, vec3.z)) { return physicalkeyboard$keybutton; } } @@ -447,7 +444,7 @@ private void updateEasterEgg(String label) { } private void drawBox(BufferBuilder buf, AABB box, RGBAColor color, PoseStack poseStack) { - org.joml.Matrix4f matrix = poseStack.last().pose(); + Matrix4f matrix = poseStack.last().pose(); float minX = (float) box.minX, minY = (float) box.minY, minZ = (float) box.minZ; float maxX = (float) box.maxX, maxY = (float) box.maxY, maxZ = (float) box.maxZ; buf.vertex(matrix, minX, minY, minZ).uv(0, 0).color(color.r, color.g, color.b, color.a).normal(0.0F, 0.0F, -1.0F).endVertex(); diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java index 215c781be..4364ae64d 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java @@ -1,9 +1,9 @@ package org.vivecraft.client_vr.menuworlds; import net.minecraft.SharedConstants; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import java.io.File; import java.io.FileInputStream; diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/InputSimulator.java b/common/src/main/java/org/vivecraft/client_vr/provider/InputSimulator.java index 6417714eb..74f41bad2 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/InputSimulator.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/InputSimulator.java @@ -7,8 +7,8 @@ import java.util.HashSet; import java.util.Set; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.common.utils.Utils; public class InputSimulator { private static final Set pressedKeys = new HashSet<>(); diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java index 39eb530dd..399dfe3bb 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java @@ -11,11 +11,10 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.TorchBlock; import net.minecraft.world.phys.Vec3; -import org.joml.Quaternionf; -import org.joml.Vector2f; +import org.joml.Math; +import org.joml.*; import org.lwjgl.glfw.GLFW; import org.vivecraft.client.VivecraftVRMod; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.QuaternionfHistory; import org.vivecraft.client_vr.VRData; @@ -33,10 +32,7 @@ import org.vivecraft.client_vr.settings.VRHotkeys; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.client_xr.render_pass.RenderPassManager; -import org.vivecraft.common.utils.lwjgl.Matrix4f; -import org.vivecraft.common.utils.lwjgl.Vector3f; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mod_compat_vr.ShadersHelper; import java.io.BufferedReader; @@ -52,19 +48,19 @@ public abstract class MCVR { protected ClientDataHolderVR dh; protected static MCVR me; protected static VivecraftVRMod mod; - protected org.vivecraft.common.utils.math.Matrix4f hmdPose = new org.vivecraft.common.utils.math.Matrix4f(); - public org.vivecraft.common.utils.math.Matrix4f hmdRotation = new org.vivecraft.common.utils.math.Matrix4f(); + protected Matrix4f hmdPose = new Matrix4f(); + public Matrix4f hmdRotation = new Matrix4f(); public HardwareType detectedHardware = HardwareType.VIVE; - protected org.vivecraft.common.utils.math.Matrix4f hmdPoseLeftEye = new org.vivecraft.common.utils.math.Matrix4f(); - protected org.vivecraft.common.utils.math.Matrix4f hmdPoseRightEye = new org.vivecraft.common.utils.math.Matrix4f(); + protected Matrix4f hmdPoseLeftEye = new Matrix4f(); + protected Matrix4f hmdPoseRightEye = new Matrix4f(); public Vec3History hmdHistory = new Vec3History(); public Vec3History hmdPivotHistory = new Vec3History(); public QuaternionfHistory hmdRotHistory = new QuaternionfHistory(); protected boolean headIsTracking; - protected org.vivecraft.common.utils.math.Matrix4f[] controllerPose = new org.vivecraft.common.utils.math.Matrix4f[3]; - protected org.vivecraft.common.utils.math.Matrix4f[] controllerRotation = new org.vivecraft.common.utils.math.Matrix4f[3]; + protected Matrix4f[] controllerPose = new Matrix4f[3]; + protected Matrix4f[] controllerRotation = new Matrix4f[3]; protected boolean[] controllerTracking = new boolean[3]; - protected org.vivecraft.common.utils.math.Matrix4f[] handRotation = new org.vivecraft.common.utils.math.Matrix4f[3]; + protected Matrix4f[] handRotation = new Matrix4f[3]; public Vec3History[] controllerHistory = new Vec3History[]{new Vec3History(), new Vec3History()}; public Vec3History[] controllerForwardHistory = new Vec3History[]{new Vec3History(), new Vec3History()}; public Vec3History[] controllerUpHistory = new Vec3History[]{new Vec3History(), new Vec3History()}; @@ -73,11 +69,9 @@ public abstract class MCVR { public boolean initialized; public String initStatus; public boolean initSuccess; - protected org.vivecraft.common.utils.math.Matrix4f[] poseMatrices; + protected Matrix4f[] poseMatrices; protected Vec3[] deviceVelocity; protected Vec3[] aimSource = new Vec3[3]; - public Vector3 forward = new Vector3(0.0F, 0.0F, -1.0F); - public Vector3 up = new Vector3(0.0F, 1.0F, 0.0F); public int hmdAvgLength = 90; public LinkedList hmdPosSamples = new LinkedList<>(); public LinkedList hmdYawSamples = new LinkedList<>(); @@ -92,9 +86,12 @@ public abstract class MCVR { protected HapticScheduler hapticScheduler; public float seatedRot; public float aimPitch = 0.0F; - protected final org.vivecraft.common.utils.math.Matrix4f Neutral_HMD = new org.vivecraft.common.utils.math.Matrix4f(1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.62F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F); - protected final org.vivecraft.common.utils.math.Matrix4f TPose_Left = new org.vivecraft.common.utils.math.Matrix4f(1.0F, 0.0F, 0.0F, 0.25F, 0.0F, 1.0F, 0.0F, 1.62F, 0.0F, 0.0F, 1.0F, 0.25F, 0.0F, 0.0F, 0.0F, 1.0F); - protected final org.vivecraft.common.utils.math.Matrix4f TPose_Right = new org.vivecraft.common.utils.math.Matrix4f(1.0F, 0.0F, 0.0F, 0.75F, 0.0F, 1.0F, 0.0F, 1.62F, 0.0F, 0.0F, 1.0F, 0.75F, 0.0F, 0.0F, 0.0F, 1.0F); + protected final Matrix4f Neutral_HMD = new Matrix4f().setTranslation(0.0F, 1.62F, 0.0F); + + protected final Matrix4f TPose_Left = new Matrix4f().setTranslation(0.25F, 1.62F, 0.25F); + + protected final Matrix4f TPose_Right = new Matrix4f().setTranslation(0.75F, 1.62F, 0.75F); + protected boolean TPose = false; public boolean hudPopup = true; protected int moveModeSwitchCount = 0; @@ -117,9 +114,9 @@ public MCVR(Minecraft mc, ClientDataHolderVR dh, VivecraftVRMod vrMod) { for (int i = 0; i < 3; ++i) { this.aimSource[i] = new Vec3(0.0D, 0.0D, 0.0D); - this.controllerPose[i] = new org.vivecraft.common.utils.math.Matrix4f(); - this.controllerRotation[i] = new org.vivecraft.common.utils.math.Matrix4f(); - this.handRotation[i] = new org.vivecraft.common.utils.math.Matrix4f(); + this.controllerPose[i] = new Matrix4f(); + this.controllerRotation[i] = new Matrix4f(); + this.handRotation[i] = new Matrix4f(); } } @@ -139,8 +136,8 @@ public double getGunAngle() { return this.gunAngle; } - public org.vivecraft.common.utils.math.Matrix4f getAimRotation(int controller) { - return this.controllerRotation[controller]; + public Matrix4f getAimRotation(int controller, Matrix4f dest) { + return dest.set(this.controllerRotation[controller]); } public Vec3 getAimSource(int controller) { @@ -148,7 +145,7 @@ public Vec3 getAimSource(int controller) { if (!this.dh.vrSettings.seated && this.dh.vrSettings.allowStandingOriginOffset) { if (this.dh.vr.isHMDTracking()) { - vec3 = vec3.add(this.dh.vrSettings.originOffset.getX(), this.dh.vrSettings.originOffset.getY(), this.dh.vrSettings.originOffset.getZ()); + vec3 = vec3.add(this.dh.vrSettings.originOffset.x(), this.dh.vrSettings.originOffset.y(), this.dh.vrSettings.originOffset.z()); } } @@ -156,8 +153,8 @@ public Vec3 getAimSource(int controller) { } public Vec3 getAimVector(int controller) { - Vector3 vector3 = this.controllerRotation[controller].transform(this.forward); - return vector3.toVector3d(); + Vector3f vector3 = this.controllerRotation[controller].transformProject(Utils.forward, new Vector3f()); + return Utils.convertToVec3(vector3); } public void triggerHapticPulse(ControllerType controller, float durationSeconds, float frequency, float amplitude) { @@ -192,19 +189,16 @@ public void triggerHapticPulse(int controller, int strength) { } } - public org.vivecraft.common.utils.math.Matrix4f getHandRotation(int controller) { - return this.handRotation[controller]; + public Matrix4f getHandRotation(int controller, Matrix4f dest) { + return dest.set(this.handRotation[controller]); } public Vec3 getHandVector(int controller) { - Vector3 vector3 = new Vector3(0.0F, 0.0F, -1.0F); - org.vivecraft.common.utils.math.Matrix4f matrix4f = this.handRotation[controller]; - Vector3 vector31 = matrix4f.transform(vector3); - return vector31.toVector3d(); + return Utils.convertToVec3(this.handRotation[controller].transformProject(0.0F, 0.0F, -1.0F, new Vector3f())); } public Vec3 getCenterEyePosition() { - Vector3 vector3 = Utils.convertMatrix4ftoTranslationVector(this.hmdPose); + Vector3f vector3 = this.hmdPose.getTranslation(new Vector3f()); if (this.dh.vrSettings.seated || this.dh.vrSettings.allowStandingOriginOffset) { if (this.dh.vr.isHMDTracking()) { @@ -212,11 +206,11 @@ public Vec3 getCenterEyePosition() { } } - return vector3.toVector3d(); + return Utils.convertToVec3(vector3); } public Vec3 getEyePosition(RenderPass eye) { - org.vivecraft.common.utils.math.Matrix4f matrix4f = this.hmdPoseRightEye; + Matrix4f matrix4f; if (eye == RenderPass.LEFT) { matrix4f = this.hmdPoseLeftEye; @@ -227,27 +221,26 @@ public Vec3 getEyePosition(RenderPass eye) { } if (matrix4f == null) { - org.vivecraft.common.utils.math.Matrix4f matrix4f2 = this.hmdPose; - Vector3 vector31 = Utils.convertMatrix4ftoTranslationVector(matrix4f2); + Vector3f vector31 = this.hmdPose.getTranslation(new Vector3f()); if (this.dh.vrSettings.seated || this.dh.vrSettings.allowStandingOriginOffset) { if (this.dh.vr.isHMDTracking()) { - vector31 = vector31.add(this.dh.vrSettings.originOffset); + vector31.add(this.dh.vrSettings.originOffset); } } - return vector31.toVector3d(); + return Utils.convertToVec3(vector31); } else { - org.vivecraft.common.utils.math.Matrix4f matrix4f1 = org.vivecraft.common.utils.math.Matrix4f.multiply(this.hmdPose, matrix4f); - Vector3 vector3 = Utils.convertMatrix4ftoTranslationVector(matrix4f1); + Matrix4f dest = this.hmdPose.mul(matrix4f); + Vector3f vector3 = dest.getTranslation(new Vector3f()); if (this.dh.vrSettings.seated || this.dh.vrSettings.allowStandingOriginOffset) { if (this.dh.vr.isHMDTracking()) { - vector3 = vector3.add(this.dh.vrSettings.originOffset); + vector3.add(this.dh.vrSettings.originOffset); } } - return vector3.toVector3d(); + return Utils.convertToVec3(vector3); } } @@ -256,12 +249,12 @@ public HardwareType getHardwareType() { } public Vec3 getHmdVector() { - Vector3 vector3 = this.hmdRotation.transform(this.forward); - return vector3.toVector3d(); + Vector3f vector3 = this.hmdRotation.transformProject(Utils.forward, new Vector3f()); + return Utils.convertToVec3(vector3); } - public org.vivecraft.common.utils.math.Matrix4f getEyeRotation(RenderPass eye) { - org.vivecraft.common.utils.math.Matrix4f matrix4f; + public Matrix4f getEyeRotation(RenderPass eye, Matrix4f dest) { + Matrix4f matrix4f; if (eye == RenderPass.LEFT) { matrix4f = this.hmdPoseLeftEye; @@ -272,26 +265,9 @@ public org.vivecraft.common.utils.math.Matrix4f getEyeRotation(RenderPass eye) { } if (matrix4f != null) { - org.vivecraft.common.utils.math.Matrix4f matrix4f1 = new org.vivecraft.common.utils.math.Matrix4f(); - matrix4f1.M[0][0] = matrix4f.M[0][0]; - matrix4f1.M[0][1] = matrix4f.M[0][1]; - matrix4f1.M[0][2] = matrix4f.M[0][2]; - matrix4f1.M[0][3] = 0.0F; - matrix4f1.M[1][0] = matrix4f.M[1][0]; - matrix4f1.M[1][1] = matrix4f.M[1][1]; - matrix4f1.M[1][2] = matrix4f.M[1][2]; - matrix4f1.M[1][3] = 0.0F; - matrix4f1.M[2][0] = matrix4f.M[2][0]; - matrix4f1.M[2][1] = matrix4f.M[2][1]; - matrix4f1.M[2][2] = matrix4f.M[2][2]; - matrix4f1.M[2][3] = 0.0F; - matrix4f1.M[3][0] = 0.0F; - matrix4f1.M[3][1] = 0.0F; - matrix4f1.M[3][2] = 0.0F; - matrix4f1.M[3][3] = 1.0F; - return org.vivecraft.common.utils.math.Matrix4f.multiply(this.hmdRotation, matrix4f1); + return this.hmdRotation.mul(new Matrix4f().set3x3(matrix4f), dest); } else { - return this.hmdRotation; + return dest.set(this.hmdRotation); } } @@ -327,12 +303,12 @@ public boolean isControllerTracking(int controller) { } public void resetPosition() { - Vec3 vec3 = this.getCenterEyePosition().scale(-1.0D).add(this.dh.vrSettings.originOffset.getX(), this.dh.vrSettings.originOffset.getY(), this.dh.vrSettings.originOffset.getZ()); - this.dh.vrSettings.originOffset = new Vector3((float) vec3.x, (float) vec3.y + 1.62F, (float) vec3.z); + Vec3 vec3 = this.getCenterEyePosition().scale(-1.0D).add(this.dh.vrSettings.originOffset.x(), this.dh.vrSettings.originOffset.y(), this.dh.vrSettings.originOffset.z()); + this.dh.vrSettings.originOffset = new Vector3f((float) vec3.x, (float) vec3.y + 1.62F, (float) vec3.z); } public void clearOffset() { - this.dh.vrSettings.originOffset = new Vector3(0.0F, 0.0F, 0.0F); + this.dh.vrSettings.originOffset.zero(); } public boolean isHMDTracking() { @@ -367,11 +343,13 @@ protected void processHotbar() { } if (this.dh.vrSettings.vrHudLockMode == VRSettings.HUDLock.WRIST) { - barStartPos = this.getAimRotation(1).transform(new Vector3((float) i * 0.02F, 0.05F, 0.26F)).toVector3d(); - barEndPos = this.getAimRotation(1).transform(new Vector3((float) i * 0.02F, 0.05F, 0.01F)).toVector3d(); + Matrix4f matrix4f = this.getAimRotation(1, new Matrix4f()); + barStartPos = Utils.convertToVec3(matrix4f.transformProject(new Vector3f((float) i * 0.02F, 0.05F, 0.26F), new Vector3f())); + barEndPos = Utils.convertToVec3(matrix4f.transformProject(new Vector3f((float) i * 0.02F, 0.05F, 0.01F), new Vector3f())); } else if (this.dh.vrSettings.vrHudLockMode == VRSettings.HUDLock.HAND) { - barStartPos = this.getAimRotation(1).transform(new Vector3((float) i * -0.18F, 0.08F, -0.01F)).toVector3d(); - barEndPos = this.getAimRotation(1).transform(new Vector3((float) i * 0.19F, 0.04F, -0.08F)).toVector3d(); + Matrix4f matrix4f = this.getAimRotation(1, new Matrix4f()); + barStartPos = Utils.convertToVec3(matrix4f.transformProject(new Vector3f((float) i * -0.18F, 0.08F, -0.01F), new Vector3f())); + barEndPos = Utils.convertToVec3(matrix4f.transformProject(new Vector3f((float) i * 0.19F, 0.04F, -0.08F), new Vector3f())); } else { return; //how did u get here } @@ -454,36 +432,27 @@ protected void hmdSampling() { this.hmdYawSamples.removeFirst(); } - float f = this.dh.vrPlayer.vrdata_room_pre.hmd.getYaw(); - - if (f < 0.0F) { - f += 360.0F; - } - - this.hmdYawTotal += Utils.angleDiff(f, this.hmdYawLast); + float f = Math.abs(this.dh.vrPlayer.vrdata_room_pre.hmd.getYaw() % 360.0F); + float f3 = Math.abs(f - this.hmdYawLast) % 360.0F; + int i = (!(f - this.hmdYawLast >= 0.0F) || !(f - this.hmdYawLast <= 180.0F)) && (!(f - this.hmdYawLast <= -180.0F) || !(f - this.hmdYawLast >= -360.0F)) ? -1 : 1; + this.hmdYawTotal += (f3 > 180.0F ? 360.0F - f3 : f3) * (float) i; this.hmdYawLast = f; - if (Math.abs(Utils.angleNormalize(this.hmdYawTotal) - this.hmdYawLast) > 1.0F || this.hmdYawTotal > 100000.0F) { + if (Math.abs(Math.abs(this.hmdYawTotal % 360.0F) - this.hmdYawLast) > 1.0F || this.hmdYawTotal > 100000.0F) { this.hmdYawTotal = this.hmdYawLast; System.out.println("HMD yaw desync/overflow corrected"); } this.hmdPosSamples.add(this.dh.vrPlayer.vrdata_room_pre.hmd.getPosition()); - float f1 = 0.0F; + float f1 = Math.abs(this.hmdYawTotal - ( + !this.hmdYawSamples.isEmpty() ? + this.hmdYawSamples.stream().reduce(0.0F, Float::sum) / this.hmdYawSamples.size() : + 0 + )); - if (this.hmdYawSamples.size() > 0) { - for (float f2 : this.hmdYawSamples) { - f1 += f2; - } - - f1 /= (float) this.hmdYawSamples.size(); - } - - if (Math.abs(this.hmdYawTotal - f1) > 20.0F) { + if (f1 > 20.0F) { this.trigger = true; - } - - if (Math.abs(this.hmdYawTotal - f1) < 1.0F) { + } else if (f1 < 1.0F) { this.trigger = false; } @@ -497,101 +466,53 @@ protected void updateAim() { if (this.mc != null) { - this.hmdRotation.M[0][0] = this.hmdPose.M[0][0]; - this.hmdRotation.M[0][1] = this.hmdPose.M[0][1]; - this.hmdRotation.M[0][2] = this.hmdPose.M[0][2]; - this.hmdRotation.M[0][3] = 0.0F; - this.hmdRotation.M[1][0] = this.hmdPose.M[1][0]; - this.hmdRotation.M[1][1] = this.hmdPose.M[1][1]; - this.hmdRotation.M[1][2] = this.hmdPose.M[1][2]; - this.hmdRotation.M[1][3] = 0.0F; - this.hmdRotation.M[2][0] = this.hmdPose.M[2][0]; - this.hmdRotation.M[2][1] = this.hmdPose.M[2][1]; - this.hmdRotation.M[2][2] = this.hmdPose.M[2][2]; - this.hmdRotation.M[2][3] = 0.0F; - this.hmdRotation.M[3][0] = 0.0F; - this.hmdRotation.M[3][1] = 0.0F; - this.hmdRotation.M[3][2] = 0.0F; - this.hmdRotation.M[3][3] = 1.0F; + this.hmdRotation.identity().set3x3(this.hmdPose); Vec3 vec3 = this.getCenterEyePosition(); this.hmdHistory.add(vec3); - Vector3 vector3 = this.hmdRotation.transform(new Vector3(0.0F, -0.1F, 0.1F)); - this.hmdPivotHistory.add(new Vec3((double) vector3.getX() + vec3.x, (double) vector3.getY() + vec3.y, (double) vector3.getZ() + vec3.z)); - hmdRotHistory.add(new Quaternionf().setFromNormalized(hmdRotation.transposed().toMCMatrix().rotateY((float) -Math.toRadians(this.dh.vrSettings.worldRotation)))); + Vector3f vector3 = this.hmdRotation.transformProject(0.0F, -0.1F, 0.1F, new Vector3f()); + this.hmdPivotHistory.add(new Vec3((double) vector3.x() + vec3.x, (double) vector3.y() + vec3.y, (double) vector3.z() + vec3.z)); + this.hmdRotHistory.add(new Quaternionf().setFromNormalized(new Matrix4f(this.hmdRotation).rotateY(-Math.toRadians(this.dh.vrSettings.worldRotation)))); if (this.dh.vrSettings.seated) { - this.controllerPose[0] = this.hmdPose.inverted().inverted(); - this.controllerPose[1] = this.hmdPose.inverted().inverted(); + this.controllerPose[1].set(this.hmdPose.invert(this.controllerPose[0]).invert()); } - org.vivecraft.common.utils.math.Matrix4f[] amatrix4f = new org.vivecraft.common.utils.math.Matrix4f[]{new org.vivecraft.common.utils.math.Matrix4f(), new org.vivecraft.common.utils.math.Matrix4f()}; - org.vivecraft.common.utils.math.Matrix4f[] amatrix4f1 = new org.vivecraft.common.utils.math.Matrix4f[]{new org.vivecraft.common.utils.math.Matrix4f(), new org.vivecraft.common.utils.math.Matrix4f()}; + Matrix4f controllerGrip0; if (this.dh.vrSettings.seated) { - amatrix4f1[0] = this.controllerPose[0]; + controllerGrip0 = this.controllerPose[0]; } else { - amatrix4f1[0] = org.vivecraft.common.utils.math.Matrix4f.multiply(this.controllerPose[0], this.getControllerComponentTransform(0, "handgrip")); + controllerGrip0 = this.controllerPose[0].mul(this.getControllerComponentTransform(0, "handgrip", new Matrix4f())); } - this.handRotation[0].M[0][0] = amatrix4f1[0].M[0][0]; - this.handRotation[0].M[0][1] = amatrix4f1[0].M[0][1]; - this.handRotation[0].M[0][2] = amatrix4f1[0].M[0][2]; - this.handRotation[0].M[0][3] = 0.0F; - this.handRotation[0].M[1][0] = amatrix4f1[0].M[1][0]; - this.handRotation[0].M[1][1] = amatrix4f1[0].M[1][1]; - this.handRotation[0].M[1][2] = amatrix4f1[0].M[1][2]; - this.handRotation[0].M[1][3] = 0.0F; - this.handRotation[0].M[2][0] = amatrix4f1[0].M[2][0]; - this.handRotation[0].M[2][1] = amatrix4f1[0].M[2][1]; - this.handRotation[0].M[2][2] = amatrix4f1[0].M[2][2]; - this.handRotation[0].M[2][3] = 0.0F; - this.handRotation[0].M[3][0] = 0.0F; - this.handRotation[0].M[3][1] = 0.0F; - this.handRotation[0].M[3][2] = 0.0F; - this.handRotation[0].M[3][3] = 1.0F; + this.handRotation[0].identity().set3x3(controllerGrip0); + + Matrix4f controllerTip0; if (this.dh.vrSettings.seated) { - amatrix4f[0] = this.controllerPose[0]; + controllerTip0 = this.controllerPose[0]; } else { - amatrix4f[0] = org.vivecraft.common.utils.math.Matrix4f.multiply(this.controllerPose[0], this.getControllerComponentTransform(0, "tip")); + controllerTip0 = this.controllerPose[0].mul(this.getControllerComponentTransform(0, "tip", new Matrix4f())); } - Vector3 vector31 = Utils.convertMatrix4ftoTranslationVector(amatrix4f[0]); - this.aimSource[0] = vector31.toVector3d(); + this.aimSource[0] = Utils.convertToVec3(controllerTip0.getTranslation(new Vector3f())); this.controllerHistory[0].add(this.getAimSource(0)); - this.controllerRotation[0].M[0][0] = amatrix4f[0].M[0][0]; - this.controllerRotation[0].M[0][1] = amatrix4f[0].M[0][1]; - this.controllerRotation[0].M[0][2] = amatrix4f[0].M[0][2]; - this.controllerRotation[0].M[0][3] = 0.0F; - this.controllerRotation[0].M[1][0] = amatrix4f[0].M[1][0]; - this.controllerRotation[0].M[1][1] = amatrix4f[0].M[1][1]; - this.controllerRotation[0].M[1][2] = amatrix4f[0].M[1][2]; - this.controllerRotation[0].M[1][3] = 0.0F; - this.controllerRotation[0].M[2][0] = amatrix4f[0].M[2][0]; - this.controllerRotation[0].M[2][1] = amatrix4f[0].M[2][1]; - this.controllerRotation[0].M[2][2] = amatrix4f[0].M[2][2]; - this.controllerRotation[0].M[2][3] = 0.0F; - this.controllerRotation[0].M[3][0] = 0.0F; - this.controllerRotation[0].M[3][1] = 0.0F; - this.controllerRotation[0].M[3][2] = 0.0F; - this.controllerRotation[0].M[3][3] = 1.0F; + this.controllerRotation[0].identity().set3x3(controllerTip0); Vec3 vec31 = this.getHmdVector(); if (this.dh.vrSettings.seated && this.mc.screen == null && this.mc.mouseHandler.isMouseGrabbed()) { - Matrix4f matrix4f = new Matrix4f(); - float f = 110.0F; - float f1 = 180.0F; - double d0 = this.mc.mouseHandler.xpos() / (double) this.mc.getWindow().getScreenWidth() * (double) f - (double) (f / 2.0F); - int i = this.mc.getWindow().getScreenHeight(); - - if (i % 2 != 0) { - --i; - } + if (this.mc.isWindowActive()) { + float f = 110.0F; + float f1 = 180.0F; + double d0 = this.mc.mouseHandler.xpos() / (double) this.mc.getWindow().getScreenWidth() * (double) f - (double) (f / 2.0F); + int i = this.mc.getWindow().getScreenHeight(); - double d1 = -this.mc.mouseHandler.ypos() / (double) i * (double) f1 + (double) (f1 / 2.0F); - double d2 = -d1; + if (i % 2 != 0) { + --i; + } - if (this.mc.isWindowActive()) { + double d1 = -this.mc.mouseHandler.ypos() / (double) i * (double) f1 + (double) (f1 / 2.0F); + double d2 = -d1; float f2 = this.dh.vrSettings.keyholeX; float f3 = 20.0F * this.dh.vrSettings.xSensitivity; int j = (int) ((double) (-f2 + f / 2.0F) * (double) this.mc.getWindow().getScreenWidth() / (double) f) + 1; @@ -620,88 +541,47 @@ protected void updateAim() { double screenY = (i * 0.5F) * (((WindowExtension) (Object) this.mc.getWindow()).vivecraft$getActualScreenHeight() / (double) this.mc.getWindow().getScreenHeight()); InputSimulator.setMousePos(screenX, screenY); GLFW.glfwSetCursorPos(this.mc.getWindow().getWindow(), screenX, screenY); - matrix4f.rotate((float) Math.toRadians(-d2), new Vector3f(1.0F, 0.0F, 0.0F)); - matrix4f.rotate((float) Math.toRadians(-180.0D + d0 - (double) this.hmdForwardYaw), new Vector3f(0.0F, 1.0F, 0.0F)); + this.controllerRotation[0].set3x3(this.controllerRotation[0] + .rotationX((float) Math.toRadians(-d2)) + .rotateY((float) Math.toRadians(-180.0D + d0 - (double) this.hmdForwardYaw)) + .transpose(this.handRotation[0]) + ); + } else { + this.controllerRotation[0].identity(); + this.handRotation[0].identity(); } - - this.controllerRotation[0].M[0][0] = matrix4f.m00; - this.controllerRotation[0].M[0][1] = matrix4f.m01; - this.controllerRotation[0].M[0][2] = matrix4f.m02; - this.controllerRotation[0].M[1][0] = matrix4f.m10; - this.controllerRotation[0].M[1][1] = matrix4f.m11; - this.controllerRotation[0].M[1][2] = matrix4f.m12; - this.controllerRotation[0].M[2][0] = matrix4f.m20; - this.controllerRotation[0].M[2][1] = matrix4f.m21; - this.controllerRotation[0].M[2][2] = matrix4f.m22; - - this.handRotation[0].M[0][0] = matrix4f.m00; - this.handRotation[0].M[0][1] = matrix4f.m01; - this.handRotation[0].M[0][2] = matrix4f.m02; - this.handRotation[0].M[1][0] = matrix4f.m10; - this.handRotation[0].M[1][1] = matrix4f.m11; - this.handRotation[0].M[1][2] = matrix4f.m12; - this.handRotation[0].M[2][0] = matrix4f.m20; - this.handRotation[0].M[2][1] = matrix4f.m21; - this.handRotation[0].M[2][2] = matrix4f.m22; } Vec3 vec32 = this.getAimVector(0); this.aimPitch = (float) Math.toDegrees(Math.asin(vec32.y / vec32.length())); this.controllerForwardHistory[0].add(vec32); - Vec3 vec33 = this.controllerRotation[0].transform(this.up).toVector3d(); + Vec3 vec33 = Utils.convertToVec3(this.controllerRotation[0].transformProject(Utils.up, new Vector3f())); this.controllerUpHistory[0].add(vec33); + Matrix4f controllerGrip1; + if (this.dh.vrSettings.seated) { - amatrix4f1[1] = this.controllerPose[1]; + controllerGrip1 = this.controllerPose[1]; } else { - amatrix4f1[1] = org.vivecraft.common.utils.math.Matrix4f.multiply(this.controllerPose[1], this.getControllerComponentTransform(1, "handgrip")); + controllerGrip1 = this.controllerPose[1].mul(this.getControllerComponentTransform(1, "handgrip", new Matrix4f())); } - this.handRotation[1].M[0][0] = amatrix4f1[1].M[0][0]; - this.handRotation[1].M[0][1] = amatrix4f1[1].M[0][1]; - this.handRotation[1].M[0][2] = amatrix4f1[1].M[0][2]; - this.handRotation[1].M[0][3] = 0.0F; - this.handRotation[1].M[1][0] = amatrix4f1[1].M[1][0]; - this.handRotation[1].M[1][1] = amatrix4f1[1].M[1][1]; - this.handRotation[1].M[1][2] = amatrix4f1[1].M[1][2]; - this.handRotation[1].M[1][3] = 0.0F; - this.handRotation[1].M[2][0] = amatrix4f1[1].M[2][0]; - this.handRotation[1].M[2][1] = amatrix4f1[1].M[2][1]; - this.handRotation[1].M[2][2] = amatrix4f1[1].M[2][2]; - this.handRotation[1].M[2][3] = 0.0F; - this.handRotation[1].M[3][0] = 0.0F; - this.handRotation[1].M[3][1] = 0.0F; - this.handRotation[1].M[3][2] = 0.0F; - this.handRotation[1].M[3][3] = 1.0F; + this.handRotation[1].identity().set3x3(controllerGrip1); + + Matrix4f controllerTip1; if (this.dh.vrSettings.seated) { - amatrix4f[1] = this.controllerPose[1]; + controllerTip1 = this.controllerPose[1]; } else { - amatrix4f[1] = org.vivecraft.common.utils.math.Matrix4f.multiply(this.controllerPose[1], this.getControllerComponentTransform(1, "tip")); + controllerTip1 = this.controllerPose[1].mul(this.getControllerComponentTransform(1, "tip", new Matrix4f())); } - vector31 = Utils.convertMatrix4ftoTranslationVector(amatrix4f[1]); - this.aimSource[1] = vector31.toVector3d(); + this.aimSource[1] = Utils.convertToVec3(controllerTip1.getTranslation(new Vector3f())); this.controllerHistory[1].add(this.getAimSource(1)); - this.controllerRotation[1].M[0][0] = amatrix4f[1].M[0][0]; - this.controllerRotation[1].M[0][1] = amatrix4f[1].M[0][1]; - this.controllerRotation[1].M[0][2] = amatrix4f[1].M[0][2]; - this.controllerRotation[1].M[0][3] = 0.0F; - this.controllerRotation[1].M[1][0] = amatrix4f[1].M[1][0]; - this.controllerRotation[1].M[1][1] = amatrix4f[1].M[1][1]; - this.controllerRotation[1].M[1][2] = amatrix4f[1].M[1][2]; - this.controllerRotation[1].M[1][3] = 0.0F; - this.controllerRotation[1].M[2][0] = amatrix4f[1].M[2][0]; - this.controllerRotation[1].M[2][1] = amatrix4f[1].M[2][1]; - this.controllerRotation[1].M[2][2] = amatrix4f[1].M[2][2]; - this.controllerRotation[1].M[2][3] = 0.0F; - this.controllerRotation[1].M[3][0] = 0.0F; - this.controllerRotation[1].M[3][1] = 0.0F; - this.controllerRotation[1].M[3][2] = 0.0F; - this.controllerRotation[1].M[3][3] = 1.0F; + this.controllerRotation[1].identity().set3x3(controllerTip1); vec31 = this.getAimVector(1); this.controllerForwardHistory[1].add(vec31); - vec32 = this.controllerRotation[1].transform(this.up).toVector3d(); + vec32 = Utils.convertToVec3(this.controllerRotation[1].transformProject(Utils.up, new Vector3f())); this.controllerUpHistory[1].add(vec32); if (this.dh.vrSettings.seated) { @@ -712,33 +592,17 @@ protected void updateAim() { boolean flag = false; if (flag) { - this.controllerPose[2] = this.controllerPose[0]; + this.controllerPose[2].set(this.controllerPose[0]); } - this.controllerRotation[2].M[0][0] = this.controllerPose[2].M[0][0]; - this.controllerRotation[2].M[0][1] = this.controllerPose[2].M[0][1]; - this.controllerRotation[2].M[0][2] = this.controllerPose[2].M[0][2]; - this.controllerRotation[2].M[0][3] = 0.0F; - this.controllerRotation[2].M[1][0] = this.controllerPose[2].M[1][0]; - this.controllerRotation[2].M[1][1] = this.controllerPose[2].M[1][1]; - this.controllerRotation[2].M[1][2] = this.controllerPose[2].M[1][2]; - this.controllerRotation[2].M[1][3] = 0.0F; - this.controllerRotation[2].M[2][0] = this.controllerPose[2].M[2][0]; - this.controllerRotation[2].M[2][1] = this.controllerPose[2].M[2][1]; - this.controllerRotation[2].M[2][2] = this.controllerPose[2].M[2][2]; - this.controllerRotation[2].M[2][3] = 0.0F; - this.controllerRotation[2].M[3][0] = 0.0F; - this.controllerRotation[2].M[3][1] = 0.0F; - this.controllerRotation[2].M[3][2] = 0.0F; - this.controllerRotation[2].M[3][3] = 1.0F; + this.controllerRotation[2].identity().set3x3(this.controllerPose[2]); if ((!this.hasThirdController() || this.dh.vrSettings.displayMirrorMode != VRSettings.MirrorMode.MIXED_REALITY && this.dh.vrSettings.displayMirrorMode != VRSettings.MirrorMode.THIRD_PERSON) && !flag) { this.mrMovingCamActive = false; - this.aimSource[2] = new Vec3(this.dh.vrSettings.vrFixedCamposX, this.dh.vrSettings.vrFixedCamposY, this.dh.vrSettings.vrFixedCamposZ); + this.aimSource[2] = Utils.convertToVec3(this.dh.vrSettings.vrFixedCampos); } else { this.mrMovingCamActive = true; - Vector3 vector32 = Utils.convertMatrix4ftoTranslationVector(this.controllerPose[2]); - this.aimSource[2] = vector32.toVector3d(); + this.aimSource[2] = Utils.convertToVec3(this.controllerPose[2].getTranslation(new Vector3f())); } } } @@ -849,10 +713,10 @@ public void processBindings() { } if (this.dh.vrSettings.worldRotationIncrement == 0.0F) { - float f4 = this.getInputAction(mod.keyRotateAxis).getAxis2DUseTracked().getX(); + float f4 = this.getInputAction(mod.keyRotateAxis).getAxis2DUseTracked().x(); if (f4 == 0.0F) { - f4 = this.getInputAction(mod.keyFreeMoveRotate).getAxis2DUseTracked().getX(); + f4 = this.getInputAction(mod.keyFreeMoveRotate).getAxis2DUseTracked().x(); } if (f4 != 0.0F) { @@ -861,10 +725,10 @@ public void processBindings() { this.dh.vrSettings.worldRotation %= 360.0F; } } else if (mod.keyRotateAxis.consumeClick() || mod.keyFreeMoveRotate.consumeClick()) { - float f5 = this.getInputAction(mod.keyRotateAxis).getAxis2D(false).getX(); + float f5 = this.getInputAction(mod.keyRotateAxis).getAxis2D(false).x(); if (f5 == 0.0F) { - f5 = this.getInputAction(mod.keyFreeMoveRotate).getAxis2D(false).getX(); + f5 = this.getInputAction(mod.keyFreeMoveRotate).getAxis2D(false).x(); } if (Math.abs(f5) > 0.5F) { @@ -993,7 +857,7 @@ public void processBindings() { VRData.VRDevicePose vrdata$vrdevicepose = this.dh.vrPlayer.vrdata_world_pre.getController(controllertype3.ordinal()); this.dh.cameraTracker.setPosition(vrdata$vrdevicepose.getPosition()); - this.dh.cameraTracker.setRotation(new Quaternion(vrdata$vrdevicepose.getMatrix().transposed())); + this.dh.cameraTracker.setRotation(new Quaternionf().setFromNormalized(vrdata$vrdevicepose.getMatrix(new Matrix4f()))); } } @@ -1010,7 +874,7 @@ public void processBindings() { VRData.VRDevicePose vrdata$vrdevicepose1 = this.dh.vrPlayer.vrdata_world_pre.getController(controllertype4.ordinal()); this.dh.cameraTracker.setPosition(vrdata$vrdevicepose1.getPosition()); - this.dh.cameraTracker.setRotation(new Quaternion(vrdata$vrdevicepose1.getMatrix().transposed())); + this.dh.cameraTracker.setRotation(new Quaternionf().setFromNormalized(vrdata$vrdevicepose1.getMatrix(new Matrix4f()))); this.dh.cameraTracker.startMoving(controllertype4.ordinal(), true); } @@ -1162,7 +1026,7 @@ private void addActionParams(Map map, KeyMapping keyBindin public abstract boolean postinit() throws RenderConfigException; - public abstract org.vivecraft.common.utils.math.Matrix4f getControllerComponentTransform(int var1, String var2); + public abstract Matrix4f getControllerComponentTransform(int var1, String var2, Matrix4f dest); public abstract boolean hasThirdController(); diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java index 3a6123c9a..0f9c0b3b5 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java @@ -54,7 +54,8 @@ public abstract class VRRenderer { public RenderTarget cameraRenderFramebuffer; protected int dispLastWidth; protected int dispLastHeight; - public Matrix4f[] eyeproj = new Matrix4f[2]; + public final Matrix4f eyeproj0 = new Matrix4f(); + public final Matrix4f eyeproj1 = new Matrix4f(); public RenderTarget framebufferEye0; public RenderTarget framebufferEye1; public RenderTarget framebufferMR; @@ -103,7 +104,7 @@ protected void checkGLError(String message) { public abstract void createRenderTexture(int var1, int var2); - public abstract Matrix4f getProjectionMatrix(int var1, float var2, float var3); + public abstract Matrix4f getProjectionMatrix(int var1, float var2, float var3, Matrix4f dest); public abstract void endFrame() throws RenderConfigException; @@ -675,8 +676,8 @@ public void setupRenderConfiguration() throws Exception { this.checkGLError("Camera render framebuffer setup"); ((GameRendererExtension) minecraft.gameRenderer).vivecraft$setupClipPlanes(); - this.eyeproj[0] = this.getProjectionMatrix(0, ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getMinClipDistance(), ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getClipDistance()); - this.eyeproj[1] = this.getProjectionMatrix(1, ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getMinClipDistance(), ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getClipDistance()); + this.getProjectionMatrix(0, ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getMinClipDistance(), ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getClipDistance(), this.eyeproj0); + this.getProjectionMatrix(1, ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getMinClipDistance(), ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getClipDistance(), this.eyeproj1); if (dataholder.vrSettings.useFsaa) { try { diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java index 1bd65a126..57a396194 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java @@ -2,10 +2,10 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; +import org.joml.Matrix4f; import org.joml.Vector2f; import org.lwjgl.glfw.GLFW; import org.vivecraft.client.VivecraftVRMod; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.MethodHolder; import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; @@ -13,7 +13,6 @@ import org.vivecraft.client_vr.provider.MCVR; import org.vivecraft.client_vr.provider.VRRenderer; import org.vivecraft.client_vr.provider.openvr_lwjgl.VRInputAction; -import org.vivecraft.common.utils.math.Matrix4f; import java.util.List; @@ -64,12 +63,12 @@ public boolean init() { this.dh.vrSettings.seated = true; this.headIsTracking = false; - Utils.Matrix4fSetIdentity(this.hmdPose); - this.hmdPose.M[1][3] = 1.62F; + this.hmdPose.identity(); + this.hmdPose.m31(1.62F); // eye offset, 10cm total distance - this.hmdPoseLeftEye.M[0][3] = -0.05F; - this.hmdPoseRightEye.M[0][3] = 0.05F; + this.hmdPoseLeftEye.m30(-0.05F); + this.hmdPoseRightEye.m30(0.05F); this.initialized = true; this.initSuccess = true; @@ -93,40 +92,21 @@ public void poll(long frameIndex) { this.updateAim(); - this.controllerPose[0].M[0][3] = 0.3F; - this.controllerPose[0].M[1][3] = 1.2F; - this.controllerPose[0].M[2][3] = -0.5F; + this.controllerPose[0].setTranslation(0.3F, 1.2F, -0.5F); - this.controllerPose[1].M[0][3] = -0.3F; - this.controllerPose[1].M[1][3] = 1.2F; - this.controllerPose[1].M[2][3] = -0.5F; + this.controllerPose[1].setTranslation(-0.3F, 1.2F, -0.5F); this.dh.vrSettings.xSensitivity = xSens; this.dh.vrSettings.keyholeX = xKey; // point head in cursor direction - hmdRotation.M[0][0] = handRotation[0].M[0][0]; - hmdRotation.M[0][1] = handRotation[0].M[0][1]; - hmdRotation.M[0][2] = handRotation[0].M[0][2]; - hmdRotation.M[1][0] = handRotation[0].M[1][0]; - hmdRotation.M[1][1] = handRotation[0].M[1][1]; - hmdRotation.M[1][2] = handRotation[0].M[1][2]; - hmdRotation.M[2][0] = handRotation[0].M[2][0]; - hmdRotation.M[2][1] = handRotation[0].M[2][1]; - hmdRotation.M[2][2] = handRotation[0].M[2][2]; + + this.hmdRotation.set3x3(this.handRotation[0]); if (GuiHandler.guiRotation_room != null) { // look at screen, so that it's centered - hmdRotation.M[0][0] = GuiHandler.guiRotation_room.M[0][0]; - hmdRotation.M[0][1] = GuiHandler.guiRotation_room.M[0][1]; - hmdRotation.M[0][2] = GuiHandler.guiRotation_room.M[0][2]; - hmdRotation.M[1][0] = GuiHandler.guiRotation_room.M[1][0]; - hmdRotation.M[1][1] = GuiHandler.guiRotation_room.M[1][1]; - hmdRotation.M[1][2] = GuiHandler.guiRotation_room.M[1][2]; - hmdRotation.M[2][0] = GuiHandler.guiRotation_room.M[2][0]; - hmdRotation.M[2][1] = GuiHandler.guiRotation_room.M[2][1]; - hmdRotation.M[2][2] = GuiHandler.guiRotation_room.M[2][2]; + this.hmdRotation.set3x3(GuiHandler.guiRotation_room); } this.mc.getProfiler().popPush("hmdSampling"); this.hmdSampling(); @@ -150,8 +130,8 @@ protected ControllerType findActiveBindingControllerType(KeyMapping binding) { } @Override - public Matrix4f getControllerComponentTransform(int controllerIndex, String componenetName) { - return new Matrix4f(); + public Matrix4f getControllerComponentTransform(int controllerIndex, String componenetName, Matrix4f dest) { + return dest; } @Override diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java index b8d020266..b2fab3868 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java @@ -30,8 +30,8 @@ public Tuple getRenderTextureSizes() { } @Override - public Matrix4f getProjectionMatrix(int eyeType, float nearClip, float farClip) { - return new Matrix4f().setPerspective(90.0F, 1.0F, nearClip, farClip); + public Matrix4f getProjectionMatrix(int eyeType, float nearClip, float farClip, Matrix4f dest) { + return dest.setPerspective(90.0F, 1.0F, nearClip, farClip); } @Override diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java index cbf78413e..84d058fdd 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java @@ -1,6 +1,5 @@ package org.vivecraft.client_vr.provider.openvr_lwjgl; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -11,14 +10,14 @@ import net.minecraft.client.resources.language.ClientLanguage; import net.minecraft.locale.Language; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.phys.Vec3; +import org.joml.Matrix4f; import org.joml.Vector2f; +import org.joml.Vector3f; import org.lwjgl.openvr.*; import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryUtil; import org.vivecraft.client.VivecraftVRMod; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler; @@ -31,8 +30,7 @@ import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.client_vr.utils.external.jinfinadeck; import org.vivecraft.client_vr.utils.external.jkatvr; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; import java.io.File; import java.io.FileOutputStream; @@ -577,12 +575,12 @@ private boolean updateActiveActionSets() { return !arraylist.isEmpty(); } - public Matrix4f getControllerComponentTransform(int controllerIndex, String componenetName) { - return this.controllerComponentTransforms != null && this.controllerComponentTransforms.containsKey(componenetName) && ((Matrix4f[]) this.controllerComponentTransforms.get(componenetName))[controllerIndex] != null ? (this.controllerComponentTransforms.get(componenetName))[controllerIndex] : Utils.Matrix4fSetIdentity(new Matrix4f()); + public Matrix4f getControllerComponentTransform(int controllerIndex, String componenetName, Matrix4f dest) { + return this.controllerComponentTransforms != null && this.controllerComponentTransforms.containsKey(componenetName) && ((Matrix4f[]) this.controllerComponentTransforms.get(componenetName))[controllerIndex] != null ? dest.set(this.controllerComponentTransforms.get(componenetName)[controllerIndex]) : dest.identity(); } - private Matrix4f getControllerComponentTransformFromButton(int controllerIndex, long button) { - return this.controllerComponentNames != null && this.controllerComponentNames.containsKey(button) ? this.getControllerComponentTransform(controllerIndex, this.controllerComponentNames.get(button)) : new Matrix4f(); + private Matrix4f getControllerComponentTransformFromButton(int controllerIndex, long button, Matrix4f dest) { + return this.controllerComponentNames != null && this.controllerComponentNames.containsKey(button) ? this.getControllerComponentTransform(controllerIndex, this.controllerComponentNames.get(button), dest) : dest.identity(); } private int getError() { @@ -633,7 +631,7 @@ private void getTransforms() { boolean flag = false; for (String s : list) { - this.controllerComponentTransforms.put(s, new Matrix4f[2]); + this.controllerComponentTransforms.put(s, new Matrix4f[]{new Matrix4f(), new Matrix4f()}); for (int j = 0; j < 2; ++j) { if (this.controllerDeviceIndex[j] == -1) { @@ -648,10 +646,7 @@ private void getTransforms() { boolean flag1 = inputProfilePath.contains("holographic"); boolean flag2 = inputProfilePath.contains("rifts"); - var componentName = s; - if (flag1 && s.equals("handgrip")) { - componentName = "body"; - } + String componentName = flag1 && s.equals("handgrip") ? "body" : s; long k = VRRenderModels_GetComponentButtonMask(renderModelName, componentName); @@ -664,30 +659,26 @@ private void getTransforms() { if (l == 0L) { flag = true; } else { - var renderModelComponentState = RenderModelComponentState.calloc(stack); + RenderModelComponentState renderModelComponentState = RenderModelComponentState.calloc(stack); boolean b0 = VRRenderModels_GetComponentStateForDevicePath(renderModelName, componentName, l, RenderModelControllerModeState.calloc(stack), renderModelComponentState); if (!b0) { flag = true; } else { - Matrix4f matrix4f = new Matrix4f(); - OpenVRUtil.convertSteamVRMatrix3ToMatrix4f(renderModelComponentState.mTrackingToComponentLocal(), matrix4f); - (this.controllerComponentTransforms.get(s))[j] = matrix4f; + Utils.convertRM34ToCM44(renderModelComponentState.mTrackingToComponentLocal().m(), this.controllerComponentTransforms.get(s)[j]); if (j == 1 && flag2 && s.equals("handgrip")) { - (this.controllerComponentTransforms.get(s))[1] = (this.controllerComponentTransforms.get(s))[0]; + this.controllerComponentTransforms.get(s)[1].set(this.controllerComponentTransforms.get(s)[0]); } if (!flag && j == 0) { try { - Matrix4f matrix4f1 = this.getControllerComponentTransform(0, "tip"); - Matrix4f matrix4f2 = this.getControllerComponentTransform(0, "handgrip"); - Vector3 vector3 = matrix4f1.transform(this.forward); - Vector3 vector31 = matrix4f2.transform(this.forward); - double d0 = Math.abs(vector3.normalized().dot(vector31.normalized())); + Vector3f vector3 = this.getControllerComponentTransform(0, "tip", new Matrix4f()).transformProject(Utils.forward, new Vector3f()); + Vector3f vector31 = this.getControllerComponentTransform(0, "handgrip", new Matrix4f()).transformProject(Utils.forward, new Vector3f()); + double d0 = Math.abs(vector3.normalize(new Vector3f()).dot(vector31.normalize(new Vector3f()))); double d1 = Math.acos(d0); double d2 = Math.toDegrees(d1); - double d3 = Math.acos(vector3.normalized().dot(this.forward.normalized())); + double d3 = Math.acos(vector3.normalize(new Vector3f()).dot(Utils.forward.normalize(new Vector3f()))); double d4 = Math.toDegrees(d3); this.gunStyle = d2 > 10.0D; this.gunAngle = d2; @@ -935,8 +926,8 @@ private void processInputAction(VRInputAction action) { private void processScrollInput(KeyMapping keyBinding, Runnable upCallback, Runnable downCallback) { VRInputAction vrinputaction = this.getInputAction(keyBinding); - if (vrinputaction.isEnabled() && vrinputaction.getLastOrigin() != 0L && vrinputaction.getAxis2D(true).getY() != 0.0F) { - float f = vrinputaction.getAxis2D(false).getY(); + if (vrinputaction.isEnabled() && vrinputaction.getLastOrigin() != 0L && vrinputaction.getAxis2D(true).y() != 0.0F) { + float f = vrinputaction.getAxis2D(false).y(); if (f > 0.0F) { upCallback.run(); @@ -1021,9 +1012,9 @@ private void readPoseData(long actionHandle) { private void updateControllerPose(int controller, long actionHandle) { if (this.TPose) { if (controller == 0) { - Utils.Matrix4fCopy(this.TPose_Right, this.controllerPose[controller]); + this.controllerPose[controller].set(this.TPose_Right); } else if (controller == 1) { - Utils.Matrix4fCopy(this.TPose_Left, this.controllerPose[controller]); + this.controllerPose[controller].set(this.TPose_Left); } this.controllerTracking[controller] = true; @@ -1044,9 +1035,8 @@ private void updateControllerPose(int controller, long actionHandle) { TrackedDevicePose trackeddevicepose = this.poseData.pose(); if (trackeddevicepose.bPoseIsValid()) { - OpenVRUtil.convertSteamVRMatrix3ToMatrix4f(trackeddevicepose.mDeviceToAbsoluteTracking(), this.poseMatrices[i]); this.deviceVelocity[i] = new Vec3(trackeddevicepose.vVelocity().v(0), trackeddevicepose.vVelocity().v(1), trackeddevicepose.vVelocity().v(2)); - Utils.Matrix4fCopy(this.poseMatrices[i], this.controllerPose[controller]); + this.controllerPose[controller].set(this.poseMatrices[i]); this.controllerTracking[controller] = true; return; } @@ -1060,7 +1050,7 @@ private void updateControllerPose(int controller, long actionHandle) { } private void updatePose() { - if (OpenVR.VRSystem != null && OpenVR.VRSystem != null) { + if (OpenVR.VRSystem != null && OpenVR.VRCompositor != null) { int i = VRCompositor_WaitGetPoses(this.hmdTrackedDevicePoses, null); if (i > 0) { @@ -1083,49 +1073,34 @@ private void updatePose() { try (MemoryStack stack = MemoryStack.stackPush()) { var hmdmatrix34 = HmdMatrix34.calloc(stack); - OpenVRUtil.convertSteamVRMatrix3ToMatrix4f(VRSystem_GetEyeToHeadTransform(0, hmdmatrix34), this.hmdPoseLeftEye); - OpenVRUtil.convertSteamVRMatrix3ToMatrix4f(VRSystem_GetEyeToHeadTransform(1, hmdmatrix34), this.hmdPoseRightEye); + Utils.convertRM34ToCM44(VRSystem_GetEyeToHeadTransform(0, hmdmatrix34).m(), this.hmdPoseLeftEye); + Utils.convertRM34ToCM44(VRSystem_GetEyeToHeadTransform(1, hmdmatrix34).m(), this.hmdPoseRightEye); } - for (int j = 0; j < 64; ++j) { - - if (this.hmdTrackedDevicePoses.get(j).bPoseIsValid()) { - OpenVRUtil.convertSteamVRMatrix3ToMatrix4f(this.hmdTrackedDevicePoses.get(j).mDeviceToAbsoluteTracking(), this.poseMatrices[j]); - this.deviceVelocity[j] = new Vec3(this.hmdTrackedDevicePoses.get(j).vVelocity().v(0), this.hmdTrackedDevicePoses.get(j).vVelocity().v(1), this.hmdTrackedDevicePoses.get(j).vVelocity().v(2)); + for (int j = 0; j < this.poseMatrices.length; ++j) { + TrackedDevicePose trackedDevicePose = this.hmdTrackedDevicePoses.get(j); + if (trackedDevicePose.bPoseIsValid()) { + Utils.convertRM34ToCM44(trackedDevicePose.mDeviceToAbsoluteTracking().m(), this.poseMatrices[j]); + this.deviceVelocity[j] = new Vec3(trackedDevicePose.vVelocity().v(0), trackedDevicePose.vVelocity().v(1), trackedDevicePose.vVelocity().v(2)); } } if (this.hmdTrackedDevicePoses.get(0).bPoseIsValid()) { - Utils.Matrix4fCopy(this.poseMatrices[0], this.hmdPose); + this.hmdPose.set(this.poseMatrices[0]); this.headIsTracking = true; } else { this.headIsTracking = false; - Utils.Matrix4fSetIdentity(this.hmdPose); - this.hmdPose.M[1][3] = 1.62F; + this.hmdPose.identity().m31(1.62F); } this.TPose = false; if (this.TPose) { - this.TPose_Right.M[0][3] = 0.0F; - this.TPose_Right.M[1][3] = 0.0F; - this.TPose_Right.M[2][3] = 0.0F; - Matrix4f matrix4f = this.TPose_Right; - Utils.Matrix4fCopy(Matrix4f.rotationY(-120.0F), this.TPose_Right); - this.TPose_Right.M[0][3] = 0.5F; - this.TPose_Right.M[1][3] = 1.0F; - this.TPose_Right.M[2][3] = -0.5F; - this.TPose_Left.M[0][3] = 0.0F; - this.TPose_Left.M[1][3] = 0.0F; - this.TPose_Left.M[2][3] = 0.0F; - matrix4f = this.TPose_Left; - Utils.Matrix4fCopy(Matrix4f.rotationY(120.0F), this.TPose_Left); - this.TPose_Left.M[0][3] = -0.5F; - this.TPose_Left.M[1][3] = 1.0F; - this.TPose_Left.M[2][3] = -0.5F; - this.Neutral_HMD.M[0][3] = 0.0F; - this.Neutral_HMD.M[1][3] = 1.8F; - Utils.Matrix4fCopy(this.Neutral_HMD, this.hmdPose); + this.TPose_Right.rotationY(-120.0F).setTranslation(0.5F, 1.0F, -0.5F); + this.TPose_Left.rotationY(120.0F).setTranslation(-0.5F, 1.0F, -0.5F); + this.Neutral_HMD.m30(0.0F); + this.Neutral_HMD.m31(1.8F); + this.hmdPose.set(this.Neutral_HMD); this.headIsTracking = true; } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java index 1d386114e..f3e826796 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java @@ -13,7 +13,6 @@ import org.lwjgl.openvr.VR; import org.lwjgl.system.MemoryStack; import org.lwjgl.system.MemoryUtil; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.provider.MCVR; import org.vivecraft.client_vr.provider.VRRenderer; import org.vivecraft.client_vr.render.RenderConfigException; @@ -71,12 +70,12 @@ public Tuple getRenderTextureSizes() { } } - public Matrix4f getProjectionMatrix(int eyeType, float nearClip, float farClip) { + public Matrix4f getProjectionMatrix(int eyeType, float nearClip, float farClip, Matrix4f dest) { try (MemoryStack stack = MemoryStack.stackPush()) { if (eyeType == 0) { - return Utils.Matrix4fFromOpenVR(VRSystem_GetProjectionMatrix(0, nearClip, farClip, HmdMatrix44.calloc(stack))); + return dest.setTransposed(VRSystem_GetProjectionMatrix(0, nearClip, farClip, HmdMatrix44.calloc(stack)).m()); } else { - return Utils.Matrix4fFromOpenVR(VRSystem_GetProjectionMatrix(1, nearClip, farClip, HmdMatrix44.calloc(stack))); + return dest.setTransposed(VRSystem_GetProjectionMatrix(1, nearClip, farClip, HmdMatrix44.calloc(stack)).m()); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRUtil.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRUtil.java deleted file mode 100644 index baf25575d..000000000 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRUtil.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.vivecraft.client_vr.provider.openvr_lwjgl; - -import org.lwjgl.openvr.HmdMatrix34; -import org.vivecraft.client.utils.Utils; -import org.vivecraft.common.utils.math.Matrix4f; -import org.vivecraft.common.utils.math.Quaternion; - -public class OpenVRUtil { - public static Matrix4f convertSteamVRMatrix3ToMatrix4f(HmdMatrix34 hmdMatrix, Matrix4f mat) { - Utils.Matrix4fSet(mat, hmdMatrix.m(0), hmdMatrix.m(1), hmdMatrix.m(2), hmdMatrix.m(3), hmdMatrix.m(4), hmdMatrix.m(5), hmdMatrix.m(6), hmdMatrix.m(7), hmdMatrix.m(8), hmdMatrix.m(9), hmdMatrix.m(10), hmdMatrix.m(11), 0.0F, 0.0F, 0.0F, 1.0F); - return mat; - } - -// public static Matrix4f convertSteamVRMatrix4ToMatrix4f(HmdMatrix44_t hmdMatrix, Matrix4f mat) -// { -// Utils.Matrix4fSet(mat, hmdMatrix.m[0], hmdMatrix.m[1], hmdMatrix.m[2], hmdMatrix.m[3], hmdMatrix.m[4], hmdMatrix.m[5], hmdMatrix.m[6], hmdMatrix.m[7], hmdMatrix.m[8], hmdMatrix.m[9], hmdMatrix.m[10], hmdMatrix.m[11], hmdMatrix.m[12], hmdMatrix.m[13], hmdMatrix.m[14], hmdMatrix.m[15]); -// return mat; -// } - - public static Quaternion convertMatrix4ftoRotationQuat(Matrix4f mat) { - return Utils.convertMatrix4ftoRotationQuat(mat.M[0][0], mat.M[0][1], mat.M[0][2], mat.M[1][0], mat.M[1][1], mat.M[1][2], mat.M[2][0], mat.M[2][1], mat.M[2][2]); - } - -// public static HmdMatrix34_t convertToMatrix34(org.joml.Matrix4f matrix) -// { -// HmdMatrix34_t hmdmatrix34_t = new HmdMatrix34_t(); -// hmdmatrix34_t.m[0] = matrix.m00(); -// hmdmatrix34_t.m[1] = matrix.m10(); -// hmdmatrix34_t.m[2] = matrix.m20(); -// hmdmatrix34_t.m[3] = matrix.m30(); -// hmdmatrix34_t.m[4] = matrix.m01(); -// hmdmatrix34_t.m[5] = matrix.m11(); -// hmdmatrix34_t.m[6] = matrix.m21(); -// hmdmatrix34_t.m[7] = matrix.m31(); -// hmdmatrix34_t.m[8] = matrix.m02(); -// hmdmatrix34_t.m[9] = matrix.m12(); -// hmdmatrix34_t.m[10] = matrix.m22(); -// hmdmatrix34_t.m[11] = matrix.m32(); -// return hmdmatrix34_t; -// } -} diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/VRInputAction.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/VRInputAction.java index 0dca0469d..63121952a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/VRInputAction.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/VRInputAction.java @@ -2,14 +2,14 @@ import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; +import org.joml.Vector2f; +import org.joml.Vector3f; import org.vivecraft.client.VivecraftVRMod; import org.vivecraft.client_vr.provider.ControllerType; import org.vivecraft.client_vr.provider.HandedKeyBinding; import org.vivecraft.client_vr.provider.InputSimulator; import org.vivecraft.client_vr.provider.MCVR; import org.vivecraft.client_vr.provider.openvr_lwjgl.control.VRInputActionSet; -import org.vivecraft.common.utils.math.Vector2; -import org.vivecraft.common.utils.math.Vector3; import javax.annotation.Nullable; import java.util.ArrayList; @@ -52,8 +52,8 @@ public boolean isButtonPressed() { if (this.type.equals("boolean")) { return this.digitalData().state; } else { - Vector3 vector3 = this.getAxis3D(false); - return Math.abs(vector3.getX()) > 0.5F || Math.abs(vector3.getY()) > 0.5F || Math.abs(vector3.getZ()) > 0.5F; + Vector3f vector3 = this.getAxis3D(false); + return Math.abs(vector3.x()) > 0.5F || Math.abs(vector3.y()) > 0.5F || Math.abs(vector3.z()) > 0.5F; } } @@ -61,9 +61,9 @@ public boolean isButtonChanged() { if (this.type.equals("boolean")) { return this.digitalData().isChanged; } else { - Vector3 vector3 = this.getAxis3D(false); - Vector3 vector31 = this.getAxis3D(true); - return Math.abs(vector3.getX() - vector31.getX()) > 0.5F != Math.abs(vector3.getX()) > 0.5F || Math.abs(vector3.getY() - vector31.getY()) > 0.5F != Math.abs(vector3.getY()) > 0.5F || Math.abs(vector3.getZ() - vector31.getZ()) > 0.5F != Math.abs(vector3.getZ()) > 0.5F; + Vector3f vector3 = this.getAxis3D(false); + Vector3f vector31 = this.getAxis3D(true); + return Math.abs(vector3.x() - vector31.x()) > 0.5F != Math.abs(vector3.x()) > 0.5F || Math.abs(vector3.y() - vector31.y()) > 0.5F != Math.abs(vector3.y()) > 0.5F || Math.abs(vector3.z() - vector31.z()) > 0.5F != Math.abs(vector3.z()) > 0.5F; } } @@ -84,43 +84,43 @@ public float getAxis1D(boolean delta) { } } - public Vector2 getAxis2D(boolean delta) { + public Vector2f getAxis2D(boolean delta) { String s = this.type; switch (s) { case "boolean": - return new Vector2(this.digitalToAnalog(delta), 0.0F); + return new Vector2f(this.digitalToAnalog(delta), 0.0F); case "vector1": - return delta ? new Vector2(this.analogData().deltaX, 0.0F) : new Vector2(this.analogData().x, 0.0F); + return delta ? new Vector2f(this.analogData().deltaX, 0.0F) : new Vector2f(this.analogData().x, 0.0F); case "vector2": case "vector3": - return delta ? new Vector2(this.analogData().deltaX, this.analogData().deltaY) : new Vector2(this.analogData().x, this.analogData().y); + return delta ? new Vector2f(this.analogData().deltaX, this.analogData().deltaY) : new Vector2f(this.analogData().x, this.analogData().y); default: - return new Vector2(); + return new Vector2f(); } } - public Vector3 getAxis3D(boolean delta) { + public Vector3f getAxis3D(boolean delta) { String s = this.type; switch (s) { case "boolean": - return new Vector3(this.digitalToAnalog(delta), 0.0F, 0.0F); + return new Vector3f(this.digitalToAnalog(delta), 0.0F, 0.0F); case "vector1": - return delta ? new Vector3(this.analogData().deltaX, 0.0F, 0.0F) : new Vector3(this.analogData().x, 0.0F, 0.0F); + return delta ? new Vector3f(this.analogData().deltaX, 0.0F, 0.0F) : new Vector3f(this.analogData().x, 0.0F, 0.0F); case "vector2": - return delta ? new Vector3(this.analogData().deltaX, this.analogData().deltaY, 0.0F) : new Vector3(this.analogData().x, this.analogData().y, 0.0F); + return delta ? new Vector3f(this.analogData().deltaX, this.analogData().deltaY, 0.0F) : new Vector3f(this.analogData().x, this.analogData().y, 0.0F); case "vector3": - return delta ? new Vector3(this.analogData().deltaX, this.analogData().deltaY, this.analogData().deltaZ) : new Vector3(this.analogData().x, this.analogData().y, this.analogData().z); + return delta ? new Vector3f(this.analogData().deltaX, this.analogData().deltaY, this.analogData().deltaZ) : new Vector3f(this.analogData().x, this.analogData().y, this.analogData().z); default: - return new Vector3(); + return new Vector3f(); } } @@ -134,22 +134,22 @@ public float getAxis1DUseTracked() { } } - public Vector2 getAxis2DUseTracked() { + public Vector2f getAxis2DUseTracked() { if (!this.currentlyInUse && !this.isEnabled()) { - return new Vector2(); + return new Vector2f(); } else { - Vector2 vector2 = this.getAxis2D(false); - this.currentlyInUse = vector2.getX() != 0.0F || vector2.getY() != 0.0F; - return vector2; + Vector2f vector2f = this.getAxis2D(false); + this.currentlyInUse = vector2f.x() != 0.0F || vector2f.y() != 0.0F; + return vector2f; } } - Vector3 getAxis3DUseTracked() { + Vector3f getAxis3DUseTracked() { if (!this.currentlyInUse && !this.isEnabled()) { - return new Vector3(); + return new Vector3f(); } else { - Vector3 vector3 = this.getAxis3D(false); - this.currentlyInUse = vector3.getX() != 0.0F || vector3.getY() != 0.0F || vector3.getZ() != 0.0F; + Vector3f vector3 = this.getAxis3D(false); + this.currentlyInUse = vector3.x() != 0.0F || vector3.y() != 0.0F || vector3.z() != 0.0F; return vector3; } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/control/TrackpadSwipeSampler.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/control/TrackpadSwipeSampler.java index fd581e0b5..3987d00d3 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/control/TrackpadSwipeSampler.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/control/TrackpadSwipeSampler.java @@ -1,10 +1,9 @@ package org.vivecraft.client_vr.provider.openvr_lwjgl.control; +import org.joml.Vector2f; import org.vivecraft.client.VivecraftVRMod; import org.vivecraft.client_vr.provider.ControllerType; import org.vivecraft.client_vr.provider.openvr_lwjgl.MCOpenVR; -import org.vivecraft.common.utils.lwjgl.Vector2f; -import org.vivecraft.common.utils.math.Vector2; public class TrackpadSwipeSampler { private static final int UP = 0; @@ -24,11 +23,14 @@ public TrackpadSwipeSampler() { } } - public void update(ControllerType hand, Vector2 position) { + public void update(ControllerType hand, Vector2f position) { MCOpenVR.get().getInputAction(VivecraftVRMod.INSTANCE.keyTrackpadTouch).setCurrentHand(hand); if (MCOpenVR.get().getInputAction(VivecraftVRMod.INSTANCE.keyTrackpadTouch).isButtonPressed()) { - this.buffer[this.index].set(position.getX(), position.getY()); + float x = position.x(); + float y = position.y(); + this.buffer[this.index].x = x; + this.buffer[this.index].y = y; if (++this.index >= this.buffer.length) { this.index = 0; @@ -37,7 +39,8 @@ public void update(ControllerType hand, Vector2 position) { ++this.count; } else { for (Vector2f vector2f : this.buffer) { - vector2f.set(0.0F, 0.0F); + vector2f.x = 0.0F; + vector2f.y = 0.0F; } this.count = 0L; @@ -68,7 +71,8 @@ public void update(ControllerType hand, Vector2 position) { int l = this.swiped[2]++; } } else { - this.accumulator.set(0.0F, 0.0F); + this.accumulator.x = 0.0F; + this.accumulator.y = 0.0F; } } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java index 83ad66774..3d3f7ed87 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/VivecraftItemRendering.java @@ -14,6 +14,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.TorchBlock; import net.minecraft.world.phys.Vec3; +import org.joml.Matrix4f; import org.joml.Quaternionf; import org.vivecraft.client.VivecraftVRMod; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -175,7 +176,7 @@ public static void applyFirstPersonItemTransforms(PoseStack pMatrixStack, Vivecr } pMatrixStack.translate(0.0D, 0.0D, 0.1D); - pMatrixStack.last().pose().mul(dh.vrPlayer.vrdata_world_render.getController(1).getMatrix().transposed().toMCMatrix()); + pMatrixStack.last().pose().mul(dh.vrPlayer.vrdata_world_render.getController(1).getMatrix(new Matrix4f())); rotation.mul(Axis.YP.rotationDegrees(f1)); rotation.mul(Axis.XP.rotationDegrees(-f)); rotation.mul(Axis.ZP.rotationDegrees(-f3)); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/XRCamera.java b/common/src/main/java/org/vivecraft/client_vr/render/XRCamera.java index 7198636db..9f5decc73 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/XRCamera.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/XRCamera.java @@ -39,7 +39,7 @@ public void setup(BlockGetter pLevel, Entity pRenderViewEntity, boolean pThirdPe Vec3 left = eye.getCustomVector(new Vec3(1.0D, 0.0D, 0.0D)); this.getLeftVector().set((float) left.x, (float) left.y, (float) left.z); - this.rotation().set(0.0F, 0.0F, 0.0F, 1.0F); + this.rotation().identity(); this.rotation().mul(Axis.YP.rotationDegrees(-this.yRot)); this.rotation().mul(Axis.XP.rotationDegrees(this.xRot)); } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java index 5e81f3ad9..67b63e0f2 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/RenderHelper.java @@ -17,6 +17,7 @@ import net.minecraft.world.phys.Vec3; import org.joml.Matrix3f; import org.joml.Matrix4f; +import org.joml.Quaternionf; import org.joml.Vector3f; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL43C; @@ -46,16 +47,15 @@ public class RenderHelper { private static final Minecraft mc = Minecraft.getInstance(); public static void applyVRModelView(RenderPass currentPass, PoseStack poseStack) { - Matrix4f modelView; if (currentPass == RenderPass.CENTER && dataHolder.vrSettings.displayMirrorCenterSmooth > 0.0F) { - modelView = new Matrix4f().rotation(MCVR.get().hmdRotHistory - .averageRotation(dataHolder.vrSettings.displayMirrorCenterSmooth)); + Quaternionf rot = MCVR.get().hmdRotHistory.averageRotation(dataHolder.vrSettings.displayMirrorCenterSmooth); + poseStack.last().pose().rotate(rot); + poseStack.last().normal().rotate(rot); } else { - modelView = dataHolder.vrPlayer.vrdata_world_render.getEye(currentPass) - .getMatrix().transposed().toMCMatrix(); + Matrix4f modelView = dataHolder.vrPlayer.vrdata_world_render.getEye(currentPass).getMatrix(new Matrix4f()).transpose(); + poseStack.last().pose().mul(modelView); + poseStack.last().normal().mul(new Matrix3f(modelView)); } - poseStack.last().pose().mul(modelView); - poseStack.last().normal().mul(new Matrix3f(modelView)); } public static Vec3 getSmoothCameraPosition(RenderPass renderpass, VRData vrData) { @@ -126,13 +126,15 @@ public static void setupRenderingAtController(int controller, PoseStack matrix) matrix.translate(aimSource.x, aimSource.y, aimSource.z); float sc = dataHolder.vrPlayer.vrdata_world_render.worldScale; if (mc.level != null && TelescopeTracker.isTelescope(mc.player.getUseItem())) { - matrix.mulPoseMatrix(dataHolder.vrPlayer.vrdata_world_render.hmd.getMatrix().inverted() - .transposed().toMCMatrix()); + matrix.mulPoseMatrix( + dataHolder.vrPlayer.vrdata_world_render.hmd.getMatrix(new Matrix4f()).invert().transpose() + ); MethodHolder.rotateDegXp(matrix, 90); matrix.translate(controller == 0 ? 0.075 * sc : -0.075 * sc, -0.025 * sc, 0.0325 * sc); } else { - matrix.mulPoseMatrix(dataHolder.vrPlayer.vrdata_world_render.getController(controller) - .getMatrix().inverted().transposed().toMCMatrix()); + matrix.mulPoseMatrix( + dataHolder.vrPlayer.vrdata_world_render.getController(controller).getMatrix(new Matrix4f()).invert().transpose() + ); } matrix.scale(sc, sc, sc); diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java index 6af70e8b7..3c28ce3de 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java @@ -19,6 +19,7 @@ import net.minecraft.network.chat.HoverEvent; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; +import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.BlockHitResult; @@ -26,6 +27,7 @@ import net.minecraft.world.phys.Vec3; import org.apache.commons.lang3.tuple.Triple; import org.joml.Matrix4f; +import org.joml.Matrix4fc; import org.joml.Vector2f; import org.lwjgl.opengl.GL11C; import org.vivecraft.client.VivecraftVRMod; @@ -33,7 +35,6 @@ import org.vivecraft.client.gui.VivecraftClickEvent; import org.vivecraft.client.gui.settings.GuiOtherHUDSettings; import org.vivecraft.client.gui.settings.GuiRenderOpticsSettings; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.MethodHolder; import org.vivecraft.client_vr.extensions.GameRendererExtension; @@ -571,14 +572,13 @@ public static void renderPhysicalKeyboard(float partialTicks, PoseStack poseStac //convert previously calculated coords to world coords Vec3 guiPos = VRPlayer.room_to_world_pos(KeyboardHandler.Pos_room, dataHolder.vrPlayer.vrdata_world_render); - org.vivecraft.common.utils.math.Matrix4f rot = org.vivecraft.common.utils.math.Matrix4f.rotationY(dataHolder.vrPlayer.vrdata_world_render.rotation_radians); - org.vivecraft.common.utils.math.Matrix4f guiRot = org.vivecraft.common.utils.math.Matrix4f.multiply(rot, KeyboardHandler.Rotation_room); + Matrix4f guiRot = KeyboardHandler.Rotation_room.rotateLocalY(dataHolder.vrPlayer.vrdata_world_render.rotation_radians, new Matrix4f()); RenderHelper.applyVRModelView(dataHolder.currentPass, poseStack); // offset from eye to gui pos poseStack.translate((float) (guiPos.x - eye.x), (float) (guiPos.y - eye.y), (float) (guiPos.z - eye.z)); - poseStack.mulPoseMatrix(guiRot.toMCMatrix()); + poseStack.mulPoseMatrix(guiRot); float scale = dataHolder.vrPlayer.vrdata_world_render.worldScale; poseStack.scale(scale, scale, scale); @@ -655,7 +655,7 @@ private static void renderScreen(PoseStack poseStack, RenderTarget screenFramebu } int minLight = ShadersHelper.ShaderLight(); - int light = Utils.getCombinedLightWithMin(mc.level, BlockPos.containing(screenPos), minLight); + int light = getCombinedLightWithMin(mc.level, BlockPos.containing(screenPos), minLight); RenderHelper.drawSizedQuadWithLightmapCutout((float) mc.getWindow().getGuiScaledWidth(), (float) mc.getWindow().getGuiScaledHeight(), 1.5F, light, color, poseStack.last().pose(), false); @@ -721,7 +721,7 @@ public static void renderGuiLayer(float partialTicks, boolean depthAlways, PoseS } } - public static void render2D(float partialTicks, RenderTarget framebuffer, Vec3 pos, org.vivecraft.common.utils.math.Matrix4f rot, boolean depthAlways, PoseStack poseStack) { + public static void render2D(float partialTicks, RenderTarget framebuffer, Vec3 pos, Matrix4fc rot, boolean depthAlways, PoseStack poseStack) { if (!dataHolder.bowTracker.isDrawing) { setupScreenRendering(poseStack, partialTicks); @@ -730,12 +730,10 @@ public static void render2D(float partialTicks, RenderTarget framebuffer, Vec3 p Vec3 eye = RenderHelper.getSmoothCameraPosition(dataHolder.currentPass, dataHolder.vrPlayer.vrdata_world_render); Vec3 guiPos = VRPlayer.room_to_world_pos(pos, dataHolder.vrPlayer.vrdata_world_render); - org.vivecraft.common.utils.math.Matrix4f yRot = org.vivecraft.common.utils.math.Matrix4f - .rotationY(dataHolder.vrPlayer.vrdata_world_render.rotation_radians); - org.vivecraft.common.utils.math.Matrix4f guiRot = org.vivecraft.common.utils.math.Matrix4f.multiply(yRot, rot); - poseStack.translate((float) (guiPos.x - eye.x), (float) (guiPos.y - eye.y), (float) (guiPos.z - eye.z)); - poseStack.mulPoseMatrix(guiRot.toMCMatrix()); + poseStack.last().pose() + .translate((float) (guiPos.x - eye.x), (float) (guiPos.y - eye.y), (float) (guiPos.z - eye.z)) + .mul(rot.rotateLocalY(dataHolder.vrPlayer.vrdata_world_render.rotation_radians, new Matrix4f())); float scale = GuiHandler.guiScale * dataHolder.vrPlayer.vrdata_world_render.worldScale; poseStack.scale(scale, scale, scale); @@ -930,4 +928,16 @@ public static void renderCrosshairAtDepth(boolean depthAlways, PoseStack poseSta mc.getProfiler().pop(); } } + + public static int getCombinedLightWithMin(BlockAndTintGetter lightReader, BlockPos pos, int minLight) { + int i = LevelRenderer.getLightColor(lightReader, pos); + int j = i >> 4 & 15; + + if (j < minLight) { + i = i & -256; + i = i | minLight << 4; + } + + return i; + } } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java index fa5302a35..12c3158c2 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRWidgetHelper.java @@ -19,8 +19,8 @@ import net.minecraft.world.inventory.InventoryMenu; import net.minecraft.world.phys.Vec3; import org.joml.Matrix3f; +import org.joml.Matrix4f; import org.joml.Vector3f; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.MethodHolder; import org.vivecraft.client_vr.extensions.GameRendererExtension; @@ -28,6 +28,7 @@ import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_vr.settings.VRHotkeys; import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import java.util.function.Function; @@ -102,7 +103,7 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs Vec3 widgetOffset = widgetPosition.subtract(eye); poseStack.translate(widgetOffset.x, widgetOffset.y, widgetOffset.z); - poseStack.mulPoseMatrix(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getMatrix().toMCMatrix()); + poseStack.mulPoseMatrix(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getMatrix(new Matrix4f())); scale = scale * dataholder.vrPlayer.vrdata_world_render.worldScale; poseStack.scale(scale, scale, scale); @@ -116,7 +117,7 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs RenderSystem.applyModelViewMatrix(); BlockPos blockpos = BlockPos.containing(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getPosition()); - int i = Utils.getCombinedLightWithMin(minecraft.level, blockpos, 0); + int i = VREffectsHelper.getCombinedLightWithMin(minecraft.level, blockpos, 0); RenderSystem.enableDepthTest(); RenderSystem.defaultBlendFunc(); @@ -135,7 +136,7 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs PoseStack poseStack2 = new PoseStack(); RenderHelper.applyVRModelView(dataholder.currentPass, poseStack2); poseStack2.last().pose().identity(); - poseStack2.last().normal().mul(new Matrix3f(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getMatrix().toMCMatrix())); + poseStack2.last().normal().mul(new Matrix3f(dataholder.vrPlayer.vrdata_world_render.getEye(renderPass).getMatrix(new Matrix4f()))); minecraft.getBlockRenderer().getModelRenderer().renderModel(poseStack2.last(), bufferbuilder, null, minecraft.getModelManager().getModel(model), 1.0F, 1.0F, 1.0F, i, OverlayTexture.NO_OVERLAY); tesselator.end(); @@ -153,7 +154,7 @@ public static void renderVRCameraWidget(float offsetX, float offsetY, float offs boolean flag = displayFaceFunc.apply(bakedquad.getDirection()) == DisplayFace.MIRROR; // make normals point up, so they are always bright // TODO: might break with shaders? - Vector3f normal = poseStack.last().normal().transform(new Vector3f(0.0F, 1.0F, 0.0F)); + Vector3f normal = poseStack.last().normal().transform(Utils.up, new Vector3f()); int j = LightTexture.pack(15, 15); int step = vertexList.length / 4; bufferbuilder1.vertex( diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java b/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java index f2f535933..da977ff6b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java @@ -4,16 +4,16 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.WinScreen; import net.minecraft.network.chat.Component; -import net.minecraft.world.phys.Vec3; +import org.joml.Math; +import org.joml.*; import org.lwjgl.glfw.GLFW; import org.vivecraft.client.utils.LangHelper; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.MethodHolder; import org.vivecraft.client_vr.VRData; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.extensions.MinecraftExtension; -import org.vivecraft.common.utils.math.*; +import org.vivecraft.common.utils.Utils; import java.io.BufferedReader; import java.io.File; @@ -27,11 +27,10 @@ public class VRHotkeys { static boolean debug = false; private static int startController; private static VRData.VRDevicePose startControllerPose; - private static float startCamposX; - private static float startCamposY; - private static float startCamposZ; - private static Quaternion startCamrotQuat; + private static final Vector3f startCampos = new Vector3f(); + private static final Quaternionf startCamrotQuat = new Quaternionf(); private static Triggerer camTriggerer; + private static final File ExternalCameraCFG = new File("ExternalCamera.cfg"); public static boolean handleKeyboardInputs(int key, int scanCode, int action, int modifiers) { if (nextRead != 0L && System.currentTimeMillis() < nextRead) { @@ -73,7 +72,8 @@ public static boolean handleKeyboardInputs(int key, int scanCode, int action, in } if (action == GLFW.GLFW_PRESS && key == GLFW.GLFW_KEY_HOME && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL)) { - snapMRCam(0); + Utils.convertToVector3f(dataholder.vrPlayer.vrdata_room_pre.getController(0).getPosition(), dataholder.vrSettings.vrFixedCampos); + dataholder.vrSettings.vrFixedCamrotQuat.setFromNormalized(dataholder.vrPlayer.vrdata_room_pre.getController(0).getMatrix(new Matrix4f())); gotKey = true; } @@ -105,65 +105,74 @@ public static boolean handleKeyboardInputs(int key, int scanCode, int action, in public static void handleMRKeys() { Minecraft minecraft = Minecraft.getInstance(); ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); + final Quaternionf cam; + final Vector3f pos; + if (dataholder.vr.mrMovingCamActive) { + cam = dataholder.vrSettings.mrMovingCamOffsetRotQuat; + pos = dataholder.vrSettings.mrMovingCamOffset; + } else { + cam = dataholder.vrSettings.vrFixedCamrotQuat; + pos = dataholder.vrSettings.vrFixedCampos; + } boolean flag = false; if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_LEFT) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && !MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamPos(new Vector3(-0.01F, 0.0F, 0.0F)); + pos.add(cam.transformUnit(-0.01F, 0.0F, 0.0F, new Vector3f())); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && !MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamPos(new Vector3(0.01F, 0.0F, 0.0F)); + pos.add(cam.transformUnit(0.01F, 0.0F, 0.0F, new Vector3f())); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_UP) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && !MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamPos(new Vector3(0.0F, 0.0F, -0.01F)); + pos.add(cam.transformUnit(0.0F, 0.0F, -0.01F, new Vector3f())); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_DOWN) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && !MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamPos(new Vector3(0.0F, 0.0F, 0.01F)); + pos.add(cam.transformUnit(0.0F, 0.0F, 0.01F, new Vector3f())); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_PAGE_UP) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && !MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamPos(new Vector3(0.0F, 0.01F, 0.0F)); + pos.add(cam.transformUnit(0.0F, 0.01F, 0.0F, new Vector3f())); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_PAGE_DOWN) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && !MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamPos(new Vector3(0.0F, -0.01F, 0.0F)); + pos.add(cam.transformUnit(0.0F, -0.01F, 0.0F, new Vector3f())); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_UP) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamRot(Axis.PITCH, 0.5F); + cam.rotateX(Math.toRadians(0.5F)); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_DOWN) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamRot(Axis.PITCH, -0.5F); + cam.rotateX(Math.toRadians(-0.5F)); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_LEFT) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamRot(Axis.YAW, 0.5F); + cam.rotateY(Math.toRadians(0.5F)); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamRot(Axis.YAW, -0.5F); + cam.rotateY(Math.toRadians(-0.5F)); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_PAGE_UP) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamRot(Axis.ROLL, 0.5F); + cam.rotateZ(Math.toRadians(0.5F)); flag = true; } if (MethodHolder.isKeyDown(GLFW.GLFW_KEY_PAGE_DOWN) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_CONTROL) && MethodHolder.isKeyDown(GLFW.GLFW_KEY_RIGHT_SHIFT)) { - adjustCamRot(Axis.ROLL, -0.5F); + cam.rotateZ(Math.toRadians(-0.5F)); flag = true; } @@ -189,73 +198,23 @@ public static void handleMRKeys() { if (flag) { dataholder.vrSettings.saveOptions(); - - if (dataholder.vr.mrMovingCamActive) { - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", dataholder.vrSettings.mrMovingCamOffsetX, dataholder.vrSettings.mrMovingCamOffsetY, dataholder.vrSettings.mrMovingCamOffsetZ))); - Angle angle = dataholder.vrSettings.mrMovingCamOffsetRotQuat.toEuler(); - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angle.getPitch(), angle.getYaw(), angle.getRoll()))); - } else { - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", dataholder.vrSettings.vrFixedCamposX, dataholder.vrSettings.vrFixedCamposY, dataholder.vrSettings.vrFixedCamposZ))); - Angle angle1 = dataholder.vrSettings.vrFixedCamrotQuat.toEuler(); - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angle1.getPitch(), angle1.getYaw(), angle1.getRoll()))); - } - } - } - - private static void adjustCamPos(Vector3 offset) { - Minecraft minecraft = Minecraft.getInstance(); - ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); - - if (dataholder.vr.mrMovingCamActive) { - offset = dataholder.vrSettings.mrMovingCamOffsetRotQuat.multiply(offset); - dataholder.vrSettings.mrMovingCamOffsetX += offset.getX(); - dataholder.vrSettings.mrMovingCamOffsetY += offset.getY(); - dataholder.vrSettings.mrMovingCamOffsetZ += offset.getZ(); - } else { - offset = dataholder.vrSettings.vrFixedCamrotQuat.inverse().multiply(offset); - dataholder.vrSettings.vrFixedCamposX += offset.getX(); - dataholder.vrSettings.vrFixedCamposY += offset.getY(); - dataholder.vrSettings.vrFixedCamposZ += offset.getZ(); + Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", pos.x, pos.y, pos.z))); + Vector3fc angles = cam.getEulerAnglesYXZ(new Vector3f()); // TODO: verify + Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angles.x(), angles.y(), angles.z()))); } } - private static void adjustCamRot(Axis axis, float degrees) { - Minecraft minecraft = Minecraft.getInstance(); - ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); - - if (dataholder.vr.mrMovingCamActive) { - dataholder.vrSettings.mrMovingCamOffsetRotQuat.set(dataholder.vrSettings.mrMovingCamOffsetRotQuat.rotate(axis, degrees, true)); - } else { - dataholder.vrSettings.vrFixedCamrotQuat.set(dataholder.vrSettings.vrFixedCamrotQuat.rotate(axis, degrees, false)); - } - } - - public static void snapMRCam(int controller) { - Minecraft minecraft = Minecraft.getInstance(); - ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); - Vec3 vec3 = dataholder.vrPlayer.vrdata_room_pre.getController(controller).getPosition(); - dataholder.vrSettings.vrFixedCamposX = (float) vec3.x; - dataholder.vrSettings.vrFixedCamposY = (float) vec3.y; - dataholder.vrSettings.vrFixedCamposZ = (float) vec3.z; - Quaternion quaternion = new Quaternion(Utils.convertOVRMatrix(dataholder.vrPlayer.vrdata_room_pre.getController(controller).getMatrix())); - dataholder.vrSettings.vrFixedCamrotQuat.set(quaternion); - } - public static void updateMovingThirdPersonCam() { Minecraft minecraft = Minecraft.getInstance(); ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); if (startControllerPose != null) { - VRData.VRDevicePose vrdata$vrdevicepose = dataholder.vrPlayer.vrdata_room_pre.getController(startController); - Vec3 vec3 = startControllerPose.getPosition(); - Vec3 vec31 = vrdata$vrdevicepose.getPosition().subtract(vec3); - Matrix4f matrix4f = Matrix4f.multiply(vrdata$vrdevicepose.getMatrix(), startControllerPose.getMatrix().inverted()); - Vector3 vector3 = new Vector3(startCamposX - (float) vec3.x, startCamposY - (float) vec3.y, startCamposZ - (float) vec3.z); - Vector3 vector31 = matrix4f.transform(vector3); - dataholder.vrSettings.vrFixedCamposX = startCamposX + (float) vec31.x + (vector31.getX() - vector3.getX()); - dataholder.vrSettings.vrFixedCamposY = startCamposY + (float) vec31.y + (vector31.getY() - vector3.getY()); - dataholder.vrSettings.vrFixedCamposZ = startCamposZ + (float) vec31.z + (vector31.getZ() - vector3.getZ()); - dataholder.vrSettings.vrFixedCamrotQuat.set(startCamrotQuat.multiply(new Quaternion(Utils.convertOVRMatrix(matrix4f)))); + VRData.VRDevicePose vrDevPose = dataholder.vrPlayer.vrdata_room_pre.getController(startController); + Vector3f vrOldPosition = Utils.convertToVector3f(startControllerPose.getPosition(), new Vector3f()); + Vector3f vrDevPosition = Utils.convertToVector3f(vrDevPose.getPosition(), new Vector3f()).sub(vrOldPosition); + Matrix4f matrix4f = vrDevPose.getMatrix(new Matrix4f()).mul(startControllerPose.getMatrix(new Matrix4f()).invert()); + matrix4f.transformProject(startCampos.sub(vrOldPosition, vrOldPosition), dataholder.vrSettings.vrFixedCampos).sub(vrOldPosition).add(vrDevPosition).add(startCampos); + dataholder.vrSettings.vrFixedCamrotQuat.setFromNormalized(matrix4f).mul(startCamrotQuat); } } @@ -264,10 +223,8 @@ public static void startMovingThirdPersonCam(int controller, Triggerer triggerer ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); startController = controller; startControllerPose = dataholder.vrPlayer.vrdata_room_pre.getController(controller); - startCamposX = dataholder.vrSettings.vrFixedCamposX; - startCamposY = dataholder.vrSettings.vrFixedCamposY; - startCamposZ = dataholder.vrSettings.vrFixedCamposZ; - startCamrotQuat = dataholder.vrSettings.vrFixedCamrotQuat.copy(); + startCampos.set(dataholder.vrSettings.vrFixedCampos); + startCamrotQuat.set(dataholder.vrSettings.vrFixedCamrotQuat); camTriggerer = triggerer; } @@ -288,50 +245,29 @@ public static Triggerer getMovingThirdPersonCamTriggerer() { } public static void loadExternalCameraConfig() { - File file1 = new File("ExternalCamera.cfg"); - - if (file1.exists()) { - float f = 0.0F; - float f1 = 0.0F; - float f2 = 0.0F; - float f3 = 0.0F; - float f4 = 0.0F; - float f5 = 0.0F; - float f6 = 40.0F; - String s; - - try (BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(file1), StandardCharsets.UTF_8))) { + if (ExternalCameraCFG.exists()) { + float x = 0.0F; + float y = 0.0F; + float z = 0.0F; + float rx = 0.0F; + float ry = 0.0F; + float rz = 0.0F; + float fov = 40.0F; + + try (BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(new FileInputStream(ExternalCameraCFG), StandardCharsets.UTF_8))) { + String s; while ((s = bufferedreader.readLine()) != null) { String[] astring = s.split("=", 2); String s1 = astring[0]; switch (s1) { - case "x": - f = Float.parseFloat(astring[1]); - break; - - case "y": - f1 = Float.parseFloat(astring[1]); - break; - - case "z": - f2 = Float.parseFloat(astring[1]); - break; - - case "rx": - f3 = Float.parseFloat(astring[1]); - break; - - case "ry": - f4 = Float.parseFloat(astring[1]); - break; - - case "rz": - f5 = Float.parseFloat(astring[1]); - break; - - case "fov": - f6 = Float.parseFloat(astring[1]); + case "x" -> x = Float.parseFloat(astring[1]); + case "y" -> y = Float.parseFloat(astring[1]); + case "z" -> z = Float.parseFloat(astring[1]); + case "rx" -> rx = Math.toRadians(Float.parseFloat(astring[1])); + case "ry" -> ry = Math.toRadians(Float.parseFloat(astring[1])); + case "rz" -> rz = Math.toRadians(Float.parseFloat(astring[1])); + case "fov" -> fov = Float.parseFloat(astring[1]); } } } catch (Exception exception) { @@ -341,21 +277,26 @@ public static void loadExternalCameraConfig() { Minecraft minecraft = Minecraft.getInstance(); ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); - Quaternion quaternion = new Quaternion(f3, f4, f5, dataholder.vrSettings.externalCameraAngleOrder); - dataholder.vrSettings.mrMovingCamOffsetX = f; - dataholder.vrSettings.mrMovingCamOffsetY = f1; - dataholder.vrSettings.mrMovingCamOffsetZ = f2; - dataholder.vrSettings.mrMovingCamOffsetRotQuat.set(quaternion); - dataholder.vrSettings.vrFixedCamposX = f; - dataholder.vrSettings.vrFixedCamposY = f1; - dataholder.vrSettings.vrFixedCamposZ = f2; - dataholder.vrSettings.vrFixedCamrotQuat.set(quaternion); - dataholder.vrSettings.mixedRealityFov = f6; + dataholder.vrSettings.mrMovingCamOffsetRotQuat.set(switch (dataholder.vrSettings.externalCameraAngleOrder) { + case XYZ -> dataholder.vrSettings.vrFixedCamrotQuat.rotationXYZ(rx, ry, rz); + case ZYX -> dataholder.vrSettings.vrFixedCamrotQuat.rotationZYX(rz, ry, rx); + case YXZ -> dataholder.vrSettings.vrFixedCamrotQuat.rotationYXZ(ry, rx, rz); + case ZXY -> // TODO: add rotationZXY to JOML + dataholder.vrSettings.vrFixedCamrotQuat.rotationZ(rz).rotateX(rx).rotateY(ry); + case YZX -> // TODO: add rotationYZX to JOML + dataholder.vrSettings.vrFixedCamrotQuat.rotationY(ry).rotateZ(rz).rotateX(rx); + case XZY -> // TODO: add rotationXZY to JOML + // default angle order + dataholder.vrSettings.vrFixedCamrotQuat.rotationX(rx).rotateZ(rz).rotateY(ry); + }); + dataholder.vrSettings.mrMovingCamOffset.set(x, y, z); + dataholder.vrSettings.vrFixedCampos.set(x, y, z); + dataholder.vrSettings.mixedRealityFov = fov; } } public static boolean hasExternalCameraConfig() { - return (new File("ExternalCamera.cfg")).exists(); + return ExternalCameraCFG.exists(); } public enum Triggerer { diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java index 9c60a7fec..c28813545 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java @@ -15,6 +15,8 @@ import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.lwjgl.glfw.GLFW; import org.vivecraft.client.utils.LangHelper; import org.vivecraft.client_vr.ClientDataHolderVR; @@ -25,9 +27,6 @@ import org.vivecraft.client_vr.settings.profile.ProfileManager; import org.vivecraft.client_vr.settings.profile.ProfileReader; import org.vivecraft.client_vr.settings.profile.ProfileWriter; -import org.vivecraft.common.utils.math.Angle; -import org.vivecraft.common.utils.math.Quaternion; -import org.vivecraft.common.utils.math.Vector3; import org.vivecraft.mod_compat_vr.ShadersHelper; import java.awt.*; @@ -153,6 +152,15 @@ public enum UpdateType implements OptionEnum { ALPHA } + public enum Order { + XYZ, + ZYX, + YXZ, + ZXY, + YZX, + XZY + } + @SettingField public int version = UNKNOWN_VERSION; @@ -279,7 +287,7 @@ public enum UpdateType implements OptionEnum { @SettingField(VrOptions.AUTO_SPRINT_THRESHOLD) public float autoSprintThreshold = 0.9f; @SettingField - public Vector3 originOffset = new Vector3(0.0F, 0.0F, 0.0F); + public Vector3f originOffset = new Vector3f(); @SettingField(VrOptions.ALLOW_STANDING_ORIGIN_OFFSET) public boolean allowStandingOriginOffset = false; @SettingField(VrOptions.SEATED_FREE_MOVE) @@ -330,24 +338,16 @@ public enum UpdateType implements OptionEnum { public boolean mixedRealityAlphaMask = false; @SettingField(VrOptions.MIXED_REALITY_FOV) public float mixedRealityFov = 40; - @SettingField - public float vrFixedCamposX = -1.0f; - @SettingField - public float vrFixedCamposY = 2.4f; - @SettingField - public float vrFixedCamposZ = 2.7f; + @SettingField(config = "vrFixedCampos", separate = true) + public Vector3f vrFixedCampos = new Vector3f(-1.0f, 2.4f, 2.7f); @SettingField(config = "vrFixedCamrot", separate = true) - public Quaternion vrFixedCamrotQuat = new Quaternion(.962f, .125f, .239f, .041f); - @SettingField - public float mrMovingCamOffsetX = 0; - @SettingField - public float mrMovingCamOffsetY = 0; - @SettingField - public float mrMovingCamOffsetZ = 0; + public Quaternionf vrFixedCamrotQuat = new Quaternionf(.125f, .239f, .041f, .962f); + @SettingField(config = "mrMovingCamOffset", separate = true) + public Vector3f mrMovingCamOffset = new Vector3f(); @SettingField(config = "mrMovingCamOffsetRot", separate = true) - public Quaternion mrMovingCamOffsetRotQuat = new Quaternion(); + public Quaternionf mrMovingCamOffsetRotQuat = new Quaternionf(); @SettingField - public Angle.Order externalCameraAngleOrder = Angle.Order.XZY; + public Order externalCameraAngleOrder = Order.XZY; @SettingField(VrOptions.HANDHELD_CAMERA_FOV) public float handCameraFov = 70; @SettingField(VrOptions.HANDHELD_CAMERA_RENDER_SCALE) @@ -510,9 +510,9 @@ private void initializeFieldInfo() { if (ann.separate() && field.getType().isArray()) { int len = Array.getLength(field.get(this)); IntStream.range(0, len).forEach(i -> fieldConfigMap.put(config + "_" + i, configEntry)); - } else if (ann.separate() && Quaternion.class.isAssignableFrom(field.getType())) { + } else if (ann.separate() && Quaternionf.class.isAssignableFrom(field.getType())) { Stream.of('W', 'X', 'Y', 'Z').forEach(suffix -> fieldConfigMap.put(config + suffix, configEntry)); - } else if (ann.separate() && Vector3.class.isAssignableFrom(field.getType())) { + } else if (ann.separate() && Vector3f.class.isAssignableFrom(field.getType())) { Stream.of('X', 'Y', 'Z').forEach(suffix -> fieldConfigMap.put(config + suffix, configEntry)); } else { fieldConfigMap.put(config, configEntry); @@ -550,8 +550,8 @@ private Object loadOption(String name, String value, Object currentValue, VrOpti } else if (type.isEnum()) { Method m = type.getMethod("valueOf", String.class); return m.invoke(null, value); - } else if (Quaternion.class.isAssignableFrom(type)) { - Quaternion quat = ((Quaternion) currentValue).copy(); + } else if (Quaternionf.class.isAssignableFrom(type)) { + Quaternionf quat = new Quaternionf(((Quaternionf) currentValue)); if (separate) { float f = Float.parseFloat(value); switch (name.charAt(name.length() - 1)) { @@ -562,14 +562,14 @@ private Object loadOption(String name, String value, Object currentValue, VrOpti } } else { String[] split = value.split(","); - quat.w = Float.parseFloat(split[0]); - quat.x = Float.parseFloat(split[1]); - quat.y = Float.parseFloat(split[2]); - quat.z = Float.parseFloat(split[3]); + quat.x = Float.parseFloat(split[0]); + quat.y = Float.parseFloat(split[1]); + quat.z = Float.parseFloat(split[2]); + quat.w = Float.parseFloat(split[3]); } return quat; - } else if (Vector3.class.isAssignableFrom(type)) { - Vector3 vec = ((Vector3) currentValue).copy(); + } else if (Vector3f.class.isAssignableFrom(type)) { + Vector3f vec = new Vector3f(((Vector3f) currentValue)); if (separate) { float f = Float.parseFloat(value); switch (name.charAt(name.length() - 1)) { @@ -605,8 +605,8 @@ private String saveOption(String name, Object obj, VrOptions option, Class ty return obj.toString(); } else if (type.isEnum()) { return ((Enum) obj).name(); - } else if (Quaternion.class.isAssignableFrom(type)) { - Quaternion quat = (Quaternion) obj; + } else if (Quaternionf.class.isAssignableFrom(type)) { + Quaternionf quat = (Quaternionf) obj; if (separate) { return Float.toString(switch (name.charAt(name.length() - 1)) { case 'W' -> quat.w; @@ -616,10 +616,10 @@ private String saveOption(String name, Object obj, VrOptions option, Class ty default -> 0; // shouldn't happen }); } else { - return quat.w + "," + quat.x + "," + quat.y + "," + quat.z; + return quat.x + "," + quat.y + "," + quat.z + "," + quat.w; } - } else if (Vector3.class.isAssignableFrom(type)) { - Vector3 vec = (Vector3) obj; + } else if (Vector3f.class.isAssignableFrom(type)) { + Vector3f vec = (Vector3f) obj; if (separate) { return Float.toString(switch (name.charAt(name.length() - 1)) { case 'X' -> vec.x; @@ -664,8 +664,8 @@ private Object loadDefault(String name, String value, VrOptions option, Class } else if (type.isEnum()) { Method m = type.getMethod("valueOf", String.class); return m.invoke(null, value); - } else if (Quaternion.class.isAssignableFrom(type)) { - Quaternion quat = new Quaternion(); + } else if (Quaternionf.class.isAssignableFrom(type)) { + Quaternionf quat = new Quaternionf(); if (separate) { Stream.of('W', 'X', 'Y', 'Z').forEach(suffix -> { String str = profileSet.get(name + suffix); @@ -679,14 +679,14 @@ private Object loadDefault(String name, String value, VrOptions option, Class }); } else { String[] split = value.split(","); - quat.w = Float.parseFloat(split[0]); - quat.x = Float.parseFloat(split[1]); - quat.y = Float.parseFloat(split[2]); - quat.z = Float.parseFloat(split[3]); + quat.x = Float.parseFloat(split[0]); + quat.y = Float.parseFloat(split[1]); + quat.z = Float.parseFloat(split[2]); + quat.w = Float.parseFloat(split[3]); } return quat; - } else if (Vector3.class.isAssignableFrom(type)) { - Vector3 vec = new Vector3(); + } else if (Vector3f.class.isAssignableFrom(type)) { + Vector3f vec = new Vector3f(); if (separate) { Stream.of('X', 'Y', 'Z').forEach(suffix -> { String str = profileSet.get(name + suffix); diff --git a/common/src/main/java/org/vivecraft/common/network/CommonNetworkHelper.java b/common/src/main/java/org/vivecraft/common/network/CommonNetworkHelper.java index ccbd20616..988b7ba5d 100644 --- a/common/src/main/java/org/vivecraft/common/network/CommonNetworkHelper.java +++ b/common/src/main/java/org/vivecraft/common/network/CommonNetworkHelper.java @@ -3,7 +3,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.phys.Vec3; -import org.vivecraft.common.utils.math.Quaternion; +import org.joml.Quaternionf; public class CommonNetworkHelper { @@ -42,18 +42,18 @@ public static void serializeF(FriendlyByteBuf buffer, Vec3 vec3) { buffer.writeFloat((float) vec3.z); } - public static void serialize(FriendlyByteBuf buffer, Quaternion quat) { - buffer.writeFloat(quat.w); + public static void serialize(FriendlyByteBuf buffer, Quaternionf quat) { buffer.writeFloat(quat.x); buffer.writeFloat(quat.y); buffer.writeFloat(quat.z); + buffer.writeFloat(quat.w); } public static Vec3 deserializeFVec3(FriendlyByteBuf buffer) { return new Vec3(buffer.readFloat(), buffer.readFloat(), buffer.readFloat()); } - public static Quaternion deserializeVivecraftQuaternion(FriendlyByteBuf buffer) { - return new Quaternion(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()); + public static Quaternionf deserializeQuaternionf(FriendlyByteBuf buffer) { + return new Quaternionf(buffer.readFloat(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat()); } } diff --git a/common/src/main/java/org/vivecraft/common/network/Pose.java b/common/src/main/java/org/vivecraft/common/network/Pose.java index 5b652f71e..b7cad3ce3 100644 --- a/common/src/main/java/org/vivecraft/common/network/Pose.java +++ b/common/src/main/java/org/vivecraft/common/network/Pose.java @@ -2,12 +2,12 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.phys.Vec3; -import org.vivecraft.common.utils.math.Quaternion; +import org.joml.Quaternionf; -public record Pose(Vec3 position, Quaternion orientation) { +public record Pose(Vec3 position, Quaternionf orientation) { public static Pose deserialize(FriendlyByteBuf byteBuf) { - return new Pose(CommonNetworkHelper.deserializeFVec3(byteBuf), CommonNetworkHelper.deserializeVivecraftQuaternion(byteBuf)); + return new Pose(CommonNetworkHelper.deserializeFVec3(byteBuf), CommonNetworkHelper.deserializeQuaternionf(byteBuf)); } public void serialize(FriendlyByteBuf buffer) { diff --git a/common/src/main/java/org/vivecraft/common/network/VrPlayerState.java b/common/src/main/java/org/vivecraft/common/network/VrPlayerState.java index a46cfbc8b..b4a83b792 100644 --- a/common/src/main/java/org/vivecraft/common/network/VrPlayerState.java +++ b/common/src/main/java/org/vivecraft/common/network/VrPlayerState.java @@ -3,14 +3,11 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.phys.Vec3; +import org.joml.Matrix4f; +import org.joml.Quaternionf; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.gameplay.VRPlayer; import org.vivecraft.client_vr.render.RenderPass; -import org.vivecraft.common.utils.lwjgl.Matrix4f; -import org.vivecraft.common.utils.math.Quaternion; - -import java.nio.Buffer; -import java.nio.FloatBuffer; public record VrPlayerState(boolean seated, Pose hmd, boolean reverseHands, Pose controller0, boolean reverseHands1legacy, Pose controller1) { @@ -27,22 +24,14 @@ public static VrPlayerState create(VRPlayer vrPlayer) { } private static Pose hmdPose(VRPlayer vrPlayer) { - FloatBuffer floatbuffer = vrPlayer.vrdata_world_post.hmd.getMatrix().toFloatBuffer(); - ((Buffer) floatbuffer).rewind(); - Matrix4f matrix4f = new Matrix4f(); - matrix4f.load(floatbuffer); Vec3 vec3 = vrPlayer.vrdata_world_post.getEye(RenderPass.CENTER).getPosition().subtract(Minecraft.getInstance().player.position()); - Quaternion quaternion = new Quaternion(matrix4f); + Quaternionf quaternion = new Quaternionf().setFromNormalized(vrPlayer.vrdata_world_post.hmd.getMatrix(new Matrix4f())); return new Pose(vec3, quaternion); } private static Pose controllerPose(VRPlayer vrPlayer, int i) { Vec3 position = vrPlayer.vrdata_world_post.getController(i).getPosition().subtract(Minecraft.getInstance().player.position()); - FloatBuffer floatbuffer1 = vrPlayer.vrdata_world_post.getController(i).getMatrix().toFloatBuffer(); - ((Buffer) floatbuffer1).rewind(); - Matrix4f matrix4f1 = new Matrix4f(); - matrix4f1.load(floatbuffer1); - Quaternion orientation = new Quaternion(matrix4f1); + Quaternionf orientation = new Quaternionf().setFromNormalized(vrPlayer.vrdata_world_post.getController(i).getMatrix(new Matrix4f())); return new Pose(position, orientation); } diff --git a/common/src/main/java/org/vivecraft/common/utils/Utils.java b/common/src/main/java/org/vivecraft/common/utils/Utils.java index 781d9b962..05ef50bbc 100644 --- a/common/src/main/java/org/vivecraft/common/utils/Utils.java +++ b/common/src/main/java/org/vivecraft/common/utils/Utils.java @@ -1,6 +1,8 @@ package org.vivecraft.common.utils; -import net.minecraft.util.Mth; +import net.minecraft.client.Minecraft; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.Resource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.animal.SnowGolem; @@ -11,9 +13,597 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.joml.Math; +import org.joml.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.vivecraft.client.Xplat; +import org.vivecraft.client_vr.render.VRShaders; +import org.vivecraft.client_vr.utils.LoaderUtils; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.DoubleBuffer; +import java.nio.FloatBuffer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * A container for useful globals like axial and directional unit vectors + * and many static functions. + */ public class Utils { + /** + * Vivecraft's logger for printing to console. + */ + public static final Logger logger = LoggerFactory.getLogger("Vivecraft"); + + /** + * x̂, X Axis + */ + public static final Vector3fc PITCH = new Vector3f(1.0F, 0.0F, 0.0F); + /** + * ŷ, Y Axis + */ + public static final Vector3fc YAW = new Vector3f(0.0F, 1.0F, 0.0F); + /** + * ẑ, Z Axis + */ + public static final Vector3fc ROLL = new Vector3f(0.0F, 0.0F, 1.0F); + /** + * Alternative/Supersedes {@link net.minecraft.world.phys.Vec3#ZERO} + * @see Vector3f#zero + */ + public static final Vector3fc ZERO = new Vector3f(0.0F, 0.0F, 0.0F); + private static final Vector3dc zero = new Vector3d(0.0D, 0.0D, 0.0D); + + /** + * @return {@link #ZERO} with double precision + * @see Vector3d#zero + */ + public static Vector3dc ZERO() { + return zero; + } + + /** + * North + */ + public static final Vector3fc forward = new Vector3f(0.0F, 0.0F, -1.0F); + private static final Vector3dc dforward = new Vector3d(0.0D, 0.0D, -1.0D); + + /** + * @return {@link #forward} with double precision + */ + public static Vector3dc forward() { + return dforward; + } + + /** + * South + * @see #ROLL + */ + public static final Vector3fc backward = ROLL; + private static final Vector3dc dbackward = new Vector3d(0.0D, 0.0D, 1.0D); + + /** + * @return {@link #backward} with double precision + */ + public static Vector3dc backward() { + return dbackward; + } + + /** + * Floorward + */ + public static final Vector3fc down = new Vector3f(0.0F, -1.0F, 0.0F); + private static final Vector3dc ddown = new Vector3d(0.0D, -1.0D, 0.0D); + + /** + * @return {@link #down} with double precision + */ + public static Vector3dc down() { + return ddown; + } + + /** + * Skyward + * @see #YAW + */ + public static final Vector3fc up = YAW; + private static final Vector3dc dup = new Vector3d(0.0D, 1.0D, 0.0D); + + /** + * @return {@link #up} with double precision + */ + public static Vector3dc up() { + return dup; + } + + /** + * West + */ + public static final Vector3fc left = new Vector3f(-1.0F, 0.0F, 0.0F); + private static final Vector3dc dleft = new Vector3d(-1.0D, 0.0D, 0.0D); + + /** + * @return {@link #left} with double precision + */ + public static Vector3dc left() { + return dleft; + } + + /** + * East + * @see #PITCH + */ + public static final Vector3fc right = PITCH; + private static final Vector3dc dright = new Vector3d(1.0D, 0.0D, 0.0D); + + /** + * @return {@link #right} with double precision + */ + public static Vector3dc right() { + return dright; + } + + /** + * Convert a {@link net.minecraft.world.phys.Vec3} to a {@link Vector3d}. + * @param vector the {@link net.minecraft.world.phys.Vec3} to copy. + * @param dest the {@link Vector3d} to overwrite. + * @return the {@code dest} assigned the same x, y, and z components as {@code vector}. + * @apiNote Use this function only when double values are required! + * @see Utils#convertToVec3(Vector3dc) + */ + public static Vector3d convertToVector3d(@Nullable net.minecraft.world.phys.Vec3 vector, @NotNull Vector3d dest) { + return vector != null ? dest.set(vector.x, vector.y, vector.z) : dest; + } + + /** + * Convert a {@link net.minecraft.world.phys.Vec3} to a {@link Vector3f}. + * @param vector the {@link net.minecraft.world.phys.Vec3} to copy. + * @param dest the {@link Vector3f} to overwrite. + * @return the {@code dest} assigned the same x, y, and z components as {@code vector}. + * @apiNote Use this function whenever reasonably possible. + * {@link net.minecraft.world.phys.Vec3} is superseded by {@link Vector3f}. + * When converting {@link net.minecraft.world.phys.Vec3} to a {@link Vector3f}, prefer this function over + * {@link net.minecraft.world.phys.Vec3#toVector3f()} + * to avoid creating multiple objects. + * @see Utils#convertToVec3(Vector3fc) + */ + public static Vector3f convertToVector3f(@Nullable net.minecraft.world.phys.Vec3 vector, @NotNull Vector3f dest) { + return vector != null ? dest.set(vector.x, vector.y, vector.z) : dest; + } + + /** + * Convert a {@link net.minecraft.core.Vec3i} to a {@link Vector3f}. + * + * @param vector the {@link net.minecraft.core.Vec3i} to copy. + * @param dest the {@link Vector3f} to overwrite. + * @return the {@code dest} assigned the same x, y, and z components as {@code vector}. + * @apiNote Use this function whenever reasonably possible. + * {@link net.minecraft.core.Vec3i} is superseded by {@link Vector3i}. + * @see Utils#convertToVec3(Vector3ic) + */ + public static Vector3f convertToVector3f(@Nullable net.minecraft.core.Vec3i vector, @NotNull Vector3f dest) { + return vector != null ? dest.set(vector.getX(), vector.getY(), vector.getZ()) : dest; + } + + /** + * Convert a {@link net.minecraft.core.Vec3i} to a {@link Vector3i}. + * + * @param vector the vector to copy. + * @param dest the {@link Vector3i} to save to. + * @return the {@code dest} assigned the same x, y, and z components as {@code vector}. + * @apiNote Use this function whenever reasonably possible. + * {@link net.minecraft.core.Vec3i} is superseded by {@link Vector3i}. + * @see Utils#convertToVec3(Vector3fc) + */ + public static Vector3i convertToVector3i(@Nullable net.minecraft.core.Vec3i vector, @NotNull Vector3i dest) { + return vector != null ? dest.set(vector.getX(), vector.getY(), vector.getZ()) : dest; + } + + /** + * Convert a {@link Vector3dc} to a {@link net.minecraft.world.phys.Vec3}. + * + * @param vector the {@link Vector3dc} to copy. + * @return a {@code new} {@link net.minecraft.world.phys.Vec3} assigned the same x, y, and z components as {@code vector}. + * @apiNote Avoid this function whenever reasonably possible. + *
+ * If there is an x, y, z signature alternative, + *
+ * instead save {@code vector} and use its {@link Vector3dc#x}, {@link Vector3dc#y}, and {@link Vector3dc#z} directly. + * @see Utils#convertToVector3d(net.minecraft.world.phys.Vec3, Vector3d) + */ + public static net.minecraft.world.phys.Vec3 convertToVec3(@NotNull Vector3dc vector) { + return new net.minecraft.world.phys.Vec3(vector.x(), vector.y(), vector.z()); + } + + /** + * Convert a {@link Vector3fc} to a {@link net.minecraft.world.phys.Vec3}. + * + * @param vector the {@link Vector3fc} to copy. + * @return a {@code new} {@link net.minecraft.world.phys.Vec3} assigned the same x, y, and z components as {@code vector}. + * @apiNote Avoid this function whenever reasonably possible. + *
+ * If there is an x, y, z signature alternative, + *
+ * instead save {@code vector} and use its {@link Vector3fc#x}, {@link Vector3fc#y}, and {@link Vector3fc#z} directly. + * @see Utils#convertToVector3f(net.minecraft.world.phys.Vec3, Vector3f) + */ + public static net.minecraft.world.phys.Vec3 convertToVec3(@NotNull Vector3fc vector) { + return new net.minecraft.world.phys.Vec3(vector.x(), vector.y(), vector.z()); + } + + /** + * Convert a {@link Vector3ic} to a {@link net.minecraft.core.Vec3i}. + * + * @param vector the {@link Vector3ic} to copy. + * @return a {@code new} {@link net.minecraft.core.Vec3i} assigned the same x, y, and z components as {@code vector}. + * @apiNote Avoid this function whenever reasonably possible. + *
+ * If there is an x, y, z signature alternative, + *
+ * instead save {@code vector} and use its {@link Vector3ic#x}, {@link Vector3ic#y}, and {@link Vector3ic#z} directly. + * @see Utils#convertToVector3i(net.minecraft.core.Vec3i, Vector3i) + */ + public static net.minecraft.core.Vec3i convertToVec3(@NotNull Vector3ic vector) { + return new net.minecraft.core.Vec3i(vector.x(), vector.y(), vector.z()); + } + + /** + * Convert a {@link FloatBuffer} containing a row-major 3x4 matrix, + * like {@link org.lwjgl.openvr.HmdMatrix34}, + * to a column-major {@link Matrix4d}. + * This function is required for {@link org.lwjgl.openvr} compatibility due to + * {@link Matrix4x3f} only accepting inputs with column-major memory layouts, whereas + * {@link org.lwjgl.openvr} uses row-major layout. + * + * @see Utils#convertRM34ToCM44(FloatBuffer, Matrix4d) + */ + public static Matrix4f convertRM34ToCM44(@NotNull FloatBuffer floatBuffer, @NotNull Matrix4f dest) { + return dest.set( + floatBuffer.get(0), floatBuffer.get(4), floatBuffer.get(8), 0.0F, + floatBuffer.get(1), floatBuffer.get(5), floatBuffer.get(9), 0.0F, + floatBuffer.get(2), floatBuffer.get(6), floatBuffer.get(10), 0.0F, + floatBuffer.get(3), floatBuffer.get(7), floatBuffer.get(11), 1.0F + ); + } + + /** + * Convert a {@link FloatBuffer} containing a row-major 3x4 matrix, + * like {@link org.lwjgl.openvr.HmdMatrix34}, + * to a column-major {@link Matrix4d}. + * This function is required for {@link org.lwjgl.openvr} compatibility due to + * {@link Matrix4x3f} only accepting inputs with column-major memory layouts, whereas + * {@link org.lwjgl.openvr} uses row-major layout. + * + * @see Utils#convertRM34ToCM44(DoubleBuffer, Matrix4d) + */ + public static Matrix4d convertRM34ToCM44(@NotNull FloatBuffer floatBuffer, @NotNull Matrix4d dest) { + return dest.set( + floatBuffer.get(0), floatBuffer.get(4), floatBuffer.get(8), 0.0F, + floatBuffer.get(1), floatBuffer.get(5), floatBuffer.get(9), 0.0F, + floatBuffer.get(2), floatBuffer.get(6), floatBuffer.get(10), 0.0F, + floatBuffer.get(3), floatBuffer.get(7), floatBuffer.get(11), 1.0F + ); + } + + /** + * Convert a {@link DoubleBuffer} containing a row-major 3x4 matrix to + * a column-major {@link Matrix4d}. + * + * @see Utils#convertRM34ToCM44(FloatBuffer, Matrix4f) + */ + public static Matrix4d convertRM34ToCM44(@NotNull DoubleBuffer doubleBuffer, @NotNull Matrix4d dest) { + return dest.set( + doubleBuffer.get(0), doubleBuffer.get(4), doubleBuffer.get(8), 0.0F, + doubleBuffer.get(1), doubleBuffer.get(5), doubleBuffer.get(9), 0.0F, + doubleBuffer.get(2), doubleBuffer.get(6), doubleBuffer.get(10), 0.0F, + doubleBuffer.get(3), doubleBuffer.get(7), doubleBuffer.get(11), 1.0F + ); + } + + public static void printStackIfContainsClass(String className) { + StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace(); + boolean flag = false; + + for (StackTraceElement stacktraceelement : astacktraceelement) { + if (stacktraceelement.getClassName().equals(className)) { + flag = true; + break; + } + } + + if (flag) { + Thread.dumpStack(); + } + } + + public static long microTime() { + return System.nanoTime() / 1000L; + } + + public static long milliTime() { + return System.nanoTime() / 1000000L; + } + + public static void wordWrap(String in, int length, ArrayList wrapped) { + // can't wrap with length 0, so return the original string + if (length == 0) { + wrapped.add(in); + return; + } + String s = "\n"; + boolean flag = false; + in = in.replace("\r", ""); + + if (in.length() < length) { + flag = true; + length = in.length(); + } + + if (in.substring(0, length).contains(s)) { + String s2 = in.substring(0, in.indexOf(s)).trim(); + wrapped.add(s2); + wordWrap(in.substring(in.indexOf(s) + 1), length, wrapped); + } else if (flag) { + wrapped.add(in); + } else { + int i = Math.max(Math.max(in.lastIndexOf(" ", length), in.lastIndexOf("\t", length)), in.lastIndexOf("-", length)); + + if (i == -1) { + i = length; + } + + String s1 = in.substring(0, i).trim(); + wrapped.add(s1); + wordWrap(in.substring(i), length, wrapped); + } + } + + public static InputStream getAssetAsStream(String name, boolean required) { + InputStream inputstream = null; + + try { + try { + Optional resource = Minecraft.getInstance().getResourceManager().getResource(new ResourceLocation("vivecraft", name)); + if (resource.isPresent()) { + inputstream = resource.get().open(); + } + } catch (NullPointerException | FileNotFoundException filenotfoundexception) { + inputstream = VRShaders.class.getResourceAsStream("/assets/vivecraft/" + name); + } + + if (inputstream == null) { + Path path1 = Paths.get(System.getProperty("user.dir")); + + if (path1.getParent() != null) { + Path path = path1.getParent().resolve("src/resources/assets/vivecraft/" + name); + + if (!path.toFile().exists() && path1.getParent().getParent() != null) { + path = path1.getParent().getParent().resolve("resources/assets/vivecraft/" + name); + } + + if (path.toFile().exists()) { + inputstream = new FileInputStream(path.toFile()); + } + } + } + } catch (Exception exception) { + handleAssetException(exception, name, required); + return null; + } + + if (inputstream == null) { + handleAssetException(new FileNotFoundException(name), name, required); + } + + return inputstream; + } + + public static void loadAssetToFile(String name, File file, boolean required) { + InputStream inputstream = getAssetAsStream(name, required); + + if (inputstream != null) { + try { + writeStreamToFile(inputstream, file); + inputstream.close(); + } catch (Exception exception) { + handleAssetException(exception, name, required); + } + } + } + + private static void handleAssetException(Throwable e, String name, boolean required) { + if (required) { + throw new RuntimeException("Failed to load asset: " + name, e); + } else { + System.out.println("Failed to load asset: " + name); + e.printStackTrace(); + } + } + + public static void unpackNatives(String directory) { + try { + (new File("openvr/" + directory)).mkdirs(); + + try { + Path path = Paths.get(System.getProperty("user.dir")); + Path path1 = path.getParent().resolve("src/resources/natives/" + directory); + + if (!path1.toFile().exists()) { + path1 = path.getParent().getParent().resolve("resources/natives/" + directory); + } + + if (path1.toFile().exists()) { + System.out.println("Copying " + directory + " natives..."); + + for (File file1 : path1.toFile().listFiles()) { + System.out.println(file1.getName()); + Files.copy(file1.toPath(), new File("openvr/" + directory + "/" + file1.getName()).toPath()); + } + + return; + } + } catch (Exception exception) { + } + + System.out.println("Unpacking " + directory + " natives..."); + + Path jarPath = Xplat.getJarPath(); + boolean didExtractSomething = false; + try (Stream natives = java.nio.file.Files.list(jarPath.resolve("natives/" + directory))) { + for (Path file : natives.collect(Collectors.toCollection(ArrayList::new))) { + didExtractSomething = true; + System.out.println(file); + java.nio.file.Files.copy(file, new File("openvr/" + directory + "/" + file.getFileName()).toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); + } + } catch (IOException e) { + System.out.println("Failed to unpack natives from jar"); + } + if (!didExtractSomething) { + ZipFile zipfile = LoaderUtils.getVivecraftZip(); + Enumeration enumeration = zipfile.entries(); + + while (enumeration.hasMoreElements()) { + ZipEntry zipentry = enumeration.nextElement(); + + if (zipentry.getName().startsWith("natives/" + directory)) { + String s = Paths.get(zipentry.getName()).getFileName().toString(); + System.out.println(s); + writeStreamToFile(zipfile.getInputStream(zipentry), new File("openvr/" + directory + "/" + s)); + } + } + + zipfile.close(); + } + } catch (Exception exception1) { + System.out.println("Failed to unpack natives"); + exception1.printStackTrace(); + } + } + + public static void writeStreamToFile(InputStream is, File file) throws IOException { + FileOutputStream fileoutputstream = new FileOutputStream(file); + byte[] abyte = new byte[4096]; + int i; + + while ((i = is.read(abyte, 0, abyte.length)) != -1) { + fileoutputstream.write(abyte, 0, i); + } + + fileoutputstream.flush(); + fileoutputstream.close(); + is.close(); + } + + public static String httpReadLine(String url) throws IOException { + HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); + httpurlconnection.setConnectTimeout(5000); + httpurlconnection.setReadTimeout(20000); + httpurlconnection.setUseCaches(false); + httpurlconnection.setDoInput(true); + BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream())); + String s = bufferedreader.readLine(); + bufferedreader.close(); + httpurlconnection.disconnect(); + return s; + } + + public static List httpReadAllLines(String url) throws IOException { + HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); + httpurlconnection.setConnectTimeout(5000); + httpurlconnection.setReadTimeout(20000); + httpurlconnection.setUseCaches(false); + httpurlconnection.setDoInput(true); + BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream())); + ArrayList arraylist = new ArrayList<>(); + String s; + + while ((s = bufferedreader.readLine()) != null) { + arraylist.add(s); + } + + bufferedreader.close(); + httpurlconnection.disconnect(); + return arraylist; + } + + public static void httpReadToFile(String url, File file, boolean writeWhenComplete) throws IOException { + HttpURLConnection httpurlconnection = (HttpURLConnection) (new URL(url)).openConnection(); + httpurlconnection.setConnectTimeout(5000); + httpurlconnection.setReadTimeout(20000); + httpurlconnection.setUseCaches(false); + httpurlconnection.setDoInput(true); + InputStream inputstream = httpurlconnection.getInputStream(); + + if (writeWhenComplete) { + ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(httpurlconnection.getContentLength()); + byte[] abyte = new byte[4096]; + int i; + + while ((i = inputstream.read(abyte, 0, abyte.length)) != -1) { + bytearrayoutputstream.write(abyte, 0, i); + } + + OutputStream outputstream = new FileOutputStream(file); + outputstream.write(bytearrayoutputstream.toByteArray()); + outputstream.flush(); + outputstream.close(); + } else { + OutputStream outputstream1 = new FileOutputStream(file); + byte[] abyte1 = new byte[4096]; + int j; + + while ((j = inputstream.read(abyte1, 0, abyte1.length)) != -1) { + outputstream1.write(abyte1, 0, j); + } + + outputstream1.flush(); + outputstream1.close(); + } + + inputstream.close(); + httpurlconnection.disconnect(); + } + + public static String getFileChecksum(File file, String algorithm) throws IOException, NoSuchAlgorithmException { + InputStream inputstream = new FileInputStream(file); + byte[] abyte = new byte[(int) file.length()]; + inputstream.read(abyte); + inputstream.close(); + MessageDigest messagedigest = MessageDigest.getInstance(algorithm); + messagedigest.update(abyte); + Formatter formatter = new Formatter(); + + for (byte b0 : messagedigest.digest()) { + formatter.format("%02x", b0); + } + + String s = formatter.toString(); + formatter.close(); + return s; + } + + public static Vec3 vecLerp(Vec3 start, Vec3 end, double fraction) { + double d0 = start.x + (end.x - start.x) * fraction; + double d1 = start.y + (end.y - start.y) * fraction; + double d2 = start.z + (end.z - start.z) * fraction; + return new Vec3(d0, d1, d2); + } + public static AABB getEntityHeadHitbox(Entity entity, double inflate) { if ((entity instanceof Player player && !player.isSwimming()) || // swimming players hitbox is just a box around their butt entity instanceof Zombie || @@ -42,7 +632,7 @@ public static AABB getEntityHeadHitbox(Entity entity, double inflate) { float yrot = -(livingEntity.yBodyRot) * 0.017453292F; // offset head in entity rotation Vec3 headpos = entity.getEyePosition() - .add(new Vec3(Mth.sin(yrot), 0, Mth.cos(yrot)) + .add(new Vec3(Math.sin(yrot), 0, Math.cos(yrot)) .scale(livingEntity.getBbWidth() * 0.5F)); double headsize = livingEntity.getBbWidth() * 0.25; @@ -54,4 +644,5 @@ public static AABB getEntityHeadHitbox(Entity entity, double inflate) { } return null; } + } diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix.java deleted file mode 100644 index 92d570c3c..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public abstract class Matrix { - public abstract Matrix setIdentity(); - - public abstract Matrix invert(); - - public abstract Matrix load(FloatBuffer var1); - - public abstract Matrix loadTranspose(FloatBuffer var1); - - public abstract Matrix negate(); - - public abstract Matrix store(FloatBuffer var1); - - public abstract Matrix storeTranspose(FloatBuffer var1); - - public abstract Matrix transpose(); - - public abstract Matrix setZero(); - - public abstract float determinant(); -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix2f.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix2f.java deleted file mode 100644 index a7b63b51f..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix2f.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public class Matrix2f extends Matrix { - public float m00; - public float m01; - public float m10; - public float m11; - - public Matrix2f() { - this.setIdentity(); - } - - public Matrix2f(Matrix2f src) { - this.load(src); - } - - public Matrix2f load(Matrix2f src) { - return load(src, this); - } - - public static Matrix2f load(Matrix2f src, Matrix2f dest) { - if (dest == null) { - dest = new Matrix2f(); - } - - dest.m00 = src.m00; - dest.m01 = src.m01; - dest.m10 = src.m10; - dest.m11 = src.m11; - return dest; - } - - public Matrix load(FloatBuffer buf) { - this.m00 = buf.get(); - this.m01 = buf.get(); - this.m10 = buf.get(); - this.m11 = buf.get(); - return this; - } - - public Matrix loadTranspose(FloatBuffer buf) { - this.m00 = buf.get(); - this.m10 = buf.get(); - this.m01 = buf.get(); - this.m11 = buf.get(); - return this; - } - - public Matrix store(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m01); - buf.put(this.m10); - buf.put(this.m11); - return this; - } - - public Matrix storeTranspose(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m10); - buf.put(this.m01); - buf.put(this.m11); - return this; - } - - public static Matrix2f add(Matrix2f left, Matrix2f right, Matrix2f dest) { - if (dest == null) { - dest = new Matrix2f(); - } - - dest.m00 = left.m00 + right.m00; - dest.m01 = left.m01 + right.m01; - dest.m10 = left.m10 + right.m10; - dest.m11 = left.m11 + right.m11; - return dest; - } - - public static Matrix2f sub(Matrix2f left, Matrix2f right, Matrix2f dest) { - if (dest == null) { - dest = new Matrix2f(); - } - - dest.m00 = left.m00 - right.m00; - dest.m01 = left.m01 - right.m01; - dest.m10 = left.m10 - right.m10; - dest.m11 = left.m11 - right.m11; - return dest; - } - - public static Matrix2f mul(Matrix2f left, Matrix2f right, Matrix2f dest) { - if (dest == null) { - dest = new Matrix2f(); - } - - float f = left.m00 * right.m00 + left.m10 * right.m01; - float f1 = left.m01 * right.m00 + left.m11 * right.m01; - float f2 = left.m00 * right.m10 + left.m10 * right.m11; - float f3 = left.m01 * right.m10 + left.m11 * right.m11; - dest.m00 = f; - dest.m01 = f1; - dest.m10 = f2; - dest.m11 = f3; - return dest; - } - - public static Vector2f transform(Matrix2f left, Vector2f right, Vector2f dest) { - if (dest == null) { - dest = new Vector2f(); - } - - float f = left.m00 * right.x + left.m10 * right.y; - float f1 = left.m01 * right.x + left.m11 * right.y; - dest.x = f; - dest.y = f1; - return dest; - } - - public Matrix transpose() { - return this.transpose(this); - } - - public Matrix2f transpose(Matrix2f dest) { - return transpose(this, dest); - } - - public static Matrix2f transpose(Matrix2f src, Matrix2f dest) { - if (dest == null) { - dest = new Matrix2f(); - } - - float f = src.m10; - float f1 = src.m01; - dest.m01 = f; - dest.m10 = f1; - return dest; - } - - public Matrix invert() { - return invert(this, this); - } - - public static Matrix2f invert(Matrix2f src, Matrix2f dest) { - float f = src.determinant(); - - if (f != 0.0F) { - if (dest == null) { - dest = new Matrix2f(); - } - - float f1 = 1.0F / f; - float f2 = src.m11 * f1; - float f3 = -src.m01 * f1; - float f4 = src.m00 * f1; - float f5 = -src.m10 * f1; - dest.m00 = f2; - dest.m01 = f3; - dest.m10 = f5; - dest.m11 = f4; - return dest; - } else { - return null; - } - } - - public String toString() { - String stringbuilder = String.valueOf(this.m00) + ' ' + this.m10 + ' ' + '\n' + - this.m01 + ' ' + this.m11 + ' ' + '\n'; - return stringbuilder; - } - - public Matrix negate() { - return this.negate(this); - } - - public Matrix2f negate(Matrix2f dest) { - return negate(this, dest); - } - - public static Matrix2f negate(Matrix2f src, Matrix2f dest) { - if (dest == null) { - dest = new Matrix2f(); - } - - dest.m00 = -src.m00; - dest.m01 = -src.m01; - dest.m10 = -src.m10; - dest.m11 = -src.m11; - return dest; - } - - public Matrix setIdentity() { - return setIdentity(this); - } - - public static Matrix2f setIdentity(Matrix2f src) { - src.m00 = 1.0F; - src.m01 = 0.0F; - src.m10 = 0.0F; - src.m11 = 1.0F; - return src; - } - - public Matrix setZero() { - return setZero(this); - } - - public static Matrix2f setZero(Matrix2f src) { - src.m00 = 0.0F; - src.m01 = 0.0F; - src.m10 = 0.0F; - src.m11 = 0.0F; - return src; - } - - public float determinant() { - return this.m00 * this.m11 - this.m01 * this.m10; - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix3f.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix3f.java deleted file mode 100644 index 99f09f356..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix3f.java +++ /dev/null @@ -1,308 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public class Matrix3f extends Matrix { - public float m00; - public float m01; - public float m02; - public float m10; - public float m11; - public float m12; - public float m20; - public float m21; - public float m22; - - public Matrix3f() { - this.setIdentity(); - } - - public Matrix3f load(Matrix3f src) { - return load(src, this); - } - - public static Matrix3f load(Matrix3f src, Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - } - - dest.m00 = src.m00; - dest.m10 = src.m10; - dest.m20 = src.m20; - dest.m01 = src.m01; - dest.m11 = src.m11; - dest.m21 = src.m21; - dest.m02 = src.m02; - dest.m12 = src.m12; - dest.m22 = src.m22; - return dest; - } - - public Matrix load(FloatBuffer buf) { - this.m00 = buf.get(); - this.m01 = buf.get(); - this.m02 = buf.get(); - this.m10 = buf.get(); - this.m11 = buf.get(); - this.m12 = buf.get(); - this.m20 = buf.get(); - this.m21 = buf.get(); - this.m22 = buf.get(); - return this; - } - - public Matrix loadTranspose(FloatBuffer buf) { - this.m00 = buf.get(); - this.m10 = buf.get(); - this.m20 = buf.get(); - this.m01 = buf.get(); - this.m11 = buf.get(); - this.m21 = buf.get(); - this.m02 = buf.get(); - this.m12 = buf.get(); - this.m22 = buf.get(); - return this; - } - - public Matrix store(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m01); - buf.put(this.m02); - buf.put(this.m10); - buf.put(this.m11); - buf.put(this.m12); - buf.put(this.m20); - buf.put(this.m21); - buf.put(this.m22); - return this; - } - - public Matrix storeTranspose(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m10); - buf.put(this.m20); - buf.put(this.m01); - buf.put(this.m11); - buf.put(this.m21); - buf.put(this.m02); - buf.put(this.m12); - buf.put(this.m22); - return this; - } - - public static Matrix3f add(Matrix3f left, Matrix3f right, Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - } - - dest.m00 = left.m00 + right.m00; - dest.m01 = left.m01 + right.m01; - dest.m02 = left.m02 + right.m02; - dest.m10 = left.m10 + right.m10; - dest.m11 = left.m11 + right.m11; - dest.m12 = left.m12 + right.m12; - dest.m20 = left.m20 + right.m20; - dest.m21 = left.m21 + right.m21; - dest.m22 = left.m22 + right.m22; - return dest; - } - - public static Matrix3f sub(Matrix3f left, Matrix3f right, Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - } - - dest.m00 = left.m00 - right.m00; - dest.m01 = left.m01 - right.m01; - dest.m02 = left.m02 - right.m02; - dest.m10 = left.m10 - right.m10; - dest.m11 = left.m11 - right.m11; - dest.m12 = left.m12 - right.m12; - dest.m20 = left.m20 - right.m20; - dest.m21 = left.m21 - right.m21; - dest.m22 = left.m22 - right.m22; - return dest; - } - - public static Matrix3f mul(Matrix3f left, Matrix3f right, Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - } - - float f = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02; - float f1 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02; - float f2 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02; - float f3 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12; - float f4 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12; - float f5 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12; - float f6 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22; - float f7 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22; - float f8 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22; - dest.m00 = f; - dest.m01 = f1; - dest.m02 = f2; - dest.m10 = f3; - dest.m11 = f4; - dest.m12 = f5; - dest.m20 = f6; - dest.m21 = f7; - dest.m22 = f8; - return dest; - } - - public static Vector3f transform(Matrix3f left, Vector3f right, Vector3f dest) { - if (dest == null) { - dest = new Vector3f(); - } - - float f = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z; - float f1 = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z; - float f2 = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z; - dest.x = f; - dest.y = f1; - dest.z = f2; - return dest; - } - - public Matrix transpose() { - return transpose(this, this); - } - - public Matrix3f transpose(Matrix3f dest) { - return transpose(this, dest); - } - - public static Matrix3f transpose(Matrix3f src, Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - } - - float f = src.m00; - float f1 = src.m10; - float f2 = src.m20; - float f3 = src.m01; - float f4 = src.m11; - float f5 = src.m21; - float f6 = src.m02; - float f7 = src.m12; - float f8 = src.m22; - dest.m00 = f; - dest.m01 = f1; - dest.m02 = f2; - dest.m10 = f3; - dest.m11 = f4; - dest.m12 = f5; - dest.m20 = f6; - dest.m21 = f7; - dest.m22 = f8; - return dest; - } - - public float determinant() { - return this.m00 * (this.m11 * this.m22 - this.m12 * this.m21) + this.m01 * (this.m12 * this.m20 - this.m10 * this.m22) + this.m02 * (this.m10 * this.m21 - this.m11 * this.m20); - } - - public String toString() { - String stringbuilder = String.valueOf(this.m00) + ' ' + this.m10 + ' ' + this.m20 + ' ' + '\n' + - this.m01 + ' ' + this.m11 + ' ' + this.m21 + ' ' + '\n' + - this.m02 + ' ' + this.m12 + ' ' + this.m22 + ' ' + '\n'; - return stringbuilder; - } - - public Matrix invert() { - return invert(this, this); - } - - public static Matrix3f invert(Matrix3f src, Matrix3f dest) { - float f = src.determinant(); - - if (f != 0.0F) { - if (dest == null) { - dest = new Matrix3f(); - } - - float f1 = 1.0F / f; - float f2 = src.m11 * src.m22 - src.m12 * src.m21; - float f3 = -src.m10 * src.m22 + src.m12 * src.m20; - float f4 = src.m10 * src.m21 - src.m11 * src.m20; - float f5 = -src.m01 * src.m22 + src.m02 * src.m21; - float f6 = src.m00 * src.m22 - src.m02 * src.m20; - float f7 = -src.m00 * src.m21 + src.m01 * src.m20; - float f8 = src.m01 * src.m12 - src.m02 * src.m11; - float f9 = -src.m00 * src.m12 + src.m02 * src.m10; - float f10 = src.m00 * src.m11 - src.m01 * src.m10; - dest.m00 = f2 * f1; - dest.m11 = f6 * f1; - dest.m22 = f10 * f1; - dest.m01 = f5 * f1; - dest.m10 = f3 * f1; - dest.m20 = f4 * f1; - dest.m02 = f8 * f1; - dest.m12 = f9 * f1; - dest.m21 = f7 * f1; - return dest; - } else { - return null; - } - } - - public Matrix negate() { - return this.negate(this); - } - - public Matrix3f negate(Matrix3f dest) { - return negate(this, dest); - } - - public static Matrix3f negate(Matrix3f src, Matrix3f dest) { - if (dest == null) { - dest = new Matrix3f(); - } - - dest.m00 = -src.m00; - dest.m01 = -src.m02; - dest.m02 = -src.m01; - dest.m10 = -src.m10; - dest.m11 = -src.m12; - dest.m12 = -src.m11; - dest.m20 = -src.m20; - dest.m21 = -src.m22; - dest.m22 = -src.m21; - return dest; - } - - public Matrix setIdentity() { - return setIdentity(this); - } - - public static Matrix3f setIdentity(Matrix3f m) { - m.m00 = 1.0F; - m.m01 = 0.0F; - m.m02 = 0.0F; - m.m10 = 0.0F; - m.m11 = 1.0F; - m.m12 = 0.0F; - m.m20 = 0.0F; - m.m21 = 0.0F; - m.m22 = 1.0F; - return m; - } - - public Matrix setZero() { - return setZero(this); - } - - public static Matrix3f setZero(Matrix3f m) { - m.m00 = 0.0F; - m.m01 = 0.0F; - m.m02 = 0.0F; - m.m10 = 0.0F; - m.m11 = 0.0F; - m.m12 = 0.0F; - m.m20 = 0.0F; - m.m21 = 0.0F; - m.m22 = 0.0F; - return m; - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix4f.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix4f.java deleted file mode 100644 index e74d08bcf..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Matrix4f.java +++ /dev/null @@ -1,591 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public class Matrix4f extends Matrix { - public float m00; - public float m01; - public float m02; - public float m03; - public float m10; - public float m11; - public float m12; - public float m13; - public float m20; - public float m21; - public float m22; - public float m23; - public float m30; - public float m31; - public float m32; - public float m33; - - public Matrix4f() { - this.setIdentity(); - } - - public Matrix4f(Matrix4f src) { - this.load(src); - } - - public Matrix4f(org.joml.Matrix4f src) { - this.m00 = src.m00(); - this.m01 = src.m01(); - this.m02 = src.m02(); - this.m03 = src.m03(); - this.m10 = src.m10(); - this.m11 = src.m11(); - this.m12 = src.m12(); - this.m13 = src.m13(); - this.m20 = src.m20(); - this.m21 = src.m21(); - this.m22 = src.m22(); - this.m23 = src.m23(); - this.m30 = src.m30(); - this.m31 = src.m31(); - this.m32 = src.m32(); - this.m33 = src.m33(); - } - - public String toString() { - String stringbuilder = String.valueOf(this.m00) + ' ' + this.m10 + ' ' + this.m20 + ' ' + this.m30 + '\n' + - this.m01 + ' ' + this.m11 + ' ' + this.m21 + ' ' + this.m31 + '\n' + - this.m02 + ' ' + this.m12 + ' ' + this.m22 + ' ' + this.m32 + '\n' + - this.m03 + ' ' + this.m13 + ' ' + this.m23 + ' ' + this.m33 + '\n'; - return stringbuilder; - } - - public Matrix setIdentity() { - return setIdentity(this); - } - - public static Matrix4f setIdentity(Matrix4f m) { - m.m00 = 1.0F; - m.m01 = 0.0F; - m.m02 = 0.0F; - m.m03 = 0.0F; - m.m10 = 0.0F; - m.m11 = 1.0F; - m.m12 = 0.0F; - m.m13 = 0.0F; - m.m20 = 0.0F; - m.m21 = 0.0F; - m.m22 = 1.0F; - m.m23 = 0.0F; - m.m30 = 0.0F; - m.m31 = 0.0F; - m.m32 = 0.0F; - m.m33 = 1.0F; - return m; - } - - public Matrix setZero() { - return setZero(this); - } - - public static Matrix4f setZero(Matrix4f m) { - m.m00 = 0.0F; - m.m01 = 0.0F; - m.m02 = 0.0F; - m.m03 = 0.0F; - m.m10 = 0.0F; - m.m11 = 0.0F; - m.m12 = 0.0F; - m.m13 = 0.0F; - m.m20 = 0.0F; - m.m21 = 0.0F; - m.m22 = 0.0F; - m.m23 = 0.0F; - m.m30 = 0.0F; - m.m31 = 0.0F; - m.m32 = 0.0F; - m.m33 = 0.0F; - return m; - } - - public Matrix4f load(Matrix4f src) { - return load(src, this); - } - - public static Matrix4f load(Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m00 = src.m00; - dest.m01 = src.m01; - dest.m02 = src.m02; - dest.m03 = src.m03; - dest.m10 = src.m10; - dest.m11 = src.m11; - dest.m12 = src.m12; - dest.m13 = src.m13; - dest.m20 = src.m20; - dest.m21 = src.m21; - dest.m22 = src.m22; - dest.m23 = src.m23; - dest.m30 = src.m30; - dest.m31 = src.m31; - dest.m32 = src.m32; - dest.m33 = src.m33; - return dest; - } - - public Matrix load(FloatBuffer buf) { - this.m00 = buf.get(); - this.m01 = buf.get(); - this.m02 = buf.get(); - this.m03 = buf.get(); - this.m10 = buf.get(); - this.m11 = buf.get(); - this.m12 = buf.get(); - this.m13 = buf.get(); - this.m20 = buf.get(); - this.m21 = buf.get(); - this.m22 = buf.get(); - this.m23 = buf.get(); - this.m30 = buf.get(); - this.m31 = buf.get(); - this.m32 = buf.get(); - this.m33 = buf.get(); - return this; - } - - public Matrix loadTranspose(FloatBuffer buf) { - this.m00 = buf.get(); - this.m10 = buf.get(); - this.m20 = buf.get(); - this.m30 = buf.get(); - this.m01 = buf.get(); - this.m11 = buf.get(); - this.m21 = buf.get(); - this.m31 = buf.get(); - this.m02 = buf.get(); - this.m12 = buf.get(); - this.m22 = buf.get(); - this.m32 = buf.get(); - this.m03 = buf.get(); - this.m13 = buf.get(); - this.m23 = buf.get(); - this.m33 = buf.get(); - return this; - } - - public Matrix store(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m01); - buf.put(this.m02); - buf.put(this.m03); - buf.put(this.m10); - buf.put(this.m11); - buf.put(this.m12); - buf.put(this.m13); - buf.put(this.m20); - buf.put(this.m21); - buf.put(this.m22); - buf.put(this.m23); - buf.put(this.m30); - buf.put(this.m31); - buf.put(this.m32); - buf.put(this.m33); - return this; - } - - public Matrix storeTranspose(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m10); - buf.put(this.m20); - buf.put(this.m30); - buf.put(this.m01); - buf.put(this.m11); - buf.put(this.m21); - buf.put(this.m31); - buf.put(this.m02); - buf.put(this.m12); - buf.put(this.m22); - buf.put(this.m32); - buf.put(this.m03); - buf.put(this.m13); - buf.put(this.m23); - buf.put(this.m33); - return this; - } - - public Matrix store3f(FloatBuffer buf) { - buf.put(this.m00); - buf.put(this.m01); - buf.put(this.m02); - buf.put(this.m10); - buf.put(this.m11); - buf.put(this.m12); - buf.put(this.m20); - buf.put(this.m21); - buf.put(this.m22); - return this; - } - - public static Matrix4f add(Matrix4f left, Matrix4f right, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m00 = left.m00 + right.m00; - dest.m01 = left.m01 + right.m01; - dest.m02 = left.m02 + right.m02; - dest.m03 = left.m03 + right.m03; - dest.m10 = left.m10 + right.m10; - dest.m11 = left.m11 + right.m11; - dest.m12 = left.m12 + right.m12; - dest.m13 = left.m13 + right.m13; - dest.m20 = left.m20 + right.m20; - dest.m21 = left.m21 + right.m21; - dest.m22 = left.m22 + right.m22; - dest.m23 = left.m23 + right.m23; - dest.m30 = left.m30 + right.m30; - dest.m31 = left.m31 + right.m31; - dest.m32 = left.m32 + right.m32; - dest.m33 = left.m33 + right.m33; - return dest; - } - - public static Matrix4f sub(Matrix4f left, Matrix4f right, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m00 = left.m00 - right.m00; - dest.m01 = left.m01 - right.m01; - dest.m02 = left.m02 - right.m02; - dest.m03 = left.m03 - right.m03; - dest.m10 = left.m10 - right.m10; - dest.m11 = left.m11 - right.m11; - dest.m12 = left.m12 - right.m12; - dest.m13 = left.m13 - right.m13; - dest.m20 = left.m20 - right.m20; - dest.m21 = left.m21 - right.m21; - dest.m22 = left.m22 - right.m22; - dest.m23 = left.m23 - right.m23; - dest.m30 = left.m30 - right.m30; - dest.m31 = left.m31 - right.m31; - dest.m32 = left.m32 - right.m32; - dest.m33 = left.m33 - right.m33; - return dest; - } - - public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - float f = left.m00 * right.m00 + left.m10 * right.m01 + left.m20 * right.m02 + left.m30 * right.m03; - float f1 = left.m01 * right.m00 + left.m11 * right.m01 + left.m21 * right.m02 + left.m31 * right.m03; - float f2 = left.m02 * right.m00 + left.m12 * right.m01 + left.m22 * right.m02 + left.m32 * right.m03; - float f3 = left.m03 * right.m00 + left.m13 * right.m01 + left.m23 * right.m02 + left.m33 * right.m03; - float f4 = left.m00 * right.m10 + left.m10 * right.m11 + left.m20 * right.m12 + left.m30 * right.m13; - float f5 = left.m01 * right.m10 + left.m11 * right.m11 + left.m21 * right.m12 + left.m31 * right.m13; - float f6 = left.m02 * right.m10 + left.m12 * right.m11 + left.m22 * right.m12 + left.m32 * right.m13; - float f7 = left.m03 * right.m10 + left.m13 * right.m11 + left.m23 * right.m12 + left.m33 * right.m13; - float f8 = left.m00 * right.m20 + left.m10 * right.m21 + left.m20 * right.m22 + left.m30 * right.m23; - float f9 = left.m01 * right.m20 + left.m11 * right.m21 + left.m21 * right.m22 + left.m31 * right.m23; - float f10 = left.m02 * right.m20 + left.m12 * right.m21 + left.m22 * right.m22 + left.m32 * right.m23; - float f11 = left.m03 * right.m20 + left.m13 * right.m21 + left.m23 * right.m22 + left.m33 * right.m23; - float f12 = left.m00 * right.m30 + left.m10 * right.m31 + left.m20 * right.m32 + left.m30 * right.m33; - float f13 = left.m01 * right.m30 + left.m11 * right.m31 + left.m21 * right.m32 + left.m31 * right.m33; - float f14 = left.m02 * right.m30 + left.m12 * right.m31 + left.m22 * right.m32 + left.m32 * right.m33; - float f15 = left.m03 * right.m30 + left.m13 * right.m31 + left.m23 * right.m32 + left.m33 * right.m33; - dest.m00 = f; - dest.m01 = f1; - dest.m02 = f2; - dest.m03 = f3; - dest.m10 = f4; - dest.m11 = f5; - dest.m12 = f6; - dest.m13 = f7; - dest.m20 = f8; - dest.m21 = f9; - dest.m22 = f10; - dest.m23 = f11; - dest.m30 = f12; - dest.m31 = f13; - dest.m32 = f14; - dest.m33 = f15; - return dest; - } - - public static Vector4f transform(Matrix4f left, Vector4f right, Vector4f dest) { - if (dest == null) { - dest = new Vector4f(); - } - - float f = left.m00 * right.x + left.m10 * right.y + left.m20 * right.z + left.m30 * right.w; - float f1 = left.m01 * right.x + left.m11 * right.y + left.m21 * right.z + left.m31 * right.w; - float f2 = left.m02 * right.x + left.m12 * right.y + left.m22 * right.z + left.m32 * right.w; - float f3 = left.m03 * right.x + left.m13 * right.y + left.m23 * right.z + left.m33 * right.w; - dest.x = f; - dest.y = f1; - dest.z = f2; - dest.w = f3; - return dest; - } - - public Matrix transpose() { - return this.transpose(this); - } - - public Matrix4f translate(Vector2f vec) { - return this.translate(vec, this); - } - - public Matrix4f translate(Vector3f vec) { - return this.translate(vec, this); - } - - public Matrix4f scale(Vector3f vec) { - return scale(vec, this, this); - } - - public static Matrix4f scale(Vector3f vec, Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m00 = src.m00 * vec.x; - dest.m01 = src.m01 * vec.x; - dest.m02 = src.m02 * vec.x; - dest.m03 = src.m03 * vec.x; - dest.m10 = src.m10 * vec.y; - dest.m11 = src.m11 * vec.y; - dest.m12 = src.m12 * vec.y; - dest.m13 = src.m13 * vec.y; - dest.m20 = src.m20 * vec.z; - dest.m21 = src.m21 * vec.z; - dest.m22 = src.m22 * vec.z; - dest.m23 = src.m23 * vec.z; - return dest; - } - - public Matrix4f rotate(float angle, Vector3f axis) { - return this.rotate(angle, axis, this); - } - - public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) { - return rotate(angle, axis, this, dest); - } - - public static Matrix4f rotate(float angle, Vector3f axis, Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - float f = (float) Math.cos(angle); - float f1 = (float) Math.sin(angle); - float f2 = 1.0F - f; - float f3 = axis.x * axis.y; - float f4 = axis.y * axis.z; - float f5 = axis.x * axis.z; - float f6 = axis.x * f1; - float f7 = axis.y * f1; - float f8 = axis.z * f1; - float f9 = axis.x * axis.x * f2 + f; - float f10 = f3 * f2 + f8; - float f11 = f5 * f2 - f7; - float f12 = f3 * f2 - f8; - float f13 = axis.y * axis.y * f2 + f; - float f14 = f4 * f2 + f6; - float f15 = f5 * f2 + f7; - float f16 = f4 * f2 - f6; - float f17 = axis.z * axis.z * f2 + f; - float f18 = src.m00 * f9 + src.m10 * f10 + src.m20 * f11; - float f19 = src.m01 * f9 + src.m11 * f10 + src.m21 * f11; - float f20 = src.m02 * f9 + src.m12 * f10 + src.m22 * f11; - float f21 = src.m03 * f9 + src.m13 * f10 + src.m23 * f11; - float f22 = src.m00 * f12 + src.m10 * f13 + src.m20 * f14; - float f23 = src.m01 * f12 + src.m11 * f13 + src.m21 * f14; - float f24 = src.m02 * f12 + src.m12 * f13 + src.m22 * f14; - float f25 = src.m03 * f12 + src.m13 * f13 + src.m23 * f14; - dest.m20 = src.m00 * f15 + src.m10 * f16 + src.m20 * f17; - dest.m21 = src.m01 * f15 + src.m11 * f16 + src.m21 * f17; - dest.m22 = src.m02 * f15 + src.m12 * f16 + src.m22 * f17; - dest.m23 = src.m03 * f15 + src.m13 * f16 + src.m23 * f17; - dest.m00 = f18; - dest.m01 = f19; - dest.m02 = f20; - dest.m03 = f21; - dest.m10 = f22; - dest.m11 = f23; - dest.m12 = f24; - dest.m13 = f25; - return dest; - } - - public Matrix4f translate(Vector3f vec, Matrix4f dest) { - return translate(vec, this, dest); - } - - public static Matrix4f translate(Vector3f vec, Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m30 += src.m00 * vec.x + src.m10 * vec.y + src.m20 * vec.z; - dest.m31 += src.m01 * vec.x + src.m11 * vec.y + src.m21 * vec.z; - dest.m32 += src.m02 * vec.x + src.m12 * vec.y + src.m22 * vec.z; - dest.m33 += src.m03 * vec.x + src.m13 * vec.y + src.m23 * vec.z; - return dest; - } - - public Matrix4f translate(Vector2f vec, Matrix4f dest) { - return translate(vec, this, dest); - } - - public static Matrix4f translate(Vector2f vec, Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m30 += src.m00 * vec.x + src.m10 * vec.y; - dest.m31 += src.m01 * vec.x + src.m11 * vec.y; - dest.m32 += src.m02 * vec.x + src.m12 * vec.y; - dest.m33 += src.m03 * vec.x + src.m13 * vec.y; - return dest; - } - - public Matrix4f transpose(Matrix4f dest) { - return transpose(this, dest); - } - - public static Matrix4f transpose(Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - float f = src.m00; - float f1 = src.m10; - float f2 = src.m20; - float f3 = src.m30; - float f4 = src.m01; - float f5 = src.m11; - float f6 = src.m21; - float f7 = src.m31; - float f8 = src.m02; - float f9 = src.m12; - float f10 = src.m22; - float f11 = src.m32; - float f12 = src.m03; - float f13 = src.m13; - float f14 = src.m23; - float f15 = src.m33; - dest.m00 = f; - dest.m01 = f1; - dest.m02 = f2; - dest.m03 = f3; - dest.m10 = f4; - dest.m11 = f5; - dest.m12 = f6; - dest.m13 = f7; - dest.m20 = f8; - dest.m21 = f9; - dest.m22 = f10; - dest.m23 = f11; - dest.m30 = f12; - dest.m31 = f13; - dest.m32 = f14; - dest.m33 = f15; - return dest; - } - - public float determinant() { - float f = this.m00 * (this.m11 * this.m22 * this.m33 + this.m12 * this.m23 * this.m31 + this.m13 * this.m21 * this.m32 - this.m13 * this.m22 * this.m31 - this.m11 * this.m23 * this.m32 - this.m12 * this.m21 * this.m33); - f = f - this.m01 * (this.m10 * this.m22 * this.m33 + this.m12 * this.m23 * this.m30 + this.m13 * this.m20 * this.m32 - this.m13 * this.m22 * this.m30 - this.m10 * this.m23 * this.m32 - this.m12 * this.m20 * this.m33); - f = f + this.m02 * (this.m10 * this.m21 * this.m33 + this.m11 * this.m23 * this.m30 + this.m13 * this.m20 * this.m31 - this.m13 * this.m21 * this.m30 - this.m10 * this.m23 * this.m31 - this.m11 * this.m20 * this.m33); - return f - this.m03 * (this.m10 * this.m21 * this.m32 + this.m11 * this.m22 * this.m30 + this.m12 * this.m20 * this.m31 - this.m12 * this.m21 * this.m30 - this.m10 * this.m22 * this.m31 - this.m11 * this.m20 * this.m32); - } - - private static float determinant3x3(float t00, float t01, float t02, float t10, float t11, float t12, float t20, float t21, float t22) { - return t00 * (t11 * t22 - t12 * t21) + t01 * (t12 * t20 - t10 * t22) + t02 * (t10 * t21 - t11 * t20); - } - - public Matrix invert() { - return invert(this, this); - } - - public static Matrix4f invert(Matrix4f src, Matrix4f dest) { - float f = src.determinant(); - - if (f != 0.0F) { - if (dest == null) { - dest = new Matrix4f(); - } - - float f1 = 1.0F / f; - float f2 = determinant3x3(src.m11, src.m12, src.m13, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); - float f3 = -determinant3x3(src.m10, src.m12, src.m13, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); - float f4 = determinant3x3(src.m10, src.m11, src.m13, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); - float f5 = -determinant3x3(src.m10, src.m11, src.m12, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); - float f6 = -determinant3x3(src.m01, src.m02, src.m03, src.m21, src.m22, src.m23, src.m31, src.m32, src.m33); - float f7 = determinant3x3(src.m00, src.m02, src.m03, src.m20, src.m22, src.m23, src.m30, src.m32, src.m33); - float f8 = -determinant3x3(src.m00, src.m01, src.m03, src.m20, src.m21, src.m23, src.m30, src.m31, src.m33); - float f9 = determinant3x3(src.m00, src.m01, src.m02, src.m20, src.m21, src.m22, src.m30, src.m31, src.m32); - float f10 = determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m31, src.m32, src.m33); - float f11 = -determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m30, src.m32, src.m33); - float f12 = determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m30, src.m31, src.m33); - float f13 = -determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m30, src.m31, src.m32); - float f14 = -determinant3x3(src.m01, src.m02, src.m03, src.m11, src.m12, src.m13, src.m21, src.m22, src.m23); - float f15 = determinant3x3(src.m00, src.m02, src.m03, src.m10, src.m12, src.m13, src.m20, src.m22, src.m23); - float f16 = -determinant3x3(src.m00, src.m01, src.m03, src.m10, src.m11, src.m13, src.m20, src.m21, src.m23); - float f17 = determinant3x3(src.m00, src.m01, src.m02, src.m10, src.m11, src.m12, src.m20, src.m21, src.m22); - dest.m00 = f2 * f1; - dest.m11 = f7 * f1; - dest.m22 = f12 * f1; - dest.m33 = f17 * f1; - dest.m01 = f6 * f1; - dest.m10 = f3 * f1; - dest.m20 = f4 * f1; - dest.m02 = f10 * f1; - dest.m12 = f11 * f1; - dest.m21 = f8 * f1; - dest.m03 = f14 * f1; - dest.m30 = f5 * f1; - dest.m13 = f15 * f1; - dest.m31 = f9 * f1; - dest.m32 = f13 * f1; - dest.m23 = f16 * f1; - return dest; - } else { - return null; - } - } - - public Matrix negate() { - return this.negate(this); - } - - public Matrix4f negate(Matrix4f dest) { - return negate(this, dest); - } - - public static Matrix4f negate(Matrix4f src, Matrix4f dest) { - if (dest == null) { - dest = new Matrix4f(); - } - - dest.m00 = -src.m00; - dest.m01 = -src.m01; - dest.m02 = -src.m02; - dest.m03 = -src.m03; - dest.m10 = -src.m10; - dest.m11 = -src.m11; - dest.m12 = -src.m12; - dest.m13 = -src.m13; - dest.m20 = -src.m20; - dest.m21 = -src.m21; - dest.m22 = -src.m22; - dest.m23 = -src.m23; - dest.m30 = -src.m30; - dest.m31 = -src.m31; - dest.m32 = -src.m32; - dest.m33 = -src.m33; - return dest; - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector.java deleted file mode 100644 index 19d491162..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public abstract class Vector { - protected Vector() { - } - - public final float length() { - return (float) Math.sqrt(this.lengthSquared()); - } - - public abstract float lengthSquared(); - - public abstract Vector load(FloatBuffer var1); - - public abstract Vector negate(); - - public final Vector normalise() { - float f = this.length(); - - if (f != 0.0F) { - float f1 = 1.0F / f; - return this.scale(f1); - } else { - throw new IllegalStateException("Zero length vector"); - } - } - - public abstract Vector store(FloatBuffer var1); - - public abstract Vector scale(float var1); -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector2f.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector2f.java deleted file mode 100644 index da8d619ab..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector2f.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public class Vector2f extends Vector { - public float x; - public float y; - - public Vector2f() { - } - - public Vector2f(float x, float y) { - this.set(x, y); - } - - public void set(float x, float y) { - this.x = x; - this.y = y; - } - - public float lengthSquared() { - return this.x * this.x + this.y * this.y; - } - - public Vector2f translate(float x, float y) { - this.x += x; - this.y += y; - return this; - } - - public Vector negate() { - this.x = -this.x; - this.y = -this.y; - return this; - } - - public Vector2f negate(Vector2f dest) { - if (dest == null) { - dest = new Vector2f(); - } - - dest.x = -this.x; - dest.y = -this.y; - return dest; - } - - public Vector2f normalise(Vector2f dest) { - float f = this.length(); - - if (dest == null) { - dest = new Vector2f(this.x / f, this.y / f); - } else { - dest.set(this.x / f, this.y / f); - } - - return dest; - } - - public static float dot(Vector2f left, Vector2f right) { - return left.x * right.x + left.y * right.y; - } - - public static float angle(Vector2f a, Vector2f b) { - float f = dot(a, b) / (a.length() * b.length()); - - if (f < -1.0F) { - f = -1.0F; - } else if (f > 1.0F) { - f = 1.0F; - } - - return (float) Math.acos(f); - } - - public static Vector2f add(Vector2f left, Vector2f right, Vector2f dest) { - if (dest == null) { - return new Vector2f(left.x + right.x, left.y + right.y); - } else { - dest.set(left.x + right.x, left.y + right.y); - return dest; - } - } - - public static Vector2f sub(Vector2f left, Vector2f right, Vector2f dest) { - if (dest == null) { - return new Vector2f(left.x - right.x, left.y - right.y); - } else { - dest.set(left.x - right.x, left.y - right.y); - return dest; - } - } - - public Vector store(FloatBuffer buf) { - buf.put(this.x); - buf.put(this.y); - return this; - } - - public Vector load(FloatBuffer buf) { - this.x = buf.get(); - this.y = buf.get(); - return this; - } - - public Vector scale(float scale) { - this.x *= scale; - this.y *= scale; - return this; - } - - public String toString() { - String stringbuilder = "Vector2f[" + - this.x + - ", " + - this.y + - ']'; - return stringbuilder; - } - - public final float getX() { - return this.x; - } - - public final float getY() { - return this.y; - } - - public final void setX(float x) { - this.x = x; - } - - public final void setY(float y) { - this.y = y; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Vector2f vector2f = (Vector2f) obj; - return this.x == vector2f.x && this.y == vector2f.y; - } - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector3f.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector3f.java deleted file mode 100644 index 4f9ce61d2..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector3f.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public class Vector3f extends Vector { - public float x; - public float y; - public float z; - - public Vector3f() { - } - - public Vector3f(float x, float y, float z) { - this.set(x, y, z); - } - - public void set(float x, float y) { - this.x = x; - this.y = y; - } - - public void set(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public float lengthSquared() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } - - public Vector3f translate(float x, float y, float z) { - this.x += x; - this.y += y; - this.z += z; - return this; - } - - public static Vector3f add(Vector3f left, Vector3f right, Vector3f dest) { - if (dest == null) { - return new Vector3f(left.x + right.x, left.y + right.y, left.z + right.z); - } else { - dest.set(left.x + right.x, left.y + right.y, left.z + right.z); - return dest; - } - } - - public static Vector3f sub(Vector3f left, Vector3f right, Vector3f dest) { - if (dest == null) { - return new Vector3f(left.x - right.x, left.y - right.y, left.z - right.z); - } else { - dest.set(left.x - right.x, left.y - right.y, left.z - right.z); - return dest; - } - } - - public static Vector3f cross(Vector3f left, Vector3f right, Vector3f dest) { - if (dest == null) { - dest = new Vector3f(); - } - - dest.set(left.y * right.z - left.z * right.y, right.x * left.z - right.z * left.x, left.x * right.y - left.y * right.x); - return dest; - } - - public Vector negate() { - this.x = -this.x; - this.y = -this.y; - this.z = -this.z; - return this; - } - - public Vector3f negate(Vector3f dest) { - if (dest == null) { - dest = new Vector3f(); - } - - dest.x = -this.x; - dest.y = -this.y; - dest.z = -this.z; - return dest; - } - - public Vector3f normalise(Vector3f dest) { - float f = this.length(); - - if (dest == null) { - dest = new Vector3f(this.x / f, this.y / f, this.z / f); - } else { - dest.set(this.x / f, this.y / f, this.z / f); - } - - return dest; - } - - public static float dot(Vector3f left, Vector3f right) { - return left.x * right.x + left.y * right.y + left.z * right.z; - } - - public static float angle(Vector3f a, Vector3f b) { - float f = dot(a, b) / (a.length() * b.length()); - - if (f < -1.0F) { - f = -1.0F; - } else if (f > 1.0F) { - f = 1.0F; - } - - return (float) Math.acos(f); - } - - public Vector load(FloatBuffer buf) { - this.x = buf.get(); - this.y = buf.get(); - this.z = buf.get(); - return this; - } - - public Vector scale(float scale) { - this.x *= scale; - this.y *= scale; - this.z *= scale; - return this; - } - - public Vector store(FloatBuffer buf) { - buf.put(this.x); - buf.put(this.y); - buf.put(this.z); - return this; - } - - public String toString() { - String stringbuilder = "Vector3f[" + - this.x + - ", " + - this.y + - ", " + - this.z + - ']'; - return stringbuilder; - } - - public final float getX() { - return this.x; - } - - public final float getY() { - return this.y; - } - - public final void setX(float x) { - this.x = x; - } - - public final void setY(float y) { - this.y = y; - } - - public void setZ(float z) { - this.z = z; - } - - public float getZ() { - return this.z; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Vector3f vector3f = (Vector3f) obj; - return this.x == vector3f.x && this.y == vector3f.y && this.z == vector3f.z; - } - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector4f.java b/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector4f.java deleted file mode 100644 index 0926c81c1..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/lwjgl/Vector4f.java +++ /dev/null @@ -1,187 +0,0 @@ -package org.vivecraft.common.utils.lwjgl; - -import java.nio.FloatBuffer; - -@Deprecated -public class Vector4f extends Vector { - public float x; - public float y; - public float z; - public float w; - - public Vector4f() { - } - - public Vector4f(float x, float y, float z, float w) { - this.set(x, y, z, w); - } - - public void set(float x, float y) { - this.x = x; - this.y = y; - } - - public void set(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public void set(float x, float y, float z, float w) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - public float lengthSquared() { - return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; - } - - public Vector4f translate(float x, float y, float z, float w) { - this.x += x; - this.y += y; - this.z += z; - this.w += w; - return this; - } - - public static Vector4f add(Vector4f left, Vector4f right, Vector4f dest) { - if (dest == null) { - return new Vector4f(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); - } else { - dest.set(left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w); - return dest; - } - } - - public static Vector4f sub(Vector4f left, Vector4f right, Vector4f dest) { - if (dest == null) { - return new Vector4f(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); - } else { - dest.set(left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w); - return dest; - } - } - - public Vector negate() { - this.x = -this.x; - this.y = -this.y; - this.z = -this.z; - this.w = -this.w; - return this; - } - - public Vector4f negate(Vector4f dest) { - if (dest == null) { - dest = new Vector4f(); - } - - dest.x = -this.x; - dest.y = -this.y; - dest.z = -this.z; - dest.w = -this.w; - return dest; - } - - public Vector4f normalise(Vector4f dest) { - float f = this.length(); - - if (dest == null) { - dest = new Vector4f(this.x / f, this.y / f, this.z / f, this.w / f); - } else { - dest.set(this.x / f, this.y / f, this.z / f, this.w / f); - } - - return dest; - } - - public static float dot(Vector4f left, Vector4f right) { - return left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w; - } - - public static float angle(Vector4f a, Vector4f b) { - float f = dot(a, b) / (a.length() * b.length()); - - if (f < -1.0F) { - f = -1.0F; - } else if (f > 1.0F) { - f = 1.0F; - } - - return (float) Math.acos(f); - } - - public Vector load(FloatBuffer buf) { - this.x = buf.get(); - this.y = buf.get(); - this.z = buf.get(); - this.w = buf.get(); - return this; - } - - public Vector scale(float scale) { - this.x *= scale; - this.y *= scale; - this.z *= scale; - this.w *= scale; - return this; - } - - public Vector store(FloatBuffer buf) { - buf.put(this.x); - buf.put(this.y); - buf.put(this.z); - buf.put(this.w); - return this; - } - - public String toString() { - return "Vector4f: " + this.x + " " + this.y + " " + this.z + " " + this.w; - } - - public final float getX() { - return this.x; - } - - public final float getY() { - return this.y; - } - - public final void setX(float x) { - this.x = x; - } - - public final void setY(float y) { - this.y = y; - } - - public void setZ(float z) { - this.z = z; - } - - public float getZ() { - return this.z; - } - - public void setW(float w) { - this.w = w; - } - - public float getW() { - return this.w; - } - - public boolean equals(Object obj) { - if (this == obj) { - return true; - } else if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Vector4f vector4f = (Vector4f) obj; - return this.x == vector4f.x && this.y == vector4f.y && this.z == vector4f.z && this.w == vector4f.w; - } - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Angle.java b/common/src/main/java/org/vivecraft/common/utils/math/Angle.java deleted file mode 100644 index 746af7f03..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Angle.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.vivecraft.common.utils.math; - -import org.vivecraft.common.utils.lwjgl.Matrix4f; - -public class Angle { - private float pitch; - private float yaw; - private float roll; - private Order order; - - public Angle() { - this.order = Order.YXZ; - } - - public Angle(Order order) { - this.order = order; - } - - public Angle(float pitch, float yaw, float roll, Order order) { - this.pitch = pitch; - this.yaw = yaw; - this.roll = roll; - this.order = order; - } - - public Angle(float pitch, float yaw, float roll) { - this(pitch, yaw, roll, Order.YXZ); - } - - public Angle(float pitch, float yaw) { - this(pitch, yaw, 0.0F, Order.YXZ); - } - - public Angle(Angle other) { - this.pitch = other.pitch; - this.yaw = other.yaw; - this.roll = other.roll; - this.order = other.order; - } - - public Angle copy() { - return new Angle(this); - } - - public void set(float pitch, float yaw, float roll) { - this.pitch = pitch; - this.yaw = yaw; - this.roll = roll; - } - - public void set(Angle other) { - this.pitch = other.pitch; - this.yaw = other.yaw; - this.roll = other.roll; - } - - public float getPitch() { - return this.pitch; - } - - public void setPitch(float pitch) { - this.pitch = pitch; - } - - public float getYaw() { - return this.yaw; - } - - public void setYaw(float yaw) { - this.yaw = yaw; - } - - public float getRoll() { - return this.roll; - } - - public void setRoll(float roll) { - this.roll = roll; - } - - public Order getOrder() { - return this.order; - } - - public void setOrder(Order order) { - this.order = order; - } - - public Angle rotate(Axis axis, float degrees) { - switch (axis) { - case PITCH: - return new Angle(this.pitch + degrees, this.yaw, this.roll); - - case YAW: - return new Angle(this.pitch, this.yaw + degrees, this.roll); - - case ROLL: - return new Angle(this.pitch, this.yaw, this.roll + degrees); - - default: - return new Angle(this); - } - } - - public Angle add(Angle other) { - return new Angle(this.pitch + other.pitch, this.yaw + other.yaw, this.roll + other.roll, this.order); - } - - public Angle subtract(Angle other) { - return new Angle(this.pitch - other.pitch, this.yaw - other.yaw, this.roll - other.roll, this.order); - } - - public Matrix4f getMatrix() { - return (new Quaternion(this)).getMatrix(); - } - - public Vector3 forward() { - return (new Vector3(0.0F, 0.0F, -1.0F)).multiply(this.getMatrix()); - } - - public Vector3 up() { - return (new Vector3(0.0F, 1.0F, 0.0F)).multiply(this.getMatrix()); - } - - public Vector3 right() { - return (new Vector3(1.0F, 0.0F, 0.0F)).multiply(this.getMatrix()); - } - - public int hashCode() { - int i = 5; - i = 89 * i + Float.floatToIntBits(this.pitch); - i = 89 * i + Float.floatToIntBits(this.yaw); - return 89 * i + Float.floatToIntBits(this.roll); - } - - public boolean equals(Object obj) { - if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Angle angle = (Angle) obj; - - if (Float.floatToIntBits(this.pitch) != Float.floatToIntBits(angle.pitch)) { - return false; - } else if (Float.floatToIntBits(this.yaw) != Float.floatToIntBits(angle.yaw)) { - return false; - } else { - return Float.floatToIntBits(this.roll) == Float.floatToIntBits(angle.roll); - } - } - } - - public String toString() { - return "Angle{pitch=" + this.pitch + ", yaw=" + this.yaw + ", roll=" + this.roll + '}'; - } - - public enum Order { - XYZ, - ZYX, - YXZ, - ZXY, - YZX, - XZY - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Axis.java b/common/src/main/java/org/vivecraft/common/utils/math/Axis.java deleted file mode 100644 index afdac88eb..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Axis.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.vivecraft.common.utils.math; - -public enum Axis { - PITCH(1.0F, 0.0F, 0.0F), - YAW(0.0F, 1.0F, 0.0F), - ROLL(0.0F, 0.0F, 1.0F), - UNKNOWN(0.0F, 0.0F, 0.0F); - - private final Vector3 vector; - - Axis(float x, float y, float z) { - this.vector = new Vector3(x, y, z); - } - - public Vector3 getVector() { - return this.vector.copy(); - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Convert.java b/common/src/main/java/org/vivecraft/common/utils/math/Convert.java deleted file mode 100644 index c01955304..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Convert.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.vivecraft.common.utils.math; - -import java.nio.Buffer; -import java.nio.FloatBuffer; - -public class Convert { - public static Matrix matrix(float[] floatArray) { - return new Matrix(floatArray); - } - - public static Matrix matrix(float[][] float2Array) { - float[] afloat = new float[float2Array.length * float2Array[0].length]; - - for (int i = 0; i < float2Array.length; ++i) { - System.arraycopy(float2Array[i], 0, afloat, i * float2Array[0].length, float2Array[0].length); - } - - return matrix(afloat); - } - - public static Matrix matrix(FloatBuffer floatBuffer) { - float[] afloat = new float[floatBuffer.capacity()]; - ((Buffer) floatBuffer).position(0); - floatBuffer.get(afloat); - ((Buffer) floatBuffer).position(0); - return matrix(afloat); - } - - public static Matrix matrix(org.vivecraft.common.utils.lwjgl.Matrix4f matrix4f) { - FloatBuffer floatbuffer = FloatBuffer.allocate(16); - matrix4f.store(floatbuffer); - return matrix(floatbuffer); - } - - public static Matrix matrix(Quaternion quaternion) { - return matrix(quaternion.getMatrix()); - } - - public static class Matrix { - int dimension; - float[] floatArray; - double[] doubleArray; - int[] intArray; - boolean floatFilled = false; - boolean doubleFilled = false; - boolean intFilled = false; - - public Matrix(float[] floatArray) { - this.dimension = (int) Math.sqrt(floatArray.length); - - if (this.dimension * this.dimension != floatArray.length) { - throw new IllegalArgumentException("Input array has invalid length"); - } else { - this.floatArray = floatArray; - this.floatFilled = true; - } - } - - private void needFloats() { - if (!this.floatFilled) { - for (int i = 0; i < this.floatArray.length; ++i) { - if (this.doubleFilled) { - this.floatArray[i] = (float) this.doubleArray[i]; - } else if (this.intFilled) { - this.floatArray[i] = (float) this.intArray[i]; - } - } - - this.floatFilled = true; - } - } - - private void needDoubles() { - if (!this.doubleFilled) { - for (int i = 0; i < this.doubleArray.length; ++i) { - if (this.floatFilled) { - this.doubleArray[i] = this.floatArray[i]; - } else if (this.intFilled) { - this.doubleArray[i] = this.intArray[i]; - } - } - - this.doubleFilled = true; - } - } - - private void needInts() { - if (!this.intFilled) { - for (int i = 0; i < this.intArray.length; ++i) { - if (this.doubleFilled) { - this.intArray[i] = (int) this.doubleArray[i]; - } else if (this.floatFilled) { - this.intArray[i] = (int) this.floatArray[i]; - } - } - - this.intFilled = true; - } - } - - public Matrix4f toOVRMatrix4f() { - this.needFloats(); - - if (this.dimension == 3) { - return new Matrix4f(this.floatArray[0], this.floatArray[1], this.floatArray[2], this.floatArray[3], this.floatArray[4], this.floatArray[5], this.floatArray[6], this.floatArray[7], this.floatArray[8]); - } else if (this.dimension == 4) { - return new Matrix4f(this.floatArray[0], this.floatArray[1], this.floatArray[2], this.floatArray[3], this.floatArray[4], this.floatArray[5], this.floatArray[6], this.floatArray[7], this.floatArray[8], this.floatArray[9], this.floatArray[10], this.floatArray[11], this.floatArray[12], this.floatArray[13], this.floatArray[14], this.floatArray[15]); - } else { - throw new IllegalArgumentException("Wrong dimension! Can't convert Matrix" + this.dimension + " to Matrix4f"); - } - } - - public org.joml.Matrix4f toMCMatrix4f() { - this.needFloats(); - - if (this.dimension == 4) { - org.joml.Matrix4f matrix4f = new org.joml.Matrix4f(); - matrix4f.get(this.toFloatBuffer()); - return matrix4f; - } else { - throw new IllegalArgumentException("Wrong dimension! Can't convert Matrix" + this.dimension + " to Matrix4f"); - } - } - - public FloatBuffer toFloatBuffer() { - return FloatBuffer.wrap(this.floatArray); - } - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Matrix4f.java b/common/src/main/java/org/vivecraft/common/utils/math/Matrix4f.java deleted file mode 100644 index 369ad9351..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Matrix4f.java +++ /dev/null @@ -1,207 +0,0 @@ -package org.vivecraft.common.utils.math; - -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; - -@Deprecated -public class Matrix4f { - public float[][] M = new float[4][4]; - - public Matrix4f(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { - this.M[0][0] = m11; - this.M[0][1] = m12; - this.M[0][2] = m13; - this.M[0][3] = m14; - this.M[1][0] = m21; - this.M[1][1] = m22; - this.M[1][2] = m23; - this.M[1][3] = m24; - this.M[2][0] = m31; - this.M[2][1] = m32; - this.M[2][2] = m33; - this.M[2][3] = m34; - this.M[3][0] = m41; - this.M[3][1] = m42; - this.M[3][2] = m43; - this.M[3][3] = m44; - } - - public Matrix4f(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { - this.M[0][0] = m11; - this.M[0][1] = m12; - this.M[0][2] = m13; - this.M[0][3] = 0.0F; - this.M[1][0] = m21; - this.M[1][1] = m22; - this.M[1][2] = m23; - this.M[1][3] = 0.0F; - this.M[2][0] = m31; - this.M[2][1] = m32; - this.M[2][2] = m33; - this.M[2][3] = 0.0F; - this.M[3][0] = 0.0F; - this.M[3][1] = 0.0F; - this.M[3][2] = 0.0F; - this.M[3][3] = 1.0F; - } - - public Matrix4f(Quaternion q) { - float f = q.w * q.w; - float f1 = q.x * q.x; - float f2 = q.y * q.y; - float f3 = q.z * q.z; - this.M[0][0] = f + f1 - f2 - f3; - this.M[0][1] = 2.0F * (q.x * q.y - q.w * q.z); - this.M[0][2] = 2.0F * (q.x * q.z + q.w * q.y); - this.M[0][3] = 0.0F; - this.M[1][0] = 2.0F * (q.x * q.y + q.w * q.z); - this.M[1][1] = f - f1 + f2 - f3; - this.M[1][2] = 2.0F * (q.y * q.z - q.w * q.x); - this.M[1][3] = 0.0F; - this.M[2][0] = 2.0F * (q.x * q.z - q.w * q.y); - this.M[2][1] = 2.0F * (q.y * q.z + q.w * q.x); - this.M[2][2] = f - f1 - f2 + f3; - this.M[2][3] = 0.0F; - this.M[3][0] = 0.0F; - this.M[3][1] = 0.0F; - this.M[3][2] = 0.0F; - this.M[3][3] = 1.0F; - } - - public Matrix4f() { - this.SetIdentity(); - } - - public void SetIdentity() { - this.M[0][0] = this.M[1][1] = this.M[2][2] = this.M[3][3] = 1.0F; - this.M[0][1] = this.M[1][0] = this.M[2][3] = this.M[3][1] = 0.0F; - this.M[0][2] = this.M[1][2] = this.M[2][0] = this.M[3][2] = 0.0F; - this.M[0][3] = this.M[1][3] = this.M[2][1] = this.M[3][0] = 0.0F; - } - - Matrix4f(Matrix4f c) { - for (int i = 0; i < 4; ++i) { - System.arraycopy(c.M[i], 0, this.M[i], 0, 4); - } - } - - public Matrix4f inverted() { - float f = this.Determinant(); - return f == 0.0F ? null : this.Adjugated().Multiply(1.0F / f); - } - - Matrix4f Multiply(float s) { - Matrix4f matrix4f = new Matrix4f(this); - - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { - float[] afloat = matrix4f.M[i]; - afloat[j] *= s; - } - } - - return matrix4f; - } - - public static Matrix4f multiply(Matrix4f a, Matrix4f b) { - int i = 0; - Matrix4f matrix4f = new Matrix4f(); - - do { - matrix4f.M[i][0] = a.M[i][0] * b.M[0][0] + a.M[i][1] * b.M[1][0] + a.M[i][2] * b.M[2][0] + a.M[i][3] * b.M[3][0]; - matrix4f.M[i][1] = a.M[i][0] * b.M[0][1] + a.M[i][1] * b.M[1][1] + a.M[i][2] * b.M[2][1] + a.M[i][3] * b.M[3][1]; - matrix4f.M[i][2] = a.M[i][0] * b.M[0][2] + a.M[i][1] * b.M[1][2] + a.M[i][2] * b.M[2][2] + a.M[i][3] * b.M[3][2]; - matrix4f.M[i][3] = a.M[i][0] * b.M[0][3] + a.M[i][1] * b.M[1][3] + a.M[i][2] * b.M[2][3] + a.M[i][3] * b.M[3][3]; - ++i; - } - while (i < 4); - - return matrix4f; - } - - public Matrix4f transposed() { - return new Matrix4f(this.M[0][0], this.M[1][0], this.M[2][0], this.M[3][0], this.M[0][1], this.M[1][1], this.M[2][1], this.M[3][1], this.M[0][2], this.M[1][2], this.M[2][2], this.M[3][2], this.M[0][3], this.M[1][3], this.M[2][3], this.M[3][3]); - } - - float SubDet(int[] rows, int[] cols) { - return this.M[rows[0]][cols[0]] * (this.M[rows[1]][cols[1]] * this.M[rows[2]][cols[2]] - this.M[rows[1]][cols[2]] * this.M[rows[2]][cols[1]]) - this.M[rows[0]][cols[1]] * (this.M[rows[1]][cols[0]] * this.M[rows[2]][cols[2]] - this.M[rows[1]][cols[2]] * this.M[rows[2]][cols[0]]) + this.M[rows[0]][cols[2]] * (this.M[rows[1]][cols[0]] * this.M[rows[2]][cols[1]] - this.M[rows[1]][cols[1]] * this.M[rows[2]][cols[0]]); - } - - float Cofactor(int I, int J) { - int[][] aint = new int[][]{{1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}}; - return (I + J & 1) != 0 ? -this.SubDet(aint[I], aint[J]) : this.SubDet(aint[I], aint[J]); - } - - float Determinant() { - return this.M[0][0] * this.Cofactor(0, 0) + this.M[0][1] * this.Cofactor(0, 1) + this.M[0][2] * this.Cofactor(0, 2) + this.M[0][3] * this.Cofactor(0, 3); - } - - Matrix4f Adjugated() { - return new Matrix4f(this.Cofactor(0, 0), this.Cofactor(1, 0), this.Cofactor(2, 0), this.Cofactor(3, 0), this.Cofactor(0, 1), this.Cofactor(1, 1), this.Cofactor(2, 1), this.Cofactor(3, 1), this.Cofactor(0, 2), this.Cofactor(1, 2), this.Cofactor(2, 2), this.Cofactor(3, 2), this.Cofactor(0, 3), this.Cofactor(1, 3), this.Cofactor(2, 3), this.Cofactor(3, 3)); - } - - public FloatBuffer toFloatBuffer() { - FloatBuffer floatbuffer = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asFloatBuffer(); - floatbuffer.put(this.M[0][0]); - floatbuffer.put(this.M[0][1]); - floatbuffer.put(this.M[0][2]); - floatbuffer.put(this.M[0][3]); - floatbuffer.put(this.M[1][0]); - floatbuffer.put(this.M[1][1]); - floatbuffer.put(this.M[1][2]); - floatbuffer.put(this.M[1][3]); - floatbuffer.put(this.M[2][0]); - floatbuffer.put(this.M[2][1]); - floatbuffer.put(this.M[2][2]); - floatbuffer.put(this.M[2][3]); - floatbuffer.put(this.M[3][0]); - floatbuffer.put(this.M[3][1]); - floatbuffer.put(this.M[3][2]); - floatbuffer.put(this.M[3][3]); - ((Buffer) floatbuffer).flip(); - return floatbuffer; - } - - public static Matrix4f rotationY(float angle) { - double d0 = Math.sin(angle); - double d1 = Math.cos(angle); - return new Matrix4f((float) d1, 0.0F, (float) d0, 0.0F, 1.0F, 0.0F, -((float) d0), 0.0F, (float) d1); - } - - public Vector3 transform(Vector3 v) { - float f = 1.0F / (this.M[3][0] * v.x + this.M[3][1] * v.y + this.M[3][2] * v.z + this.M[3][3]); - return new Vector3((this.M[0][0] * v.x + this.M[0][1] * v.y + this.M[0][2] * v.z + this.M[0][3]) * f, (this.M[1][0] * v.x + this.M[1][1] * v.y + this.M[1][2] * v.z + this.M[1][3]) * f, (this.M[2][0] * v.x + this.M[2][1] * v.y + this.M[2][2] * v.z + this.M[2][3]) * f); - } - - public static Matrix4f translation(Vector3 v) { - Matrix4f matrix4f = new Matrix4f(); - matrix4f.M[0][3] = v.x; - matrix4f.M[1][3] = v.y; - matrix4f.M[2][3] = v.z; - return matrix4f; - } - - public static Matrix4f lookAtRH(Vector3 eye, Vector3 at, Vector3 up) { - Vector3 vector3 = eye.subtract(at).normalized(); - Vector3 vector31 = up.cross(vector3).normalized(); - Vector3 vector32 = vector3.cross(vector31); - return new Matrix4f(vector31.x, vector31.y, vector31.z, -vector31.dot(eye), vector32.x, vector32.y, vector32.z, -vector32.dot(eye), vector3.x, vector3.y, vector3.z, -vector3.dot(eye), 0.0F, 0.0F, 0.0F, 1.0F); - } - - public org.joml.Matrix4f toMCMatrix() { - return new org.joml.Matrix4f(this.M[0][0], this.M[1][0], this.M[2][0], this.M[3][0], - this.M[0][1], this.M[1][1], this.M[2][1], this.M[3][1], - this.M[0][2], this.M[1][2], this.M[2][2], this.M[3][2], - this.M[0][3], this.M[1][3], this.M[2][3], this.M[3][3]); - } - - public String toString() { - String stringbuilder = String.valueOf(this.M[0][0]) + ' ' + this.M[1][0] + ' ' + this.M[2][0] + ' ' + this.M[3][0] + '\n' + - this.M[0][1] + ' ' + this.M[1][1] + ' ' + this.M[2][1] + ' ' + this.M[3][1] + '\n' + - this.M[0][2] + ' ' + this.M[1][2] + ' ' + this.M[2][2] + ' ' + this.M[3][2] + '\n' + - this.M[0][3] + ' ' + this.M[1][3] + ' ' + this.M[2][3] + ' ' + this.M[3][3] + '\n'; - return stringbuilder; - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Quaternion.java b/common/src/main/java/org/vivecraft/common/utils/math/Quaternion.java deleted file mode 100644 index febc939bd..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Quaternion.java +++ /dev/null @@ -1,337 +0,0 @@ -package org.vivecraft.common.utils.math; - -import net.minecraft.world.phys.Vec3; -import org.vivecraft.client.utils.Utils; -import org.vivecraft.common.utils.lwjgl.Matrix3f; - -@Deprecated -public class Quaternion { - public float w; - public float x; - public float y; - public float z; - - public Quaternion() { - this.w = 1.0F; - } - - public Quaternion(float w, float x, float y, float z) { - this.w = w; - this.x = x; - this.y = y; - this.z = z; - } - - public Quaternion(Quaternion other) { - this.w = other.w; - this.x = other.x; - this.y = other.y; - this.z = other.z; - } - - public Quaternion(Vector3 vector, float rotation) { - rotation = (float) Math.toRadians(rotation); - float f = (float) Math.sin(rotation / 2.0F); - this.w = (float) Math.cos(rotation / 2.0F); - this.x = vector.x * f; - this.y = vector.y * f; - this.z = vector.z * f; - } - - public Quaternion(Axis axis, float rotation) { - this(axis.getVector(), rotation); - } - - public Quaternion(float pitch, float yaw, float roll, Angle.Order order) { - Quaternion quaternion = new Quaternion(new Vector3(1.0F, 0.0F, 0.0F), pitch); - Quaternion quaternion1 = new Quaternion(new Vector3(0.0F, 1.0F, 0.0F), yaw); - Quaternion quaternion2 = new Quaternion(new Vector3(0.0F, 0.0F, 1.0F), roll); - Quaternion quaternion3 = null; - - switch (order) { - case XYZ: - quaternion3 = quaternion.multiply(quaternion1).multiply(quaternion2); - break; - - case ZYX: - quaternion3 = quaternion2.multiply(quaternion1).multiply(quaternion); - break; - - case YXZ: - quaternion3 = quaternion1.multiply(quaternion).multiply(quaternion2); - break; - - case ZXY: - quaternion3 = quaternion2.multiply(quaternion).multiply(quaternion1); - break; - - case YZX: - quaternion3 = quaternion1.multiply(quaternion2).multiply(quaternion); - break; - - case XZY: - quaternion3 = quaternion.multiply(quaternion2).multiply(quaternion1); - } - - this.w = quaternion3.w; - this.x = quaternion3.x; - this.y = quaternion3.y; - this.z = quaternion3.z; - } - - public Quaternion(float pitch, float yaw, float roll) { - this(pitch, yaw, roll, Angle.Order.YXZ); - } - - public Quaternion(Angle angle) { - this(angle.getPitch(), angle.getYaw(), angle.getRoll(), angle.getOrder()); - } - - public Quaternion(Matrix3f matrix) { - this(matrix.m00, matrix.m01, matrix.m02, matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, matrix.m22); - } - - public Quaternion(org.vivecraft.common.utils.lwjgl.Matrix4f matrix) { - this(matrix.m00, matrix.m01, matrix.m02, matrix.m10, matrix.m11, matrix.m12, matrix.m20, matrix.m21, matrix.m22); - } - - public Quaternion(Matrix4f matrix) { - this(matrix.M[0][0], matrix.M[0][1], matrix.M[0][2], matrix.M[1][0], matrix.M[1][1], matrix.M[1][2], matrix.M[2][0], matrix.M[2][1], matrix.M[2][2]); - } - - private Quaternion(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22) { - float f1 = m00 + m11 + m22; - - if ((double) f1 >= 0.0D) { - float f = (float) Math.sqrt((double) f1 + 1.0D); - this.w = f * 0.5F; - f = 0.5F / f; - this.x = (m21 - m12) * f; - this.y = (m02 - m20) * f; - this.z = (m10 - m01) * f; - } else { - float f2 = Math.max(Math.max(m00, m11), m22); - - if (f2 == m00) { - float f3 = (float) Math.sqrt((double) (m00 - (m11 + m22)) + 1.0D); - this.x = f3 * 0.5F; - f3 = 0.5F / f3; - this.y = (m01 + m10) * f3; - this.z = (m20 + m02) * f3; - this.w = (m21 - m12) * f3; - } else if (f2 == m11) { - float f4 = (float) Math.sqrt((double) (m11 - (m22 + m00)) + 1.0D); - this.y = f4 * 0.5F; - f4 = 0.5F / f4; - this.z = (m12 + m21) * f4; - this.x = (m01 + m10) * f4; - this.w = (m02 - m20) * f4; - } else { - float f5 = (float) Math.sqrt((double) (m22 - (m00 + m11)) + 1.0D); - this.z = f5 * 0.5F; - f5 = 0.5F / f5; - this.x = (m20 + m02) * f5; - this.y = (m12 + m21) * f5; - this.w = (m10 - m01) * f5; - } - } - } - - public Quaternion copy() { - return new Quaternion(this); - } - - public float getW() { - return this.w; - } - - public void setW(float w) { - this.w = w; - } - - public float getX() { - return this.x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return this.y; - } - - public void setY(float y) { - this.y = y; - } - - public float getZ() { - return this.z; - } - - public void setZ(float z) { - this.z = z; - } - - public void set(Quaternion other) { - this.w = other.w; - this.x = other.x; - this.y = other.y; - this.z = other.z; - } - - public void normalize() { - float f = (float) Math.sqrt(this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z); - - if (f > 0.0F) { - this.w /= f; - this.x /= f; - this.y /= f; - this.z /= f; - } else { - this.w = 1.0F; - this.x = 0.0F; - this.y = 0.0F; - this.z = 0.0F; - } - } - - public Quaternion normalized() { - float f4 = (float) Math.sqrt(this.w * this.w + this.x * this.x + this.y * this.y + this.z * this.z); - float f; - float f1; - float f2; - float f3; - - if (f4 > 0.0F) { - f = this.w / f4; - f1 = this.x / f4; - f2 = this.y / f4; - f3 = this.z / f4; - } else { - f = 1.0F; - f1 = 0.0F; - f2 = 0.0F; - f3 = 0.0F; - } - - return new Quaternion(f, f1, f2, f3); - } - - public Angle toEuler() { - Angle angle = new Angle(); - angle.setYaw((float) Math.toDegrees(Math.atan2(2.0F * (this.x * this.z + this.w * this.y), this.w * this.w - this.x * this.x - this.y * this.y + this.z * this.z))); - angle.setPitch((float) Math.toDegrees(Math.asin(-2.0F * (this.y * this.z - this.w * this.x)))); - angle.setRoll((float) Math.toDegrees(Math.atan2(2.0F * (this.x * this.y + this.w * this.z), this.w * this.w - this.x * this.x + this.y * this.y - this.z * this.z))); - return angle; - } - - public Quaternion rotate(Axis axis, float degrees, boolean local) { - if (local) { - return this.multiply(new Quaternion(axis, degrees)); - } else { - org.vivecraft.common.utils.lwjgl.Matrix4f matrix4f = this.getMatrix(); - matrix4f.rotate((float) Math.toRadians(degrees), Utils.convertVector(axis.getVector())); - return new Quaternion(matrix4f); - } - } - - public Quaternion multiply(Quaternion other) { - float f = this.w * other.w - this.x * other.x - this.y * other.y - this.z * other.z; - float f1 = this.w * other.x + other.w * this.x + this.y * other.z - this.z * other.y; - float f2 = this.w * other.y + other.w * this.y - this.x * other.z + this.z * other.x; - float f3 = this.w * other.z + other.w * this.z + this.x * other.y - this.y * other.x; - return new Quaternion(f, f1, f2, f3); - } - - public org.vivecraft.common.utils.lwjgl.Matrix4f getMatrix() { - org.vivecraft.common.utils.lwjgl.Matrix4f matrix4f = new org.vivecraft.common.utils.lwjgl.Matrix4f(); - float f = this.w * this.w; - float f1 = this.x * this.x; - float f2 = this.y * this.y; - float f3 = this.z * this.z; - float f4 = 1.0F / (f1 + f2 + f3 + f); - matrix4f.m00 = (f1 - f2 - f3 + f) * f4; - matrix4f.m11 = (-f1 + f2 - f3 + f) * f4; - matrix4f.m22 = (-f1 - f2 + f3 + f) * f4; - float f5 = this.x * this.y; - float f6 = this.z * this.w; - matrix4f.m10 = 2.0F * (f5 + f6) * f4; - matrix4f.m01 = 2.0F * (f5 - f6) * f4; - f5 = this.x * this.z; - f6 = this.y * this.w; - matrix4f.m20 = 2.0F * (f5 - f6) * f4; - matrix4f.m02 = 2.0F * (f5 + f6) * f4; - f5 = this.y * this.z; - f6 = this.x * this.w; - matrix4f.m21 = 2.0F * (f5 + f6) * f4; - matrix4f.m12 = 2.0F * (f5 - f6) * f4; - return matrix4f; - } - - public Quaternion inverse() { - return new Quaternion(this.w, -this.x, -this.y, -this.z); - } - - public static Quaternion createFromToVector(Vector3 from, Vector3 to) { - Vector3 vector3 = from.cross(to); - float f = (float) (Math.sqrt(Math.pow(from.length(), 2.0D) * Math.pow(to.length(), 2.0D)) + (double) from.dot(to)); - return (new Quaternion(f, vector3.x, vector3.y, vector3.z)).normalized(); - } - - public int hashCode() { - int i = 3; - i = 23 * i + Float.floatToIntBits(this.w); - i = 23 * i + Float.floatToIntBits(this.x); - i = 23 * i + Float.floatToIntBits(this.y); - return 23 * i + Float.floatToIntBits(this.z); - } - - public boolean equals(Object obj) { - if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Quaternion quaternion = (Quaternion) obj; - - if (Float.floatToIntBits(this.w) != Float.floatToIntBits(quaternion.w)) { - return false; - } else if (Float.floatToIntBits(this.x) != Float.floatToIntBits(quaternion.x)) { - return false; - } else if (Float.floatToIntBits(this.y) != Float.floatToIntBits(quaternion.y)) { - return false; - } else { - return Float.floatToIntBits(this.z) == Float.floatToIntBits(quaternion.z); - } - } - } - - public Vector3 multiply(Vector3 vec) { - float f = this.x * 2.0F; - float f1 = this.y * 2.0F; - float f2 = this.z * 2.0F; - float f3 = this.x * f; - float f4 = this.y * f1; - float f5 = this.z * f2; - float f6 = this.x * f1; - float f7 = this.x * f2; - float f8 = this.y * f2; - float f9 = this.w * f; - float f10 = this.w * f1; - float f11 = this.w * f2; - Vector3 vector3 = new Vector3(); - vector3.x = (1.0F - (f4 + f5)) * vec.x + (f6 - f11) * vec.y + (f7 + f10) * vec.z; - vector3.y = (f6 + f11) * vec.x + (1.0F - (f3 + f5)) * vec.y + (f8 - f9) * vec.z; - vector3.z = (f7 - f10) * vec.x + (f8 + f9) * vec.y + (1.0F - (f3 + f4)) * vec.z; - return vector3; - } - - public Vec3 multiply(Vec3 vec) { - return this.multiply(new Vector3(vec)).toVector3d(); - } - - public String toString() { - return "Quaternion{w=" + this.w + ", x=" + this.x + ", y=" + this.y + ", z=" + this.z + '}'; - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Vector2.java b/common/src/main/java/org/vivecraft/common/utils/math/Vector2.java deleted file mode 100644 index 48c2cf5ce..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Vector2.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.vivecraft.common.utils.math; - -import org.vivecraft.common.utils.lwjgl.Vector2f; - -@Deprecated -public class Vector2 { - protected float x; - protected float y; - - public Vector2() { - } - - public Vector2(float x, float y) { - this.x = x; - this.y = y; - } - - public Vector2(Vector2 other) { - this.x = other.x; - this.y = other.y; - } - - public Vector2(Vector2f other) { - this.x = other.x; - this.y = other.y; - } - - public Vector2 copy() { - return new Vector2(this); - } - - public float getX() { - return this.x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return this.y; - } - - public void setY(float y) { - this.y = y; - } - - public void set(float x, float y) { - this.x = x; - this.y = y; - } - - public void set(Vector2 other) { - this.x = other.x; - this.y = other.y; - } - - public Vector2 add(Vector2 other) { - return new Vector2(this.x + other.x, this.y + other.y); - } - - public Vector2 subtract(Vector2 other) { - return new Vector2(this.x - other.x, this.y - other.y); - } - - public Vector2 multiply(float number) { - return new Vector2(this.x * number, this.y * number); - } - - public Vector2 divide(float number) { - return new Vector2(this.x / number, this.y / number); - } - - public Vector2 negate() { - return new Vector2(-this.x, -this.y); - } - - public float angle(Vector2 other) { - return (float) Math.toDegrees(Math.atan2(other.y - this.y, other.x - this.x)); - } - - public float length() { - return (float) Math.sqrt(this.x * this.x + this.y * this.y); - } - - public float lengthSquared() { - return this.x * this.x + this.y * this.y; - } - - public float distance(Vector2 other) { - return other.subtract(this).length(); - } - - public float distanceSquared(Vector2 other) { - return other.subtract(this).lengthSquared(); - } - - public void normalize() { - this.set(this.divide(this.length())); - } - - public Vector2 normalized() { - return this.divide(this.length()); - } - - public float dot(Vector2 other) { - return this.x * other.x + this.y * other.y; - } - - public static Vector2 direction(float angle) { - double d0 = Math.toRadians(angle); - return new Vector2((float) Math.cos(d0), (float) Math.sin(d0)); - } - - public int hashCode() { - int i = 7; - i = 37 * i + Float.floatToIntBits(this.x); - return 37 * i + Float.floatToIntBits(this.y); - } - - public boolean equals(Object obj) { - if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Vector2 vector2 = (Vector2) obj; - - if (Float.floatToIntBits(this.x) != Float.floatToIntBits(vector2.x)) { - return false; - } else { - return Float.floatToIntBits(this.y) == Float.floatToIntBits(vector2.y); - } - } - } - - public String toString() { - return "Vector2{x=" + this.x + ", y=" + this.y + '}'; - } -} diff --git a/common/src/main/java/org/vivecraft/common/utils/math/Vector3.java b/common/src/main/java/org/vivecraft/common/utils/math/Vector3.java deleted file mode 100644 index 3bd0581dd..000000000 --- a/common/src/main/java/org/vivecraft/common/utils/math/Vector3.java +++ /dev/null @@ -1,262 +0,0 @@ -package org.vivecraft.common.utils.math; - -import net.minecraft.world.phys.Vec3; -import org.vivecraft.common.utils.lwjgl.Matrix3f; -import org.vivecraft.common.utils.lwjgl.Matrix4f; -import org.vivecraft.common.utils.lwjgl.Vector3f; - -@Deprecated -public class Vector3 { - public float x; - public float y; - public float z; - - public Vector3() { - } - - public Vector3(Vec3 vec3d) { - this.x = (float) vec3d.x; - this.y = (float) vec3d.y; - this.z = (float) vec3d.z; - } - - public Vector3(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public Vector3(Vector3 other) { - this.x = other.x; - this.y = other.y; - this.z = other.z; - } - - public Vector3(Vector3f other) { - this.x = other.x; - this.y = other.y; - this.z = other.z; - } - - public Vec3 toVector3d() { - return new Vec3(this.x, this.y, this.z); - } - - public Vector3 copy() { - return new Vector3(this); - } - - public float getX() { - return this.x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return this.y; - } - - public void setY(float y) { - this.y = y; - } - - public float getZ() { - return this.z; - } - - public void setZ(float z) { - this.z = z; - } - - public void set(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public void set(Vector3 other) { - this.x = other.x; - this.y = other.y; - this.z = other.z; - } - - public Vector3 add(Vector3 other) { - return new Vector3(this.x + other.x, this.y + other.y, this.z + other.z); - } - - public Vector3 add(float number) { - return new Vector3(this.x + number, this.y + number, this.z + number); - } - - public Vector3 subtract(Vector3 other) { - return new Vector3(this.x - other.x, this.y - other.y, this.z - other.z); - } - - public Vector3 subtract(float number) { - return new Vector3(this.x - number, this.y - number, this.z - number); - } - - public Vector3 multiply(float number) { - return new Vector3(this.x * number, this.y * number, this.z * number); - } - - public Vector3 multiply(Matrix3f matrix) { - float f = matrix.m00 * this.x + matrix.m01 * this.y + matrix.m02 * this.z; - float f1 = matrix.m10 * this.x + matrix.m11 * this.y + matrix.m12 * this.z; - float f2 = matrix.m20 * this.x + matrix.m21 * this.y + matrix.m22 * this.z; - return new Vector3(f, f1, f2); - } - - public Vector3 multiply(Matrix4f matrix) { - float f = matrix.m00 * this.x + matrix.m01 * this.y + matrix.m02 * this.z + matrix.m03; - float f1 = matrix.m10 * this.x + matrix.m11 * this.y + matrix.m12 * this.z + matrix.m13; - float f2 = matrix.m20 * this.x + matrix.m21 * this.y + matrix.m22 * this.z + matrix.m23; - return new Vector3(f, f1, f2); - } - - public Vector3 divide(float number) { - return new Vector3(this.x / number, this.y / number, this.z / number); - } - - public Vector3 negate() { - return new Vector3(-this.x, -this.y, -this.z); - } - - public Angle angle(Vector3 other) { - float f = other.x - this.x; - float f1 = other.z - this.z; - float f2 = (float) Math.toDegrees(Math.atan2(other.y - this.y, Math.sqrt(f * f + f1 * f1))); - float f3 = (float) Math.toDegrees(Math.atan2(-f, -f1)); - return new Angle(f2, f3); - } - - public float length() { - return (float) Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); - } - - public float lengthSquared() { - return this.x * this.x + this.y * this.y + this.z * this.z; - } - - public float distance(Vector3 other) { - float f = other.x - this.x; - float f1 = other.y - this.y; - float f2 = other.z - this.z; - return (float) Math.sqrt(f * f + f1 * f1 + f2 * f2); - } - - public float distanceSquared(Vector3 other) { - float f = other.x - this.x; - float f1 = other.y - this.y; - float f2 = other.z - this.z; - return f * f + f1 * f1 + f2 * f2; - } - - public float distance2D(Vector2 other) { - return other.subtract(new Vector2(this.x, this.z)).length(); - } - - public float distanceSquared2D(Vector2 other) { - return other.subtract(new Vector2(this.x, this.z)).lengthSquared(); - } - - public float distance2D(Vector3 other) { - return this.distance2D(new Vector2(other.x, other.z)); - } - - public float distanceSquared2D(Vector3 other) { - return this.distanceSquared2D(new Vector2(other.x, other.z)); - } - - public void normalize() { - this.set(this.divide(this.length())); - } - - public Vector3 normalized() { - return this.divide(this.length()); - } - - public float dot(Vector3 other) { - return this.x * other.x + this.y * other.y + this.z * other.z; - } - - public Vector3 cross(Vector3 other) { - return new Vector3(this.y * other.z - this.z * other.y, this.z * other.x - this.x * other.z, this.x * other.y - this.y * other.x); - } - - public Vector3 project(Vector3 other) { - return other.multiply(other.dot(this) / other.dot(other)); - } - - public static Vector3 forward() { - return new Vector3(0.0F, 0.0F, -1.0F); - } - - public static Vector3 up() { - return new Vector3(0.0F, -1.0F, 0.0F); - } - - public static Vector3 right() { - return new Vector3(-1.0F, 0.0F, 0.0F); - } - - public static Vector3 lerp(Vector3 start, Vector3 end, float fraction) { - return start.add(end.subtract(start).multiply(fraction)); - } - - public static Vector3 slerp(Vector3 start, Vector3 end, float fraction) { - float f = start.dot(end); - float f1 = (float) Math.acos(f) * fraction; - Vector3 vector3 = end.subtract(start.multiply(f)); - vector3.normalize(); - return start.multiply((float) Math.cos(f1)).add(vector3.multiply((float) Math.sin(f1))); - } - - public static Matrix3f lookMatrix(Vector3 forward, Vector3 up) { - Vector3 vector3 = forward.normalized(); - Vector3 vector31 = up.cross(vector3).normalized(); - Vector3 vector32 = vector3.cross(vector31); - Matrix3f matrix3f = new Matrix3f(); - matrix3f.m00 = vector31.x; - matrix3f.m01 = vector31.y; - matrix3f.m02 = vector31.z; - matrix3f.m10 = vector32.x; - matrix3f.m11 = vector32.y; - matrix3f.m12 = vector32.z; - matrix3f.m20 = vector3.x; - matrix3f.m21 = vector3.y; - matrix3f.m22 = vector3.z; - return matrix3f; - } - - public int hashCode() { - int i = 7; - i = 53 * i + Float.floatToIntBits(this.x); - i = 53 * i + Float.floatToIntBits(this.y); - return 53 * i + Float.floatToIntBits(this.z); - } - - public boolean equals(Object obj) { - if (obj == null) { - return false; - } else if (this.getClass() != obj.getClass()) { - return false; - } else { - Vector3 vector3 = (Vector3) obj; - - if (Float.floatToIntBits(this.x) != Float.floatToIntBits(vector3.x)) { - return false; - } else if (Float.floatToIntBits(this.y) != Float.floatToIntBits(vector3.y)) { - return false; - } else { - return Float.floatToIntBits(this.z) == Float.floatToIntBits(vector3.z); - } - } - } - - public String toString() { - return "(" + String.format("%.2f", this.x) + ", " + String.format("%.2f", this.y) + ", " + String.format("%.2f", this.z) + ")"; - } -} diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java index 96d79eeff..6f902f312 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/KeyboardInputVRMixin.java @@ -4,6 +4,7 @@ import net.minecraft.client.Options; import net.minecraft.client.player.Input; import net.minecraft.client.player.KeyboardInput; +import org.joml.Vector2f; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -12,12 +13,10 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.vivecraft.client.VivecraftVRMod; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler; import org.vivecraft.client_vr.provider.openvr_lwjgl.VRInputAction; -import org.vivecraft.common.utils.math.Vector2; import static org.vivecraft.client_vr.provider.openvr_lwjgl.control.VivecraftMovementInput.getMovementAxisValue; @@ -89,21 +88,21 @@ public class KeyboardInputVRMixin extends Input { if (!climbing && !dataholder.vrSettings.seated && minecraft.screen == null && !KeyboardHandler.Showing) { VRInputAction vrinputaction = dataholder.vr.getInputAction(VivecraftVRMod.INSTANCE.keyFreeMoveStrafe); VRInputAction vrinputaction1 = dataholder.vr.getInputAction(VivecraftVRMod.INSTANCE.keyFreeMoveRotate); - Vector2 vector2 = vrinputaction.getAxis2DUseTracked(); - Vector2 vector21 = vrinputaction1.getAxis2DUseTracked(); + Vector2f vector2f = vrinputaction.getAxis2DUseTracked(); + Vector2f vector21f = vrinputaction1.getAxis2DUseTracked(); - if (vector2.getX() == 0.0F && vector2.getY() == 0.0F) { - if (vector21.getY() != 0.0F) { + if (vector2f.x() == 0.0F && vector2f.y() == 0.0F) { + if (vector21f.y() != 0.0F) { flag1 = true; - f = vector21.getY(); + f = vector21f.y(); if (dataholder.vrSettings.analogMovement) { - this.forwardImpulse = vector21.getY(); + this.forwardImpulse = vector21f.y(); this.leftImpulse = 0.0F; this.leftImpulse -= getMovementAxisValue(this.options.keyRight); this.leftImpulse += getMovementAxisValue(this.options.keyLeft); } else { - this.forwardImpulse = this.vivecraft$axisToDigitalMovement(vector21.getY()); + this.forwardImpulse = this.vivecraft$axisToDigitalMovement(vector21f.y()); } } else if (dataholder.vrSettings.analogMovement) { flag1 = true; @@ -121,19 +120,33 @@ public class KeyboardInputVRMixin extends Input { this.leftImpulse -= getMovementAxisValue(this.options.keyRight); this.leftImpulse += getMovementAxisValue(this.options.keyLeft); float f2 = 0.05F; - this.forwardImpulse = Utils.applyDeadzone(this.forwardImpulse, f2); - this.leftImpulse = Utils.applyDeadzone(this.leftImpulse, f2); + float f4 = 1.0F / (1.0F - f2); + float f12 = 0.0F; + + if (Math.abs(this.forwardImpulse) > f2) { + f12 = (Math.abs(this.forwardImpulse) - f2) * f4 * Math.signum(this.forwardImpulse); + } + + this.forwardImpulse = f12; + float f3 = 1.0F / (1.0F - f2); + float f11 = 0.0F; + + if (Math.abs(this.leftImpulse) > f2) { + f11 = (Math.abs(this.leftImpulse) - f2) * f3 * Math.signum(this.leftImpulse); + } + + this.leftImpulse = f11; } } else { flag1 = true; - f = vector2.getY(); + f = vector2f.y(); if (dataholder.vrSettings.analogMovement) { - this.forwardImpulse = vector2.getY(); - this.leftImpulse = -vector2.getX(); + this.forwardImpulse = vector2f.y(); + this.leftImpulse = -vector2f.x(); } else { - this.forwardImpulse = this.vivecraft$axisToDigitalMovement(vector2.getY()); - this.leftImpulse = this.vivecraft$axisToDigitalMovement(-vector2.getX()); + this.forwardImpulse = this.vivecraft$axisToDigitalMovement(vector2f.y()); + this.leftImpulse = this.vivecraft$axisToDigitalMovement(-vector2f.x()); } } diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java index 404ee7f98..2850c70c2 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java @@ -40,6 +40,7 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.joml.Matrix4f; +import org.joml.Vector3f; import org.lwjgl.glfw.GLFW; import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Final; @@ -58,7 +59,6 @@ import org.vivecraft.client.gui.screens.UpdateScreen; import org.vivecraft.client.network.ClientNetworking; import org.vivecraft.client.utils.UpdateChecker; -import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.extensions.*; @@ -79,7 +79,7 @@ import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.client_xr.render_pass.RenderPassManager; import org.vivecraft.client_xr.render_pass.WorldRenderPass; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mod_compat_vr.optifine.OptifineHelper; import javax.annotation.Nullable; @@ -482,7 +482,11 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { } this.mainRenderTarget.unbindWrite(); - Utils.takeScreenshot(rendertarget); + Screenshot.grab(((Minecraft) (Object) this).gameDirectory, rendertarget, (text) -> + ((Minecraft) (Object) this).execute(() -> + ((Minecraft) (Object) this).gui.getChat().addMessage(text) + ) + ); this.window.updateDisplay(); ClientDataHolderVR.getInstance().grabScreenShot = false; } @@ -1002,17 +1006,15 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { Vec3 camPlayer = ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.getHeadPivot() .subtract(ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.getEye(RenderPass.THIRD).getPosition()); - Matrix4f viewMatrix = ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.getEye(RenderPass.THIRD) - .getMatrix().transposed().toMCMatrix(); - Vector3 cameraLook = ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.getEye(RenderPass.THIRD).getMatrix() - .transform(Vector3.forward()); + Matrix4f viewMatrix = ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.getEye(RenderPass.THIRD).getMatrix(new Matrix4f()).transpose(); + Vector3f cameraLook = viewMatrix.transformProject(Utils.forward, new Vector3f()); // set uniforms VRShaders._DepthMask_projectionMatrix.set(((GameRendererExtension) this.gameRenderer).vivecraft$getThirdPassProjectionMatrix()); VRShaders._DepthMask_viewMatrix.set(viewMatrix); VRShaders._DepthMask_hmdViewPosition.set((float) camPlayer.x, (float) camPlayer.y, (float) camPlayer.z); - VRShaders._DepthMask_hmdPlaneNormal.set(-cameraLook.getX(), 0.0F, -cameraLook.getZ()); + VRShaders._DepthMask_hmdPlaneNormal.set(-cameraLook.x(), 0.0F, -cameraLook.z()); boolean alphaMask = ClientDataHolderVR.getInstance().vrSettings.mixedRealityUnityLike && ClientDataHolderVR.getInstance().vrSettings.mixedRealityAlphaMask; diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java index 3fe4e515b..d2a37c4c2 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/renderer/GameRendererVRMixin.java @@ -241,9 +241,9 @@ public abstract class GameRendererVRMixin PoseStack posestack = new PoseStack(); vivecraft$setupClipPlanes(); if (vivecraft$DATA_HOLDER.currentPass == RenderPass.LEFT) { - posestack.mulPoseMatrix(vivecraft$DATA_HOLDER.vrRenderer.eyeproj[0]); + posestack.mulPoseMatrix(vivecraft$DATA_HOLDER.vrRenderer.eyeproj0); } else if (vivecraft$DATA_HOLDER.currentPass == RenderPass.RIGHT) { - posestack.mulPoseMatrix(vivecraft$DATA_HOLDER.vrRenderer.eyeproj[1]); + posestack.mulPoseMatrix(vivecraft$DATA_HOLDER.vrRenderer.eyeproj1); } else if (vivecraft$DATA_HOLDER.currentPass == RenderPass.THIRD) { if (vivecraft$DATA_HOLDER.vrSettings.displayMirrorMode == VRSettings.MirrorMode.MIXED_REALITY) { posestack.mulPoseMatrix( diff --git a/common/src/main/java/org/vivecraft/mixin/world/item/CrossbowItemMixin.java b/common/src/main/java/org/vivecraft/mixin/world/item/CrossbowItemMixin.java index b267c581c..3f6783d57 100644 --- a/common/src/main/java/org/vivecraft/mixin/world/item/CrossbowItemMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/world/item/CrossbowItemMixin.java @@ -4,10 +4,10 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.CrossbowItem; import net.minecraft.world.phys.Vec3; +import org.joml.Vector3f; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; -import org.vivecraft.common.utils.math.Vector3; import org.vivecraft.server.ServerVRPlayers; import org.vivecraft.server.ServerVivePlayer; @@ -22,7 +22,7 @@ public class CrossbowItemMixin { ServerVivePlayer serverviveplayer = ServerVRPlayers.getVivePlayer(player); if (serverviveplayer != null && serverviveplayer.isVR()) { vec3 = serverviveplayer.getControllerDir(serverviveplayer.activeHand); - serverviveplayer.getControllerVectorCustom(serverviveplayer.activeHand, new Vector3(0.0F, 1.0F, 0.0F)); + serverviveplayer.getControllerVectorCustom(serverviveplayer.activeHand, new Vector3f(0.0F, 1.0F, 0.0F)); } } return vec3; diff --git a/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java b/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java index 75bbda55b..99308d347 100644 --- a/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java +++ b/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java @@ -3,9 +3,10 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.Vec3; +import org.joml.Vector3f; import org.vivecraft.common.network.CommonNetworkHelper; import org.vivecraft.common.network.VrPlayerState; -import org.vivecraft.common.utils.math.Vector3; +import org.vivecraft.common.utils.Utils; import javax.annotation.Nullable; @@ -20,7 +21,6 @@ public class ServerVivePlayer { private boolean isVR = false; public Vec3 offset = new Vec3(0.0D, 0.0D, 0.0D); public ServerPlayer player; - final Vector3 forward = new Vector3(0.0F, 0.0F, -1.0F); public int networkVersion = CommonNetworkHelper.MAX_SUPPORTED_NETWORK_VERSION; @@ -32,7 +32,7 @@ public float getDraw() { return this.draw; } - public Vec3 getControllerVectorCustom(int controller, Vector3 direction) { + public Vec3 getControllerVectorCustom(int controller, Vector3f direction) { if (this.isSeated()) { controller = 0; } @@ -40,21 +40,21 @@ public Vec3 getControllerVectorCustom(int controller, Vector3 direction) { var controllerPose = controller == 0 ? this.vrPlayerState.controller0() : this.vrPlayerState.controller1(); if (controllerPose != null) { - Vector3 vector3 = controllerPose.orientation().multiply(direction); - return new Vec3(vector3.getX(), vector3.getY(), vector3.getZ()); + Vector3f vector3 = controllerPose.orientation().transformUnit(direction, new Vector3f()); + return Utils.convertToVec3(vector3); } else { return this.player.getLookAngle(); } } public Vec3 getControllerDir(int controller) { - return this.getControllerVectorCustom(controller, this.forward); + return this.getControllerVectorCustom(controller, new Vector3f(Utils.forward)); } public Vec3 getHMDDir() { if (this.vrPlayerState != null) { - Vector3 vector3 = this.vrPlayerState.hmd().orientation().multiply(this.forward); - return new Vec3(vector3.getX(), vector3.getY(), vector3.getZ()); + Vector3f vector3 = this.vrPlayerState.hmd().orientation().transformUnit(Utils.forward, new Vector3f()); + return new Vec3(vector3.x(), vector3.y(), vector3.z()); } return this.player.getLookAngle(); }