Skip to content

Commit

Permalink
Use split offsets and rename foot_offset to foot_shift (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erimelowo committed Jun 28, 2022
1 parent ceb1cc7 commit 7c37fdb
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 113 deletions.
2 changes: 1 addition & 1 deletion slime-java-commons
2 changes: 1 addition & 1 deletion src/main/java/dev/slimevr/autobone/AutoBone.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void reloadConfigValues(List<PoseFrameTracker> trackers) {

// Keep "feet" at ankles
staticConfigs.put(SkeletonConfigValue.FOOT_LENGTH, 0f);
staticConfigs.put(SkeletonConfigValue.FOOT_OFFSET, 0f);
staticConfigs.put(SkeletonConfigValue.FOOT_SHIFT, 0f);
staticConfigs.put(SkeletonConfigValue.SKELETON_OFFSET, 0f);
}

Expand Down
27 changes: 1 addition & 26 deletions src/main/java/dev/slimevr/vr/processor/skeleton/BoneType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@


/**
* Keys for all bones in the skeleton. TODO: Some bones are deprecated because
* they are still used as SkeletonNodeOffset, and represent both left and right
* offsets, but they should be split into two.
* Keys for all bones in the skeleton.
*/
public enum BoneType {

Expand All @@ -20,52 +18,29 @@ public enum BoneType {
HIP_TRACKER(BodyPart.HIP),
LEFT_HIP,
RIGHT_HIP,
@Deprecated
UPPER_LEG,
LEFT_UPPER_LEG(BodyPart.LEFT_UPPER_LEG),
RIGHT_UPPER_LEG(BodyPart.RIGHT_UPPER_LEG),
@Deprecated
KNEE_TRACKER,
LEFT_KNEE_TRACKER,
RIGHT_KNEE_TRACKER,
@Deprecated
LOWER_LEG,
LEFT_LOWER_LEG(BodyPart.LEFT_LOWER_LEG),
RIGHT_LOWER_LEG(BodyPart.RIGHT_LOWER_LEG),
@Deprecated
FOOT,
LEFT_FOOT(BodyPart.LEFT_FOOT),
RIGHT_FOOT(BodyPart.RIGHT_FOOT),
@Deprecated
FOOT_TRACKER,
LEFT_FOOT_TRACKER(BodyPart.LEFT_FOOT),
RIGHT_FOOT_TRACKER(BodyPart.RIGHT_FOOT),
@Deprecated
CONTROLLER,
LEFT_CONTROLLER(BodyPart.LEFT_CONTROLLER),
RIGHT_CONTROLLER(BodyPart.RIGHT_CONTROLLER),
@Deprecated
LOWER_ARM,
LEFT_LOWER_ARM(BodyPart.LEFT_LOWER_ARM),
RIGHT_LOWER_ARM(BodyPart.RIGHT_LOWER_ARM),
@Deprecated
LOWER_ARM_HMD,
@Deprecated
ELBOW_TRACKER,
LEFT_ELBOW_TRACKER,
RIGHT_ELBOW_TRACKER,
@Deprecated
UPPER_ARM,
LEFT_UPPER_ARM(BodyPart.LEFT_UPPER_ARM),
RIGHT_UPPER_ARM(BodyPart.RIGHT_UPPER_ARM),
LEFT_SHOULDER,
RIGHT_SHOULDER,
@Deprecated
HAND,
LEFT_HAND(BodyPart.LEFT_HAND),
RIGHT_HAND(BodyPart.RIGHT_HAND),
@Deprecated
HAND_TRACKER,
LEFT_HAND_TRACKER,
RIGHT_HAND_TRACKER;

Expand Down
28 changes: 8 additions & 20 deletions src/main/java/dev/slimevr/vr/processor/skeleton/HumanSkeleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class HumanSkeleton extends Skeleton implements SkeletonConfigCallback {
false
);
// #endregion
protected final Quaternion kneeRotation = new Quaternion();
// #region Buffers
private final Vector3f posBuf = new Vector3f();
private final Quaternion rotBuf1 = new Quaternion();
Expand All @@ -129,8 +128,6 @@ public class HumanSkeleton extends Skeleton implements SkeletonConfigCallback {
private final Quaternion rotBuf4 = new Quaternion();
protected boolean hasSpineTracker;
protected boolean hasKneeTrackers;
protected float minKneePitch = 0f * FastMath.DEG_TO_RAD;
protected float maxKneePitch = 90f * FastMath.DEG_TO_RAD;
static final Quaternion FORWARD_QUATERNION = new Quaternion()
.fromAngles(FastMath.HALF_PI, 0, 0);
static final float FLOOR_OFFSET = 0.05f;
Expand Down Expand Up @@ -1223,49 +1220,46 @@ public void updateNodeOffset(BoneType nodeOffset, Vector3f offset) {
case RIGHT_HIP:
rightHipNode.localTransform.setTranslation(offset);
break;
case UPPER_LEG:
case LEFT_UPPER_LEG:
case RIGHT_UPPER_LEG:
leftKneeNode.localTransform.setTranslation(offset);
rightKneeNode.localTransform.setTranslation(offset);
break;
case KNEE_TRACKER:
case LEFT_KNEE_TRACKER:
case RIGHT_KNEE_TRACKER:
trackerLeftKneeNode.localTransform.setTranslation(offset);
trackerRightKneeNode.localTransform.setTranslation(offset);
break;
case LOWER_LEG:
case LEFT_LOWER_LEG:
case RIGHT_LOWER_LEG:
leftAnkleNode.localTransform.setTranslation(offset);
rightAnkleNode.localTransform.setTranslation(offset);
break;
case FOOT:
case LEFT_FOOT:
case RIGHT_FOOT:
leftFootNode.localTransform.setTranslation(offset);
rightFootNode.localTransform.setTranslation(offset);
break;
case FOOT_TRACKER:
case LEFT_FOOT_TRACKER:
case RIGHT_FOOT_TRACKER:
trackerLeftFootNode.localTransform.setTranslation(offset);
trackerRightFootNode.localTransform.setTranslation(offset);
break;
case CONTROLLER:
case LEFT_CONTROLLER:
case RIGHT_CONTROLLER:
leftWristNodeContrl.localTransform.setTranslation(offset);
rightWristNodeContrl.localTransform.setTranslation(offset);
break;
case LOWER_ARM:
case LEFT_LOWER_ARM:
case RIGHT_LOWER_ARM:
leftElbowNodeContrl.localTransform.setTranslation(offset);
rightElbowNodeContrl.localTransform.setTranslation(offset);
// Dirty hack: from HMD goes the opposite way as from
// controllers, so we negate the offset.
Vector3f negatedOffset = offset.negate();
leftWristNodeHmd.localTransform.setTranslation(negatedOffset);
rightWristNodeHmd.localTransform.setTranslation(negatedOffset);
break;
case ELBOW_TRACKER:
case LEFT_ELBOW_TRACKER:
case RIGHT_ELBOW_TRACKER:
trackerLeftElbowNodeContrl.localTransform.setTranslation(offset);
Expand All @@ -1279,22 +1273,16 @@ public void updateNodeOffset(BoneType nodeOffset, Vector3f offset) {
case RIGHT_SHOULDER:
rightShoulderNodeHmd.localTransform.setTranslation(offset);
break;
case HAND:
case LEFT_HAND:
case RIGHT_HAND:
leftHandNodeHmd.localTransform.setTranslation(offset);
rightHandNodeHmd.localTransform.setTranslation(offset);
break;
case UPPER_ARM:
case LEFT_UPPER_ARM:
case RIGHT_UPPER_ARM:
leftElbowNodeHmd.localTransform.setTranslation(offset);
rightElbowNodeHmd.localTransform.setTranslation(offset);
break;
case LOWER_ARM_HMD:
leftWristNodeHmd.localTransform.setTranslation(offset);
rightWristNodeHmd.localTransform.setTranslation(offset);
break;
default:
break;
}
Expand Down Expand Up @@ -1349,7 +1337,7 @@ public void updatePoseAffectedByConfig(SkeletonConfigValue config) {
rightFootNode.update();
updateComputedTrackers();
break;
case FOOT_OFFSET:
case FOOT_SHIFT:
leftAnkleNode.update();
rightAnkleNode.update();
updateComputedTrackers();
Expand Down Expand Up @@ -1476,8 +1464,8 @@ public void resetSkeletonConfig(SkeletonConfigValue config) {
case FOOT_LENGTH:
skeletonConfig.setConfig(SkeletonConfigValue.FOOT_LENGTH, null);
break;
case FOOT_OFFSET:
skeletonConfig.setConfig(SkeletonConfigValue.FOOT_OFFSET, null);
case FOOT_SHIFT:
skeletonConfig.setConfig(SkeletonConfigValue.FOOT_SHIFT, null);
break;
case SKELETON_OFFSET:
skeletonConfig.setConfig(SkeletonConfigValue.SKELETON_OFFSET, null);
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/dev/slimevr/vr/processor/skeleton/SkeletonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,14 @@ public void computeNodeOffset(BoneType nodeOffset) {
-getConfig(SkeletonConfigValue.SKELETON_OFFSET)
);
break;

case LEFT_HIP:
setNodeOffset(nodeOffset, -getConfig(SkeletonConfigValue.HIPS_WIDTH) / 2f, 0, 0);
break;
case RIGHT_HIP:
setNodeOffset(nodeOffset, getConfig(SkeletonConfigValue.HIPS_WIDTH) / 2f, 0, 0);
break;

case UPPER_LEG:
case LEFT_UPPER_LEG:
case RIGHT_UPPER_LEG:
setNodeOffset(
nodeOffset,
0,
Expand All @@ -311,50 +310,55 @@ public void computeNodeOffset(BoneType nodeOffset) {
0
);
break;
case KNEE_TRACKER:
case LEFT_KNEE_TRACKER:
case RIGHT_KNEE_TRACKER:
setNodeOffset(nodeOffset, 0, 0, -getConfig(SkeletonConfigValue.SKELETON_OFFSET));
break;
case LOWER_LEG:
case LEFT_LOWER_LEG:
case RIGHT_LOWER_LEG:
setNodeOffset(
nodeOffset,
0,
-getConfig(SkeletonConfigValue.KNEE_HEIGHT),
-getConfig(SkeletonConfigValue.FOOT_OFFSET)
-getConfig(SkeletonConfigValue.FOOT_SHIFT)
);
break;
case FOOT:
case LEFT_FOOT:
case RIGHT_FOOT:
setNodeOffset(nodeOffset, 0, 0, -getConfig(SkeletonConfigValue.FOOT_LENGTH));
break;
case FOOT_TRACKER:
case LEFT_FOOT_TRACKER:
case RIGHT_FOOT_TRACKER:
setNodeOffset(nodeOffset, 0, 0, -getConfig(SkeletonConfigValue.SKELETON_OFFSET));
break;

case CONTROLLER:
case LEFT_CONTROLLER:
case RIGHT_CONTROLLER:
setNodeOffset(
nodeOffset,
0,
getConfig(SkeletonConfigValue.CONTROLLER_DISTANCE_Y),
getConfig(SkeletonConfigValue.CONTROLLER_DISTANCE_Z)
);
break;
case HAND:
case LEFT_HAND:
case RIGHT_HAND:
setNodeOffset(
nodeOffset,
0,
-getConfig(SkeletonConfigValue.CONTROLLER_DISTANCE_Y),
-getConfig(SkeletonConfigValue.CONTROLLER_DISTANCE_Z)
);
break;
case LOWER_ARM:
case LEFT_LOWER_ARM:
case RIGHT_LOWER_ARM:
setNodeOffset(nodeOffset, 0, getConfig(SkeletonConfigValue.LOWER_ARM_LENGTH), 0);
break;
case LOWER_ARM_HMD:
setNodeOffset(nodeOffset, 0, -getConfig(SkeletonConfigValue.LOWER_ARM_LENGTH), 0);
break;
case ELBOW_TRACKER:
case LEFT_ELBOW_TRACKER:
case RIGHT_ELBOW_TRACKER:
setNodeOffset(nodeOffset, 0, getConfig(SkeletonConfigValue.ELBOW_OFFSET), 0);
break;
case UPPER_ARM:
case LEFT_UPPER_ARM:
case RIGHT_UPPER_ARM:
setNodeOffset(nodeOffset, 0, -getConfig(SkeletonConfigValue.UPPER_ARM_LENGTH), 0);
break;
case LEFT_SHOULDER:
Expand Down
Loading

0 comments on commit 7c37fdb

Please sign in to comment.