Skip to content

Commit

Permalink
Don't filter non-temporal trackers (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ButterscotchV authored Jan 2, 2025
1 parent 0eb81ee commit 4e698b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data class TrackerFrames(val name: String = "", val frames: FastList<TrackerFram
// Make sure this is false!! Otherwise HumanSkeleton ignores it
isInternal = false,
isComputed = true,
trackRotDirection = false,
)

tracker.status = TrackerStatus.OK
Expand Down
39 changes: 24 additions & 15 deletions server/core/src/main/java/dev/slimevr/tracking/trackers/Tracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ class Tracker @JvmOverloads constructor(
val needsReset: Boolean = false,
val needsMounting: Boolean = false,
val isHmd: Boolean = false,
/**
* Whether to track the direction of the tracker's rotation
* (positive vs negative rotation). This needs to be disabled for AutoBone and
* unit tests, where the rotation is absolute and not temporal.
*/
val trackRotDirection: Boolean = true,
magStatus: MagnetometerStatus = MagnetometerStatus.NOT_SUPPORTED,
/**
* Rotation by default.
Expand Down Expand Up @@ -310,7 +316,9 @@ class Tracker @JvmOverloads constructor(
fun dataTick() {
timer.update()
timeAtLastUpdate = System.currentTimeMillis()
filteringHandler.dataTick(_rotation)
if (trackRotDirection) {
filteringHandler.dataTick(_rotation)
}
}

/**
Expand All @@ -320,6 +328,19 @@ class Tracker @JvmOverloads constructor(
timeAtLastUpdate = System.currentTimeMillis()
}

private fun getFilteredRotation(): Quaternion = if (trackRotDirection) {
if (filteringHandler.filteringEnabled) {
// Get filtered rotation
filteringHandler.getFilteredRotation()
} else {
// Get unfiltered rotation
filteringHandler.getTrackedRotation()
}
} else {
// Get raw rotation
_rotation
}

/**
* Gets the adjusted tracker rotation after all corrections
* (filtering, reset, mounting and drift compensation).
Expand All @@ -328,13 +349,7 @@ class Tracker @JvmOverloads constructor(
* it too much should be avoided for performance reasons.
*/
fun getRotation(): Quaternion {
var rot = if (allowFiltering && filteringHandler.filteringEnabled) {
// Get filtered rotation
filteringHandler.getFilteredRotation()
} else {
// Get unfiltered rotation
filteringHandler.getTrackedRotation()
}
var rot = getFilteredRotation()

// Reset if needed and is not computed and internal
if (needsReset && !(isComputed && isInternal) && trackerDataType == TrackerDataType.ROTATION) {
Expand All @@ -360,13 +375,7 @@ class Tracker @JvmOverloads constructor(
* This is used for debugging/visualizing tracker data
*/
fun getIdentityAdjustedRotation(): Quaternion {
var rot = if (filteringHandler.filteringEnabled) {
// Get filtered rotation
filteringHandler.getFilteredRotation()
} else {
// Get unfiltered rotation
filteringHandler.getTrackedRotation()
}
var rot = getFilteredRotation()

// Reset if needed or is a computed tracker besides head
if (needsReset && !(isComputed && trackerPosition != TrackerPosition.HEAD) && trackerDataType == TrackerDataType.ROTATION) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MountingResetTests {
imuType = IMUType.UNKNOWN,
needsReset = true,
needsMounting = true,
trackRotDirection = false,
)

// Apply full reset and mounting
Expand Down Expand Up @@ -130,6 +131,7 @@ class MountingResetTests {
imuType = IMUType.UNKNOWN,
needsReset = true,
needsMounting = true,
trackRotDirection = false,
)

// Apply full reset and mounting
Expand Down

0 comments on commit 4e698b6

Please sign in to comment.