diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/direct-link.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/direct-link.kt index 6bb1540da..b7e52e441 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/direct-link.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/direct-link.kt @@ -11,7 +11,6 @@ import solarxr_protocol.datatypes.BodyPart */ val BONE_DIRECT_LINK_SOURCES = arrayOf( BodyPart.HEAD to BodyPart.NECK, - BodyPart.NECK to BodyPart.HEAD, BodyPart.LEFT_FOOT to BodyPart.LEFT_LOWER_LEG, BodyPart.RIGHT_FOOT to BodyPart.RIGHT_LOWER_LEG, diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt index 6d342f851..d6f9bdd28 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/head-position-fallback.kt @@ -1,6 +1,5 @@ package dev.slimevr.skeleton.inputprocessors -import dev.slimevr.config.Settings import dev.slimevr.skeleton.InputSkeleton import dev.slimevr.skeleton.SkeletonInputProcessor import io.github.axisangles.ktmath.Vector3 @@ -9,7 +8,7 @@ import solarxr_protocol.datatypes.BodyPart /** * Moves the head input to the skeleton height. Else, it would default to (0, 0, 0). */ -class HeadPositionFallbackProcessor(val settings: Settings) : SkeletonInputProcessor { +class HeadPositionFallbackInputProcessor : SkeletonInputProcessor { override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { val headBone = mutableInputSkeleton[BodyPart.HEAD] ?: return if (headBone.position != null) return diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt new file mode 100644 index 000000000..79b6a6d27 --- /dev/null +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/neck.kt @@ -0,0 +1,38 @@ +package dev.slimevr.skeleton.inputprocessors + +import dev.slimevr.skeleton.InputSkeleton +import dev.slimevr.skeleton.SkeletonInputProcessor +import io.github.axisangles.ktmath.Vector3 +import solarxr_protocol.datatypes.BodyPart + +private const val UP_RATIO = 0.9f +private const val DOWN_RATIO = 1.1f + +/** + * Guesses where the neck is supposed to be when the user has a head tracker but no neck tracker. + * + * Tries to mitigate the problem where looking down make your whole tracking go down (or + * knees bend if floorclip is enabled). + */ +class NeckInputProcessor : SkeletonInputProcessor { + override fun process(mutableInputSkeleton: InputSkeleton, skeletonHeight: Float) { + val headBone = mutableInputSkeleton[BodyPart.HEAD] ?: return + val neckBone = mutableInputSkeleton[BodyPart.NECK] ?: return + val upperChestBone = mutableInputSkeleton[BodyPart.UPPER_CHEST] ?: return + if (!headBone.isRotationActive || neckBone.isRotationActive) return + + // Work with the rotation delta to avoid axes being ambiguous + val delta = upperChestBone.rotation.inv() * headBone.rotation + + // Decompose the delta into its twist (forward) and swing (remaining/sides) along the x-axis + val forward = delta.project(Vector3.POS_X).unit() + val side = delta / forward + + // Get the ratio depending on if the user is looking down or up + val ratio = if (forward.x < 0f) DOWN_RATIO else UP_RATIO + + val scaledDelta = side * forward.pow(ratio) + val newRotation = upperChestBone.rotation * scaledDelta + mutableInputSkeleton[BodyPart.NECK] = neckBone.copy(rotation = newRotation) + } +} diff --git a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt index 1a11d29eb..6107b0c1a 100644 --- a/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt +++ b/server/core/src/main/java/dev/slimevr/skeleton/inputprocessors/spine.kt @@ -147,7 +147,7 @@ private fun averageRotation(inputSkeleton: InputSkeleton, takeBodyParts: Array