mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-12-06 08:42:32 -08:00
Make yaw and mounting reset properly reset polarity
This commit is contained in:
1 parent
c829bdc06e
commit
2fd5c68429
2 files changed
+16
-4
No files matched your search
@@ -68,6 +68,7 @@ data class TrackerState(
|
||||
val lastMountingMethod: MountingMethod,
|
||||
val mountingOrientation: HeadingAlignment,
|
||||
val restOrientation: RestOrientation,
|
||||
val polarityReference: RawRotation,
|
||||
val sessionCalibration: SessionCalibration,
|
||||
val rawRotation: RawRotation,
|
||||
val rotation: CalibratedRotation,
|
||||
@@ -193,6 +194,7 @@ class Tracker(
|
||||
lastMountingMethod = MountingMethod.MANUAL,
|
||||
mountingOrientation = Quaternion.IDENTITY,
|
||||
restOrientation = Quaternion.IDENTITY,
|
||||
polarityReference = Quaternion.IDENTITY,
|
||||
sessionCalibration = SessionCalibration(),
|
||||
rawRotation = Quaternion.IDENTITY,
|
||||
rotation = Quaternion.IDENTITY,
|
||||
|
||||
@@ -83,7 +83,7 @@ fun reduce(
|
||||
val shouldAlignAttitude = !isHead || !isPositional || action.resetPositionalHeadAttitude
|
||||
val shouldAlignHeadingWithReference = !isHead && isPositional
|
||||
|
||||
// Align the raw rotation to the default polarity we use
|
||||
// Use the shortest rotation/default polarity
|
||||
val shortestRawRotation = state.rawRotation.twinNearest(Quaternion.IDENTITY)
|
||||
|
||||
val headingCorrection =
|
||||
@@ -118,17 +118,21 @@ fun reduce(
|
||||
attitudeAlignment = attitudeAlignment,
|
||||
headingAlignment = headingAlignment,
|
||||
),
|
||||
rawRotation = shortestRawRotation,
|
||||
// Full reset snaps: cancel any in-progress yaw smoothing.
|
||||
yawResetSmoothing = null,
|
||||
rawRotation = shortestRawRotation,
|
||||
polarityReference = shortestRawRotation,
|
||||
)
|
||||
}
|
||||
|
||||
is TrackerActions.YawReset -> {
|
||||
val cal = state.sessionCalibration
|
||||
|
||||
// Use the shortest rotation to our full reset raw rotation
|
||||
val shortestRawRotation = state.rawRotation.twinNearest(state.polarityReference)
|
||||
|
||||
val newHeading = estimateHeadingCorrect(
|
||||
applyCalibration(state.rawRotation, attitudeAlign = cal.attitudeAlignment, headingAlign = cal.headingAlignment),
|
||||
applyCalibration(shortestRawRotation, attitudeAlign = cal.attitudeAlignment, headingAlign = cal.headingAlignment),
|
||||
action.referenceRotation,
|
||||
)
|
||||
|
||||
@@ -142,12 +146,14 @@ fun reduce(
|
||||
to = newHeading,
|
||||
duration = action.smoothTime,
|
||||
),
|
||||
rawRotation = shortestRawRotation,
|
||||
)
|
||||
} else {
|
||||
// Snap: apply the new heading immediately (default, no smoothing configured).
|
||||
state.copy(
|
||||
sessionCalibration = cal.copy(headingCorrection = newHeading),
|
||||
yawResetSmoothing = null,
|
||||
rawRotation = shortestRawRotation,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -155,8 +161,11 @@ fun reduce(
|
||||
is TrackerActions.PoseMountingReset -> {
|
||||
val cal = state.sessionCalibration
|
||||
|
||||
// Use the shortest rotation to our full reset raw rotation
|
||||
val shortestRawRotation = state.rawRotation.twinNearest(state.polarityReference)
|
||||
|
||||
val headingAlignment = estimateHeadingAlign(
|
||||
state.rawRotation,
|
||||
shortestRawRotation,
|
||||
action.referenceRotation,
|
||||
cal.headingCorrection,
|
||||
cal.attitudeAlignment,
|
||||
@@ -168,6 +177,7 @@ fun reduce(
|
||||
state.copy(
|
||||
sessionCalibration = state.sessionCalibration.copy(headingAlignment = headingAlignment),
|
||||
lastMountingMethod = MountingMethod.POSE,
|
||||
rawRotation = shortestRawRotation
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user