diff --git a/common/src/main/java/org/vivecraft/api/VivecraftAPI.java b/common/src/main/java/org/vivecraft/api/VivecraftAPI.java index dfdac485e..eafa86d21 100644 --- a/common/src/main/java/org/vivecraft/api/VivecraftAPI.java +++ b/common/src/main/java/org/vivecraft/api/VivecraftAPI.java @@ -1,7 +1,7 @@ package org.vivecraft.api; import net.minecraft.world.entity.player.Player; -import org.vivecraft.api.data.VRData; +import org.vivecraft.api.data.VRPose; import org.vivecraft.common.api_impl.VivecraftAPIImpl; import javax.annotation.Nullable; @@ -24,12 +24,12 @@ static VivecraftAPI getInstance() { boolean isVRPlayer(Player player); /** - * Returns the VR data for the given player. Will return null if the player isn't in VR, - * or if being called from the client, and the client has yet to receive any data for the player. + * Returns the VR pose for the given player. Will return null if the player isn't in VR, + * or if being called from the client and the client has yet to receive any data for the player. * - * @param player Player to get the VR data of. - * @return The VR data for a player, or null if the player isn't in VR or no data has been received for said player. + * @param player Player to get the VR pose of. + * @return The VR pose for a player, or null if the player isn't in VR or no data has been received for said player. */ @Nullable - VRData getVRData(Player player); + VRPose getVRPose(Player player); } diff --git a/common/src/main/java/org/vivecraft/api/client/Tracker.java b/common/src/main/java/org/vivecraft/api/client/Tracker.java index eb54d2efe..008f06dbb 100644 --- a/common/src/main/java/org/vivecraft/api/client/Tracker.java +++ b/common/src/main/java/org/vivecraft/api/client/Tracker.java @@ -8,7 +8,7 @@ * they are in VR. Using trackers are one of the cleanest ways to interact with Vivecraft's data; it's how Vivecraft * itself does. Trackers should generally use {@link VivecraftClientAPI#getPreTickWorldData()}, as this provides * the most up-to-date data, and other methods such as {@link VivecraftClientAPI#getPostTickWorldData()} or - * {@link org.vivecraft.api.VivecraftAPI#getVRData(Player)} may not have data available when the tracker is run. + * {@link org.vivecraft.api.VivecraftAPI#getVRPose(Player)} may not have data available when the tracker is run. */ public interface Tracker { diff --git a/common/src/main/java/org/vivecraft/api/client/VivecraftClientAPI.java b/common/src/main/java/org/vivecraft/api/client/VivecraftClientAPI.java index 76f1536fa..5d4521e5a 100644 --- a/common/src/main/java/org/vivecraft/api/client/VivecraftClientAPI.java +++ b/common/src/main/java/org/vivecraft/api/client/VivecraftClientAPI.java @@ -2,8 +2,8 @@ import com.google.common.annotations.Beta; import net.minecraft.world.InteractionHand; -import org.vivecraft.api.client.data.VRPoseHistory; -import org.vivecraft.api.data.VRData; +import org.vivecraft.api.client.data.VRBodyPartHistory; +import org.vivecraft.api.data.VRPose; import org.vivecraft.client.api_impl.VivecraftClientAPIImpl; import org.vivecraft.client_vr.render.RenderPass; @@ -30,7 +30,7 @@ static VivecraftClientAPI getInstance() { * @return Data representing the devices in the room pre-tick, or null if the local player isn't in VR. */ @Nullable - VRData getPreTickRoomData(); + VRPose getPreTickRoomData(); /** * Gets data representing the devices as they exist in the room after the game tick. @@ -39,19 +39,19 @@ static VivecraftClientAPI getInstance() { * @return Data representing the devices in the room post-tick, or null if the local player isn't in VR. */ @Nullable - VRData getPostTickRoomData(); + VRPose getPostTickRoomData(); /** * Gets data representing the devices as they exist in Minecraft coordinates before the game tick. * This is the same as {@link #getPreTickRoomData()} with translation to Minecraft's coordinates as of the last - * tick, and is the main data source used by Vivecraft. If you're unsure which {@link VRData} method to use, you + * tick, and is the main data source used by Vivecraft. If you're unsure which {@link VRPose} method to use, you * likely want to use this one. * Note that this data is gathered BEFORE mod loaders' pre-tick events. * * @return Data representing the devices in Minecraft space pre-tick, or null if the local player isn't in VR. */ @Nullable - VRData getPreTickWorldData(); + VRPose getPreTickWorldData(); /** * Gets data representing the devices as they exist in Minecraft coordinates after the game tick. @@ -61,7 +61,7 @@ static VivecraftClientAPI getInstance() { * @return Data representing the devices in Minecraft space post-tick, or null if the local player isn't in VR. */ @Nullable - VRData getPostTickWorldData(); + VRPose getPostTickWorldData(); /** * Gets data representing the devices as they exist in Minecraft coordinates after the game tick interpolated for @@ -72,7 +72,7 @@ static VivecraftClientAPI getInstance() { * local player isn't in VR. */ @Nullable - VRData getWorldRenderData(); + VRPose getWorldRenderData(); /** * Causes a haptic pulse (vibration/rumble) for the specified controller. @@ -137,7 +137,7 @@ default void triggerHapticPulse(int controllerNum, float duration) { * @return The historical VR data for the player's HMD, or null if the player isn't in VR. */ @Nullable - VRPoseHistory getHistoricalVRHMDPoses(); + VRBodyPartHistory getHistoricalVRHMDPoses(); /** * Returns the history of VR poses for the player for a controller. Will return null if the player isn't @@ -147,7 +147,7 @@ default void triggerHapticPulse(int controllerNum, float duration) { * @return The historical VR data for the player's controller, or null if the player isn't in VR. */ @Nullable - VRPoseHistory getHistoricalVRControllerPoses(int controller); + VRBodyPartHistory getHistoricalVRControllerPoses(int controller); /** * Returns the history of VR poses for the player for a controller. Will return null if the player isn't @@ -157,7 +157,7 @@ default void triggerHapticPulse(int controllerNum, float duration) { * @return The historical VR data for the player's controller, or null if the player isn't in VR. */ @Nullable - default VRPoseHistory getHistoricalVRControllerPoses(InteractionHand hand) { + default VRBodyPartHistory getHistoricalVRControllerPoses(InteractionHand hand) { return getHistoricalVRControllerPoses(hand.ordinal()); } @@ -168,7 +168,7 @@ default VRPoseHistory getHistoricalVRControllerPoses(InteractionHand hand) { * @return The historical VR data for the player's primary controller, or null if the player isn't in VR. */ @Nullable - default VRPoseHistory getHistoricalVRController0Poses() { + default VRBodyPartHistory getHistoricalVRController0Poses() { return getHistoricalVRControllerPoses(0); } @@ -179,7 +179,7 @@ default VRPoseHistory getHistoricalVRController0Poses() { * @return The historical VR data for the player's secondary controller, or null if the player isn't in VR. */ @Nullable - default VRPoseHistory getHistoricalVRController1Poses() { + default VRBodyPartHistory getHistoricalVRController1Poses() { return getHistoricalVRControllerPoses(1); } diff --git a/common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java b/common/src/main/java/org/vivecraft/api/client/data/VRBodyPartHistory.java similarity index 86% rename from common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java rename to common/src/main/java/org/vivecraft/api/client/data/VRBodyPartHistory.java index b0a50549c..60d681693 100644 --- a/common/src/main/java/org/vivecraft/api/client/data/VRPoseHistory.java +++ b/common/src/main/java/org/vivecraft/api/client/data/VRBodyPartHistory.java @@ -1,14 +1,14 @@ package org.vivecraft.api.client.data; import net.minecraft.world.phys.Vec3; -import org.vivecraft.api.data.VRPose; +import org.vivecraft.api.data.VRBodyPart; import java.util.List; /** - * Represents historical VRData associated with a player. + * Represents historical {@link VRBodyPart}s associated with a player. */ -public interface VRPoseHistory { +public interface VRBodyPartHistory { /** * The maximum amount of ticks back data is held for. @@ -22,27 +22,27 @@ public interface VRPoseHistory { /** * @return The amount of ticks worth of history being held. The number returned by this methodwill never be higher - * than {@link VRPoseHistory#MAX_TICKS_BACK}, however can be lower than it. + * than {@link VRBodyPartHistory#MAX_TICKS_BACK}, however can be lower than it. */ int ticksOfHistory(); /** - * Gets a raw list of {@link VRPose} instances, with index 0 representing the least recent pose known. + * Gets a raw list of {@link VRBodyPart} instances, with index 0 representing the least recent pose known. * - * @return The aforementioned list of {@link VRPose} instances. + * @return The aforementioned list of {@link VRBodyPart} instances. */ - List getAllHistoricalData() throws IllegalArgumentException; + List getAllHistoricalData() throws IllegalArgumentException; /** * Gets the historical data ticksBack ticks back. This will throw an IllegalStateException if the data cannot * be retrieved due to not having enough history. * * @param ticksBack Ticks back to retrieve data. - * @return A {@link VRPose} instance from index ticks ago. + * @return A {@link VRBodyPart} instance from index ticks ago. * @throws IllegalStateException If ticksBack references a tick that there is not yet data for. * @throws IllegalArgumentException Thrown when maxTicksBack is larger than {@value #MAX_TICKS_BACK} or less than 0. */ - VRPose getHistoricalData(int ticksBack) throws IllegalArgumentException, IllegalStateException; + VRBodyPart getHistoricalData(int ticksBack) throws IllegalArgumentException, IllegalStateException; /** * Gets the net movement between the most recent data in this instance and the oldest position that can be diff --git a/common/src/main/java/org/vivecraft/api/data/VRBodyPart.java b/common/src/main/java/org/vivecraft/api/data/VRBodyPart.java new file mode 100644 index 000000000..ee71a2ee3 --- /dev/null +++ b/common/src/main/java/org/vivecraft/api/data/VRBodyPart.java @@ -0,0 +1,41 @@ +package org.vivecraft.api.data; + +import net.minecraft.world.phys.Vec3; +import org.joml.Quaternionfc; + +/** + * Represents the data for a body part, or a device usually tied to a body part in VR, such as the HMD or a + * controller. + */ +public interface VRBodyPart { + + /** + * @return The position of the body part in Minecraft world coordinates. + */ + Vec3 getPos(); + + /** + * @return The rotation of the body part. + */ + Vec3 getRot(); + + /** + * @return The pitch of the body part in radians. + */ + double getPitch(); + + /** + * @return The yaw of the body part in radians. + */ + double getYaw(); + + /** + * @return The roll of the body part in radians. + */ + double getRoll(); + + /** + * @return The quaternion representing the rotation of the body part. + */ + Quaternionfc getQuaternion(); +} diff --git a/common/src/main/java/org/vivecraft/api/data/VRData.java b/common/src/main/java/org/vivecraft/api/data/VRData.java deleted file mode 100644 index 70770c627..000000000 --- a/common/src/main/java/org/vivecraft/api/data/VRData.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.vivecraft.api.data; - -import net.minecraft.world.InteractionHand; - -/** - * Represents all VR data associated with a given player, mainly the pose of the HMD and both controllers - * of the player. If the player is in seated mode, controller 1 carries the HMD's data, and controller 0 is - * based on the direction being looked at via the mouse pointer. - */ -public interface VRData { - - /** - * @return Pose data for the HMD. - */ - VRPose getHMD(); - - /** - * Gets the pose data for a given controller. - * - * @param controller The controller number to get, with 0 being the primary controller. - * @return The specified controller's pose data. - */ - VRPose getController(int controller); - - /** - * @return Whether the player is currently in seated mode. - */ - boolean isSeated(); - - /** - * @return Whether the player is playing with left-handed controls. - */ - boolean isLeftHanded(); - - /** - * Gets the pose for a given controller. - * - * @param hand The interaction hand to get controller data for. - * @return The specified controller's pose data. - */ - default VRPose getController(InteractionHand hand) { - return getController(hand.ordinal()); - } - - /** - * Gets the pose for the primary controller. - * - * @return The main controller's pose data. - */ - default VRPose getController0() { - return getController(0); - } - - /** - * Gets the pose for the secondary controller. - * - * @return The main controller's pose data. - */ - default VRPose getController1() { - return getController(1); - } -} diff --git a/common/src/main/java/org/vivecraft/api/data/VRPose.java b/common/src/main/java/org/vivecraft/api/data/VRPose.java index 176827aaa..5b0f21ae7 100644 --- a/common/src/main/java/org/vivecraft/api/data/VRPose.java +++ b/common/src/main/java/org/vivecraft/api/data/VRPose.java @@ -1,42 +1,61 @@ package org.vivecraft.api.data; -import net.minecraft.world.phys.Vec3; -import org.joml.Quaternionf; -import org.joml.Quaternionfc; +import net.minecraft.world.InteractionHand; /** - * Represents the pose data, such as position and rotation, for a given trackable object, such as the HMD or - * a controller. + * Represents the pose of the VR player. In other words, the position and rotation data of all tracked body parts of + * the VR player. */ public interface VRPose { /** - * @return The position of the device in Minecraft world coordinates. + * @return Pose data for the HMD. */ - Vec3 getPos(); + VRBodyPart getHMD(); /** - * @return The rotation of the device. + * Gets the pose data for a given controller. + * + * @param controller The controller number to get, with 0 being the primary controller. + * @return The specified controller's pose data. */ - Vec3 getRot(); + VRBodyPart getController(int controller); /** - * @return The pitch of the device in radians. + * @return Whether the player is currently in seated mode. */ - double getPitch(); + boolean isSeated(); /** - * @return The yaw of the device in radians. + * @return Whether the player is playing with left-handed controls. */ - double getYaw(); + boolean isLeftHanded(); /** - * @return The roll of the device in radians. + * Gets the pose for a given controller. + * + * @param hand The interaction hand to get controller data for. + * @return The specified controller's pose data. */ - double getRoll(); + default VRBodyPart getController(InteractionHand hand) { + return getController(hand.ordinal()); + } /** - * @return The quaternion representing the rotation of the device. + * Gets the pose for the primary controller. + * + * @return The main controller's pose data. */ - Quaternionfc getQuaternion(); + default VRBodyPart getController0() { + return getController(0); + } + + /** + * Gets the pose for the secondary controller. + * + * @return The main controller's pose data. + */ + default VRBodyPart getController1() { + return getController(1); + } } diff --git a/common/src/main/java/org/vivecraft/client/ClientVRPlayers.java b/common/src/main/java/org/vivecraft/client/ClientVRPlayers.java index 0d2952897..2e8247aa3 100644 --- a/common/src/main/java/org/vivecraft/client/ClientVRPlayers.java +++ b/common/src/main/java/org/vivecraft/client/ClientVRPlayers.java @@ -13,6 +13,7 @@ import org.joml.Quaternionfc; import org.joml.Vector3f; import org.joml.Vector3fc; +import org.vivecraft.api.data.VRPose; import org.vivecraft.client.extensions.SparkParticleExtension; import org.vivecraft.client.utils.ClientUtils; import org.vivecraft.client.utils.ModelUtils; @@ -24,8 +25,8 @@ import org.vivecraft.client_vr.render.helpers.RenderHelper; import org.vivecraft.client_vr.settings.AutoCalibration; import org.vivecraft.client_vr.settings.VRSettings; -import org.vivecraft.common.api_impl.data.VRDataImpl; import org.vivecraft.common.api_impl.data.VRPoseImpl; +import org.vivecraft.common.api_impl.data.VRBodyPartImpl; import org.vivecraft.common.network.FBTMode; import org.vivecraft.common.network.VrPlayerState; import org.vivecraft.common.utils.MathUtils; @@ -534,11 +535,11 @@ public float getBodyYawRad() { return (float) Math.atan2(-dir.x, dir.z); } - public org.vivecraft.api.data.VRData asVRData() { - return new VRDataImpl( - new VRPoseImpl(fromVector3fc(this.headPos), fromVector3fc(this.headRot), this.headQuat), - new VRPoseImpl(fromVector3fc(this.mainHandPos), fromVector3fc(this.mainHandRot), this.mainHandQuat), - new VRPoseImpl(fromVector3fc(this.offHandPos), fromVector3fc(this.offHandPos), this.offHandQuat), + public VRPose asVRPose() { + return new VRPoseImpl( + new VRBodyPartImpl(fromVector3fc(this.headPos), fromVector3fc(this.headRot), this.headQuat), + new VRBodyPartImpl(fromVector3fc(this.mainHandPos), fromVector3fc(this.mainHandRot), this.mainHandQuat), + new VRBodyPartImpl(fromVector3fc(this.offHandPos), fromVector3fc(this.offHandPos), this.offHandQuat), this.seated, this.leftHanded ); diff --git a/common/src/main/java/org/vivecraft/client/api_impl/VivecraftClientAPIImpl.java b/common/src/main/java/org/vivecraft/client/api_impl/VivecraftClientAPIImpl.java index 55ec77497..dc1a82fa2 100644 --- a/common/src/main/java/org/vivecraft/client/api_impl/VivecraftClientAPIImpl.java +++ b/common/src/main/java/org/vivecraft/client/api_impl/VivecraftClientAPIImpl.java @@ -2,10 +2,10 @@ import org.jetbrains.annotations.Nullable; import org.vivecraft.api.client.Tracker; -import org.vivecraft.api.client.data.VRPoseHistory; +import org.vivecraft.api.client.data.VRBodyPartHistory; import org.vivecraft.api.client.VivecraftClientAPI; -import org.vivecraft.api.data.VRData; -import org.vivecraft.client.api_impl.data.VRPoseHistoryImpl; +import org.vivecraft.api.data.VRPose; +import org.vivecraft.client.api_impl.data.VRBodyPartHistoryImpl; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.gameplay.screenhandlers.KeyboardHandler; @@ -17,9 +17,9 @@ public final class VivecraftClientAPIImpl implements VivecraftClientAPI { public static final VivecraftClientAPIImpl INSTANCE = new VivecraftClientAPIImpl(); - private final VRPoseHistoryImpl hmdHistory = new VRPoseHistoryImpl(); - private VRPoseHistoryImpl c0History = new VRPoseHistoryImpl(); - private VRPoseHistoryImpl c1History = new VRPoseHistoryImpl(); + private final VRBodyPartHistoryImpl hmdHistory = new VRBodyPartHistoryImpl(); + private VRBodyPartHistoryImpl c0History = new VRBodyPartHistoryImpl(); + private VRBodyPartHistoryImpl c1History = new VRBodyPartHistoryImpl(); private VivecraftClientAPIImpl() { } @@ -30,7 +30,7 @@ public void clearHistories() { this.c1History.clear(); } - public void addPosesToHistory(VRData data) { + public void addPosesToHistory(VRPose data) { this.hmdHistory.addPose(data.getHMD()); this.c0History.addPose(data.getController0()); this.c1History.addPose(data.getController1()); @@ -38,47 +38,47 @@ public void addPosesToHistory(VRData data) { @Nullable @Override - public VRData getPreTickRoomData() { + public VRPose getPreTickRoomData() { if (!isVrActive()) { return null; } - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.asVRData(); + return ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_pre.asVRPose(); } @Nullable @Override - public VRData getPostTickRoomData() { + public VRPose getPostTickRoomData() { if (!isVrActive()) { return null; } - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_post.asVRData(); + return ClientDataHolderVR.getInstance().vrPlayer.vrdata_room_post.asVRPose(); } @Nullable @Override - public VRData getPreTickWorldData() { + public VRPose getPreTickWorldData() { if (!isVrActive()) { return null; } - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_pre.asVRData(); + return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_pre.asVRPose(); } @Nullable @Override - public VRData getPostTickWorldData() { + public VRPose getPostTickWorldData() { if (!isVrActive()) { return null; } - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_post.asVRData(); + return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_post.asVRPose(); } @Nullable @Override - public VRData getWorldRenderData() { + public VRPose getWorldRenderData() { if (!isVrActive()) { return null; } - return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.asVRData(); + return ClientDataHolderVR.getInstance().vrPlayer.vrdata_world_render.asVRPose(); } @Override @@ -136,7 +136,7 @@ public void registerTracker(Tracker tracker) { @Nullable @Override - public VRPoseHistory getHistoricalVRHMDPoses() { + public VRBodyPartHistory getHistoricalVRHMDPoses() { if (!isVrActive()) { return null; } @@ -145,7 +145,7 @@ public VRPoseHistory getHistoricalVRHMDPoses() { @Nullable @Override - public VRPoseHistory getHistoricalVRControllerPoses(int controller) { + public VRBodyPartHistory getHistoricalVRControllerPoses(int controller) { if (controller != 0 && controller != 1) { throw new IllegalArgumentException("Historical VR controller data only available for controllers 0 and 1."); } else if (!isVrActive()) { diff --git a/common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java b/common/src/main/java/org/vivecraft/client/api_impl/data/VRBodyPartHistoryImpl.java similarity index 75% rename from common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java rename to common/src/main/java/org/vivecraft/client/api_impl/data/VRBodyPartHistoryImpl.java index 3058a06cd..79f722e62 100644 --- a/common/src/main/java/org/vivecraft/client/api_impl/data/VRPoseHistoryImpl.java +++ b/common/src/main/java/org/vivecraft/client/api_impl/data/VRBodyPartHistoryImpl.java @@ -1,21 +1,21 @@ package org.vivecraft.client.api_impl.data; import net.minecraft.world.phys.Vec3; -import org.vivecraft.api.client.data.VRPoseHistory; -import org.vivecraft.api.data.VRPose; +import org.vivecraft.api.client.data.VRBodyPartHistory; +import org.vivecraft.api.data.VRBodyPart; import java.util.*; -public class VRPoseHistoryImpl implements VRPoseHistory { +public class VRBodyPartHistoryImpl implements VRBodyPartHistory { - private final LinkedList dataQueue = new LinkedList<>(); + private final LinkedList dataQueue = new LinkedList<>(); - public VRPoseHistoryImpl() { + public VRBodyPartHistoryImpl() { } - public void addPose(VRPose pose) { + public void addPose(VRBodyPart pose) { this.dataQueue.addFirst(pose); - if (this.dataQueue.size() > VRPoseHistory.MAX_TICKS_BACK) { + if (this.dataQueue.size() > VRBodyPartHistory.MAX_TICKS_BACK) { this.dataQueue.removeLast(); } } @@ -30,12 +30,12 @@ public int ticksOfHistory() { } @Override - public List getAllHistoricalData() { + public List getAllHistoricalData() { return new ArrayList<>(this.dataQueue); } @Override - public VRPose getHistoricalData(int ticksBack) throws IllegalArgumentException, IllegalStateException { + public VRBodyPart getHistoricalData(int ticksBack) throws IllegalArgumentException, IllegalStateException { checkTicksBack(ticksBack); if (this.dataQueue.size() <= ticksBack) { throw new IllegalStateException("Cannot retrieve data from " + ticksBack + " ticks ago, when there is " + @@ -64,7 +64,7 @@ public Vec3 averageVelocity(int maxTicksBack) throws IllegalArgumentException { public Vec3 averagePosition(int maxTicksBack) throws IllegalArgumentException { checkTicksBack(maxTicksBack); int iters = getNumTicksBack(maxTicksBack); - ListIterator iterator = this.dataQueue.listIterator(this.dataQueue.size() - 1); + ListIterator iterator = this.dataQueue.listIterator(this.dataQueue.size() - 1); Vec3 avg = this.dataQueue.getLast().getPos(); int i = iters; while (i > 0) { @@ -75,12 +75,12 @@ public Vec3 averagePosition(int maxTicksBack) throws IllegalArgumentException { } private void checkTicksBack(int ticksBack) { - if (ticksBack < 0 || ticksBack > VRPoseHistory.MAX_TICKS_BACK) { - throw new IllegalArgumentException("Value must be between 0 and " + VRPoseHistory.MAX_TICKS_BACK + "."); + if (ticksBack < 0 || ticksBack > VRBodyPartHistory.MAX_TICKS_BACK) { + throw new IllegalArgumentException("Value must be between 0 and " + VRBodyPartHistory.MAX_TICKS_BACK + "."); } } - private VRPose getOldPose(int maxTicksBack) { + private VRBodyPart getOldPose(int maxTicksBack) { if (this.dataQueue.size() <= maxTicksBack) { return this.dataQueue.getFirst(); } else { 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 2a7950d24..5e07f0547 100644 --- a/common/src/main/java/org/vivecraft/client_vr/VRData.java +++ b/common/src/main/java/org/vivecraft/client_vr/VRData.java @@ -4,6 +4,7 @@ import net.minecraft.util.Mth; import net.minecraft.world.phys.Vec3; import org.joml.*; +import org.vivecraft.api.data.VRPose; import org.vivecraft.client.ClientVRPlayers; import org.vivecraft.client.gui.screens.FBTCalibrationScreen; import org.vivecraft.client_vr.provider.MCVR; @@ -15,9 +16,9 @@ import javax.annotation.Nullable; import java.lang.Math; import org.joml.Quaternionf; -import org.vivecraft.api.data.VRPose; -import org.vivecraft.common.api_impl.data.VRDataImpl; +import org.vivecraft.api.data.VRBodyPart; import org.vivecraft.common.api_impl.data.VRPoseImpl; +import org.vivecraft.common.api_impl.data.VRBodyPartImpl; public class VRData { // headset center @@ -365,11 +366,11 @@ public VRDevicePose getEye(RenderPass pass) { /** * @return this data in a manner better-suited for the API */ - public org.vivecraft.api.data.VRData asVRData() { - return new VRDataImpl( - this.hmd.asVRPose(), - this.c0.asVRPose(), - this.c1.asVRPose(), + public VRPose asVRPose() { + return new VRPoseImpl( + this.hmd.asVRBodyPart(), + this.c0.asVRBodyPart(), + this.c1.asVRBodyPart(), ClientDataHolderVR.getInstance().vrSettings.seated, ClientDataHolderVR.getInstance().vrSettings.reverseHands ); @@ -519,10 +520,10 @@ public Matrix4f getMatrix() { return new Matrix4f().rotationY(VRData.this.rotation_radians).mul(this.matrix); } - public VRPose asVRPose() { + public VRBodyPart asVRBodyPart() { Quaternionf quat = new Quaternionf(); quat.setFromUnnormalized(getMatrix()); - return new VRPoseImpl( + return new VRBodyPartImpl( getPosition(), new Vec3(getDirection()), quat 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 80b97de78..f8e58c31f 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 @@ -237,7 +237,7 @@ public void preTick() { this.dh.vrSettings.worldRotation = this.dh.vr.seatedRot; } - VivecraftClientAPIImpl.INSTANCE.addPosesToHistory(this.vrdata_world_pre.asVRData()); + VivecraftClientAPIImpl.INSTANCE.addPosesToHistory(this.vrdata_world_pre.asVRPose()); } public void postTick() { diff --git a/common/src/main/java/org/vivecraft/common/api_impl/VivecraftAPIImpl.java b/common/src/main/java/org/vivecraft/common/api_impl/VivecraftAPIImpl.java index 824780ab1..e23614bb5 100644 --- a/common/src/main/java/org/vivecraft/common/api_impl/VivecraftAPIImpl.java +++ b/common/src/main/java/org/vivecraft/common/api_impl/VivecraftAPIImpl.java @@ -5,7 +5,7 @@ import org.vivecraft.api.VivecraftAPI; import org.vivecraft.client.ClientVRPlayers; import org.jetbrains.annotations.Nullable; -import org.vivecraft.api.data.VRData; +import org.vivecraft.api.data.VRPose; import org.vivecraft.server.ServerVRPlayers; public final class VivecraftAPIImpl implements VivecraftAPI { @@ -26,14 +26,14 @@ public boolean isVRPlayer(Player player) { @Nullable @Override - public VRData getVRData(Player player) { + public VRPose getVRPose(Player player) { if (!isVRPlayer(player)) { return null; } if (player instanceof ServerPlayer serverPlayer) { - return ServerVRPlayers.getVivePlayer(serverPlayer).asVRData(); + return ServerVRPlayers.getVivePlayer(serverPlayer).asVRPose(); } - return ClientVRPlayers.getInstance().getRotationsForPlayer(player.getUUID()).asVRData(); + return ClientVRPlayers.getInstance().getRotationsForPlayer(player.getUUID()).asVRPose(); } } diff --git a/common/src/main/java/org/vivecraft/common/api_impl/data/VRBodyPartImpl.java b/common/src/main/java/org/vivecraft/common/api_impl/data/VRBodyPartImpl.java new file mode 100644 index 000000000..fcdda5760 --- /dev/null +++ b/common/src/main/java/org/vivecraft/common/api_impl/data/VRBodyPartImpl.java @@ -0,0 +1,54 @@ +package org.vivecraft.common.api_impl.data; + +import net.minecraft.world.phys.Vec3; +import org.joml.Quaternionfc; +import org.vivecraft.api.data.VRBodyPart; + +public class VRBodyPartImpl implements VRBodyPart { + + private final Vec3 pos; + private final Vec3 rot; + private final Quaternionfc quaternion; + + public VRBodyPartImpl(Vec3 pos, Vec3 rot, Quaternionfc quaternion) { + this.pos = pos; + this.rot = rot; + this.quaternion = quaternion; + } + + @Override + public Vec3 getPos() { + return this.pos; + } + + @Override + public Vec3 getRot() { + return this.rot; + } + + @Override + public double getPitch() { + return Math.asin(this.rot.y / this.rot.length()); + } + + @Override + public double getYaw() { + return Math.atan2(-this.rot.x, this.rot.z); + } + + @Override + public double getRoll() { + return -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()); + } + + @Override + public Quaternionfc getQuaternion() { + return this.quaternion; + } + + @Override + public String toString() { + return "Position: " + getPos() + "\tRotation: " + getRot(); + } +} diff --git a/common/src/main/java/org/vivecraft/common/api_impl/data/VRDataImpl.java b/common/src/main/java/org/vivecraft/common/api_impl/data/VRDataImpl.java deleted file mode 100644 index fc248c49f..000000000 --- a/common/src/main/java/org/vivecraft/common/api_impl/data/VRDataImpl.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.vivecraft.common.api_impl.data; - -import org.vivecraft.api.data.VRData; -import org.vivecraft.api.data.VRPose; - -public class VRDataImpl implements VRData { - - private final VRPose hmd; - private final VRPose c0; - private final VRPose c1; - private final boolean isSeated; - private final boolean isLeftHanded; - - public VRDataImpl(VRPose hmd, VRPose c0, VRPose c1, boolean isSeated, boolean isLeftHanded) { - this.hmd = hmd; - this.c0 = c0; - this.c1 = c1; - this.isSeated = isSeated; - this.isLeftHanded = isLeftHanded; - } - - @Override - public VRPose getHMD() { - return this.hmd; - } - - @Override - public VRPose getController(int controller) { - if (controller != 0 && controller != 1) { - throw new IllegalArgumentException("Controller number must be controller 0 or controller 1."); - } - return controller == 0 ? this.c0 : this.c1; - } - - @Override - public boolean isSeated() { - return this.isSeated; - } - - @Override - public boolean isLeftHanded() { - return this.isLeftHanded; - } - - @Override - public String toString() { - return "HMD: " + getHMD() + "\nController 0: " + getController0() + "\nController 1: " + getController1(); - } -} diff --git a/common/src/main/java/org/vivecraft/common/api_impl/data/VRPoseImpl.java b/common/src/main/java/org/vivecraft/common/api_impl/data/VRPoseImpl.java index db371a765..71b402461 100644 --- a/common/src/main/java/org/vivecraft/common/api_impl/data/VRPoseImpl.java +++ b/common/src/main/java/org/vivecraft/common/api_impl/data/VRPoseImpl.java @@ -1,55 +1,49 @@ package org.vivecraft.common.api_impl.data; -import net.minecraft.world.phys.Vec3; -import org.joml.Quaternionf; -import org.joml.Quaternionfc; import org.vivecraft.api.data.VRPose; +import org.vivecraft.api.data.VRBodyPart; public class VRPoseImpl implements VRPose { - private final Vec3 pos; - private final Vec3 rot; - private final Quaternionfc quaternion; + private final VRBodyPart hmd; + private final VRBodyPart c0; + private final VRBodyPart c1; + private final boolean isSeated; + private final boolean isLeftHanded; - public VRPoseImpl(Vec3 pos, Vec3 rot, Quaternionfc quaternion) { - this.pos = pos; - this.rot = rot; - this.quaternion = quaternion; + public VRPoseImpl(VRBodyPart hmd, VRBodyPart c0, VRBodyPart c1, boolean isSeated, boolean isLeftHanded) { + this.hmd = hmd; + this.c0 = c0; + this.c1 = c1; + this.isSeated = isSeated; + this.isLeftHanded = isLeftHanded; } @Override - public Vec3 getPos() { - return this.pos; + public VRBodyPart getHMD() { + return this.hmd; } @Override - public Vec3 getRot() { - return this.rot; + public VRBodyPart getController(int controller) { + if (controller != 0 && controller != 1) { + throw new IllegalArgumentException("Controller number must be controller 0 or controller 1."); + } + return controller == 0 ? this.c0 : this.c1; } @Override - public double getPitch() { - return Math.asin(this.rot.y / this.rot.length()); + public boolean isSeated() { + return this.isSeated; } @Override - public double getYaw() { - return Math.atan2(-this.rot.x, this.rot.z); - } - - @Override - public double getRoll() { - return -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()); - } - - @Override - public Quaternionfc getQuaternion() { - return this.quaternion; + public boolean isLeftHanded() { + return this.isLeftHanded; } @Override public String toString() { - return "Position: " + getPos() + "\tRotation: " + getRot(); + return "HMD: " + getHMD() + "\nController 0: " + getController0() + "\nController 1: " + getController1(); } } diff --git a/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java b/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java index c7d812a21..c957c226b 100644 --- a/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java +++ b/common/src/main/java/org/vivecraft/server/ServerVivePlayer.java @@ -8,9 +8,9 @@ import org.joml.Vector3fc; import org.vivecraft.common.network.*; import org.vivecraft.common.utils.MathUtils; -import org.vivecraft.api.data.VRData; -import org.vivecraft.common.api_impl.data.VRDataImpl; +import org.vivecraft.api.data.VRPose; import org.vivecraft.common.api_impl.data.VRPoseImpl; +import org.vivecraft.common.api_impl.data.VRBodyPartImpl; import org.vivecraft.common.network.CommonNetworkHelper; import org.vivecraft.common.network.Pose; import org.vivecraft.common.network.VrPlayerState; @@ -190,14 +190,14 @@ public boolean usingReversedHands() { return this.vrPlayerState.leftHanded(); } - public VRData asVRData() { + public VRPose asVRPose() { if (this.vrPlayerState == null) { return null; } - return new VRDataImpl( - new VRPoseImpl(this.getHMDPos(), this.getHMDDir(), this.vrPlayerState.hmd().orientation()), - new VRPoseImpl(getPos(this.vrPlayerState.mainHand()), getDir(this.vrPlayerState.mainHand()), this.vrPlayerState.mainHand().orientation()), - new VRPoseImpl(getPos(this.vrPlayerState.offHand()), getDir(this.vrPlayerState.offHand()), this.vrPlayerState.mainHand().orientation()), + return new VRPoseImpl( + new VRBodyPartImpl(this.getHMDPos(), this.getHMDDir(), this.vrPlayerState.hmd().orientation()), + new VRBodyPartImpl(getPos(this.vrPlayerState.mainHand()), getDir(this.vrPlayerState.mainHand()), this.vrPlayerState.mainHand().orientation()), + new VRBodyPartImpl(getPos(this.vrPlayerState.offHand()), getDir(this.vrPlayerState.offHand()), this.vrPlayerState.mainHand().orientation()), this.isSeated(), this.usingReversedHands() );