Skip to content

Commit

Permalink
VRPose and VRBodyPart Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 committed Jan 13, 2025
1 parent 86c0fa6 commit dea1552
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 246 deletions.
12 changes: 6 additions & 6 deletions common/src/main/java/org/vivecraft/api/VivecraftAPI.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion common/src/main/java/org/vivecraft/api/client/Tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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());
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<VRPose> getAllHistoricalData() throws IllegalArgumentException;
List<VRBodyPart> 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
Expand Down
41 changes: 41 additions & 0 deletions common/src/main/java/org/vivecraft/api/data/VRBodyPart.java
Original file line number Diff line number Diff line change
@@ -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();
}
62 changes: 0 additions & 62 deletions common/src/main/java/org/vivecraft/api/data/VRData.java

This file was deleted.

53 changes: 36 additions & 17 deletions common/src/main/java/org/vivecraft/api/data/VRPose.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit dea1552

Please sign in to comment.