Mounting reset improvements (#641)

This commit is contained in:
Butterscotch! authored and GitHub committed 2023-03-31 17:01:50 +03:00
1 parent c27b66f716
commit 06a9937b75
6 files changed
+38 -8

No files matched your search

@@ -226,7 +226,7 @@ public class PoseFrameTracker implements Tracker, Iterable<TrackerFrame> {
}
@Override
public void resetMounting(boolean reverseYaw) {
public void resetMounting(boolean reverseYaw, Quaternion reference) {
throw new UnsupportedOperationException("PoseFrameTracker does not implement calibration");
}
@@ -212,7 +212,7 @@ public final class TrackerFrame implements Tracker {
}
@Override
public void resetMounting(boolean reverseYaw) {
public void resetMounting(boolean reverseYaw, Quaternion reference) {
throw new UnsupportedOperationException("TrackerFrame does not implement calibration");
}
@@ -1644,6 +1644,10 @@ public class HumanSkeleton {
&& position != TrackerPosition.RIGHT_FOOT;
}
private boolean shouldResetMounting(Tracker tracker) {
return shouldResetMounting(tracker.getBodyPosition());
}
private boolean shouldReverseYaw(TrackerPosition position) {
switch (position) {
case LEFT_UPPER_LEG:
@@ -1658,19 +1662,28 @@ public class HumanSkeleton {
}
}
private boolean shouldReverseYaw(Tracker tracker) {
return shouldReverseYaw(tracker.getBodyPosition());
}
@VRServerThread
public void resetTrackersMounting(String resetSourceName) {
// Pass all trackers through trackerPreUpdate
Tracker hmdTracker = trackerPreUpdate(this.hmdTracker);
Tracker[] trackersToReset = getTrackersToReset();
// Resets the mounting rotation of the trackers with the HMD as
// reference.
Quaternion referenceRotation = new Quaternion();
if (hmdTracker != null) {
if (hmdTracker instanceof IMUTracker)
hmdTracker.resetMounting(shouldReverseYaw(hmdTracker.getBodyPosition()));
hmdTracker.resetMounting(shouldReverseYaw(hmdTracker), referenceRotation);
hmdTracker.getRotation(referenceRotation);
}
for (Tracker tracker : trackersToReset) {
if (tracker != null && shouldResetMounting(tracker.getBodyPosition())) {
tracker.resetMounting(shouldReverseYaw(tracker.getBodyPosition()));
if (tracker != null && shouldResetMounting(tracker)) {
tracker.resetMounting(shouldReverseYaw(tracker), referenceRotation);
}
}
this.legTweaks.resetBuffer();
@@ -122,7 +122,7 @@ public class ComputedTracker implements Tracker, TrackerWithTPS {
}
@Override
public void resetMounting(boolean reverseYaw) {
public void resetMounting(boolean reverseYaw, Quaternion reference) {
}
@Override
@@ -167,6 +167,9 @@ public class IMUTracker
} else {
mountAdjust.loadIdentity();
}
// Clear the mounting reset now that it's been set manually
clearMounting();
}
public boolean getAllowDriftCompensation() {
@@ -478,12 +481,19 @@ public class IMUTracker
}
@Override
public void resetMounting(boolean reverseYaw) {
public void resetMounting(boolean reverseYaw, Quaternion reference) {
// Use only yaw HMD rotation
reference = reference.clone();
reference.fromAngles(0, reference.getYaw(), 0);
// Get the current calibrated rotation
Quaternion buffer = getMountedAdjustedDriftRotation();
gyroFix.mult(buffer, buffer);
buffer.multLocal(attachmentFix);
// Use the HMD as the reference
buffer.multLocal(reference.inverseLocal());
// Reset the vector for the rotation to point straight up
rotVector.set(0f, 1f, 0f);
// Rotate the vector by the quat, then flatten and normalize the vector
@@ -507,6 +517,13 @@ public class IMUTracker
yawFix.multLocal(buffer.inverseLocal());
}
public void clearMounting() {
// Undo the effect on yaw fix
yawFix.multLocal(mountRotFix.inverseLocal());
// Clear the mounting reset
mountRotFix.loadIdentity();
}
private void fixYaw(Quaternion sensorRotation, Quaternion reference) {
// Use only yaw HMD rotation
reference = reference.clone();
@@ -38,7 +38,7 @@ public interface Tracker {
void resetYaw(Quaternion reference);
void resetMounting(boolean reverseYaw);
void resetMounting(boolean reverseYaw, Quaternion reference);
void tick();